blob: ce6e6a93ea70f073e3ae1a8b5b6435330a19fd4f [file] [log] [blame]
Victor Stinner5cf47822020-11-02 22:03:28 +01001// File automatically generated by Parser/asdl_c.py.
2
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003#include "Python.h"
Victor Stinnerd36d6a92021-04-07 13:01:09 +02004#include "pycore_ast.h"
Victor Stinnere0bf70d2021-03-18 02:46:06 +01005#include "pycore_ast_state.h" // struct ast_state
6#include "pycore_interp.h" // _PyInterpreterState.ast
7#include "pycore_pystate.h" // _PyInterpreterState_GET()
Victor Stinnerd36d6a92021-04-07 13:01:09 +02008#include "structmember.h"
9#include <stddef.h>
Dino Viehlandac46eb42019-09-11 10:16:34 -070010
Victor Stinnere5fbe0c2020-09-15 18:03:34 +020011// Forward declaration
Victor Stinner5cf47822020-11-02 22:03:28 +010012static int init_types(struct ast_state *state);
Victor Stinnere5fbe0c2020-09-15 18:03:34 +020013
Victor Stinner5cf47822020-11-02 22:03:28 +010014static struct ast_state*
15get_ast_state(void)
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020016{
Victor Stinner5cf47822020-11-02 22:03:28 +010017 PyInterpreterState *interp = _PyInterpreterState_GET();
18 struct ast_state *state = &interp->ast;
Victor Stinnere5fbe0c2020-09-15 18:03:34 +020019 if (!init_types(state)) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020020 return NULL;
21 }
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020022 return state;
Victor Stinner74419f02020-07-03 11:35:37 +020023}
Victor Stinner5cf47822020-11-02 22:03:28 +010024
Victor Stinnerfd957c12020-11-03 18:07:15 +010025void _PyAST_Fini(PyInterpreterState *interp)
Victor Stinnere5fbe0c2020-09-15 18:03:34 +020026{
Victor Stinnerfd957c12020-11-03 18:07:15 +010027 struct ast_state *state = &interp->ast;
Victor Stinner5cf47822020-11-02 22:03:28 +010028
Victor Stinner74419f02020-07-03 11:35:37 +020029 Py_CLEAR(state->AST_type);
30 Py_CLEAR(state->Add_singleton);
31 Py_CLEAR(state->Add_type);
32 Py_CLEAR(state->And_singleton);
33 Py_CLEAR(state->And_type);
34 Py_CLEAR(state->AnnAssign_type);
35 Py_CLEAR(state->Assert_type);
36 Py_CLEAR(state->Assign_type);
37 Py_CLEAR(state->AsyncFor_type);
38 Py_CLEAR(state->AsyncFunctionDef_type);
39 Py_CLEAR(state->AsyncWith_type);
40 Py_CLEAR(state->Attribute_type);
41 Py_CLEAR(state->AugAssign_type);
42 Py_CLEAR(state->Await_type);
43 Py_CLEAR(state->BinOp_type);
44 Py_CLEAR(state->BitAnd_singleton);
45 Py_CLEAR(state->BitAnd_type);
46 Py_CLEAR(state->BitOr_singleton);
47 Py_CLEAR(state->BitOr_type);
48 Py_CLEAR(state->BitXor_singleton);
49 Py_CLEAR(state->BitXor_type);
50 Py_CLEAR(state->BoolOp_type);
51 Py_CLEAR(state->Break_type);
52 Py_CLEAR(state->Call_type);
53 Py_CLEAR(state->ClassDef_type);
54 Py_CLEAR(state->Compare_type);
55 Py_CLEAR(state->Constant_type);
56 Py_CLEAR(state->Continue_type);
57 Py_CLEAR(state->Del_singleton);
58 Py_CLEAR(state->Del_type);
59 Py_CLEAR(state->Delete_type);
60 Py_CLEAR(state->DictComp_type);
61 Py_CLEAR(state->Dict_type);
62 Py_CLEAR(state->Div_singleton);
63 Py_CLEAR(state->Div_type);
64 Py_CLEAR(state->Eq_singleton);
65 Py_CLEAR(state->Eq_type);
66 Py_CLEAR(state->ExceptHandler_type);
67 Py_CLEAR(state->Expr_type);
68 Py_CLEAR(state->Expression_type);
69 Py_CLEAR(state->FloorDiv_singleton);
70 Py_CLEAR(state->FloorDiv_type);
71 Py_CLEAR(state->For_type);
72 Py_CLEAR(state->FormattedValue_type);
73 Py_CLEAR(state->FunctionDef_type);
74 Py_CLEAR(state->FunctionType_type);
75 Py_CLEAR(state->GeneratorExp_type);
76 Py_CLEAR(state->Global_type);
77 Py_CLEAR(state->GtE_singleton);
78 Py_CLEAR(state->GtE_type);
79 Py_CLEAR(state->Gt_singleton);
80 Py_CLEAR(state->Gt_type);
81 Py_CLEAR(state->IfExp_type);
82 Py_CLEAR(state->If_type);
83 Py_CLEAR(state->ImportFrom_type);
84 Py_CLEAR(state->Import_type);
85 Py_CLEAR(state->In_singleton);
86 Py_CLEAR(state->In_type);
87 Py_CLEAR(state->Interactive_type);
88 Py_CLEAR(state->Invert_singleton);
89 Py_CLEAR(state->Invert_type);
90 Py_CLEAR(state->IsNot_singleton);
91 Py_CLEAR(state->IsNot_type);
92 Py_CLEAR(state->Is_singleton);
93 Py_CLEAR(state->Is_type);
94 Py_CLEAR(state->JoinedStr_type);
95 Py_CLEAR(state->LShift_singleton);
96 Py_CLEAR(state->LShift_type);
97 Py_CLEAR(state->Lambda_type);
98 Py_CLEAR(state->ListComp_type);
99 Py_CLEAR(state->List_type);
100 Py_CLEAR(state->Load_singleton);
101 Py_CLEAR(state->Load_type);
102 Py_CLEAR(state->LtE_singleton);
103 Py_CLEAR(state->LtE_type);
104 Py_CLEAR(state->Lt_singleton);
105 Py_CLEAR(state->Lt_type);
106 Py_CLEAR(state->MatMult_singleton);
107 Py_CLEAR(state->MatMult_type);
Brandt Bucher145bf262021-02-26 14:51:55 -0800108 Py_CLEAR(state->MatchAs_type);
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000109 Py_CLEAR(state->MatchClass_type);
110 Py_CLEAR(state->MatchMapping_type);
Brandt Bucher145bf262021-02-26 14:51:55 -0800111 Py_CLEAR(state->MatchOr_type);
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000112 Py_CLEAR(state->MatchSequence_type);
113 Py_CLEAR(state->MatchSingleton_type);
114 Py_CLEAR(state->MatchStar_type);
115 Py_CLEAR(state->MatchValue_type);
Brandt Bucher145bf262021-02-26 14:51:55 -0800116 Py_CLEAR(state->Match_type);
Victor Stinner74419f02020-07-03 11:35:37 +0200117 Py_CLEAR(state->Mod_singleton);
118 Py_CLEAR(state->Mod_type);
119 Py_CLEAR(state->Module_type);
120 Py_CLEAR(state->Mult_singleton);
121 Py_CLEAR(state->Mult_type);
122 Py_CLEAR(state->Name_type);
123 Py_CLEAR(state->NamedExpr_type);
124 Py_CLEAR(state->Nonlocal_type);
125 Py_CLEAR(state->NotEq_singleton);
126 Py_CLEAR(state->NotEq_type);
127 Py_CLEAR(state->NotIn_singleton);
128 Py_CLEAR(state->NotIn_type);
129 Py_CLEAR(state->Not_singleton);
130 Py_CLEAR(state->Not_type);
131 Py_CLEAR(state->Or_singleton);
132 Py_CLEAR(state->Or_type);
133 Py_CLEAR(state->Pass_type);
134 Py_CLEAR(state->Pow_singleton);
135 Py_CLEAR(state->Pow_type);
136 Py_CLEAR(state->RShift_singleton);
137 Py_CLEAR(state->RShift_type);
138 Py_CLEAR(state->Raise_type);
139 Py_CLEAR(state->Return_type);
140 Py_CLEAR(state->SetComp_type);
141 Py_CLEAR(state->Set_type);
142 Py_CLEAR(state->Slice_type);
143 Py_CLEAR(state->Starred_type);
144 Py_CLEAR(state->Store_singleton);
145 Py_CLEAR(state->Store_type);
146 Py_CLEAR(state->Sub_singleton);
147 Py_CLEAR(state->Sub_type);
148 Py_CLEAR(state->Subscript_type);
149 Py_CLEAR(state->Try_type);
150 Py_CLEAR(state->Tuple_type);
151 Py_CLEAR(state->TypeIgnore_type);
152 Py_CLEAR(state->UAdd_singleton);
153 Py_CLEAR(state->UAdd_type);
154 Py_CLEAR(state->USub_singleton);
155 Py_CLEAR(state->USub_type);
156 Py_CLEAR(state->UnaryOp_type);
157 Py_CLEAR(state->While_type);
158 Py_CLEAR(state->With_type);
159 Py_CLEAR(state->YieldFrom_type);
160 Py_CLEAR(state->Yield_type);
161 Py_CLEAR(state->__dict__);
162 Py_CLEAR(state->__doc__);
Brandt Bucher145bf262021-02-26 14:51:55 -0800163 Py_CLEAR(state->__match_args__);
Victor Stinner74419f02020-07-03 11:35:37 +0200164 Py_CLEAR(state->__module__);
165 Py_CLEAR(state->_attributes);
166 Py_CLEAR(state->_fields);
167 Py_CLEAR(state->alias_type);
168 Py_CLEAR(state->annotation);
169 Py_CLEAR(state->arg);
170 Py_CLEAR(state->arg_type);
171 Py_CLEAR(state->args);
172 Py_CLEAR(state->argtypes);
173 Py_CLEAR(state->arguments_type);
174 Py_CLEAR(state->asname);
175 Py_CLEAR(state->ast);
176 Py_CLEAR(state->attr);
177 Py_CLEAR(state->bases);
178 Py_CLEAR(state->body);
179 Py_CLEAR(state->boolop_type);
Brandt Bucher145bf262021-02-26 14:51:55 -0800180 Py_CLEAR(state->cases);
Victor Stinner74419f02020-07-03 11:35:37 +0200181 Py_CLEAR(state->cause);
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000182 Py_CLEAR(state->cls);
Victor Stinner74419f02020-07-03 11:35:37 +0200183 Py_CLEAR(state->cmpop_type);
184 Py_CLEAR(state->col_offset);
185 Py_CLEAR(state->comparators);
186 Py_CLEAR(state->comprehension_type);
187 Py_CLEAR(state->context_expr);
188 Py_CLEAR(state->conversion);
189 Py_CLEAR(state->ctx);
190 Py_CLEAR(state->decorator_list);
191 Py_CLEAR(state->defaults);
192 Py_CLEAR(state->elt);
193 Py_CLEAR(state->elts);
194 Py_CLEAR(state->end_col_offset);
195 Py_CLEAR(state->end_lineno);
196 Py_CLEAR(state->exc);
197 Py_CLEAR(state->excepthandler_type);
198 Py_CLEAR(state->expr_context_type);
199 Py_CLEAR(state->expr_type);
200 Py_CLEAR(state->finalbody);
201 Py_CLEAR(state->format_spec);
202 Py_CLEAR(state->func);
203 Py_CLEAR(state->generators);
Brandt Bucher145bf262021-02-26 14:51:55 -0800204 Py_CLEAR(state->guard);
Victor Stinner74419f02020-07-03 11:35:37 +0200205 Py_CLEAR(state->handlers);
206 Py_CLEAR(state->id);
207 Py_CLEAR(state->ifs);
208 Py_CLEAR(state->is_async);
209 Py_CLEAR(state->items);
210 Py_CLEAR(state->iter);
211 Py_CLEAR(state->key);
212 Py_CLEAR(state->keys);
213 Py_CLEAR(state->keyword_type);
214 Py_CLEAR(state->keywords);
215 Py_CLEAR(state->kind);
216 Py_CLEAR(state->kw_defaults);
217 Py_CLEAR(state->kwarg);
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000218 Py_CLEAR(state->kwd_attrs);
219 Py_CLEAR(state->kwd_patterns);
Victor Stinner74419f02020-07-03 11:35:37 +0200220 Py_CLEAR(state->kwonlyargs);
221 Py_CLEAR(state->left);
222 Py_CLEAR(state->level);
223 Py_CLEAR(state->lineno);
224 Py_CLEAR(state->lower);
Brandt Bucher145bf262021-02-26 14:51:55 -0800225 Py_CLEAR(state->match_case_type);
Victor Stinner74419f02020-07-03 11:35:37 +0200226 Py_CLEAR(state->mod_type);
227 Py_CLEAR(state->module);
228 Py_CLEAR(state->msg);
229 Py_CLEAR(state->name);
230 Py_CLEAR(state->names);
231 Py_CLEAR(state->op);
232 Py_CLEAR(state->operand);
233 Py_CLEAR(state->operator_type);
234 Py_CLEAR(state->ops);
235 Py_CLEAR(state->optional_vars);
236 Py_CLEAR(state->orelse);
Brandt Bucher145bf262021-02-26 14:51:55 -0800237 Py_CLEAR(state->pattern);
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000238 Py_CLEAR(state->pattern_type);
Brandt Bucher145bf262021-02-26 14:51:55 -0800239 Py_CLEAR(state->patterns);
Victor Stinner74419f02020-07-03 11:35:37 +0200240 Py_CLEAR(state->posonlyargs);
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000241 Py_CLEAR(state->rest);
Victor Stinner74419f02020-07-03 11:35:37 +0200242 Py_CLEAR(state->returns);
243 Py_CLEAR(state->right);
244 Py_CLEAR(state->simple);
245 Py_CLEAR(state->slice);
246 Py_CLEAR(state->step);
247 Py_CLEAR(state->stmt_type);
Brandt Bucher145bf262021-02-26 14:51:55 -0800248 Py_CLEAR(state->subject);
Victor Stinner74419f02020-07-03 11:35:37 +0200249 Py_CLEAR(state->tag);
250 Py_CLEAR(state->target);
251 Py_CLEAR(state->targets);
252 Py_CLEAR(state->test);
253 Py_CLEAR(state->type);
254 Py_CLEAR(state->type_comment);
255 Py_CLEAR(state->type_ignore_type);
256 Py_CLEAR(state->type_ignores);
257 Py_CLEAR(state->unaryop_type);
258 Py_CLEAR(state->upper);
259 Py_CLEAR(state->value);
260 Py_CLEAR(state->values);
261 Py_CLEAR(state->vararg);
262 Py_CLEAR(state->withitem_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700263
Victor Stinnere0bf70d2021-03-18 02:46:06 +0100264#if !defined(NDEBUG)
Victor Stinnerfd957c12020-11-03 18:07:15 +0100265 state->initialized = -1;
266#else
Victor Stinnere5fbe0c2020-09-15 18:03:34 +0200267 state->initialized = 0;
Victor Stinnerfd957c12020-11-03 18:07:15 +0100268#endif
Dino Viehlandac46eb42019-09-11 10:16:34 -0700269}
270
Victor Stinner5cf47822020-11-02 22:03:28 +0100271static int init_identifiers(struct ast_state *state)
Dino Viehlandac46eb42019-09-11 10:16:34 -0700272{
Dino Viehlandac46eb42019-09-11 10:16:34 -0700273 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300274 if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0;
Brandt Bucher145bf262021-02-26 14:51:55 -0800275 if ((state->__match_args__ = PyUnicode_InternFromString("__match_args__")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700276 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700277 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
278 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
279 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
280 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
281 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
282 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
283 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200284 if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700285 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
286 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
287 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
Brandt Bucher145bf262021-02-26 14:51:55 -0800288 if ((state->cases = PyUnicode_InternFromString("cases")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700289 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000290 if ((state->cls = PyUnicode_InternFromString("cls")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700291 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
292 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
293 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
294 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
295 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
296 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
297 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700298 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
299 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
300 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
301 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
302 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
303 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
304 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
305 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
306 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
Brandt Bucher145bf262021-02-26 14:51:55 -0800307 if ((state->guard = PyUnicode_InternFromString("guard")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700308 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
309 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
310 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
311 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
312 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
313 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
314 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
315 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
316 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
317 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
318 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
319 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000320 if ((state->kwd_attrs = PyUnicode_InternFromString("kwd_attrs")) == NULL) return 0;
321 if ((state->kwd_patterns = PyUnicode_InternFromString("kwd_patterns")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700322 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
323 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
324 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
325 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
326 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
327 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
328 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
329 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
330 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
331 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
332 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
333 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
334 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
335 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
Brandt Bucher145bf262021-02-26 14:51:55 -0800336 if ((state->pattern = PyUnicode_InternFromString("pattern")) == NULL) return 0;
337 if ((state->patterns = PyUnicode_InternFromString("patterns")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700338 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000339 if ((state->rest = PyUnicode_InternFromString("rest")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700340 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
341 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
342 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
343 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
344 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
Brandt Bucher145bf262021-02-26 14:51:55 -0800345 if ((state->subject = PyUnicode_InternFromString("subject")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700346 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
347 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
348 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
349 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
350 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
351 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
352 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
353 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
354 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
355 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
356 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
357 return 1;
358};
359
Pablo Galindoa5634c42020-09-16 19:42:00 +0100360GENERATE_ASDL_SEQ_CONSTRUCTOR(mod, mod_ty)
361GENERATE_ASDL_SEQ_CONSTRUCTOR(stmt, stmt_ty)
362GENERATE_ASDL_SEQ_CONSTRUCTOR(expr, expr_ty)
363GENERATE_ASDL_SEQ_CONSTRUCTOR(comprehension, comprehension_ty)
364GENERATE_ASDL_SEQ_CONSTRUCTOR(excepthandler, excepthandler_ty)
365GENERATE_ASDL_SEQ_CONSTRUCTOR(arguments, arguments_ty)
366GENERATE_ASDL_SEQ_CONSTRUCTOR(arg, arg_ty)
367GENERATE_ASDL_SEQ_CONSTRUCTOR(keyword, keyword_ty)
368GENERATE_ASDL_SEQ_CONSTRUCTOR(alias, alias_ty)
369GENERATE_ASDL_SEQ_CONSTRUCTOR(withitem, withitem_ty)
Brandt Bucher145bf262021-02-26 14:51:55 -0800370GENERATE_ASDL_SEQ_CONSTRUCTOR(match_case, match_case_ty)
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000371GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty)
Pablo Galindoa5634c42020-09-16 19:42:00 +0100372GENERATE_ASDL_SEQ_CONSTRUCTOR(type_ignore, type_ignore_ty)
373
Victor Stinner5cf47822020-11-02 22:03:28 +0100374static PyObject* ast2obj_mod(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300375static const char * const Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200376 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800377 "type_ignores",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000378};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300379static const char * const Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200380 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000381};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300382static const char * const Expression_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200383 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000384};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300385static const char * const FunctionType_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800386 "argtypes",
387 "returns",
388};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300389static const char * const stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200390 "lineno",
391 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000392 "end_lineno",
393 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000394};
Victor Stinner5cf47822020-11-02 22:03:28 +0100395static PyObject* ast2obj_stmt(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300396static const char * const FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200397 "name",
398 "args",
399 "body",
400 "decorator_list",
401 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800402 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000403};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300404static const char * const AsyncFunctionDef_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400405 "name",
406 "args",
407 "body",
408 "decorator_list",
409 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800410 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400411};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300412static const char * const ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200413 "name",
414 "bases",
415 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200416 "body",
417 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000418};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300419static const char * const Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200420 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000421};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300422static const char * const Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200423 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000424};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300425static const char * const Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200426 "targets",
427 "value",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800428 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000429};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300430static const char * const AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200431 "target",
432 "op",
433 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000434};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300435static const char * const AnnAssign_fields[]={
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700436 "target",
437 "annotation",
438 "value",
439 "simple",
440};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300441static const char * const For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200442 "target",
443 "iter",
444 "body",
445 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800446 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000447};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300448static const char * const AsyncFor_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400449 "target",
450 "iter",
451 "body",
452 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800453 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400454};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300455static const char * const While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200456 "test",
457 "body",
458 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300460static const char * const If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200461 "test",
462 "body",
463 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000464};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300465static const char * const With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200466 "items",
467 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800468 "type_comment",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000469};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300470static const char * const AsyncWith_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400471 "items",
472 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800473 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400474};
Brandt Bucher145bf262021-02-26 14:51:55 -0800475static const char * const Match_fields[]={
476 "subject",
477 "cases",
478};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300479static const char * const Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200480 "exc",
481 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000482};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300483static const char * const Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200484 "body",
485 "handlers",
486 "orelse",
487 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300489static const char * const Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200490 "test",
491 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300493static const char * const Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200494 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300496static const char * const ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200497 "module",
498 "names",
499 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000500};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300501static const char * const Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200502 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000503};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300504static const char * const Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200505 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000506};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300507static const char * const Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200508 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000509};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300510static const char * const expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200511 "lineno",
512 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000513 "end_lineno",
514 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515};
Victor Stinner5cf47822020-11-02 22:03:28 +0100516static PyObject* ast2obj_expr(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300517static const char * const BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200518 "op",
519 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300521static const char * const NamedExpr_fields[]={
Emily Morehouse8f59ee02019-01-24 16:49:56 -0700522 "target",
523 "value",
524};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300525static const char * const BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200526 "left",
527 "op",
528 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300530static const char * const UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200531 "op",
532 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300534static const char * const Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200535 "args",
536 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300538static const char * const IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200539 "test",
540 "body",
541 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000542};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300543static const char * const Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200544 "keys",
545 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000546};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300547static const char * const Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200548 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000549};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300550static const char * const ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200551 "elt",
552 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000553};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300554static const char * const SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200555 "elt",
556 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000557};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300558static const char * const DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200559 "key",
560 "value",
561 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000562};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300563static const char * const GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200564 "elt",
565 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300567static const char * const Await_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400568 "value",
569};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300570static const char * const Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200571 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500572};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300573static const char * const YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200574 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000575};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300576static const char * const Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200577 "left",
578 "ops",
579 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000580};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300581static const char * const Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200582 "func",
583 "args",
584 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300586static const char * const FormattedValue_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400587 "value",
588 "conversion",
589 "format_spec",
590};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300591static const char * const JoinedStr_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400592 "values",
593};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300594static const char * const Constant_fields[]={
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100595 "value",
Guido van Rossum10f8ce62019-03-13 13:00:46 -0700596 "kind",
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100597};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300598static const char * const Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200599 "value",
600 "attr",
601 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000602};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300603static const char * const Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200604 "value",
605 "slice",
606 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000607};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300608static const char * const Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200609 "value",
610 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +0000611};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300612static const char * const Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200613 "id",
614 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000615};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300616static const char * const List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200617 "elts",
618 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000619};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300620static const char * const Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200621 "elts",
622 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000623};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300624static const char * const Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200625 "lower",
626 "upper",
627 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000628};
Victor Stinner5cf47822020-11-02 22:03:28 +0100629static PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty);
630static PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty);
631static PyObject* ast2obj_operator(struct ast_state *state, operator_ty);
632static PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty);
633static PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty);
634static PyObject* ast2obj_comprehension(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300635static const char * const comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200636 "target",
637 "iter",
638 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -0700639 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000640};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300641static const char * const excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200642 "lineno",
643 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000644 "end_lineno",
645 "end_col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +0000646};
Victor Stinner5cf47822020-11-02 22:03:28 +0100647static PyObject* ast2obj_excepthandler(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300648static const char * const ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200649 "type",
650 "name",
651 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000652};
Victor Stinner5cf47822020-11-02 22:03:28 +0100653static PyObject* ast2obj_arguments(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300654static const char * const arguments_fields[]={
Pablo Galindo8c77b8c2019-04-29 13:36:57 +0100655 "posonlyargs",
Pablo Galindocd6e83b2019-07-15 01:32:18 +0200656 "args",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200657 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200658 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200659 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +0200660 "kwarg",
661 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000662};
Victor Stinner5cf47822020-11-02 22:03:28 +0100663static PyObject* ast2obj_arg(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300664static const char * const arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +0200665 "lineno",
666 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000667 "end_lineno",
668 "end_col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700669};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300670static const char * const arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200671 "arg",
672 "annotation",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800673 "type_comment",
Neal Norwitzc1505362006-12-28 06:47:50 +0000674};
Victor Stinner5cf47822020-11-02 22:03:28 +0100675static PyObject* ast2obj_keyword(struct ast_state *state, void*);
Pablo Galindo168660b2020-04-02 00:47:39 +0100676static const char * const keyword_attributes[] = {
677 "lineno",
678 "col_offset",
679 "end_lineno",
680 "end_col_offset",
681};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300682static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200683 "arg",
684 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000685};
Victor Stinner5cf47822020-11-02 22:03:28 +0100686static PyObject* ast2obj_alias(struct ast_state *state, void*);
Matthew Suozzo75a06f02021-04-10 16:56:28 -0400687static const char * const alias_attributes[] = {
688 "lineno",
689 "col_offset",
690 "end_lineno",
691 "end_col_offset",
692};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300693static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200694 "name",
695 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000696};
Victor Stinner5cf47822020-11-02 22:03:28 +0100697static PyObject* ast2obj_withitem(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300698static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200699 "context_expr",
700 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500701};
Brandt Bucher145bf262021-02-26 14:51:55 -0800702static PyObject* ast2obj_match_case(struct ast_state *state, void*);
703static const char * const match_case_fields[]={
704 "pattern",
705 "guard",
706 "body",
707};
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000708static const char * const pattern_attributes[] = {
709 "lineno",
710 "col_offset",
711 "end_lineno",
712 "end_col_offset",
713};
714static PyObject* ast2obj_pattern(struct ast_state *state, void*);
715static const char * const MatchValue_fields[]={
716 "value",
717};
718static const char * const MatchSingleton_fields[]={
719 "value",
720};
721static const char * const MatchSequence_fields[]={
722 "patterns",
723};
724static const char * const MatchMapping_fields[]={
725 "keys",
726 "patterns",
727 "rest",
728};
729static const char * const MatchClass_fields[]={
730 "cls",
731 "patterns",
732 "kwd_attrs",
733 "kwd_patterns",
734};
735static const char * const MatchStar_fields[]={
736 "name",
737};
738static const char * const MatchAs_fields[]={
739 "pattern",
740 "name",
741};
742static const char * const MatchOr_fields[]={
743 "patterns",
744};
Victor Stinner5cf47822020-11-02 22:03:28 +0100745static PyObject* ast2obj_type_ignore(struct ast_state *state, void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300746static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800747 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -0700748 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800749};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000750
751
INADA Naokifc489082017-01-25 22:33:43 +0900752
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700753typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +0100754 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700755 PyObject *dict;
756} AST_object;
757
Benjamin Peterson1767e022012-03-14 21:50:29 -0500758static void
759ast_dealloc(AST_object *self)
760{
INADA Naokia6296d32017-08-24 14:55:17 +0900761 /* bpo-31095: UnTrack is needed before calling any callbacks */
Eddie Elizondo0247e802019-09-14 09:38:17 -0400762 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +0900763 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -0500764 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -0400765 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
766 assert(free_func != NULL);
767 free_func(self);
768 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -0500769}
770
Neal Norwitz207c9f32008-03-31 04:42:11 +0000771static int
Benjamin Peterson81071762012-07-08 11:03:46 -0700772ast_traverse(AST_object *self, visitproc visit, void *arg)
773{
Pablo Galindo1cf15af2020-05-27 10:03:38 +0100774 Py_VISIT(Py_TYPE(self));
Benjamin Peterson81071762012-07-08 11:03:46 -0700775 Py_VISIT(self->dict);
776 return 0;
777}
778
Serhiy Storchakaa5c42282018-05-31 07:34:34 +0300779static int
Benjamin Peterson81071762012-07-08 11:03:46 -0700780ast_clear(AST_object *self)
781{
782 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +0300783 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -0700784}
785
786static int
Neal Norwitz207c9f32008-03-31 04:42:11 +0000787ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
788{
Victor Stinner5cf47822020-11-02 22:03:28 +0100789 struct ast_state *state = get_ast_state();
Victor Stinner1f764532020-07-04 23:18:15 +0200790 if (state == NULL) {
791 return -1;
792 }
793
Neal Norwitz207c9f32008-03-31 04:42:11 +0000794 Py_ssize_t i, numfields = 0;
795 int res = -1;
796 PyObject *key, *value, *fields;
Victor Stinner74419f02020-07-03 11:35:37 +0200797 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +0200798 goto cleanup;
799 }
Neal Norwitz207c9f32008-03-31 04:42:11 +0000800 if (fields) {
801 numfields = PySequence_Size(fields);
Rémi Lapeyrec73914a2020-05-24 23:12:57 +0200802 if (numfields == -1) {
Neal Norwitz207c9f32008-03-31 04:42:11 +0000803 goto cleanup;
Rémi Lapeyrec73914a2020-05-24 23:12:57 +0200804 }
Neal Norwitz207c9f32008-03-31 04:42:11 +0000805 }
INADA Naoki4c78c522017-02-24 02:48:17 +0900806
Neal Norwitz207c9f32008-03-31 04:42:11 +0000807 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +0900808 if (numfields < PyTuple_GET_SIZE(args)) {
809 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
810 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -0700811 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +0900812 numfields, numfields == 1 ? "" : "s");
813 res = -1;
814 goto cleanup;
815 }
816 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
817 /* cannot be reached when fields is NULL */
818 PyObject *name = PySequence_GetItem(fields, i);
819 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +0000820 res = -1;
821 goto cleanup;
822 }
INADA Naoki4c78c522017-02-24 02:48:17 +0900823 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
824 Py_DECREF(name);
Rémi Lapeyrec73914a2020-05-24 23:12:57 +0200825 if (res < 0) {
INADA Naoki4c78c522017-02-24 02:48:17 +0900826 goto cleanup;
Rémi Lapeyrec73914a2020-05-24 23:12:57 +0200827 }
Neal Norwitz207c9f32008-03-31 04:42:11 +0000828 }
829 if (kw) {
830 i = 0; /* needed by PyDict_Next */
831 while (PyDict_Next(kw, &i, &key, &value)) {
Rémi Lapeyrec73914a2020-05-24 23:12:57 +0200832 int contains = PySequence_Contains(fields, key);
833 if (contains == -1) {
834 res = -1;
Neal Norwitz207c9f32008-03-31 04:42:11 +0000835 goto cleanup;
Rémi Lapeyrec73914a2020-05-24 23:12:57 +0200836 } else if (contains == 1) {
837 Py_ssize_t p = PySequence_Index(fields, key);
838 if (p == -1) {
839 res = -1;
840 goto cleanup;
841 }
842 if (p < PyTuple_GET_SIZE(args)) {
843 PyErr_Format(PyExc_TypeError,
844 "%.400s got multiple values for argument '%U'",
845 Py_TYPE(self)->tp_name, key);
846 res = -1;
847 goto cleanup;
848 }
849 }
850 res = PyObject_SetAttr(self, key, value);
851 if (res < 0) {
852 goto cleanup;
853 }
Neal Norwitz207c9f32008-03-31 04:42:11 +0000854 }
855 }
856 cleanup:
857 Py_XDECREF(fields);
858 return res;
859}
860
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000861/* Pickling support */
862static PyObject *
863ast_type_reduce(PyObject *self, PyObject *unused)
864{
Victor Stinner5cf47822020-11-02 22:03:28 +0100865 struct ast_state *state = get_ast_state();
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +0200866 if (state == NULL) {
867 return NULL;
868 }
869
Serhiy Storchakaf320be72018-01-25 10:49:40 +0200870 PyObject *dict;
Victor Stinner74419f02020-07-03 11:35:37 +0200871 if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +0200872 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000873 }
874 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +0200875 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000876 }
877 return Py_BuildValue("O()", Py_TYPE(self));
878}
879
Eddie Elizondo3368f3c2019-09-19 09:29:05 -0700880static PyMemberDef ast_type_members[] = {
881 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
882 {NULL} /* Sentinel */
883};
884
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000885static PyMethodDef ast_type_methods[] = {
886 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
887 {NULL}
888};
889
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700890static PyGetSetDef ast_type_getsets[] = {
891 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
892 {NULL}
893};
894
Dino Viehlandac46eb42019-09-11 10:16:34 -0700895static PyType_Slot AST_type_slots[] = {
896 {Py_tp_dealloc, ast_dealloc},
897 {Py_tp_getattro, PyObject_GenericGetAttr},
898 {Py_tp_setattro, PyObject_GenericSetAttr},
899 {Py_tp_traverse, ast_traverse},
900 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -0700901 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -0700902 {Py_tp_methods, ast_type_methods},
903 {Py_tp_getset, ast_type_getsets},
904 {Py_tp_init, ast_type_init},
905 {Py_tp_alloc, PyType_GenericAlloc},
906 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -0700907 {Py_tp_free, PyObject_GC_Del},
908 {0, 0},
909};
910
911static PyType_Spec AST_type_spec = {
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200912 "ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700913 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +0000914 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -0700915 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
916 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +0000917};
918
Dino Viehlandac46eb42019-09-11 10:16:34 -0700919static PyObject *
Victor Stinner5cf47822020-11-02 22:03:28 +0100920make_type(struct ast_state *state, const char *type, PyObject* base,
Victor Stinner74419f02020-07-03 11:35:37 +0200921 const char* const* fields, int num_fields, const char *doc)
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000922{
923 PyObject *fnames, *result;
924 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000925 fnames = PyTuple_New(num_fields);
926 if (!fnames) return NULL;
927 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300928 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000929 if (!field) {
930 Py_DECREF(fnames);
931 return NULL;
932 }
933 PyTuple_SET_ITEM(fnames, i, field);
934 }
Brandt Bucher145bf262021-02-26 14:51:55 -0800935 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
INADA Naokifc489082017-01-25 22:33:43 +0900936 type, base,
Victor Stinner74419f02020-07-03 11:35:37 +0200937 state->_fields, fnames,
Brandt Bucher145bf262021-02-26 14:51:55 -0800938 state->__match_args__, fnames,
Victor Stinner74419f02020-07-03 11:35:37 +0200939 state->__module__,
940 state->ast,
941 state->__doc__, doc);
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000942 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700943 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000944}
945
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300946static int
Victor Stinner5cf47822020-11-02 22:03:28 +0100947add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000948{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000949 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +0000950 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +0000951 if (!l)
952 return 0;
953 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300954 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000955 if (!s) {
956 Py_DECREF(l);
957 return 0;
958 }
Neal Norwitz207c9f32008-03-31 04:42:11 +0000959 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000960 }
Victor Stinner74419f02020-07-03 11:35:37 +0200961 result = PyObject_SetAttr(type, state->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000962 Py_DECREF(l);
963 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000964}
965
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000966/* Conversion AST -> Python */
967
Victor Stinner5cf47822020-11-02 22:03:28 +0100968static PyObject* ast2obj_list(struct ast_state *state, asdl_seq *seq, PyObject* (*func)(struct ast_state *state, void*))
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000969{
Benjamin Peterson77fa9372012-05-15 10:10:27 -0700970 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000971 PyObject *result = PyList_New(n);
972 PyObject *value;
973 if (!result)
974 return NULL;
975 for (i = 0; i < n; i++) {
Pablo Galindoa5634c42020-09-16 19:42:00 +0100976 value = func(state, asdl_seq_GET_UNTYPED(seq, i));
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000977 if (!value) {
978 Py_DECREF(result);
979 return NULL;
980 }
981 PyList_SET_ITEM(result, i, value);
982 }
983 return result;
984}
985
Victor Stinner5cf47822020-11-02 22:03:28 +0100986static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), void *o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000987{
988 if (!o)
989 o = Py_None;
990 Py_INCREF((PyObject*)o);
991 return (PyObject*)o;
992}
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100993#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000994#define ast2obj_identifier ast2obj_object
995#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000996
Victor Stinner5cf47822020-11-02 22:03:28 +0100997static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000998{
Christian Heimes217cfd12007-12-02 14:31:20 +0000999 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001000}
1001
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001002/* Conversion Python -> AST */
1003
Victor Stinner5cf47822020-11-02 22:03:28 +01001004static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001005{
1006 if (obj == Py_None)
1007 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001008 if (obj) {
Victor Stinner8370e072021-03-24 02:23:01 +01001009 if (_PyArena_AddPyObject(arena, obj) < 0) {
Christian Heimes70c94e72013-07-27 00:33:13 +02001010 *out = NULL;
1011 return -1;
1012 }
1013 Py_INCREF(obj);
1014 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001015 *out = obj;
1016 return 0;
1017}
1018
Victor Stinner5cf47822020-11-02 22:03:28 +01001019static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001020{
Victor Stinner8370e072021-03-24 02:23:01 +01001021 if (_PyArena_AddPyObject(arena, obj) < 0) {
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001022 *out = NULL;
1023 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001024 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001025 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001026 *out = obj;
1027 return 0;
1028}
1029
Victor Stinner5cf47822020-11-02 22:03:28 +01001030static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001031{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001032 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1033 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001034 return 1;
1035 }
Victor Stinner74419f02020-07-03 11:35:37 +02001036 return obj2ast_object(state, obj, out, arena);
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001037}
1038
Victor Stinner5cf47822020-11-02 22:03:28 +01001039static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001040{
1041 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1042 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1043 return 1;
1044 }
Victor Stinner74419f02020-07-03 11:35:37 +02001045 return obj2ast_object(state, obj, out, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001046}
1047
Victor Stinner5cf47822020-11-02 22:03:28 +01001048static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001049{
1050 int i;
1051 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001052 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001053 return 1;
1054 }
1055
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001056 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001057 if (i == -1 && PyErr_Occurred())
1058 return 1;
1059 *out = i;
1060 return 0;
1061}
1062
Victor Stinner5cf47822020-11-02 22:03:28 +01001063static int add_ast_fields(struct ast_state *state)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001064{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001065 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001066 empty_tuple = PyTuple_New(0);
1067 if (!empty_tuple ||
Victor Stinner74419f02020-07-03 11:35:37 +02001068 PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
Brandt Bucher145bf262021-02-26 14:51:55 -08001069 PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
Victor Stinner74419f02020-07-03 11:35:37 +02001070 PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001071 Py_XDECREF(empty_tuple);
1072 return -1;
1073 }
1074 Py_DECREF(empty_tuple);
1075 return 0;
1076}
1077
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001078
Victor Stinnerfd957c12020-11-03 18:07:15 +01001079
1080static int
1081init_types(struct ast_state *state)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001082{
Victor Stinnerfd957c12020-11-03 18:07:15 +01001083 // init_types() must not be called after _PyAST_Fini()
1084 // has been called
1085 assert(state->initialized >= 0);
1086
1087 if (state->initialized) {
1088 return 1;
1089 }
1090 if (init_identifiers(state) < 0) {
1091 return 0;
1092 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001093 state->AST_type = PyType_FromSpec(&AST_type_spec);
Victor Stinnerfd957c12020-11-03 18:07:15 +01001094 if (!state->AST_type) {
1095 return 0;
1096 }
1097 if (add_ast_fields(state) < 0) {
1098 return 0;
1099 }
Victor Stinner74419f02020-07-03 11:35:37 +02001100 state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001101 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1102 " | Interactive(stmt* body)\n"
1103 " | Expression(expr body)\n"
1104 " | FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001105 if (!state->mod_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001106 if (!add_attributes(state, state->mod_type, NULL, 0)) return 0;
1107 state->Module_type = make_type(state, "Module", state->mod_type,
1108 Module_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001109 "Module(stmt* body, type_ignore* type_ignores)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001110 if (!state->Module_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001111 state->Interactive_type = make_type(state, "Interactive", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001112 Interactive_fields, 1,
1113 "Interactive(stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001114 if (!state->Interactive_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001115 state->Expression_type = make_type(state, "Expression", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001116 Expression_fields, 1,
1117 "Expression(expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001118 if (!state->Expression_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001119 state->FunctionType_type = make_type(state, "FunctionType",
1120 state->mod_type, FunctionType_fields,
1121 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001122 "FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001123 if (!state->FunctionType_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001124 state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001125 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1126 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1127 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1128 " | Return(expr? value)\n"
1129 " | Delete(expr* targets)\n"
1130 " | Assign(expr* targets, expr value, string? type_comment)\n"
1131 " | AugAssign(expr target, operator op, expr value)\n"
1132 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1133 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1134 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1135 " | While(expr test, stmt* body, stmt* orelse)\n"
1136 " | If(expr test, stmt* body, stmt* orelse)\n"
1137 " | With(withitem* items, stmt* body, string? type_comment)\n"
1138 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
Brandt Bucher145bf262021-02-26 14:51:55 -08001139 " | Match(expr subject, match_case* cases)\n"
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001140 " | Raise(expr? exc, expr? cause)\n"
1141 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1142 " | Assert(expr test, expr? msg)\n"
1143 " | Import(alias* names)\n"
1144 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1145 " | Global(identifier* names)\n"
1146 " | Nonlocal(identifier* names)\n"
1147 " | Expr(expr value)\n"
1148 " | Pass\n"
1149 " | Break\n"
1150 " | Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001151 if (!state->stmt_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001152 if (!add_attributes(state, state->stmt_type, stmt_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001153 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1154 return 0;
1155 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1156 -1)
1157 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001158 state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001159 FunctionDef_fields, 6,
1160 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001161 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001162 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1163 -1)
1164 return 0;
1165 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1166 == -1)
1167 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001168 state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001169 state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001170 AsyncFunctionDef_fields, 6,
1171 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001172 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001173 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1174 == -1)
1175 return 0;
1176 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1177 Py_None) == -1)
1178 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001179 state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001180 ClassDef_fields, 5,
1181 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001182 if (!state->ClassDef_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001183 state->Return_type = make_type(state, "Return", state->stmt_type,
1184 Return_fields, 1,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001185 "Return(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001186 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001187 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1188 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001189 state->Delete_type = make_type(state, "Delete", state->stmt_type,
1190 Delete_fields, 1,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001191 "Delete(expr* targets)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001192 if (!state->Delete_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001193 state->Assign_type = make_type(state, "Assign", state->stmt_type,
1194 Assign_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001195 "Assign(expr* targets, expr value, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001196 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001197 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1198 -1)
1199 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001200 state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001201 AugAssign_fields, 3,
1202 "AugAssign(expr target, operator op, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001203 if (!state->AugAssign_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001204 state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001205 AnnAssign_fields, 4,
1206 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001207 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001208 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1209 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001210 state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001211 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001212 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001213 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1214 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001215 state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001216 AsyncFor_fields, 5,
1217 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001218 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001219 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1220 -1)
1221 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001222 state->While_type = make_type(state, "While", state->stmt_type,
1223 While_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001224 "While(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001225 if (!state->While_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001226 state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001227 "If(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001228 if (!state->If_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001229 state->With_type = make_type(state, "With", state->stmt_type, With_fields,
1230 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001231 "With(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001232 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001233 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1234 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001235 state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001236 AsyncWith_fields, 3,
1237 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001238 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001239 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1240 == -1)
1241 return 0;
Brandt Bucher145bf262021-02-26 14:51:55 -08001242 state->Match_type = make_type(state, "Match", state->stmt_type,
1243 Match_fields, 2,
1244 "Match(expr subject, match_case* cases)");
1245 if (!state->Match_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001246 state->Raise_type = make_type(state, "Raise", state->stmt_type,
1247 Raise_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001248 "Raise(expr? exc, expr? cause)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001249 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001250 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1251 return 0;
1252 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1253 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001254 state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001255 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001256 if (!state->Try_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001257 state->Assert_type = make_type(state, "Assert", state->stmt_type,
1258 Assert_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001259 "Assert(expr test, expr? msg)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001260 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001261 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1262 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001263 state->Import_type = make_type(state, "Import", state->stmt_type,
1264 Import_fields, 1,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001265 "Import(alias* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001266 if (!state->Import_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001267 state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001268 ImportFrom_fields, 3,
1269 "ImportFrom(identifier? module, alias* names, int? level)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001270 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001271 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1272 return 0;
1273 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1274 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001275 state->Global_type = make_type(state, "Global", state->stmt_type,
1276 Global_fields, 1,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001277 "Global(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001278 if (!state->Global_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001279 state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001280 Nonlocal_fields, 1,
1281 "Nonlocal(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001282 if (!state->Nonlocal_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001283 state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
1284 1,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001285 "Expr(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001286 if (!state->Expr_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001287 state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001288 "Pass");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001289 if (!state->Pass_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001290 state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001291 "Break");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001292 if (!state->Break_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001293 state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
1294 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001295 "Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001296 if (!state->Continue_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001297 state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001298 "expr = BoolOp(boolop op, expr* values)\n"
1299 " | NamedExpr(expr target, expr value)\n"
1300 " | BinOp(expr left, operator op, expr right)\n"
1301 " | UnaryOp(unaryop op, expr operand)\n"
1302 " | Lambda(arguments args, expr body)\n"
1303 " | IfExp(expr test, expr body, expr orelse)\n"
1304 " | Dict(expr* keys, expr* values)\n"
1305 " | Set(expr* elts)\n"
1306 " | ListComp(expr elt, comprehension* generators)\n"
1307 " | SetComp(expr elt, comprehension* generators)\n"
1308 " | DictComp(expr key, expr value, comprehension* generators)\n"
1309 " | GeneratorExp(expr elt, comprehension* generators)\n"
1310 " | Await(expr value)\n"
1311 " | Yield(expr? value)\n"
1312 " | YieldFrom(expr value)\n"
1313 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1314 " | Call(expr func, expr* args, keyword* keywords)\n"
1315 " | FormattedValue(expr value, int? conversion, expr? format_spec)\n"
1316 " | JoinedStr(expr* values)\n"
1317 " | Constant(constant value, string? kind)\n"
1318 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1319 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1320 " | Starred(expr value, expr_context ctx)\n"
1321 " | Name(identifier id, expr_context ctx)\n"
1322 " | List(expr* elts, expr_context ctx)\n"
1323 " | Tuple(expr* elts, expr_context ctx)\n"
Nick Coghlan1e7b8582021-04-29 15:58:44 +10001324 " | Slice(expr? lower, expr? upper, expr? step)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001325 if (!state->expr_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001326 if (!add_attributes(state, state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001327 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1328 return 0;
1329 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1330 -1)
1331 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001332 state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
1333 BoolOp_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001334 "BoolOp(boolop op, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001335 if (!state->BoolOp_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001336 state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001337 NamedExpr_fields, 2,
1338 "NamedExpr(expr target, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001339 if (!state->NamedExpr_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001340 state->BinOp_type = make_type(state, "BinOp", state->expr_type,
1341 BinOp_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001342 "BinOp(expr left, operator op, expr right)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001343 if (!state->BinOp_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001344 state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001345 UnaryOp_fields, 2,
1346 "UnaryOp(unaryop op, expr operand)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001347 if (!state->UnaryOp_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001348 state->Lambda_type = make_type(state, "Lambda", state->expr_type,
1349 Lambda_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001350 "Lambda(arguments args, expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001351 if (!state->Lambda_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001352 state->IfExp_type = make_type(state, "IfExp", state->expr_type,
1353 IfExp_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001354 "IfExp(expr test, expr body, expr orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001355 if (!state->IfExp_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001356 state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
1357 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001358 "Dict(expr* keys, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001359 if (!state->Dict_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001360 state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001361 "Set(expr* elts)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001362 if (!state->Set_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001363 state->ListComp_type = make_type(state, "ListComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001364 ListComp_fields, 2,
1365 "ListComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001366 if (!state->ListComp_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001367 state->SetComp_type = make_type(state, "SetComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001368 SetComp_fields, 2,
1369 "SetComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001370 if (!state->SetComp_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001371 state->DictComp_type = make_type(state, "DictComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001372 DictComp_fields, 3,
1373 "DictComp(expr key, expr value, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001374 if (!state->DictComp_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001375 state->GeneratorExp_type = make_type(state, "GeneratorExp",
1376 state->expr_type, GeneratorExp_fields,
1377 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001378 "GeneratorExp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001379 if (!state->GeneratorExp_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001380 state->Await_type = make_type(state, "Await", state->expr_type,
1381 Await_fields, 1,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001382 "Await(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001383 if (!state->Await_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001384 state->Yield_type = make_type(state, "Yield", state->expr_type,
1385 Yield_fields, 1,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001386 "Yield(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001387 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001388 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1389 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001390 state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001391 YieldFrom_fields, 1,
1392 "YieldFrom(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001393 if (!state->YieldFrom_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001394 state->Compare_type = make_type(state, "Compare", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001395 Compare_fields, 3,
1396 "Compare(expr left, cmpop* ops, expr* comparators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001397 if (!state->Compare_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001398 state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
1399 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001400 "Call(expr func, expr* args, keyword* keywords)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001401 if (!state->Call_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001402 state->FormattedValue_type = make_type(state, "FormattedValue",
1403 state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001404 FormattedValue_fields, 3,
1405 "FormattedValue(expr value, int? conversion, expr? format_spec)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001406 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001407 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1408 Py_None) == -1)
1409 return 0;
1410 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1411 Py_None) == -1)
1412 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001413 state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001414 JoinedStr_fields, 1,
1415 "JoinedStr(expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001416 if (!state->JoinedStr_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001417 state->Constant_type = make_type(state, "Constant", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001418 Constant_fields, 2,
1419 "Constant(constant value, string? kind)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001420 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001421 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1422 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001423 state->Attribute_type = make_type(state, "Attribute", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001424 Attribute_fields, 3,
1425 "Attribute(expr value, identifier attr, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001426 if (!state->Attribute_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001427 state->Subscript_type = make_type(state, "Subscript", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001428 Subscript_fields, 3,
1429 "Subscript(expr value, expr slice, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001430 if (!state->Subscript_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001431 state->Starred_type = make_type(state, "Starred", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001432 Starred_fields, 2,
1433 "Starred(expr value, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001434 if (!state->Starred_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001435 state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
1436 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001437 "Name(identifier id, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001438 if (!state->Name_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001439 state->List_type = make_type(state, "List", state->expr_type, List_fields,
1440 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001441 "List(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001442 if (!state->List_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001443 state->Tuple_type = make_type(state, "Tuple", state->expr_type,
1444 Tuple_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001445 "Tuple(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001446 if (!state->Tuple_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001447 state->Slice_type = make_type(state, "Slice", state->expr_type,
1448 Slice_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001449 "Slice(expr? lower, expr? upper, expr? step)");
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001450 if (!state->Slice_type) return 0;
1451 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1452 return 0;
1453 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1454 return 0;
1455 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1456 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001457 state->expr_context_type = make_type(state, "expr_context",
1458 state->AST_type, NULL, 0,
Serhiy Storchaka6b975982020-03-17 23:41:08 +02001459 "expr_context = Load | Store | Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001460 if (!state->expr_context_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001461 if (!add_attributes(state, state->expr_context_type, NULL, 0)) return 0;
1462 state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
1463 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001464 "Load");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001465 if (!state->Load_type) return 0;
1466 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1467 NULL, NULL);
1468 if (!state->Load_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001469 state->Store_type = make_type(state, "Store", state->expr_context_type,
1470 NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001471 "Store");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001472 if (!state->Store_type) return 0;
1473 state->Store_singleton = PyType_GenericNew((PyTypeObject
1474 *)state->Store_type, NULL, NULL);
1475 if (!state->Store_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001476 state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001477 "Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001478 if (!state->Del_type) return 0;
1479 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1480 NULL, NULL);
1481 if (!state->Del_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001482 state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001483 "boolop = And | Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001484 if (!state->boolop_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001485 if (!add_attributes(state, state->boolop_type, NULL, 0)) return 0;
1486 state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001487 "And");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001488 if (!state->And_type) return 0;
1489 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1490 NULL, NULL);
1491 if (!state->And_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001492 state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001493 "Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001494 if (!state->Or_type) return 0;
1495 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1496 NULL, NULL);
1497 if (!state->Or_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001498 state->operator_type = make_type(state, "operator", state->AST_type, NULL,
1499 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001500 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001501 if (!state->operator_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001502 if (!add_attributes(state, state->operator_type, NULL, 0)) return 0;
1503 state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001504 "Add");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001505 if (!state->Add_type) return 0;
1506 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1507 NULL, NULL);
1508 if (!state->Add_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001509 state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001510 "Sub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001511 if (!state->Sub_type) return 0;
1512 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1513 NULL, NULL);
1514 if (!state->Sub_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001515 state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001516 "Mult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001517 if (!state->Mult_type) return 0;
1518 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1519 NULL, NULL);
1520 if (!state->Mult_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001521 state->MatMult_type = make_type(state, "MatMult", state->operator_type,
1522 NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001523 "MatMult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001524 if (!state->MatMult_type) return 0;
1525 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1526 *)state->MatMult_type, NULL,
1527 NULL);
1528 if (!state->MatMult_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001529 state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001530 "Div");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001531 if (!state->Div_type) return 0;
1532 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1533 NULL, NULL);
1534 if (!state->Div_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001535 state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001536 "Mod");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001537 if (!state->Mod_type) return 0;
1538 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1539 NULL, NULL);
1540 if (!state->Mod_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001541 state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001542 "Pow");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001543 if (!state->Pow_type) return 0;
1544 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1545 NULL, NULL);
1546 if (!state->Pow_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001547 state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
1548 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001549 "LShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001550 if (!state->LShift_type) return 0;
1551 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1552 *)state->LShift_type, NULL,
1553 NULL);
1554 if (!state->LShift_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001555 state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
1556 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001557 "RShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001558 if (!state->RShift_type) return 0;
1559 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1560 *)state->RShift_type, NULL,
1561 NULL);
1562 if (!state->RShift_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001563 state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001564 "BitOr");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001565 if (!state->BitOr_type) return 0;
1566 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1567 *)state->BitOr_type, NULL, NULL);
1568 if (!state->BitOr_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001569 state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
1570 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001571 "BitXor");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001572 if (!state->BitXor_type) return 0;
1573 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1574 *)state->BitXor_type, NULL,
1575 NULL);
1576 if (!state->BitXor_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001577 state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
1578 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001579 "BitAnd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001580 if (!state->BitAnd_type) return 0;
1581 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1582 *)state->BitAnd_type, NULL,
1583 NULL);
1584 if (!state->BitAnd_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001585 state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
1586 NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001587 "FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001588 if (!state->FloorDiv_type) return 0;
1589 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1590 *)state->FloorDiv_type, NULL,
1591 NULL);
1592 if (!state->FloorDiv_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001593 state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001594 "unaryop = Invert | Not | UAdd | USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001595 if (!state->unaryop_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001596 if (!add_attributes(state, state->unaryop_type, NULL, 0)) return 0;
1597 state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
1598 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001599 "Invert");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001600 if (!state->Invert_type) return 0;
1601 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1602 *)state->Invert_type, NULL,
1603 NULL);
1604 if (!state->Invert_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001605 state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001606 "Not");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001607 if (!state->Not_type) return 0;
1608 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1609 NULL, NULL);
1610 if (!state->Not_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001611 state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001612 "UAdd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001613 if (!state->UAdd_type) return 0;
1614 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1615 NULL, NULL);
1616 if (!state->UAdd_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001617 state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001618 "USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001619 if (!state->USub_type) return 0;
1620 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1621 NULL, NULL);
1622 if (!state->USub_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001623 state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001624 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001625 if (!state->cmpop_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001626 if (!add_attributes(state, state->cmpop_type, NULL, 0)) return 0;
1627 state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001628 "Eq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001629 if (!state->Eq_type) return 0;
1630 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1631 NULL, NULL);
1632 if (!state->Eq_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001633 state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001634 "NotEq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001635 if (!state->NotEq_type) return 0;
1636 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1637 *)state->NotEq_type, NULL, NULL);
1638 if (!state->NotEq_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001639 state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001640 "Lt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001641 if (!state->Lt_type) return 0;
1642 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1643 NULL, NULL);
1644 if (!state->Lt_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001645 state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001646 "LtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001647 if (!state->LtE_type) return 0;
1648 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1649 NULL, NULL);
1650 if (!state->LtE_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001651 state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001652 "Gt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001653 if (!state->Gt_type) return 0;
1654 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1655 NULL, NULL);
1656 if (!state->Gt_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001657 state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001658 "GtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001659 if (!state->GtE_type) return 0;
1660 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1661 NULL, NULL);
1662 if (!state->GtE_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001663 state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001664 "Is");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001665 if (!state->Is_type) return 0;
1666 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1667 NULL, NULL);
1668 if (!state->Is_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001669 state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001670 "IsNot");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001671 if (!state->IsNot_type) return 0;
1672 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1673 *)state->IsNot_type, NULL, NULL);
1674 if (!state->IsNot_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001675 state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001676 "In");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001677 if (!state->In_type) return 0;
1678 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1679 NULL, NULL);
1680 if (!state->In_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001681 state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001682 "NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001683 if (!state->NotIn_type) return 0;
1684 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1685 *)state->NotIn_type, NULL, NULL);
1686 if (!state->NotIn_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001687 state->comprehension_type = make_type(state, "comprehension",
1688 state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001689 comprehension_fields, 4,
1690 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001691 if (!state->comprehension_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001692 if (!add_attributes(state, state->comprehension_type, NULL, 0)) return 0;
1693 state->excepthandler_type = make_type(state, "excepthandler",
1694 state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001695 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001696 if (!state->excepthandler_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001697 if (!add_attributes(state, state->excepthandler_type,
1698 excepthandler_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001699 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1700 == -1)
1701 return 0;
1702 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1703 Py_None) == -1)
1704 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001705 state->ExceptHandler_type = make_type(state, "ExceptHandler",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001706 state->excepthandler_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001707 ExceptHandler_fields, 3,
1708 "ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001709 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001710 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1711 return 0;
1712 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1713 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001714 state->arguments_type = make_type(state, "arguments", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001715 arguments_fields, 7,
1716 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001717 if (!state->arguments_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001718 if (!add_attributes(state, state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001719 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1720 return 0;
1721 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1722 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001723 state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001724 "arg(identifier arg, expr? annotation, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001725 if (!state->arg_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001726 if (!add_attributes(state, state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001727 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1728 return 0;
1729 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1730 return 0;
1731 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1732 return 0;
1733 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1734 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001735 state->keyword_type = make_type(state, "keyword", state->AST_type,
1736 keyword_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001737 "keyword(identifier? arg, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001738 if (!state->keyword_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001739 if (!add_attributes(state, state->keyword_type, keyword_attributes, 4))
1740 return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001741 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1742 return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01001743 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
1744 return 0;
1745 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
1746 == -1)
1747 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001748 state->alias_type = make_type(state, "alias", state->AST_type,
1749 alias_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001750 "alias(identifier name, identifier? asname)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001751 if (!state->alias_type) return 0;
Matthew Suozzo75a06f02021-04-10 16:56:28 -04001752 if (!add_attributes(state, state->alias_type, alias_attributes, 4)) return
1753 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001754 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
1755 return 0;
Matthew Suozzo75a06f02021-04-10 16:56:28 -04001756 if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
1757 return 0;
1758 if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
1759 -1)
1760 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001761 state->withitem_type = make_type(state, "withitem", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001762 withitem_fields, 2,
1763 "withitem(expr context_expr, expr? optional_vars)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001764 if (!state->withitem_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001765 if (!add_attributes(state, state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001766 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
1767 == -1)
1768 return 0;
Brandt Bucher145bf262021-02-26 14:51:55 -08001769 state->match_case_type = make_type(state, "match_case", state->AST_type,
1770 match_case_fields, 3,
Nick Coghlan1e7b8582021-04-29 15:58:44 +10001771 "match_case(pattern pattern, expr? guard, stmt* body)");
Brandt Bucher145bf262021-02-26 14:51:55 -08001772 if (!state->match_case_type) return 0;
1773 if (!add_attributes(state, state->match_case_type, NULL, 0)) return 0;
1774 if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
1775 return 0;
Nick Coghlan1e7b8582021-04-29 15:58:44 +10001776 state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
1777 "pattern = MatchValue(expr value)\n"
1778 " | MatchSingleton(constant value)\n"
1779 " | MatchSequence(pattern* patterns)\n"
1780 " | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
1781 " | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
1782 " | MatchStar(identifier? name)\n"
1783 " | MatchAs(pattern? pattern, identifier? name)\n"
1784 " | MatchOr(pattern* patterns)");
1785 if (!state->pattern_type) return 0;
1786 if (!add_attributes(state, state->pattern_type, pattern_attributes, 4))
1787 return 0;
1788 state->MatchValue_type = make_type(state, "MatchValue",
1789 state->pattern_type, MatchValue_fields,
1790 1,
1791 "MatchValue(expr value)");
1792 if (!state->MatchValue_type) return 0;
1793 state->MatchSingleton_type = make_type(state, "MatchSingleton",
1794 state->pattern_type,
1795 MatchSingleton_fields, 1,
1796 "MatchSingleton(constant value)");
1797 if (!state->MatchSingleton_type) return 0;
1798 state->MatchSequence_type = make_type(state, "MatchSequence",
1799 state->pattern_type,
1800 MatchSequence_fields, 1,
1801 "MatchSequence(pattern* patterns)");
1802 if (!state->MatchSequence_type) return 0;
1803 state->MatchMapping_type = make_type(state, "MatchMapping",
1804 state->pattern_type,
1805 MatchMapping_fields, 3,
1806 "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
1807 if (!state->MatchMapping_type) return 0;
1808 if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
1809 return 0;
1810 state->MatchClass_type = make_type(state, "MatchClass",
1811 state->pattern_type, MatchClass_fields,
1812 4,
1813 "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
1814 if (!state->MatchClass_type) return 0;
1815 state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
1816 MatchStar_fields, 1,
1817 "MatchStar(identifier? name)");
1818 if (!state->MatchStar_type) return 0;
1819 if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
1820 return 0;
1821 state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
1822 MatchAs_fields, 2,
1823 "MatchAs(pattern? pattern, identifier? name)");
1824 if (!state->MatchAs_type) return 0;
1825 if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
1826 return 0;
1827 if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
1828 return 0;
1829 state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
1830 MatchOr_fields, 1,
1831 "MatchOr(pattern* patterns)");
1832 if (!state->MatchOr_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001833 state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
1834 NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001835 "type_ignore = TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001836 if (!state->type_ignore_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001837 if (!add_attributes(state, state->type_ignore_type, NULL, 0)) return 0;
1838 state->TypeIgnore_type = make_type(state, "TypeIgnore",
1839 state->type_ignore_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001840 TypeIgnore_fields, 2,
1841 "TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001842 if (!state->TypeIgnore_type) return 0;
Victor Stinnerfd957c12020-11-03 18:07:15 +01001843
Dino Viehlandac46eb42019-09-11 10:16:34 -07001844 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001845 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001846}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001847
Victor Stinner5cf47822020-11-02 22:03:28 +01001848static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001849 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001850static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001851 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001852static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001853 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001854static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001855 expr_context_ty* out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001856static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
1857 out, PyArena* arena);
1858static int obj2ast_operator(struct ast_state *state, PyObject* obj,
1859 operator_ty* out, PyArena* arena);
1860static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
Victor Stinner74419f02020-07-03 11:35:37 +02001861 out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001862static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001863 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001864static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001865 comprehension_ty* out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001866static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001867 excepthandler_ty* out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001868static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001869 arguments_ty* out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001870static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001871 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001872static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
Victor Stinner74419f02020-07-03 11:35:37 +02001873 out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001874static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001875 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001876static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
1877 withitem_ty* out, PyArena* arena);
Brandt Bucher145bf262021-02-26 14:51:55 -08001878static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
1879 match_case_ty* out, PyArena* arena);
Nick Coghlan1e7b8582021-04-29 15:58:44 +10001880static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
1881 out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001882static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001883 type_ignore_ty* out, PyArena* arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001884
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001885mod_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001886_PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
1887 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001888{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001889 mod_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01001890 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001891 if (!p)
1892 return NULL;
1893 p->kind = Module_kind;
1894 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001895 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001896 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001897}
1898
1899mod_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001900_PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001901{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001902 mod_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01001903 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001904 if (!p)
1905 return NULL;
1906 p->kind = Interactive_kind;
1907 p->v.Interactive.body = body;
1908 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001909}
1910
1911mod_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001912_PyAST_Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001913{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001914 mod_ty p;
1915 if (!body) {
1916 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001917 "field 'body' is required for Expression");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001918 return NULL;
1919 }
Victor Stinner8370e072021-03-24 02:23:01 +01001920 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001921 if (!p)
1922 return NULL;
1923 p->kind = Expression_kind;
1924 p->v.Expression.body = body;
1925 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001926}
1927
1928mod_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001929_PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001930{
1931 mod_ty p;
1932 if (!returns) {
1933 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001934 "field 'returns' is required for FunctionType");
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001935 return NULL;
1936 }
Victor Stinner8370e072021-03-24 02:23:01 +01001937 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001938 if (!p)
1939 return NULL;
1940 p->kind = FunctionType_kind;
1941 p->v.FunctionType.argtypes = argtypes;
1942 p->v.FunctionType.returns = returns;
1943 return p;
1944}
1945
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001946stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001947_PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
1948 asdl_expr_seq * decorator_list, expr_ty returns, string
1949 type_comment, int lineno, int col_offset, int end_lineno,
1950 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001951{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001952 stmt_ty p;
1953 if (!name) {
1954 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001955 "field 'name' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001956 return NULL;
1957 }
1958 if (!args) {
1959 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001960 "field 'args' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001961 return NULL;
1962 }
Victor Stinner8370e072021-03-24 02:23:01 +01001963 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001964 if (!p)
1965 return NULL;
1966 p->kind = FunctionDef_kind;
1967 p->v.FunctionDef.name = name;
1968 p->v.FunctionDef.args = args;
1969 p->v.FunctionDef.body = body;
1970 p->v.FunctionDef.decorator_list = decorator_list;
1971 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001972 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001973 p->lineno = lineno;
1974 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001975 p->end_lineno = end_lineno;
1976 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001977 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001978}
1979
1980stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001981_PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
1982 body, asdl_expr_seq * decorator_list, expr_ty returns,
1983 string type_comment, int lineno, int col_offset, int
1984 end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04001985{
1986 stmt_ty p;
1987 if (!name) {
1988 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001989 "field 'name' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04001990 return NULL;
1991 }
1992 if (!args) {
1993 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001994 "field 'args' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04001995 return NULL;
1996 }
Victor Stinner8370e072021-03-24 02:23:01 +01001997 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanov75445082015-05-11 22:57:16 -04001998 if (!p)
1999 return NULL;
2000 p->kind = AsyncFunctionDef_kind;
2001 p->v.AsyncFunctionDef.name = name;
2002 p->v.AsyncFunctionDef.args = args;
2003 p->v.AsyncFunctionDef.body = body;
2004 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2005 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002006 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002007 p->lineno = lineno;
2008 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002009 p->end_lineno = end_lineno;
2010 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002011 return p;
2012}
2013
2014stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002015_PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
2016 keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
2017 int lineno, int col_offset, int end_lineno, int end_col_offset,
2018 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002019{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002020 stmt_ty p;
2021 if (!name) {
2022 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002023 "field 'name' is required for ClassDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002024 return NULL;
2025 }
Victor Stinner8370e072021-03-24 02:23:01 +01002026 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002027 if (!p)
2028 return NULL;
2029 p->kind = ClassDef_kind;
2030 p->v.ClassDef.name = name;
2031 p->v.ClassDef.bases = bases;
2032 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002033 p->v.ClassDef.body = body;
2034 p->v.ClassDef.decorator_list = decorator_list;
2035 p->lineno = lineno;
2036 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002037 p->end_lineno = end_lineno;
2038 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002039 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002040}
2041
2042stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002043_PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2044 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002045{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002046 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002047 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002048 if (!p)
2049 return NULL;
2050 p->kind = Return_kind;
2051 p->v.Return.value = value;
2052 p->lineno = lineno;
2053 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002054 p->end_lineno = end_lineno;
2055 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002056 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002057}
2058
2059stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002060_PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
2061 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002062{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002063 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002064 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002065 if (!p)
2066 return NULL;
2067 p->kind = Delete_kind;
2068 p->v.Delete.targets = targets;
2069 p->lineno = lineno;
2070 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002071 p->end_lineno = end_lineno;
2072 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002073 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002074}
2075
2076stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002077_PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
2078 lineno, int col_offset, int end_lineno, int end_col_offset,
2079 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002080{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002081 stmt_ty p;
2082 if (!value) {
2083 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002084 "field 'value' is required for Assign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002085 return NULL;
2086 }
Victor Stinner8370e072021-03-24 02:23:01 +01002087 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002088 if (!p)
2089 return NULL;
2090 p->kind = Assign_kind;
2091 p->v.Assign.targets = targets;
2092 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002093 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002094 p->lineno = lineno;
2095 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002096 p->end_lineno = end_lineno;
2097 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002098 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002099}
2100
2101stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002102_PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
2103 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002104{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002105 stmt_ty p;
2106 if (!target) {
2107 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002108 "field 'target' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002109 return NULL;
2110 }
2111 if (!op) {
2112 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002113 "field 'op' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002114 return NULL;
2115 }
2116 if (!value) {
2117 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002118 "field 'value' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002119 return NULL;
2120 }
Victor Stinner8370e072021-03-24 02:23:01 +01002121 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002122 if (!p)
2123 return NULL;
2124 p->kind = AugAssign_kind;
2125 p->v.AugAssign.target = target;
2126 p->v.AugAssign.op = op;
2127 p->v.AugAssign.value = value;
2128 p->lineno = lineno;
2129 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002130 p->end_lineno = end_lineno;
2131 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002132 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002133}
2134
2135stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002136_PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
2137 int lineno, int col_offset, int end_lineno, int
2138 end_col_offset, PyArena *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002139{
2140 stmt_ty p;
2141 if (!target) {
2142 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002143 "field 'target' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002144 return NULL;
2145 }
2146 if (!annotation) {
2147 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002148 "field 'annotation' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002149 return NULL;
2150 }
Victor Stinner8370e072021-03-24 02:23:01 +01002151 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002152 if (!p)
2153 return NULL;
2154 p->kind = AnnAssign_kind;
2155 p->v.AnnAssign.target = target;
2156 p->v.AnnAssign.annotation = annotation;
2157 p->v.AnnAssign.value = value;
2158 p->v.AnnAssign.simple = simple;
2159 p->lineno = lineno;
2160 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002161 p->end_lineno = end_lineno;
2162 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002163 return p;
2164}
2165
2166stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002167_PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
2168 orelse, string type_comment, int lineno, int col_offset, int
2169 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002170{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002171 stmt_ty p;
2172 if (!target) {
2173 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002174 "field 'target' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002175 return NULL;
2176 }
2177 if (!iter) {
2178 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002179 "field 'iter' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002180 return NULL;
2181 }
Victor Stinner8370e072021-03-24 02:23:01 +01002182 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002183 if (!p)
2184 return NULL;
2185 p->kind = For_kind;
2186 p->v.For.target = target;
2187 p->v.For.iter = iter;
2188 p->v.For.body = body;
2189 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002190 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002191 p->lineno = lineno;
2192 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002193 p->end_lineno = end_lineno;
2194 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002195 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002196}
2197
2198stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002199_PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
2200 asdl_stmt_seq * orelse, string type_comment, int lineno, int
2201 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002202{
2203 stmt_ty p;
2204 if (!target) {
2205 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002206 "field 'target' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002207 return NULL;
2208 }
2209 if (!iter) {
2210 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002211 "field 'iter' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002212 return NULL;
2213 }
Victor Stinner8370e072021-03-24 02:23:01 +01002214 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanov75445082015-05-11 22:57:16 -04002215 if (!p)
2216 return NULL;
2217 p->kind = AsyncFor_kind;
2218 p->v.AsyncFor.target = target;
2219 p->v.AsyncFor.iter = iter;
2220 p->v.AsyncFor.body = body;
2221 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002222 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002223 p->lineno = lineno;
2224 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002225 p->end_lineno = end_lineno;
2226 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002227 return p;
2228}
2229
2230stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002231_PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2232 lineno, int col_offset, int end_lineno, int end_col_offset,
2233 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002234{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002235 stmt_ty p;
2236 if (!test) {
2237 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002238 "field 'test' is required for While");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002239 return NULL;
2240 }
Victor Stinner8370e072021-03-24 02:23:01 +01002241 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002242 if (!p)
2243 return NULL;
2244 p->kind = While_kind;
2245 p->v.While.test = test;
2246 p->v.While.body = body;
2247 p->v.While.orelse = orelse;
2248 p->lineno = lineno;
2249 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002250 p->end_lineno = end_lineno;
2251 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002252 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002253}
2254
2255stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002256_PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2257 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2258 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002259{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002260 stmt_ty p;
2261 if (!test) {
2262 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002263 "field 'test' is required for If");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002264 return NULL;
2265 }
Victor Stinner8370e072021-03-24 02:23:01 +01002266 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002267 if (!p)
2268 return NULL;
2269 p->kind = If_kind;
2270 p->v.If.test = test;
2271 p->v.If.body = body;
2272 p->v.If.orelse = orelse;
2273 p->lineno = lineno;
2274 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002275 p->end_lineno = end_lineno;
2276 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002277 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002278}
2279
2280stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002281_PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2282 type_comment, int lineno, int col_offset, int end_lineno, int
2283 end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002284{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002285 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002286 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002287 if (!p)
2288 return NULL;
2289 p->kind = With_kind;
2290 p->v.With.items = items;
2291 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002292 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002293 p->lineno = lineno;
2294 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002295 p->end_lineno = end_lineno;
2296 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002297 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002298}
2299
2300stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002301_PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2302 type_comment, int lineno, int col_offset, int end_lineno, int
2303 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002304{
2305 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002306 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanov75445082015-05-11 22:57:16 -04002307 if (!p)
2308 return NULL;
2309 p->kind = AsyncWith_kind;
2310 p->v.AsyncWith.items = items;
2311 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002312 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002313 p->lineno = lineno;
2314 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002315 p->end_lineno = end_lineno;
2316 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002317 return p;
2318}
2319
2320stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002321_PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
2322 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Brandt Bucher145bf262021-02-26 14:51:55 -08002323{
2324 stmt_ty p;
2325 if (!subject) {
2326 PyErr_SetString(PyExc_ValueError,
2327 "field 'subject' is required for Match");
2328 return NULL;
2329 }
Victor Stinner8370e072021-03-24 02:23:01 +01002330 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Brandt Bucher145bf262021-02-26 14:51:55 -08002331 if (!p)
2332 return NULL;
2333 p->kind = Match_kind;
2334 p->v.Match.subject = subject;
2335 p->v.Match.cases = cases;
2336 p->lineno = lineno;
2337 p->col_offset = col_offset;
2338 p->end_lineno = end_lineno;
2339 p->end_col_offset = end_col_offset;
2340 return p;
2341}
2342
2343stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002344_PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
2345 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002346{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002347 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002348 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002349 if (!p)
2350 return NULL;
2351 p->kind = Raise_kind;
2352 p->v.Raise.exc = exc;
2353 p->v.Raise.cause = cause;
2354 p->lineno = lineno;
2355 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002356 p->end_lineno = end_lineno;
2357 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002358 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002359}
2360
2361stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002362_PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
2363 asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
2364 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002365{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002366 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002367 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002368 if (!p)
2369 return NULL;
2370 p->kind = Try_kind;
2371 p->v.Try.body = body;
2372 p->v.Try.handlers = handlers;
2373 p->v.Try.orelse = orelse;
2374 p->v.Try.finalbody = finalbody;
2375 p->lineno = lineno;
2376 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002377 p->end_lineno = end_lineno;
2378 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002379 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002380}
2381
2382stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002383_PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
2384 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002385{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002386 stmt_ty p;
2387 if (!test) {
2388 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002389 "field 'test' is required for Assert");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002390 return NULL;
2391 }
Victor Stinner8370e072021-03-24 02:23:01 +01002392 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002393 if (!p)
2394 return NULL;
2395 p->kind = Assert_kind;
2396 p->v.Assert.test = test;
2397 p->v.Assert.msg = msg;
2398 p->lineno = lineno;
2399 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002400 p->end_lineno = end_lineno;
2401 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002402 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002403}
2404
2405stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002406_PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
2407 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002408{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002409 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002410 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002411 if (!p)
2412 return NULL;
2413 p->kind = Import_kind;
2414 p->v.Import.names = names;
2415 p->lineno = lineno;
2416 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002417 p->end_lineno = end_lineno;
2418 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002419 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002420}
2421
2422stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002423_PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
2424 lineno, int col_offset, int end_lineno, int end_col_offset,
2425 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002426{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002427 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002428 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002429 if (!p)
2430 return NULL;
2431 p->kind = ImportFrom_kind;
2432 p->v.ImportFrom.module = module;
2433 p->v.ImportFrom.names = names;
2434 p->v.ImportFrom.level = level;
2435 p->lineno = lineno;
2436 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002437 p->end_lineno = end_lineno;
2438 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002439 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002440}
2441
2442stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002443_PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
2444 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002445{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002446 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002447 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002448 if (!p)
2449 return NULL;
2450 p->kind = Global_kind;
2451 p->v.Global.names = names;
2452 p->lineno = lineno;
2453 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002454 p->end_lineno = end_lineno;
2455 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002456 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002457}
2458
2459stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002460_PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
2461 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002462{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002463 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002464 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002465 if (!p)
2466 return NULL;
2467 p->kind = Nonlocal_kind;
2468 p->v.Nonlocal.names = names;
2469 p->lineno = lineno;
2470 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002471 p->end_lineno = end_lineno;
2472 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002473 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002474}
2475
2476stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002477_PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2478 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002479{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002480 stmt_ty p;
2481 if (!value) {
2482 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002483 "field 'value' is required for Expr");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002484 return NULL;
2485 }
Victor Stinner8370e072021-03-24 02:23:01 +01002486 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002487 if (!p)
2488 return NULL;
2489 p->kind = Expr_kind;
2490 p->v.Expr.value = value;
2491 p->lineno = lineno;
2492 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002493 p->end_lineno = end_lineno;
2494 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002495 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002496}
2497
2498stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002499_PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
2500 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002501{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002502 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002503 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002504 if (!p)
2505 return NULL;
2506 p->kind = Pass_kind;
2507 p->lineno = lineno;
2508 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002509 p->end_lineno = end_lineno;
2510 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002511 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002512}
2513
2514stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002515_PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
2516 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002517{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002518 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002519 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002520 if (!p)
2521 return NULL;
2522 p->kind = Break_kind;
2523 p->lineno = lineno;
2524 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002525 p->end_lineno = end_lineno;
2526 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002527 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002528}
2529
2530stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002531_PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2532 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002533{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002534 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002535 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002536 if (!p)
2537 return NULL;
2538 p->kind = Continue_kind;
2539 p->lineno = lineno;
2540 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002541 p->end_lineno = end_lineno;
2542 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002543 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002544}
2545
2546expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002547_PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
2548 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002549{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002550 expr_ty p;
2551 if (!op) {
2552 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002553 "field 'op' is required for BoolOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002554 return NULL;
2555 }
Victor Stinner8370e072021-03-24 02:23:01 +01002556 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002557 if (!p)
2558 return NULL;
2559 p->kind = BoolOp_kind;
2560 p->v.BoolOp.op = op;
2561 p->v.BoolOp.values = values;
2562 p->lineno = lineno;
2563 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002564 p->end_lineno = end_lineno;
2565 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002566 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002567}
2568
2569expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002570_PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2571 end_lineno, int end_col_offset, PyArena *arena)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002572{
2573 expr_ty p;
2574 if (!target) {
2575 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002576 "field 'target' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002577 return NULL;
2578 }
2579 if (!value) {
2580 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002581 "field 'value' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002582 return NULL;
2583 }
Victor Stinner8370e072021-03-24 02:23:01 +01002584 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002585 if (!p)
2586 return NULL;
2587 p->kind = NamedExpr_kind;
2588 p->v.NamedExpr.target = target;
2589 p->v.NamedExpr.value = value;
2590 p->lineno = lineno;
2591 p->col_offset = col_offset;
2592 p->end_lineno = end_lineno;
2593 p->end_col_offset = end_col_offset;
2594 return p;
2595}
2596
2597expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002598_PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
2599 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002600{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002601 expr_ty p;
2602 if (!left) {
2603 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002604 "field 'left' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002605 return NULL;
2606 }
2607 if (!op) {
2608 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002609 "field 'op' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002610 return NULL;
2611 }
2612 if (!right) {
2613 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002614 "field 'right' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002615 return NULL;
2616 }
Victor Stinner8370e072021-03-24 02:23:01 +01002617 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002618 if (!p)
2619 return NULL;
2620 p->kind = BinOp_kind;
2621 p->v.BinOp.left = left;
2622 p->v.BinOp.op = op;
2623 p->v.BinOp.right = right;
2624 p->lineno = lineno;
2625 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002626 p->end_lineno = end_lineno;
2627 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002628 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002629}
2630
2631expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002632_PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2633 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002634{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002635 expr_ty p;
2636 if (!op) {
2637 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002638 "field 'op' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002639 return NULL;
2640 }
2641 if (!operand) {
2642 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002643 "field 'operand' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002644 return NULL;
2645 }
Victor Stinner8370e072021-03-24 02:23:01 +01002646 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002647 if (!p)
2648 return NULL;
2649 p->kind = UnaryOp_kind;
2650 p->v.UnaryOp.op = op;
2651 p->v.UnaryOp.operand = operand;
2652 p->lineno = lineno;
2653 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002654 p->end_lineno = end_lineno;
2655 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002656 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002657}
2658
2659expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002660_PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2661 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002662{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002663 expr_ty p;
2664 if (!args) {
2665 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002666 "field 'args' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002667 return NULL;
2668 }
2669 if (!body) {
2670 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002671 "field 'body' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002672 return NULL;
2673 }
Victor Stinner8370e072021-03-24 02:23:01 +01002674 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002675 if (!p)
2676 return NULL;
2677 p->kind = Lambda_kind;
2678 p->v.Lambda.args = args;
2679 p->v.Lambda.body = body;
2680 p->lineno = lineno;
2681 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002682 p->end_lineno = end_lineno;
2683 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002684 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002685}
2686
2687expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002688_PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
2689 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002690{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002691 expr_ty p;
2692 if (!test) {
2693 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002694 "field 'test' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002695 return NULL;
2696 }
2697 if (!body) {
2698 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002699 "field 'body' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002700 return NULL;
2701 }
2702 if (!orelse) {
2703 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002704 "field 'orelse' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002705 return NULL;
2706 }
Victor Stinner8370e072021-03-24 02:23:01 +01002707 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002708 if (!p)
2709 return NULL;
2710 p->kind = IfExp_kind;
2711 p->v.IfExp.test = test;
2712 p->v.IfExp.body = body;
2713 p->v.IfExp.orelse = orelse;
2714 p->lineno = lineno;
2715 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002716 p->end_lineno = end_lineno;
2717 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002718 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002719}
2720
2721expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002722_PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
2723 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002724{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002725 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002726 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002727 if (!p)
2728 return NULL;
2729 p->kind = Dict_kind;
2730 p->v.Dict.keys = keys;
2731 p->v.Dict.values = values;
2732 p->lineno = lineno;
2733 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002734 p->end_lineno = end_lineno;
2735 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002736 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002737}
2738
2739expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002740_PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
2741 int end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002742{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002743 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002744 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002745 if (!p)
2746 return NULL;
2747 p->kind = Set_kind;
2748 p->v.Set.elts = elts;
2749 p->lineno = lineno;
2750 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002751 p->end_lineno = end_lineno;
2752 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002753 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002754}
2755
2756expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002757_PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2758 int col_offset, int end_lineno, int end_col_offset, PyArena
2759 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002760{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002761 expr_ty p;
2762 if (!elt) {
2763 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002764 "field 'elt' is required for ListComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002765 return NULL;
2766 }
Victor Stinner8370e072021-03-24 02:23:01 +01002767 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002768 if (!p)
2769 return NULL;
2770 p->kind = ListComp_kind;
2771 p->v.ListComp.elt = elt;
2772 p->v.ListComp.generators = generators;
2773 p->lineno = lineno;
2774 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002775 p->end_lineno = end_lineno;
2776 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002777 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002778}
2779
2780expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002781_PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2782 int col_offset, int end_lineno, int end_col_offset, PyArena
2783 *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002784{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002785 expr_ty p;
2786 if (!elt) {
2787 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002788 "field 'elt' is required for SetComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002789 return NULL;
2790 }
Victor Stinner8370e072021-03-24 02:23:01 +01002791 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002792 if (!p)
2793 return NULL;
2794 p->kind = SetComp_kind;
2795 p->v.SetComp.elt = elt;
2796 p->v.SetComp.generators = generators;
2797 p->lineno = lineno;
2798 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002799 p->end_lineno = end_lineno;
2800 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002801 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002802}
2803
2804expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002805_PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
2806 generators, int lineno, int col_offset, int end_lineno, int
2807 end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002808{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002809 expr_ty p;
2810 if (!key) {
2811 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002812 "field 'key' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002813 return NULL;
2814 }
2815 if (!value) {
2816 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002817 "field 'value' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002818 return NULL;
2819 }
Victor Stinner8370e072021-03-24 02:23:01 +01002820 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002821 if (!p)
2822 return NULL;
2823 p->kind = DictComp_kind;
2824 p->v.DictComp.key = key;
2825 p->v.DictComp.value = value;
2826 p->v.DictComp.generators = generators;
2827 p->lineno = lineno;
2828 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002829 p->end_lineno = end_lineno;
2830 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002831 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002832}
2833
2834expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002835_PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
2836 lineno, int col_offset, int end_lineno, int end_col_offset,
2837 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002838{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002839 expr_ty p;
2840 if (!elt) {
2841 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002842 "field 'elt' is required for GeneratorExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002843 return NULL;
2844 }
Victor Stinner8370e072021-03-24 02:23:01 +01002845 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002846 if (!p)
2847 return NULL;
2848 p->kind = GeneratorExp_kind;
2849 p->v.GeneratorExp.elt = elt;
2850 p->v.GeneratorExp.generators = generators;
2851 p->lineno = lineno;
2852 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002853 p->end_lineno = end_lineno;
2854 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002855 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002856}
2857
2858expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002859_PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2860 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002861{
2862 expr_ty p;
2863 if (!value) {
2864 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002865 "field 'value' is required for Await");
Yury Selivanov75445082015-05-11 22:57:16 -04002866 return NULL;
2867 }
Victor Stinner8370e072021-03-24 02:23:01 +01002868 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanov75445082015-05-11 22:57:16 -04002869 if (!p)
2870 return NULL;
2871 p->kind = Await_kind;
2872 p->v.Await.value = value;
2873 p->lineno = lineno;
2874 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002875 p->end_lineno = end_lineno;
2876 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002877 return p;
2878}
2879
2880expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002881_PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2882 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002883{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002884 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002885 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002886 if (!p)
2887 return NULL;
2888 p->kind = Yield_kind;
2889 p->v.Yield.value = value;
2890 p->lineno = lineno;
2891 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002892 p->end_lineno = end_lineno;
2893 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002894 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002895}
2896
2897expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002898_PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2899 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002900{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002901 expr_ty p;
2902 if (!value) {
2903 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002904 "field 'value' is required for YieldFrom");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002905 return NULL;
2906 }
Victor Stinner8370e072021-03-24 02:23:01 +01002907 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002908 if (!p)
2909 return NULL;
2910 p->kind = YieldFrom_kind;
2911 p->v.YieldFrom.value = value;
2912 p->lineno = lineno;
2913 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002914 p->end_lineno = end_lineno;
2915 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002916 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002917}
2918
2919expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002920_PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
2921 int lineno, int col_offset, int end_lineno, int end_col_offset,
2922 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002923{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002924 expr_ty p;
2925 if (!left) {
2926 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002927 "field 'left' is required for Compare");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002928 return NULL;
2929 }
Victor Stinner8370e072021-03-24 02:23:01 +01002930 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002931 if (!p)
2932 return NULL;
2933 p->kind = Compare_kind;
2934 p->v.Compare.left = left;
2935 p->v.Compare.ops = ops;
2936 p->v.Compare.comparators = comparators;
2937 p->lineno = lineno;
2938 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002939 p->end_lineno = end_lineno;
2940 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002941 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002942}
2943
2944expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002945_PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
2946 int lineno, int col_offset, int end_lineno, int end_col_offset,
2947 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002948{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002949 expr_ty p;
2950 if (!func) {
2951 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002952 "field 'func' is required for Call");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002953 return NULL;
2954 }
Victor Stinner8370e072021-03-24 02:23:01 +01002955 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002956 if (!p)
2957 return NULL;
2958 p->kind = Call_kind;
2959 p->v.Call.func = func;
2960 p->v.Call.args = args;
2961 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002962 p->lineno = lineno;
2963 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002964 p->end_lineno = end_lineno;
2965 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002966 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002967}
2968
2969expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002970_PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
2971 lineno, int col_offset, int end_lineno, int
2972 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002973{
2974 expr_ty p;
2975 if (!value) {
2976 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002977 "field 'value' is required for FormattedValue");
Eric V. Smith235a6f02015-09-19 14:51:32 -04002978 return NULL;
2979 }
Victor Stinner8370e072021-03-24 02:23:01 +01002980 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Eric V. Smith235a6f02015-09-19 14:51:32 -04002981 if (!p)
2982 return NULL;
2983 p->kind = FormattedValue_kind;
2984 p->v.FormattedValue.value = value;
2985 p->v.FormattedValue.conversion = conversion;
2986 p->v.FormattedValue.format_spec = format_spec;
2987 p->lineno = lineno;
2988 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002989 p->end_lineno = end_lineno;
2990 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002991 return p;
2992}
2993
2994expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002995_PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
2996 end_lineno, int end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002997{
2998 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002999 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Eric V. Smith235a6f02015-09-19 14:51:32 -04003000 if (!p)
3001 return NULL;
3002 p->kind = JoinedStr_kind;
3003 p->v.JoinedStr.values = values;
3004 p->lineno = lineno;
3005 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003006 p->end_lineno = end_lineno;
3007 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003008 return p;
3009}
3010
3011expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003012_PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
3013 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003014{
3015 expr_ty p;
3016 if (!value) {
3017 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003018 "field 'value' is required for Constant");
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003019 return NULL;
3020 }
Victor Stinner8370e072021-03-24 02:23:01 +01003021 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003022 if (!p)
3023 return NULL;
3024 p->kind = Constant_kind;
3025 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003026 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003027 p->lineno = lineno;
3028 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003029 p->end_lineno = end_lineno;
3030 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003031 return p;
3032}
3033
3034expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003035_PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
3036 lineno, int col_offset, int end_lineno, int end_col_offset,
3037 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003038{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003039 expr_ty p;
3040 if (!value) {
3041 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003042 "field 'value' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003043 return NULL;
3044 }
3045 if (!attr) {
3046 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003047 "field 'attr' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003048 return NULL;
3049 }
3050 if (!ctx) {
3051 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003052 "field 'ctx' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003053 return NULL;
3054 }
Victor Stinner8370e072021-03-24 02:23:01 +01003055 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003056 if (!p)
3057 return NULL;
3058 p->kind = Attribute_kind;
3059 p->v.Attribute.value = value;
3060 p->v.Attribute.attr = attr;
3061 p->v.Attribute.ctx = ctx;
3062 p->lineno = lineno;
3063 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003064 p->end_lineno = end_lineno;
3065 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003066 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003067}
3068
3069expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003070_PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
3071 int col_offset, int end_lineno, int end_col_offset, PyArena
3072 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003073{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003074 expr_ty p;
3075 if (!value) {
3076 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003077 "field 'value' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003078 return NULL;
3079 }
3080 if (!slice) {
3081 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003082 "field 'slice' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003083 return NULL;
3084 }
3085 if (!ctx) {
3086 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003087 "field 'ctx' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003088 return NULL;
3089 }
Victor Stinner8370e072021-03-24 02:23:01 +01003090 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003091 if (!p)
3092 return NULL;
3093 p->kind = Subscript_kind;
3094 p->v.Subscript.value = value;
3095 p->v.Subscript.slice = slice;
3096 p->v.Subscript.ctx = ctx;
3097 p->lineno = lineno;
3098 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003099 p->end_lineno = end_lineno;
3100 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003101 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003102}
3103
3104expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003105_PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
3106 int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003107{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003108 expr_ty p;
3109 if (!value) {
3110 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003111 "field 'value' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003112 return NULL;
3113 }
3114 if (!ctx) {
3115 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003116 "field 'ctx' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003117 return NULL;
3118 }
Victor Stinner8370e072021-03-24 02:23:01 +01003119 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003120 if (!p)
3121 return NULL;
3122 p->kind = Starred_kind;
3123 p->v.Starred.value = value;
3124 p->v.Starred.ctx = ctx;
3125 p->lineno = lineno;
3126 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003127 p->end_lineno = end_lineno;
3128 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003129 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003130}
3131
3132expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003133_PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3134 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003135{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003136 expr_ty p;
3137 if (!id) {
3138 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003139 "field 'id' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003140 return NULL;
3141 }
3142 if (!ctx) {
3143 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003144 "field 'ctx' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003145 return NULL;
3146 }
Victor Stinner8370e072021-03-24 02:23:01 +01003147 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003148 if (!p)
3149 return NULL;
3150 p->kind = Name_kind;
3151 p->v.Name.id = id;
3152 p->v.Name.ctx = ctx;
3153 p->lineno = lineno;
3154 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003155 p->end_lineno = end_lineno;
3156 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003157 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003158}
3159
3160expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003161_PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3162 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003163{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003164 expr_ty p;
3165 if (!ctx) {
3166 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003167 "field 'ctx' is required for List");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003168 return NULL;
3169 }
Victor Stinner8370e072021-03-24 02:23:01 +01003170 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003171 if (!p)
3172 return NULL;
3173 p->kind = List_kind;
3174 p->v.List.elts = elts;
3175 p->v.List.ctx = ctx;
3176 p->lineno = lineno;
3177 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003178 p->end_lineno = end_lineno;
3179 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003180 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003181}
3182
3183expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003184_PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3185 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003186{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003187 expr_ty p;
3188 if (!ctx) {
3189 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003190 "field 'ctx' is required for Tuple");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003191 return NULL;
3192 }
Victor Stinner8370e072021-03-24 02:23:01 +01003193 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003194 if (!p)
3195 return NULL;
3196 p->kind = Tuple_kind;
3197 p->v.Tuple.elts = elts;
3198 p->v.Tuple.ctx = ctx;
3199 p->lineno = lineno;
3200 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003201 p->end_lineno = end_lineno;
3202 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003203 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003204}
3205
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003206expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003207_PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
3208 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003209{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003210 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01003211 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003212 if (!p)
3213 return NULL;
3214 p->kind = Slice_kind;
3215 p->v.Slice.lower = lower;
3216 p->v.Slice.upper = upper;
3217 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003218 p->lineno = lineno;
3219 p->col_offset = col_offset;
3220 p->end_lineno = end_lineno;
3221 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003222 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003223}
3224
3225comprehension_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003226_PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
3227 is_async, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003228{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003229 comprehension_ty p;
3230 if (!target) {
3231 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003232 "field 'target' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003233 return NULL;
3234 }
3235 if (!iter) {
3236 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003237 "field 'iter' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003238 return NULL;
3239 }
Victor Stinner8370e072021-03-24 02:23:01 +01003240 p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003241 if (!p)
3242 return NULL;
3243 p->target = target;
3244 p->iter = iter;
3245 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003246 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003247 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003248}
3249
3250excepthandler_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003251_PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
3252 lineno, int col_offset, int end_lineno, int
3253 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003254{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003255 excepthandler_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01003256 p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003257 if (!p)
3258 return NULL;
3259 p->kind = ExceptHandler_kind;
3260 p->v.ExceptHandler.type = type;
3261 p->v.ExceptHandler.name = name;
3262 p->v.ExceptHandler.body = body;
3263 p->lineno = lineno;
3264 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003265 p->end_lineno = end_lineno;
3266 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003267 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003268}
3269
3270arguments_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003271_PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
3272 vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
3273 kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
3274 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003275{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003276 arguments_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01003277 p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003278 if (!p)
3279 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003280 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003281 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003282 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003283 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003284 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003285 p->kwarg = kwarg;
3286 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003287 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003288}
3289
Neal Norwitzc1505362006-12-28 06:47:50 +00003290arg_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003291_PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
3292 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003293{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003294 arg_ty p;
3295 if (!arg) {
3296 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003297 "field 'arg' is required for arg");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003298 return NULL;
3299 }
Victor Stinner8370e072021-03-24 02:23:01 +01003300 p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003301 if (!p)
3302 return NULL;
3303 p->arg = arg;
3304 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003305 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003306 p->lineno = lineno;
3307 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003308 p->end_lineno = end_lineno;
3309 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003310 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003311}
3312
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003313keyword_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003314_PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3315 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003316{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003317 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003318 if (!value) {
3319 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003320 "field 'value' is required for keyword");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003321 return NULL;
3322 }
Victor Stinner8370e072021-03-24 02:23:01 +01003323 p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003324 if (!p)
3325 return NULL;
3326 p->arg = arg;
3327 p->value = value;
Pablo Galindo168660b2020-04-02 00:47:39 +01003328 p->lineno = lineno;
3329 p->col_offset = col_offset;
3330 p->end_lineno = end_lineno;
3331 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003332 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003333}
3334
3335alias_ty
Matthew Suozzo75a06f02021-04-10 16:56:28 -04003336_PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
3337 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003338{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003339 alias_ty p;
3340 if (!name) {
3341 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003342 "field 'name' is required for alias");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003343 return NULL;
3344 }
Victor Stinner8370e072021-03-24 02:23:01 +01003345 p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003346 if (!p)
3347 return NULL;
3348 p->name = name;
3349 p->asname = asname;
Matthew Suozzo75a06f02021-04-10 16:56:28 -04003350 p->lineno = lineno;
3351 p->col_offset = col_offset;
3352 p->end_lineno = end_lineno;
3353 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003354 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003355}
3356
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003357withitem_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003358_PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003359{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003360 withitem_ty p;
3361 if (!context_expr) {
3362 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003363 "field 'context_expr' is required for withitem");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003364 return NULL;
3365 }
Victor Stinner8370e072021-03-24 02:23:01 +01003366 p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003367 if (!p)
3368 return NULL;
3369 p->context_expr = context_expr;
3370 p->optional_vars = optional_vars;
3371 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003372}
3373
Brandt Bucher145bf262021-02-26 14:51:55 -08003374match_case_ty
Nick Coghlan1e7b8582021-04-29 15:58:44 +10003375_PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
3376 PyArena *arena)
Brandt Bucher145bf262021-02-26 14:51:55 -08003377{
3378 match_case_ty p;
3379 if (!pattern) {
3380 PyErr_SetString(PyExc_ValueError,
3381 "field 'pattern' is required for match_case");
3382 return NULL;
3383 }
Victor Stinner8370e072021-03-24 02:23:01 +01003384 p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
Brandt Bucher145bf262021-02-26 14:51:55 -08003385 if (!p)
3386 return NULL;
3387 p->pattern = pattern;
3388 p->guard = guard;
3389 p->body = body;
3390 return p;
3391}
3392
Nick Coghlan1e7b8582021-04-29 15:58:44 +10003393pattern_ty
3394_PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
3395 int end_col_offset, PyArena *arena)
3396{
3397 pattern_ty p;
3398 if (!value) {
3399 PyErr_SetString(PyExc_ValueError,
3400 "field 'value' is required for MatchValue");
3401 return NULL;
3402 }
3403 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3404 if (!p)
3405 return NULL;
3406 p->kind = MatchValue_kind;
3407 p->v.MatchValue.value = value;
3408 p->lineno = lineno;
3409 p->col_offset = col_offset;
3410 p->end_lineno = end_lineno;
3411 p->end_col_offset = end_col_offset;
3412 return p;
3413}
3414
3415pattern_ty
3416_PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
3417 end_lineno, int end_col_offset, PyArena *arena)
3418{
3419 pattern_ty p;
3420 if (!value) {
3421 PyErr_SetString(PyExc_ValueError,
3422 "field 'value' is required for MatchSingleton");
3423 return NULL;
3424 }
3425 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3426 if (!p)
3427 return NULL;
3428 p->kind = MatchSingleton_kind;
3429 p->v.MatchSingleton.value = value;
3430 p->lineno = lineno;
3431 p->col_offset = col_offset;
3432 p->end_lineno = end_lineno;
3433 p->end_col_offset = end_col_offset;
3434 return p;
3435}
3436
3437pattern_ty
3438_PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
3439 int end_lineno, int end_col_offset, PyArena *arena)
3440{
3441 pattern_ty p;
3442 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3443 if (!p)
3444 return NULL;
3445 p->kind = MatchSequence_kind;
3446 p->v.MatchSequence.patterns = patterns;
3447 p->lineno = lineno;
3448 p->col_offset = col_offset;
3449 p->end_lineno = end_lineno;
3450 p->end_col_offset = end_col_offset;
3451 return p;
3452}
3453
3454pattern_ty
3455_PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
3456 identifier rest, int lineno, int col_offset, int
3457 end_lineno, int end_col_offset, PyArena *arena)
3458{
3459 pattern_ty p;
3460 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3461 if (!p)
3462 return NULL;
3463 p->kind = MatchMapping_kind;
3464 p->v.MatchMapping.keys = keys;
3465 p->v.MatchMapping.patterns = patterns;
3466 p->v.MatchMapping.rest = rest;
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
3474pattern_ty
3475_PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
3476 * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
3477 col_offset, int end_lineno, int end_col_offset, PyArena
3478 *arena)
3479{
3480 pattern_ty p;
3481 if (!cls) {
3482 PyErr_SetString(PyExc_ValueError,
3483 "field 'cls' is required for MatchClass");
3484 return NULL;
3485 }
3486 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3487 if (!p)
3488 return NULL;
3489 p->kind = MatchClass_kind;
3490 p->v.MatchClass.cls = cls;
3491 p->v.MatchClass.patterns = patterns;
3492 p->v.MatchClass.kwd_attrs = kwd_attrs;
3493 p->v.MatchClass.kwd_patterns = kwd_patterns;
3494 p->lineno = lineno;
3495 p->col_offset = col_offset;
3496 p->end_lineno = end_lineno;
3497 p->end_col_offset = end_col_offset;
3498 return p;
3499}
3500
3501pattern_ty
3502_PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
3503 int end_col_offset, PyArena *arena)
3504{
3505 pattern_ty p;
3506 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3507 if (!p)
3508 return NULL;
3509 p->kind = MatchStar_kind;
3510 p->v.MatchStar.name = name;
3511 p->lineno = lineno;
3512 p->col_offset = col_offset;
3513 p->end_lineno = end_lineno;
3514 p->end_col_offset = end_col_offset;
3515 return p;
3516}
3517
3518pattern_ty
3519_PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
3520 int end_lineno, int end_col_offset, PyArena *arena)
3521{
3522 pattern_ty p;
3523 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3524 if (!p)
3525 return NULL;
3526 p->kind = MatchAs_kind;
3527 p->v.MatchAs.pattern = pattern;
3528 p->v.MatchAs.name = name;
3529 p->lineno = lineno;
3530 p->col_offset = col_offset;
3531 p->end_lineno = end_lineno;
3532 p->end_col_offset = end_col_offset;
3533 return p;
3534}
3535
3536pattern_ty
3537_PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
3538 end_lineno, int end_col_offset, PyArena *arena)
3539{
3540 pattern_ty p;
3541 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3542 if (!p)
3543 return NULL;
3544 p->kind = MatchOr_kind;
3545 p->v.MatchOr.patterns = patterns;
3546 p->lineno = lineno;
3547 p->col_offset = col_offset;
3548 p->end_lineno = end_lineno;
3549 p->end_col_offset = end_col_offset;
3550 return p;
3551}
3552
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003553type_ignore_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003554_PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003555{
3556 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003557 if (!tag) {
3558 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003559 "field 'tag' is required for TypeIgnore");
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003560 return NULL;
3561 }
Victor Stinner8370e072021-03-24 02:23:01 +01003562 p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003563 if (!p)
3564 return NULL;
3565 p->kind = TypeIgnore_kind;
3566 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003567 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003568 return p;
3569}
3570
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003571
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003572PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01003573ast2obj_mod(struct ast_state *state, void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003574{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003575 mod_ty o = (mod_ty)_o;
3576 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003577 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003578 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003579 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003580 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003581 switch (o->kind) {
3582 case Module_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003583 tp = (PyTypeObject *)state->Module_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003584 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003585 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003586 value = ast2obj_list(state, (asdl_seq*)o->v.Module.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003587 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003588 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003589 goto failed;
3590 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003591 value = ast2obj_list(state, (asdl_seq*)o->v.Module.type_ignores,
Victor Stinner74419f02020-07-03 11:35:37 +02003592 ast2obj_type_ignore);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003593 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003594 if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003595 goto failed;
3596 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003597 break;
3598 case Interactive_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003599 tp = (PyTypeObject *)state->Interactive_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003600 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003601 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003602 value = ast2obj_list(state, (asdl_seq*)o->v.Interactive.body,
3603 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003604 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003605 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003606 goto failed;
3607 Py_DECREF(value);
3608 break;
3609 case Expression_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003610 tp = (PyTypeObject *)state->Expression_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003611 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003612 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003613 value = ast2obj_expr(state, o->v.Expression.body);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003614 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003615 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003616 goto failed;
3617 Py_DECREF(value);
3618 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003619 case FunctionType_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003620 tp = (PyTypeObject *)state->FunctionType_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003621 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003622 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003623 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionType.argtypes,
3624 ast2obj_expr);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003625 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003626 if (PyObject_SetAttr(result, state->argtypes, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003627 goto failed;
3628 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003629 value = ast2obj_expr(state, o->v.FunctionType.returns);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003630 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003631 if (PyObject_SetAttr(result, state->returns, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003632 goto failed;
3633 Py_DECREF(value);
3634 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003635 }
3636 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003637failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003638 Py_XDECREF(value);
3639 Py_XDECREF(result);
3640 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003641}
3642
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003643PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01003644ast2obj_stmt(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003645{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003646 stmt_ty o = (stmt_ty)_o;
3647 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003648 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003649 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003650 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003651 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003652 switch (o->kind) {
3653 case FunctionDef_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003654 tp = (PyTypeObject *)state->FunctionDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003655 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003656 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003657 value = ast2obj_identifier(state, o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003658 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003659 if (PyObject_SetAttr(result, state->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003660 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003661 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003662 value = ast2obj_arguments(state, o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003663 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003664 if (PyObject_SetAttr(result, state->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003665 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003666 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003667 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.body,
3668 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003669 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003670 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003671 goto failed;
3672 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003673 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.decorator_list,
Victor Stinner74419f02020-07-03 11:35:37 +02003674 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003675 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003676 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003677 goto failed;
3678 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003679 value = ast2obj_expr(state, o->v.FunctionDef.returns);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003680 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003681 if (PyObject_SetAttr(result, state->returns, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003682 goto failed;
3683 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003684 value = ast2obj_string(state, o->v.FunctionDef.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003685 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003686 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003687 goto failed;
3688 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003689 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003690 case AsyncFunctionDef_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003691 tp = (PyTypeObject *)state->AsyncFunctionDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003692 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003693 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003694 value = ast2obj_identifier(state, o->v.AsyncFunctionDef.name);
Yury Selivanov75445082015-05-11 22:57:16 -04003695 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003696 if (PyObject_SetAttr(result, state->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003697 goto failed;
3698 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003699 value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
Yury Selivanov75445082015-05-11 22:57:16 -04003700 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003701 if (PyObject_SetAttr(result, state->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003702 goto failed;
3703 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003704 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFunctionDef.body,
3705 ast2obj_stmt);
Yury Selivanov75445082015-05-11 22:57:16 -04003706 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003707 if (PyObject_SetAttr(result, state->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003708 goto failed;
3709 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003710 value = ast2obj_list(state,
3711 (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
Yury Selivanov75445082015-05-11 22:57:16 -04003712 ast2obj_expr);
3713 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003714 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003715 goto failed;
3716 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003717 value = ast2obj_expr(state, o->v.AsyncFunctionDef.returns);
Yury Selivanov75445082015-05-11 22:57:16 -04003718 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003719 if (PyObject_SetAttr(result, state->returns, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003720 goto failed;
3721 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003722 value = ast2obj_string(state, o->v.AsyncFunctionDef.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003723 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003724 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003725 goto failed;
3726 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003727 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003728 case ClassDef_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003729 tp = (PyTypeObject *)state->ClassDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003730 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003731 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003732 value = ast2obj_identifier(state, o->v.ClassDef.name);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003733 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003734 if (PyObject_SetAttr(result, state->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003735 goto failed;
3736 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003737 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
3738 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003739 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003740 if (PyObject_SetAttr(result, state->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003741 goto failed;
3742 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003743 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.keywords,
3744 ast2obj_keyword);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003745 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003746 if (PyObject_SetAttr(result, state->keywords, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003747 goto failed;
3748 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003749 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.body,
3750 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003751 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003752 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003753 goto failed;
3754 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003755 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.decorator_list,
3756 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003757 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003758 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003759 goto failed;
3760 Py_DECREF(value);
3761 break;
3762 case Return_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003763 tp = (PyTypeObject *)state->Return_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003764 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003765 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003766 value = ast2obj_expr(state, o->v.Return.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003767 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003768 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003769 goto failed;
3770 Py_DECREF(value);
3771 break;
3772 case Delete_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003773 tp = (PyTypeObject *)state->Delete_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003774 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003775 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003776 value = ast2obj_list(state, (asdl_seq*)o->v.Delete.targets,
3777 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003778 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003779 if (PyObject_SetAttr(result, state->targets, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003780 goto failed;
3781 Py_DECREF(value);
3782 break;
3783 case Assign_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003784 tp = (PyTypeObject *)state->Assign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003785 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003786 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003787 value = ast2obj_list(state, (asdl_seq*)o->v.Assign.targets,
3788 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003789 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003790 if (PyObject_SetAttr(result, state->targets, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003791 goto failed;
3792 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003793 value = ast2obj_expr(state, o->v.Assign.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003794 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003795 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003796 goto failed;
3797 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003798 value = ast2obj_string(state, o->v.Assign.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003799 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003800 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003801 goto failed;
3802 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003803 break;
3804 case AugAssign_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003805 tp = (PyTypeObject *)state->AugAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003806 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003807 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003808 value = ast2obj_expr(state, o->v.AugAssign.target);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003809 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003810 if (PyObject_SetAttr(result, state->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003811 goto failed;
3812 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003813 value = ast2obj_operator(state, o->v.AugAssign.op);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003814 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003815 if (PyObject_SetAttr(result, state->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003816 goto failed;
3817 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003818 value = ast2obj_expr(state, o->v.AugAssign.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003819 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003820 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003821 goto failed;
3822 Py_DECREF(value);
3823 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003824 case AnnAssign_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003825 tp = (PyTypeObject *)state->AnnAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003826 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003827 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003828 value = ast2obj_expr(state, o->v.AnnAssign.target);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003829 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003830 if (PyObject_SetAttr(result, state->target, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003831 goto failed;
3832 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003833 value = ast2obj_expr(state, o->v.AnnAssign.annotation);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003834 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003835 if (PyObject_SetAttr(result, state->annotation, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003836 goto failed;
3837 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003838 value = ast2obj_expr(state, o->v.AnnAssign.value);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003839 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003840 if (PyObject_SetAttr(result, state->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003841 goto failed;
3842 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003843 value = ast2obj_int(state, o->v.AnnAssign.simple);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003844 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003845 if (PyObject_SetAttr(result, state->simple, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003846 goto failed;
3847 Py_DECREF(value);
3848 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003849 case For_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003850 tp = (PyTypeObject *)state->For_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003851 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003852 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003853 value = ast2obj_expr(state, o->v.For.target);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003854 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003855 if (PyObject_SetAttr(result, state->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003856 goto failed;
3857 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003858 value = ast2obj_expr(state, o->v.For.iter);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003859 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003860 if (PyObject_SetAttr(result, state->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003861 goto failed;
3862 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003863 value = ast2obj_list(state, (asdl_seq*)o->v.For.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003864 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003865 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003866 goto failed;
3867 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003868 value = ast2obj_list(state, (asdl_seq*)o->v.For.orelse, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003869 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003870 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003871 goto failed;
3872 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003873 value = ast2obj_string(state, o->v.For.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003874 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003875 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003876 goto failed;
3877 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003878 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003879 case AsyncFor_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003880 tp = (PyTypeObject *)state->AsyncFor_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003881 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003882 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003883 value = ast2obj_expr(state, o->v.AsyncFor.target);
Yury Selivanov75445082015-05-11 22:57:16 -04003884 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003885 if (PyObject_SetAttr(result, state->target, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003886 goto failed;
3887 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003888 value = ast2obj_expr(state, o->v.AsyncFor.iter);
Yury Selivanov75445082015-05-11 22:57:16 -04003889 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003890 if (PyObject_SetAttr(result, state->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003891 goto failed;
3892 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003893 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.body,
3894 ast2obj_stmt);
Yury Selivanov75445082015-05-11 22:57:16 -04003895 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003896 if (PyObject_SetAttr(result, state->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003897 goto failed;
3898 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003899 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.orelse,
3900 ast2obj_stmt);
Yury Selivanov75445082015-05-11 22:57:16 -04003901 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003902 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003903 goto failed;
3904 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003905 value = ast2obj_string(state, o->v.AsyncFor.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003906 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003907 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003908 goto failed;
3909 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003910 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003911 case While_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003912 tp = (PyTypeObject *)state->While_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003913 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003914 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003915 value = ast2obj_expr(state, o->v.While.test);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003916 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003917 if (PyObject_SetAttr(result, state->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003918 goto failed;
3919 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003920 value = ast2obj_list(state, (asdl_seq*)o->v.While.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003921 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003922 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003923 goto failed;
3924 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003925 value = ast2obj_list(state, (asdl_seq*)o->v.While.orelse, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003926 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003927 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003928 goto failed;
3929 Py_DECREF(value);
3930 break;
3931 case If_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003932 tp = (PyTypeObject *)state->If_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003933 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003934 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003935 value = ast2obj_expr(state, o->v.If.test);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003936 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003937 if (PyObject_SetAttr(result, state->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003938 goto failed;
3939 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003940 value = ast2obj_list(state, (asdl_seq*)o->v.If.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003941 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003942 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003943 goto failed;
3944 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003945 value = ast2obj_list(state, (asdl_seq*)o->v.If.orelse, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003946 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003947 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003948 goto failed;
3949 Py_DECREF(value);
3950 break;
3951 case With_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003952 tp = (PyTypeObject *)state->With_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003953 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003954 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003955 value = ast2obj_list(state, (asdl_seq*)o->v.With.items,
3956 ast2obj_withitem);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003957 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003958 if (PyObject_SetAttr(result, state->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003959 goto failed;
3960 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003961 value = ast2obj_list(state, (asdl_seq*)o->v.With.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003962 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003963 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003964 goto failed;
3965 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003966 value = ast2obj_string(state, o->v.With.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003967 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003968 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003969 goto failed;
3970 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003971 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003972 case AsyncWith_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003973 tp = (PyTypeObject *)state->AsyncWith_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003974 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003975 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003976 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.items,
3977 ast2obj_withitem);
Yury Selivanov75445082015-05-11 22:57:16 -04003978 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003979 if (PyObject_SetAttr(result, state->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003980 goto failed;
3981 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003982 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.body,
3983 ast2obj_stmt);
Yury Selivanov75445082015-05-11 22:57:16 -04003984 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003985 if (PyObject_SetAttr(result, state->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003986 goto failed;
3987 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003988 value = ast2obj_string(state, o->v.AsyncWith.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003989 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003990 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003991 goto failed;
3992 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003993 break;
Brandt Bucher145bf262021-02-26 14:51:55 -08003994 case Match_kind:
3995 tp = (PyTypeObject *)state->Match_type;
3996 result = PyType_GenericNew(tp, NULL, NULL);
3997 if (!result) goto failed;
3998 value = ast2obj_expr(state, o->v.Match.subject);
3999 if (!value) goto failed;
4000 if (PyObject_SetAttr(result, state->subject, value) == -1)
4001 goto failed;
4002 Py_DECREF(value);
4003 value = ast2obj_list(state, (asdl_seq*)o->v.Match.cases,
4004 ast2obj_match_case);
4005 if (!value) goto failed;
4006 if (PyObject_SetAttr(result, state->cases, value) == -1)
4007 goto failed;
4008 Py_DECREF(value);
4009 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004010 case Raise_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004011 tp = (PyTypeObject *)state->Raise_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004012 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004013 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004014 value = ast2obj_expr(state, o->v.Raise.exc);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004015 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004016 if (PyObject_SetAttr(result, state->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004017 goto failed;
4018 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004019 value = ast2obj_expr(state, o->v.Raise.cause);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004020 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004021 if (PyObject_SetAttr(result, state->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004022 goto failed;
4023 Py_DECREF(value);
4024 break;
4025 case Try_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004026 tp = (PyTypeObject *)state->Try_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004027 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004028 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004029 value = ast2obj_list(state, (asdl_seq*)o->v.Try.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004030 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004031 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004032 goto failed;
4033 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004034 value = ast2obj_list(state, (asdl_seq*)o->v.Try.handlers,
4035 ast2obj_excepthandler);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004036 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004037 if (PyObject_SetAttr(result, state->handlers, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004038 goto failed;
4039 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004040 value = ast2obj_list(state, (asdl_seq*)o->v.Try.orelse, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004041 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004042 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004043 goto failed;
4044 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004045 value = ast2obj_list(state, (asdl_seq*)o->v.Try.finalbody,
4046 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004047 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004048 if (PyObject_SetAttr(result, state->finalbody, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004049 goto failed;
4050 Py_DECREF(value);
4051 break;
4052 case Assert_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004053 tp = (PyTypeObject *)state->Assert_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004054 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004055 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004056 value = ast2obj_expr(state, o->v.Assert.test);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004057 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004058 if (PyObject_SetAttr(result, state->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004059 goto failed;
4060 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004061 value = ast2obj_expr(state, o->v.Assert.msg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004062 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004063 if (PyObject_SetAttr(result, state->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004064 goto failed;
4065 Py_DECREF(value);
4066 break;
4067 case Import_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004068 tp = (PyTypeObject *)state->Import_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004069 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004070 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004071 value = ast2obj_list(state, (asdl_seq*)o->v.Import.names,
4072 ast2obj_alias);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004073 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004074 if (PyObject_SetAttr(result, state->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004075 goto failed;
4076 Py_DECREF(value);
4077 break;
4078 case ImportFrom_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004079 tp = (PyTypeObject *)state->ImportFrom_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004080 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004081 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004082 value = ast2obj_identifier(state, o->v.ImportFrom.module);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004083 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004084 if (PyObject_SetAttr(result, state->module, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004085 goto failed;
4086 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004087 value = ast2obj_list(state, (asdl_seq*)o->v.ImportFrom.names,
4088 ast2obj_alias);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004089 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004090 if (PyObject_SetAttr(result, state->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004091 goto failed;
4092 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004093 value = ast2obj_int(state, o->v.ImportFrom.level);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004094 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004095 if (PyObject_SetAttr(result, state->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004096 goto failed;
4097 Py_DECREF(value);
4098 break;
4099 case Global_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004100 tp = (PyTypeObject *)state->Global_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004101 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004102 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004103 value = ast2obj_list(state, (asdl_seq*)o->v.Global.names,
4104 ast2obj_identifier);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004105 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004106 if (PyObject_SetAttr(result, state->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004107 goto failed;
4108 Py_DECREF(value);
4109 break;
4110 case Nonlocal_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004111 tp = (PyTypeObject *)state->Nonlocal_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004112 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004113 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004114 value = ast2obj_list(state, (asdl_seq*)o->v.Nonlocal.names,
4115 ast2obj_identifier);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004116 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004117 if (PyObject_SetAttr(result, state->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004118 goto failed;
4119 Py_DECREF(value);
4120 break;
4121 case Expr_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004122 tp = (PyTypeObject *)state->Expr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004123 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004124 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004125 value = ast2obj_expr(state, o->v.Expr.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004126 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004127 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004128 goto failed;
4129 Py_DECREF(value);
4130 break;
4131 case Pass_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004132 tp = (PyTypeObject *)state->Pass_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004133 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004134 if (!result) goto failed;
4135 break;
4136 case Break_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004137 tp = (PyTypeObject *)state->Break_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004138 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004139 if (!result) goto failed;
4140 break;
4141 case Continue_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004142 tp = (PyTypeObject *)state->Continue_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004143 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004144 if (!result) goto failed;
4145 break;
4146 }
Victor Stinner74419f02020-07-03 11:35:37 +02004147 value = ast2obj_int(state, o->lineno);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004148 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004149 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004150 goto failed;
4151 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004152 value = ast2obj_int(state, o->col_offset);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004153 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004154 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004155 goto failed;
4156 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004157 value = ast2obj_int(state, o->end_lineno);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004158 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004159 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004160 goto failed;
4161 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004162 value = ast2obj_int(state, o->end_col_offset);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004163 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004164 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004165 goto failed;
4166 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004167 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004168failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004169 Py_XDECREF(value);
4170 Py_XDECREF(result);
4171 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004172}
4173
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004174PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004175ast2obj_expr(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004176{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004177 expr_ty o = (expr_ty)_o;
4178 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004179 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004180 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004181 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004182 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004183 switch (o->kind) {
4184 case BoolOp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004185 tp = (PyTypeObject *)state->BoolOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004186 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004187 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004188 value = ast2obj_boolop(state, o->v.BoolOp.op);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004189 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004190 if (PyObject_SetAttr(result, state->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004191 goto failed;
4192 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004193 value = ast2obj_list(state, (asdl_seq*)o->v.BoolOp.values,
4194 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004195 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004196 if (PyObject_SetAttr(result, state->values, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004197 goto failed;
4198 Py_DECREF(value);
4199 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004200 case NamedExpr_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004201 tp = (PyTypeObject *)state->NamedExpr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004202 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004203 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004204 value = ast2obj_expr(state, o->v.NamedExpr.target);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004205 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004206 if (PyObject_SetAttr(result, state->target, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004207 goto failed;
4208 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004209 value = ast2obj_expr(state, o->v.NamedExpr.value);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004210 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004211 if (PyObject_SetAttr(result, state->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004212 goto failed;
4213 Py_DECREF(value);
4214 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004215 case BinOp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004216 tp = (PyTypeObject *)state->BinOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004217 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004218 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004219 value = ast2obj_expr(state, o->v.BinOp.left);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004220 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004221 if (PyObject_SetAttr(result, state->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004222 goto failed;
4223 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004224 value = ast2obj_operator(state, o->v.BinOp.op);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004225 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004226 if (PyObject_SetAttr(result, state->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004227 goto failed;
4228 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004229 value = ast2obj_expr(state, o->v.BinOp.right);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004230 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004231 if (PyObject_SetAttr(result, state->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004232 goto failed;
4233 Py_DECREF(value);
4234 break;
4235 case UnaryOp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004236 tp = (PyTypeObject *)state->UnaryOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004237 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004238 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004239 value = ast2obj_unaryop(state, o->v.UnaryOp.op);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004240 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004241 if (PyObject_SetAttr(result, state->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004242 goto failed;
4243 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004244 value = ast2obj_expr(state, o->v.UnaryOp.operand);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004245 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004246 if (PyObject_SetAttr(result, state->operand, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004247 goto failed;
4248 Py_DECREF(value);
4249 break;
4250 case Lambda_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004251 tp = (PyTypeObject *)state->Lambda_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004252 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004253 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004254 value = ast2obj_arguments(state, o->v.Lambda.args);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004255 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004256 if (PyObject_SetAttr(result, state->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004257 goto failed;
4258 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004259 value = ast2obj_expr(state, o->v.Lambda.body);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004260 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004261 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004262 goto failed;
4263 Py_DECREF(value);
4264 break;
4265 case IfExp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004266 tp = (PyTypeObject *)state->IfExp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004267 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004268 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004269 value = ast2obj_expr(state, o->v.IfExp.test);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004270 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004271 if (PyObject_SetAttr(result, state->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004272 goto failed;
4273 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004274 value = ast2obj_expr(state, o->v.IfExp.body);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004275 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004276 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004277 goto failed;
4278 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004279 value = ast2obj_expr(state, o->v.IfExp.orelse);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004280 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004281 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004282 goto failed;
4283 Py_DECREF(value);
4284 break;
4285 case Dict_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004286 tp = (PyTypeObject *)state->Dict_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004287 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004288 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004289 value = ast2obj_list(state, (asdl_seq*)o->v.Dict.keys, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004290 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004291 if (PyObject_SetAttr(result, state->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004292 goto failed;
4293 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004294 value = ast2obj_list(state, (asdl_seq*)o->v.Dict.values, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004295 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004296 if (PyObject_SetAttr(result, state->values, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004297 goto failed;
4298 Py_DECREF(value);
4299 break;
4300 case Set_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004301 tp = (PyTypeObject *)state->Set_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004302 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004303 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004304 value = ast2obj_list(state, (asdl_seq*)o->v.Set.elts, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004305 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004306 if (PyObject_SetAttr(result, state->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004307 goto failed;
4308 Py_DECREF(value);
4309 break;
4310 case ListComp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004311 tp = (PyTypeObject *)state->ListComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004312 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004313 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004314 value = ast2obj_expr(state, o->v.ListComp.elt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004315 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004316 if (PyObject_SetAttr(result, state->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004317 goto failed;
4318 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004319 value = ast2obj_list(state, (asdl_seq*)o->v.ListComp.generators,
Victor Stinner74419f02020-07-03 11:35:37 +02004320 ast2obj_comprehension);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004321 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004322 if (PyObject_SetAttr(result, state->generators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004323 goto failed;
4324 Py_DECREF(value);
4325 break;
4326 case SetComp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004327 tp = (PyTypeObject *)state->SetComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004328 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004329 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004330 value = ast2obj_expr(state, o->v.SetComp.elt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004331 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004332 if (PyObject_SetAttr(result, state->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004333 goto failed;
4334 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004335 value = ast2obj_list(state, (asdl_seq*)o->v.SetComp.generators,
Victor Stinner74419f02020-07-03 11:35:37 +02004336 ast2obj_comprehension);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004337 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004338 if (PyObject_SetAttr(result, state->generators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004339 goto failed;
4340 Py_DECREF(value);
4341 break;
4342 case DictComp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004343 tp = (PyTypeObject *)state->DictComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004344 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004345 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004346 value = ast2obj_expr(state, o->v.DictComp.key);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004347 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004348 if (PyObject_SetAttr(result, state->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004349 goto failed;
4350 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004351 value = ast2obj_expr(state, o->v.DictComp.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004352 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004353 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004354 goto failed;
4355 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004356 value = ast2obj_list(state, (asdl_seq*)o->v.DictComp.generators,
Victor Stinner74419f02020-07-03 11:35:37 +02004357 ast2obj_comprehension);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004358 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004359 if (PyObject_SetAttr(result, state->generators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004360 goto failed;
4361 Py_DECREF(value);
4362 break;
4363 case GeneratorExp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004364 tp = (PyTypeObject *)state->GeneratorExp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004365 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004366 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004367 value = ast2obj_expr(state, o->v.GeneratorExp.elt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004368 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004369 if (PyObject_SetAttr(result, state->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004370 goto failed;
4371 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004372 value = ast2obj_list(state, (asdl_seq*)o->v.GeneratorExp.generators,
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004373 ast2obj_comprehension);
4374 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004375 if (PyObject_SetAttr(result, state->generators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004376 goto failed;
4377 Py_DECREF(value);
4378 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004379 case Await_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004380 tp = (PyTypeObject *)state->Await_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004381 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004382 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004383 value = ast2obj_expr(state, o->v.Await.value);
Yury Selivanov75445082015-05-11 22:57:16 -04004384 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004385 if (PyObject_SetAttr(result, state->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004386 goto failed;
4387 Py_DECREF(value);
4388 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004389 case Yield_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004390 tp = (PyTypeObject *)state->Yield_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004391 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004392 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004393 value = ast2obj_expr(state, o->v.Yield.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004394 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004395 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004396 goto failed;
4397 Py_DECREF(value);
4398 break;
4399 case YieldFrom_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004400 tp = (PyTypeObject *)state->YieldFrom_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004401 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004402 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004403 value = ast2obj_expr(state, o->v.YieldFrom.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004404 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004405 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004406 goto failed;
4407 Py_DECREF(value);
4408 break;
4409 case Compare_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004410 tp = (PyTypeObject *)state->Compare_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004411 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004412 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004413 value = ast2obj_expr(state, o->v.Compare.left);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004414 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004415 if (PyObject_SetAttr(result, state->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004416 goto failed;
4417 Py_DECREF(value);
4418 {
4419 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4420 value = PyList_New(n);
4421 if (!value) goto failed;
4422 for(i = 0; i < n; i++)
Victor Stinner74419f02020-07-03 11:35:37 +02004423 PyList_SET_ITEM(value, i, ast2obj_cmpop(state, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004424 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004425 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004426 if (PyObject_SetAttr(result, state->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004427 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004428 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004429 value = ast2obj_list(state, (asdl_seq*)o->v.Compare.comparators,
4430 ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004431 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004432 if (PyObject_SetAttr(result, state->comparators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004433 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004434 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004435 break;
4436 case Call_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004437 tp = (PyTypeObject *)state->Call_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004438 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004439 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004440 value = ast2obj_expr(state, o->v.Call.func);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004441 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004442 if (PyObject_SetAttr(result, state->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004443 goto failed;
4444 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004445 value = ast2obj_list(state, (asdl_seq*)o->v.Call.args, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004446 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004447 if (PyObject_SetAttr(result, state->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004448 goto failed;
4449 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004450 value = ast2obj_list(state, (asdl_seq*)o->v.Call.keywords,
4451 ast2obj_keyword);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004452 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004453 if (PyObject_SetAttr(result, state->keywords, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004454 goto failed;
4455 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004456 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004457 case FormattedValue_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004458 tp = (PyTypeObject *)state->FormattedValue_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004459 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004460 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004461 value = ast2obj_expr(state, o->v.FormattedValue.value);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004462 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004463 if (PyObject_SetAttr(result, state->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004464 goto failed;
4465 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004466 value = ast2obj_int(state, o->v.FormattedValue.conversion);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004467 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004468 if (PyObject_SetAttr(result, state->conversion, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004469 goto failed;
4470 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004471 value = ast2obj_expr(state, o->v.FormattedValue.format_spec);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004472 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004473 if (PyObject_SetAttr(result, state->format_spec, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004474 goto failed;
4475 Py_DECREF(value);
4476 break;
4477 case JoinedStr_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004478 tp = (PyTypeObject *)state->JoinedStr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004479 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004480 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004481 value = ast2obj_list(state, (asdl_seq*)o->v.JoinedStr.values,
4482 ast2obj_expr);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004483 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004484 if (PyObject_SetAttr(result, state->values, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004485 goto failed;
4486 Py_DECREF(value);
4487 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004488 case Constant_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004489 tp = (PyTypeObject *)state->Constant_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004490 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004491 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004492 value = ast2obj_constant(state, o->v.Constant.value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004493 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004494 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004495 goto failed;
4496 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004497 value = ast2obj_string(state, o->v.Constant.kind);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004498 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004499 if (PyObject_SetAttr(result, state->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004500 goto failed;
4501 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004502 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004503 case Attribute_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004504 tp = (PyTypeObject *)state->Attribute_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004505 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004506 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004507 value = ast2obj_expr(state, o->v.Attribute.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004508 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004509 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004510 goto failed;
4511 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004512 value = ast2obj_identifier(state, o->v.Attribute.attr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004513 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004514 if (PyObject_SetAttr(result, state->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004515 goto failed;
4516 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004517 value = ast2obj_expr_context(state, o->v.Attribute.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004518 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004519 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004520 goto failed;
4521 Py_DECREF(value);
4522 break;
4523 case Subscript_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004524 tp = (PyTypeObject *)state->Subscript_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004525 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004526 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004527 value = ast2obj_expr(state, o->v.Subscript.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004528 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004529 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004530 goto failed;
4531 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004532 value = ast2obj_expr(state, o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004533 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004534 if (PyObject_SetAttr(result, state->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004535 goto failed;
4536 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004537 value = ast2obj_expr_context(state, o->v.Subscript.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004538 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004539 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004540 goto failed;
4541 Py_DECREF(value);
4542 break;
4543 case Starred_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004544 tp = (PyTypeObject *)state->Starred_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004545 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004546 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004547 value = ast2obj_expr(state, o->v.Starred.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004548 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004549 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004550 goto failed;
4551 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004552 value = ast2obj_expr_context(state, o->v.Starred.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004553 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004554 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004555 goto failed;
4556 Py_DECREF(value);
4557 break;
4558 case Name_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004559 tp = (PyTypeObject *)state->Name_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004560 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004561 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004562 value = ast2obj_identifier(state, o->v.Name.id);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004563 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004564 if (PyObject_SetAttr(result, state->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004565 goto failed;
4566 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004567 value = ast2obj_expr_context(state, o->v.Name.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004568 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004569 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004570 goto failed;
4571 Py_DECREF(value);
4572 break;
4573 case List_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004574 tp = (PyTypeObject *)state->List_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004575 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004576 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004577 value = ast2obj_list(state, (asdl_seq*)o->v.List.elts, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004578 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004579 if (PyObject_SetAttr(result, state->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004580 goto failed;
4581 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004582 value = ast2obj_expr_context(state, o->v.List.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004583 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004584 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004585 goto failed;
4586 Py_DECREF(value);
4587 break;
4588 case Tuple_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004589 tp = (PyTypeObject *)state->Tuple_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004590 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004591 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004592 value = ast2obj_list(state, (asdl_seq*)o->v.Tuple.elts, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004593 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004594 if (PyObject_SetAttr(result, state->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004595 goto failed;
4596 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004597 value = ast2obj_expr_context(state, o->v.Tuple.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004598 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004599 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004600 goto failed;
4601 Py_DECREF(value);
4602 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004603 case Slice_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004604 tp = (PyTypeObject *)state->Slice_type;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004605 result = PyType_GenericNew(tp, NULL, NULL);
4606 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004607 value = ast2obj_expr(state, o->v.Slice.lower);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004608 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004609 if (PyObject_SetAttr(result, state->lower, value) == -1)
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004610 goto failed;
4611 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004612 value = ast2obj_expr(state, o->v.Slice.upper);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004613 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004614 if (PyObject_SetAttr(result, state->upper, value) == -1)
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004615 goto failed;
4616 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004617 value = ast2obj_expr(state, o->v.Slice.step);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004618 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004619 if (PyObject_SetAttr(result, state->step, value) == -1)
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004620 goto failed;
4621 Py_DECREF(value);
4622 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004623 }
Victor Stinner74419f02020-07-03 11:35:37 +02004624 value = ast2obj_int(state, o->lineno);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004625 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004626 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004627 goto failed;
4628 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004629 value = ast2obj_int(state, o->col_offset);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004630 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004631 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004632 goto failed;
4633 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004634 value = ast2obj_int(state, o->end_lineno);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004635 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004636 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004637 goto failed;
4638 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004639 value = ast2obj_int(state, o->end_col_offset);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004640 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004641 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004642 goto failed;
4643 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004644 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004645failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004646 Py_XDECREF(value);
4647 Py_XDECREF(result);
4648 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004649}
4650
Victor Stinner5cf47822020-11-02 22:03:28 +01004651PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004652{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004653 switch(o) {
4654 case Load:
Victor Stinner74419f02020-07-03 11:35:37 +02004655 Py_INCREF(state->Load_singleton);
4656 return state->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004657 case Store:
Victor Stinner74419f02020-07-03 11:35:37 +02004658 Py_INCREF(state->Store_singleton);
4659 return state->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004660 case Del:
Victor Stinner74419f02020-07-03 11:35:37 +02004661 Py_INCREF(state->Del_singleton);
4662 return state->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004663 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004664 Py_UNREACHABLE();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004665}
Victor Stinner5cf47822020-11-02 22:03:28 +01004666PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004667{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004668 switch(o) {
4669 case And:
Victor Stinner74419f02020-07-03 11:35:37 +02004670 Py_INCREF(state->And_singleton);
4671 return state->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004672 case Or:
Victor Stinner74419f02020-07-03 11:35:37 +02004673 Py_INCREF(state->Or_singleton);
4674 return state->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004675 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004676 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004677}
Victor Stinner5cf47822020-11-02 22:03:28 +01004678PyObject* ast2obj_operator(struct ast_state *state, operator_ty o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004679{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004680 switch(o) {
4681 case Add:
Victor Stinner74419f02020-07-03 11:35:37 +02004682 Py_INCREF(state->Add_singleton);
4683 return state->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004684 case Sub:
Victor Stinner74419f02020-07-03 11:35:37 +02004685 Py_INCREF(state->Sub_singleton);
4686 return state->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004687 case Mult:
Victor Stinner74419f02020-07-03 11:35:37 +02004688 Py_INCREF(state->Mult_singleton);
4689 return state->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004690 case MatMult:
Victor Stinner74419f02020-07-03 11:35:37 +02004691 Py_INCREF(state->MatMult_singleton);
4692 return state->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004693 case Div:
Victor Stinner74419f02020-07-03 11:35:37 +02004694 Py_INCREF(state->Div_singleton);
4695 return state->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004696 case Mod:
Victor Stinner74419f02020-07-03 11:35:37 +02004697 Py_INCREF(state->Mod_singleton);
4698 return state->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004699 case Pow:
Victor Stinner74419f02020-07-03 11:35:37 +02004700 Py_INCREF(state->Pow_singleton);
4701 return state->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004702 case LShift:
Victor Stinner74419f02020-07-03 11:35:37 +02004703 Py_INCREF(state->LShift_singleton);
4704 return state->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004705 case RShift:
Victor Stinner74419f02020-07-03 11:35:37 +02004706 Py_INCREF(state->RShift_singleton);
4707 return state->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004708 case BitOr:
Victor Stinner74419f02020-07-03 11:35:37 +02004709 Py_INCREF(state->BitOr_singleton);
4710 return state->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004711 case BitXor:
Victor Stinner74419f02020-07-03 11:35:37 +02004712 Py_INCREF(state->BitXor_singleton);
4713 return state->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004714 case BitAnd:
Victor Stinner74419f02020-07-03 11:35:37 +02004715 Py_INCREF(state->BitAnd_singleton);
4716 return state->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004717 case FloorDiv:
Victor Stinner74419f02020-07-03 11:35:37 +02004718 Py_INCREF(state->FloorDiv_singleton);
4719 return state->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004720 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004721 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004722}
Victor Stinner5cf47822020-11-02 22:03:28 +01004723PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004724{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004725 switch(o) {
4726 case Invert:
Victor Stinner74419f02020-07-03 11:35:37 +02004727 Py_INCREF(state->Invert_singleton);
4728 return state->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004729 case Not:
Victor Stinner74419f02020-07-03 11:35:37 +02004730 Py_INCREF(state->Not_singleton);
4731 return state->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004732 case UAdd:
Victor Stinner74419f02020-07-03 11:35:37 +02004733 Py_INCREF(state->UAdd_singleton);
4734 return state->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004735 case USub:
Victor Stinner74419f02020-07-03 11:35:37 +02004736 Py_INCREF(state->USub_singleton);
4737 return state->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004738 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004739 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004740}
Victor Stinner5cf47822020-11-02 22:03:28 +01004741PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004742{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004743 switch(o) {
4744 case Eq:
Victor Stinner74419f02020-07-03 11:35:37 +02004745 Py_INCREF(state->Eq_singleton);
4746 return state->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004747 case NotEq:
Victor Stinner74419f02020-07-03 11:35:37 +02004748 Py_INCREF(state->NotEq_singleton);
4749 return state->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004750 case Lt:
Victor Stinner74419f02020-07-03 11:35:37 +02004751 Py_INCREF(state->Lt_singleton);
4752 return state->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004753 case LtE:
Victor Stinner74419f02020-07-03 11:35:37 +02004754 Py_INCREF(state->LtE_singleton);
4755 return state->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004756 case Gt:
Victor Stinner74419f02020-07-03 11:35:37 +02004757 Py_INCREF(state->Gt_singleton);
4758 return state->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004759 case GtE:
Victor Stinner74419f02020-07-03 11:35:37 +02004760 Py_INCREF(state->GtE_singleton);
4761 return state->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004762 case Is:
Victor Stinner74419f02020-07-03 11:35:37 +02004763 Py_INCREF(state->Is_singleton);
4764 return state->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004765 case IsNot:
Victor Stinner74419f02020-07-03 11:35:37 +02004766 Py_INCREF(state->IsNot_singleton);
4767 return state->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004768 case In:
Victor Stinner74419f02020-07-03 11:35:37 +02004769 Py_INCREF(state->In_singleton);
4770 return state->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004771 case NotIn:
Victor Stinner74419f02020-07-03 11:35:37 +02004772 Py_INCREF(state->NotIn_singleton);
4773 return state->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004774 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004775 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004776}
4777PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004778ast2obj_comprehension(struct ast_state *state, void* _o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004779{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004780 comprehension_ty o = (comprehension_ty)_o;
4781 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004782 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004783 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004784 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004785 }
Victor Stinner74419f02020-07-03 11:35:37 +02004786 tp = (PyTypeObject *)state->comprehension_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004787 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004788 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02004789 value = ast2obj_expr(state, o->target);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004790 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004791 if (PyObject_SetAttr(result, state->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004792 goto failed;
4793 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004794 value = ast2obj_expr(state, o->iter);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004795 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004796 if (PyObject_SetAttr(result, state->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004797 goto failed;
4798 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004799 value = ast2obj_list(state, (asdl_seq*)o->ifs, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004800 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004801 if (PyObject_SetAttr(result, state->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004802 goto failed;
4803 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004804 value = ast2obj_int(state, o->is_async);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004805 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004806 if (PyObject_SetAttr(result, state->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004807 goto failed;
4808 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004809 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004810failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004811 Py_XDECREF(value);
4812 Py_XDECREF(result);
4813 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004814}
4815
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004816PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004817ast2obj_excepthandler(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004818{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004819 excepthandler_ty o = (excepthandler_ty)_o;
4820 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004821 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004822 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004823 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004824 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004825 switch (o->kind) {
4826 case ExceptHandler_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004827 tp = (PyTypeObject *)state->ExceptHandler_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004828 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004829 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004830 value = ast2obj_expr(state, o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004831 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004832 if (PyObject_SetAttr(result, state->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004833 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004834 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004835 value = ast2obj_identifier(state, o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004836 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004837 if (PyObject_SetAttr(result, state->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004838 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004839 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004840 value = ast2obj_list(state, (asdl_seq*)o->v.ExceptHandler.body,
4841 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004842 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004843 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004844 goto failed;
4845 Py_DECREF(value);
4846 break;
4847 }
Victor Stinner74419f02020-07-03 11:35:37 +02004848 value = ast2obj_int(state, o->lineno);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004849 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004850 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004851 goto failed;
4852 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004853 value = ast2obj_int(state, o->col_offset);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004854 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004855 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004856 goto failed;
4857 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004858 value = ast2obj_int(state, o->end_lineno);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004859 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004860 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004861 goto failed;
4862 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004863 value = ast2obj_int(state, o->end_col_offset);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004864 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004865 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004866 goto failed;
4867 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004868 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004869failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004870 Py_XDECREF(value);
4871 Py_XDECREF(result);
4872 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004873}
4874
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004875PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004876ast2obj_arguments(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004877{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004878 arguments_ty o = (arguments_ty)_o;
4879 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004880 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004881 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004882 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004883 }
Victor Stinner74419f02020-07-03 11:35:37 +02004884 tp = (PyTypeObject *)state->arguments_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004885 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004886 if (!result) return NULL;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004887 value = ast2obj_list(state, (asdl_seq*)o->posonlyargs, ast2obj_arg);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004888 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004889 if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004890 goto failed;
4891 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004892 value = ast2obj_list(state, (asdl_seq*)o->args, ast2obj_arg);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004893 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004894 if (PyObject_SetAttr(result, state->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004895 goto failed;
4896 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004897 value = ast2obj_arg(state, o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004898 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004899 if (PyObject_SetAttr(result, state->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004900 goto failed;
4901 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004902 value = ast2obj_list(state, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004903 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004904 if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004905 goto failed;
4906 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004907 value = ast2obj_list(state, (asdl_seq*)o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004908 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004909 if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004910 goto failed;
4911 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004912 value = ast2obj_arg(state, o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004913 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004914 if (PyObject_SetAttr(result, state->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004915 goto failed;
4916 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004917 value = ast2obj_list(state, (asdl_seq*)o->defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004918 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004919 if (PyObject_SetAttr(result, state->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004920 goto failed;
4921 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004922 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004923failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004924 Py_XDECREF(value);
4925 Py_XDECREF(result);
4926 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004927}
4928
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004929PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004930ast2obj_arg(struct ast_state *state, void* _o)
Neal Norwitzc1505362006-12-28 06:47:50 +00004931{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004932 arg_ty o = (arg_ty)_o;
4933 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004934 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004935 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004936 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004937 }
Victor Stinner74419f02020-07-03 11:35:37 +02004938 tp = (PyTypeObject *)state->arg_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004939 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004940 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02004941 value = ast2obj_identifier(state, o->arg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004942 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004943 if (PyObject_SetAttr(result, state->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004944 goto failed;
4945 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004946 value = ast2obj_expr(state, o->annotation);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004947 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004948 if (PyObject_SetAttr(result, state->annotation, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004949 goto failed;
4950 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004951 value = ast2obj_string(state, o->type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004952 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004953 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004954 goto failed;
4955 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004956 value = ast2obj_int(state, o->lineno);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004957 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004958 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004959 goto failed;
4960 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004961 value = ast2obj_int(state, o->col_offset);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004962 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004963 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004964 goto failed;
4965 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004966 value = ast2obj_int(state, o->end_lineno);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004967 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004968 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004969 goto failed;
4970 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004971 value = ast2obj_int(state, o->end_col_offset);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004972 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004973 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004974 goto failed;
4975 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004976 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004977failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004978 Py_XDECREF(value);
4979 Py_XDECREF(result);
4980 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004981}
4982
4983PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004984ast2obj_keyword(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004985{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004986 keyword_ty o = (keyword_ty)_o;
4987 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004988 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004989 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004990 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004991 }
Victor Stinner74419f02020-07-03 11:35:37 +02004992 tp = (PyTypeObject *)state->keyword_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004993 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004994 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02004995 value = ast2obj_identifier(state, o->arg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004996 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004997 if (PyObject_SetAttr(result, state->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004998 goto failed;
4999 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005000 value = ast2obj_expr(state, o->value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005001 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005002 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005003 goto failed;
5004 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005005 value = ast2obj_int(state, o->lineno);
Pablo Galindo168660b2020-04-02 00:47:39 +01005006 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005007 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Pablo Galindo168660b2020-04-02 00:47:39 +01005008 goto failed;
5009 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005010 value = ast2obj_int(state, o->col_offset);
Pablo Galindo168660b2020-04-02 00:47:39 +01005011 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005012 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Pablo Galindo168660b2020-04-02 00:47:39 +01005013 goto failed;
5014 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005015 value = ast2obj_int(state, o->end_lineno);
Pablo Galindo168660b2020-04-02 00:47:39 +01005016 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005017 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Pablo Galindo168660b2020-04-02 00:47:39 +01005018 goto failed;
5019 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005020 value = ast2obj_int(state, o->end_col_offset);
Pablo Galindo168660b2020-04-02 00:47:39 +01005021 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005022 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Pablo Galindo168660b2020-04-02 00:47:39 +01005023 goto failed;
5024 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005025 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005026failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005027 Py_XDECREF(value);
5028 Py_XDECREF(result);
5029 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005030}
5031
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005032PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01005033ast2obj_alias(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005034{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005035 alias_ty o = (alias_ty)_o;
5036 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005037 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005038 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005039 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005040 }
Victor Stinner74419f02020-07-03 11:35:37 +02005041 tp = (PyTypeObject *)state->alias_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005042 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005043 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02005044 value = ast2obj_identifier(state, o->name);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005045 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005046 if (PyObject_SetAttr(result, state->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005047 goto failed;
5048 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005049 value = ast2obj_identifier(state, o->asname);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005050 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005051 if (PyObject_SetAttr(result, state->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005052 goto failed;
5053 Py_DECREF(value);
Matthew Suozzo75a06f02021-04-10 16:56:28 -04005054 value = ast2obj_int(state, o->lineno);
5055 if (!value) goto failed;
5056 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5057 goto failed;
5058 Py_DECREF(value);
5059 value = ast2obj_int(state, o->col_offset);
5060 if (!value) goto failed;
5061 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5062 goto failed;
5063 Py_DECREF(value);
5064 value = ast2obj_int(state, o->end_lineno);
5065 if (!value) goto failed;
5066 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5067 goto failed;
5068 Py_DECREF(value);
5069 value = ast2obj_int(state, o->end_col_offset);
5070 if (!value) goto failed;
5071 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5072 goto failed;
5073 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005074 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005075failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005076 Py_XDECREF(value);
5077 Py_XDECREF(result);
5078 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005079}
5080
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005081PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01005082ast2obj_withitem(struct ast_state *state, void* _o)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005083{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005084 withitem_ty o = (withitem_ty)_o;
5085 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005086 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005087 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005088 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005089 }
Victor Stinner74419f02020-07-03 11:35:37 +02005090 tp = (PyTypeObject *)state->withitem_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005091 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005092 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02005093 value = ast2obj_expr(state, o->context_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005094 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005095 if (PyObject_SetAttr(result, state->context_expr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005096 goto failed;
5097 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005098 value = ast2obj_expr(state, o->optional_vars);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005099 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005100 if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005101 goto failed;
5102 Py_DECREF(value);
5103 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005104failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005105 Py_XDECREF(value);
5106 Py_XDECREF(result);
5107 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005108}
5109
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005110PyObject*
Brandt Bucher145bf262021-02-26 14:51:55 -08005111ast2obj_match_case(struct ast_state *state, void* _o)
5112{
5113 match_case_ty o = (match_case_ty)_o;
5114 PyObject *result = NULL, *value = NULL;
5115 PyTypeObject *tp;
5116 if (!o) {
5117 Py_RETURN_NONE;
5118 }
5119 tp = (PyTypeObject *)state->match_case_type;
5120 result = PyType_GenericNew(tp, NULL, NULL);
5121 if (!result) return NULL;
Nick Coghlan1e7b8582021-04-29 15:58:44 +10005122 value = ast2obj_pattern(state, o->pattern);
Brandt Bucher145bf262021-02-26 14:51:55 -08005123 if (!value) goto failed;
5124 if (PyObject_SetAttr(result, state->pattern, value) == -1)
5125 goto failed;
5126 Py_DECREF(value);
5127 value = ast2obj_expr(state, o->guard);
5128 if (!value) goto failed;
5129 if (PyObject_SetAttr(result, state->guard, value) == -1)
5130 goto failed;
5131 Py_DECREF(value);
5132 value = ast2obj_list(state, (asdl_seq*)o->body, ast2obj_stmt);
5133 if (!value) goto failed;
5134 if (PyObject_SetAttr(result, state->body, value) == -1)
5135 goto failed;
5136 Py_DECREF(value);
5137 return result;
5138failed:
5139 Py_XDECREF(value);
5140 Py_XDECREF(result);
5141 return NULL;
5142}
5143
5144PyObject*
Nick Coghlan1e7b8582021-04-29 15:58:44 +10005145ast2obj_pattern(struct ast_state *state, void* _o)
5146{
5147 pattern_ty o = (pattern_ty)_o;
5148 PyObject *result = NULL, *value = NULL;
5149 PyTypeObject *tp;
5150 if (!o) {
5151 Py_RETURN_NONE;
5152 }
5153 switch (o->kind) {
5154 case MatchValue_kind:
5155 tp = (PyTypeObject *)state->MatchValue_type;
5156 result = PyType_GenericNew(tp, NULL, NULL);
5157 if (!result) goto failed;
5158 value = ast2obj_expr(state, o->v.MatchValue.value);
5159 if (!value) goto failed;
5160 if (PyObject_SetAttr(result, state->value, value) == -1)
5161 goto failed;
5162 Py_DECREF(value);
5163 break;
5164 case MatchSingleton_kind:
5165 tp = (PyTypeObject *)state->MatchSingleton_type;
5166 result = PyType_GenericNew(tp, NULL, NULL);
5167 if (!result) goto failed;
5168 value = ast2obj_constant(state, o->v.MatchSingleton.value);
5169 if (!value) goto failed;
5170 if (PyObject_SetAttr(result, state->value, value) == -1)
5171 goto failed;
5172 Py_DECREF(value);
5173 break;
5174 case MatchSequence_kind:
5175 tp = (PyTypeObject *)state->MatchSequence_type;
5176 result = PyType_GenericNew(tp, NULL, NULL);
5177 if (!result) goto failed;
5178 value = ast2obj_list(state, (asdl_seq*)o->v.MatchSequence.patterns,
5179 ast2obj_pattern);
5180 if (!value) goto failed;
5181 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5182 goto failed;
5183 Py_DECREF(value);
5184 break;
5185 case MatchMapping_kind:
5186 tp = (PyTypeObject *)state->MatchMapping_type;
5187 result = PyType_GenericNew(tp, NULL, NULL);
5188 if (!result) goto failed;
5189 value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.keys,
5190 ast2obj_expr);
5191 if (!value) goto failed;
5192 if (PyObject_SetAttr(result, state->keys, value) == -1)
5193 goto failed;
5194 Py_DECREF(value);
5195 value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.patterns,
5196 ast2obj_pattern);
5197 if (!value) goto failed;
5198 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5199 goto failed;
5200 Py_DECREF(value);
5201 value = ast2obj_identifier(state, o->v.MatchMapping.rest);
5202 if (!value) goto failed;
5203 if (PyObject_SetAttr(result, state->rest, value) == -1)
5204 goto failed;
5205 Py_DECREF(value);
5206 break;
5207 case MatchClass_kind:
5208 tp = (PyTypeObject *)state->MatchClass_type;
5209 result = PyType_GenericNew(tp, NULL, NULL);
5210 if (!result) goto failed;
5211 value = ast2obj_expr(state, o->v.MatchClass.cls);
5212 if (!value) goto failed;
5213 if (PyObject_SetAttr(result, state->cls, value) == -1)
5214 goto failed;
5215 Py_DECREF(value);
5216 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.patterns,
5217 ast2obj_pattern);
5218 if (!value) goto failed;
5219 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5220 goto failed;
5221 Py_DECREF(value);
5222 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_attrs,
5223 ast2obj_identifier);
5224 if (!value) goto failed;
5225 if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
5226 goto failed;
5227 Py_DECREF(value);
5228 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_patterns,
5229 ast2obj_pattern);
5230 if (!value) goto failed;
5231 if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
5232 goto failed;
5233 Py_DECREF(value);
5234 break;
5235 case MatchStar_kind:
5236 tp = (PyTypeObject *)state->MatchStar_type;
5237 result = PyType_GenericNew(tp, NULL, NULL);
5238 if (!result) goto failed;
5239 value = ast2obj_identifier(state, o->v.MatchStar.name);
5240 if (!value) goto failed;
5241 if (PyObject_SetAttr(result, state->name, value) == -1)
5242 goto failed;
5243 Py_DECREF(value);
5244 break;
5245 case MatchAs_kind:
5246 tp = (PyTypeObject *)state->MatchAs_type;
5247 result = PyType_GenericNew(tp, NULL, NULL);
5248 if (!result) goto failed;
5249 value = ast2obj_pattern(state, o->v.MatchAs.pattern);
5250 if (!value) goto failed;
5251 if (PyObject_SetAttr(result, state->pattern, value) == -1)
5252 goto failed;
5253 Py_DECREF(value);
5254 value = ast2obj_identifier(state, o->v.MatchAs.name);
5255 if (!value) goto failed;
5256 if (PyObject_SetAttr(result, state->name, value) == -1)
5257 goto failed;
5258 Py_DECREF(value);
5259 break;
5260 case MatchOr_kind:
5261 tp = (PyTypeObject *)state->MatchOr_type;
5262 result = PyType_GenericNew(tp, NULL, NULL);
5263 if (!result) goto failed;
5264 value = ast2obj_list(state, (asdl_seq*)o->v.MatchOr.patterns,
5265 ast2obj_pattern);
5266 if (!value) goto failed;
5267 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5268 goto failed;
5269 Py_DECREF(value);
5270 break;
5271 }
5272 value = ast2obj_int(state, o->lineno);
5273 if (!value) goto failed;
5274 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5275 goto failed;
5276 Py_DECREF(value);
5277 value = ast2obj_int(state, o->col_offset);
5278 if (!value) goto failed;
5279 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5280 goto failed;
5281 Py_DECREF(value);
5282 value = ast2obj_int(state, o->end_lineno);
5283 if (!value) goto failed;
5284 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5285 goto failed;
5286 Py_DECREF(value);
5287 value = ast2obj_int(state, o->end_col_offset);
5288 if (!value) goto failed;
5289 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5290 goto failed;
5291 Py_DECREF(value);
5292 return result;
5293failed:
5294 Py_XDECREF(value);
5295 Py_XDECREF(result);
5296 return NULL;
5297}
5298
5299PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01005300ast2obj_type_ignore(struct ast_state *state, void* _o)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005301{
5302 type_ignore_ty o = (type_ignore_ty)_o;
5303 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005304 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005305 if (!o) {
5306 Py_RETURN_NONE;
5307 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005308 switch (o->kind) {
5309 case TypeIgnore_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02005310 tp = (PyTypeObject *)state->TypeIgnore_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005311 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005312 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005313 value = ast2obj_int(state, o->v.TypeIgnore.lineno);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005314 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005315 if (PyObject_SetAttr(result, state->lineno, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005316 goto failed;
5317 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005318 value = ast2obj_string(state, o->v.TypeIgnore.tag);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005319 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005320 if (PyObject_SetAttr(result, state->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005321 goto failed;
5322 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005323 break;
5324 }
5325 return result;
5326failed:
5327 Py_XDECREF(value);
5328 Py_XDECREF(result);
5329 return NULL;
5330}
5331
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005332
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005333int
Victor Stinner5cf47822020-11-02 22:03:28 +01005334obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005335{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005336 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005337
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005338 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005339 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005340
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005341 if (obj == Py_None) {
5342 *out = NULL;
5343 return 0;
5344 }
Victor Stinner74419f02020-07-03 11:35:37 +02005345 tp = state->Module_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005346 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005347 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005348 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005349 }
5350 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01005351 asdl_stmt_seq* body;
5352 asdl_type_ignore_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005353
Victor Stinner74419f02020-07-03 11:35:37 +02005354 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005355 return 1;
5356 }
5357 if (tmp == NULL) {
5358 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5359 return 1;
5360 }
5361 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005362 int res;
5363 Py_ssize_t len;
5364 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005365 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005366 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005367 goto failed;
5368 }
5369 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005370 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005371 if (body == NULL) goto failed;
5372 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005373 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005374 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5375 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005376 if (Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5377 goto failed;
5378 }
Victor Stinner74419f02020-07-03 11:35:37 +02005379 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005380 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005381 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005382 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005383 if (len != PyList_GET_SIZE(tmp)) {
5384 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5385 goto failed;
5386 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005387 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005388 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005389 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005390 }
Victor Stinner74419f02020-07-03 11:35:37 +02005391 if (_PyObject_LookupAttr(obj, state->type_ignores, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005392 return 1;
5393 }
5394 if (tmp == NULL) {
5395 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5396 return 1;
5397 }
5398 else {
5399 int res;
5400 Py_ssize_t len;
5401 Py_ssize_t i;
5402 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005403 PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005404 goto failed;
5405 }
5406 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005407 type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005408 if (type_ignores == NULL) goto failed;
5409 for (i = 0; i < len; i++) {
5410 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005411 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5412 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005413 if (Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5414 goto failed;
5415 }
Victor Stinner74419f02020-07-03 11:35:37 +02005416 res = obj2ast_type_ignore(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005417 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005418 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005419 if (res != 0) goto failed;
5420 if (len != PyList_GET_SIZE(tmp)) {
5421 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5422 goto failed;
5423 }
5424 asdl_seq_SET(type_ignores, i, val);
5425 }
5426 Py_CLEAR(tmp);
5427 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005428 *out = _PyAST_Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005429 if (*out == NULL) goto failed;
5430 return 0;
5431 }
Victor Stinner74419f02020-07-03 11:35:37 +02005432 tp = state->Interactive_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005433 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005434 if (isinstance == -1) {
5435 return 1;
5436 }
5437 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01005438 asdl_stmt_seq* body;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005439
Victor Stinner74419f02020-07-03 11:35:37 +02005440 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005441 return 1;
5442 }
5443 if (tmp == NULL) {
5444 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5445 return 1;
5446 }
5447 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005448 int res;
5449 Py_ssize_t len;
5450 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005451 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005452 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005453 goto failed;
5454 }
5455 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005456 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005457 if (body == NULL) goto failed;
5458 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005459 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005460 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5461 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005462 if (Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
5463 goto failed;
5464 }
Victor Stinner74419f02020-07-03 11:35:37 +02005465 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005466 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005467 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005468 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005469 if (len != PyList_GET_SIZE(tmp)) {
5470 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5471 goto failed;
5472 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005473 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005474 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005475 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005476 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005477 *out = _PyAST_Interactive(body, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005478 if (*out == NULL) goto failed;
5479 return 0;
5480 }
Victor Stinner74419f02020-07-03 11:35:37 +02005481 tp = state->Expression_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005482 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005483 if (isinstance == -1) {
5484 return 1;
5485 }
5486 if (isinstance) {
5487 expr_ty body;
5488
Victor Stinner74419f02020-07-03 11:35:37 +02005489 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005490 return 1;
5491 }
5492 if (tmp == NULL) {
5493 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5494 return 1;
5495 }
5496 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005497 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005498 if (Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
5499 goto failed;
5500 }
Victor Stinner74419f02020-07-03 11:35:37 +02005501 res = obj2ast_expr(state, tmp, &body, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005502 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005503 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005504 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005505 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005506 *out = _PyAST_Expression(body, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005507 if (*out == NULL) goto failed;
5508 return 0;
5509 }
Victor Stinner74419f02020-07-03 11:35:37 +02005510 tp = state->FunctionType_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005511 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005512 if (isinstance == -1) {
5513 return 1;
5514 }
5515 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01005516 asdl_expr_seq* argtypes;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005517 expr_ty returns;
5518
Victor Stinner74419f02020-07-03 11:35:37 +02005519 if (_PyObject_LookupAttr(obj, state->argtypes, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005520 return 1;
5521 }
5522 if (tmp == NULL) {
5523 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5524 return 1;
5525 }
5526 else {
5527 int res;
5528 Py_ssize_t len;
5529 Py_ssize_t i;
5530 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005531 PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005532 goto failed;
5533 }
5534 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005535 argtypes = _Py_asdl_expr_seq_new(len, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005536 if (argtypes == NULL) goto failed;
5537 for (i = 0; i < len; i++) {
5538 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005539 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5540 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005541 if (Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5542 goto failed;
5543 }
Victor Stinner74419f02020-07-03 11:35:37 +02005544 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005545 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005546 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005547 if (res != 0) goto failed;
5548 if (len != PyList_GET_SIZE(tmp)) {
5549 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5550 goto failed;
5551 }
5552 asdl_seq_SET(argtypes, i, val);
5553 }
5554 Py_CLEAR(tmp);
5555 }
Victor Stinner74419f02020-07-03 11:35:37 +02005556 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005557 return 1;
5558 }
5559 if (tmp == NULL) {
5560 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5561 return 1;
5562 }
5563 else {
5564 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005565 if (Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5566 goto failed;
5567 }
Victor Stinner74419f02020-07-03 11:35:37 +02005568 res = obj2ast_expr(state, tmp, &returns, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005569 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005570 if (res != 0) goto failed;
5571 Py_CLEAR(tmp);
5572 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005573 *out = _PyAST_FunctionType(argtypes, returns, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005574 if (*out == NULL) goto failed;
5575 return 0;
5576 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005577
5578 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5579 failed:
5580 Py_XDECREF(tmp);
5581 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005582}
5583
5584int
Victor Stinner5cf47822020-11-02 22:03:28 +01005585obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
5586 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005587{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005588 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005589
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005590 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005591 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005592 int lineno;
5593 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005594 int end_lineno;
5595 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005596
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005597 if (obj == Py_None) {
5598 *out = NULL;
5599 return 0;
5600 }
Victor Stinner74419f02020-07-03 11:35:37 +02005601 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005602 return 1;
5603 }
5604 if (tmp == NULL) {
5605 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5606 return 1;
5607 }
5608 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005609 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005610 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5611 goto failed;
5612 }
Victor Stinner74419f02020-07-03 11:35:37 +02005613 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005614 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005615 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005616 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005617 }
Victor Stinner74419f02020-07-03 11:35:37 +02005618 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005619 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005620 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005621 if (tmp == NULL) {
5622 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5623 return 1;
5624 }
5625 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005626 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005627 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5628 goto failed;
5629 }
Victor Stinner74419f02020-07-03 11:35:37 +02005630 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005631 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005632 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005633 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005634 }
Victor Stinner74419f02020-07-03 11:35:37 +02005635 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005636 return 1;
5637 }
5638 if (tmp == NULL || tmp == Py_None) {
5639 Py_CLEAR(tmp);
5640 end_lineno = 0;
5641 }
5642 else {
5643 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005644 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5645 goto failed;
5646 }
Victor Stinner74419f02020-07-03 11:35:37 +02005647 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005648 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005649 if (res != 0) goto failed;
5650 Py_CLEAR(tmp);
5651 }
Victor Stinner74419f02020-07-03 11:35:37 +02005652 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005653 return 1;
5654 }
5655 if (tmp == NULL || tmp == Py_None) {
5656 Py_CLEAR(tmp);
5657 end_col_offset = 0;
5658 }
5659 else {
5660 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005661 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5662 goto failed;
5663 }
Victor Stinner74419f02020-07-03 11:35:37 +02005664 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005665 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005666 if (res != 0) goto failed;
5667 Py_CLEAR(tmp);
5668 }
Victor Stinner74419f02020-07-03 11:35:37 +02005669 tp = state->FunctionDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005670 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005671 if (isinstance == -1) {
5672 return 1;
5673 }
5674 if (isinstance) {
5675 identifier name;
5676 arguments_ty args;
Pablo Galindoa5634c42020-09-16 19:42:00 +01005677 asdl_stmt_seq* body;
5678 asdl_expr_seq* decorator_list;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005679 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005680 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005681
Victor Stinner74419f02020-07-03 11:35:37 +02005682 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005683 return 1;
5684 }
5685 if (tmp == NULL) {
5686 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5687 return 1;
5688 }
5689 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005690 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005691 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5692 goto failed;
5693 }
Victor Stinner74419f02020-07-03 11:35:37 +02005694 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005695 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005696 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005697 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005698 }
Victor Stinner74419f02020-07-03 11:35:37 +02005699 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005700 return 1;
5701 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005702 if (tmp == NULL) {
5703 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5704 return 1;
5705 }
5706 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005707 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005708 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5709 goto failed;
5710 }
Victor Stinner74419f02020-07-03 11:35:37 +02005711 res = obj2ast_arguments(state, tmp, &args, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005712 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005713 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005714 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005715 }
Victor Stinner74419f02020-07-03 11:35:37 +02005716 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005717 return 1;
5718 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005719 if (tmp == NULL) {
5720 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5721 return 1;
5722 }
5723 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005724 int res;
5725 Py_ssize_t len;
5726 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005727 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005728 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005729 goto failed;
5730 }
5731 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005732 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005733 if (body == NULL) goto failed;
5734 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005735 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005736 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5737 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005738 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5739 goto failed;
5740 }
Victor Stinner74419f02020-07-03 11:35:37 +02005741 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005742 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005743 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005744 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005745 if (len != PyList_GET_SIZE(tmp)) {
5746 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5747 goto failed;
5748 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005749 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005750 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005751 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005752 }
Victor Stinner74419f02020-07-03 11:35:37 +02005753 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005754 return 1;
5755 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005756 if (tmp == NULL) {
5757 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5758 return 1;
5759 }
5760 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005761 int res;
5762 Py_ssize_t len;
5763 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005764 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005765 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005766 goto failed;
5767 }
5768 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005769 decorator_list = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005770 if (decorator_list == NULL) goto failed;
5771 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005772 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005773 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5774 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005775 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5776 goto failed;
5777 }
Victor Stinner74419f02020-07-03 11:35:37 +02005778 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005779 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005780 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005781 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005782 if (len != PyList_GET_SIZE(tmp)) {
5783 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5784 goto failed;
5785 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005786 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005787 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005788 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005789 }
Victor Stinner74419f02020-07-03 11:35:37 +02005790 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005791 return 1;
5792 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005793 if (tmp == NULL || tmp == Py_None) {
5794 Py_CLEAR(tmp);
5795 returns = NULL;
5796 }
5797 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005798 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005799 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5800 goto failed;
5801 }
Victor Stinner74419f02020-07-03 11:35:37 +02005802 res = obj2ast_expr(state, tmp, &returns, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005803 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005804 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005805 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005806 }
Victor Stinner74419f02020-07-03 11:35:37 +02005807 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005808 return 1;
5809 }
5810 if (tmp == NULL || tmp == Py_None) {
5811 Py_CLEAR(tmp);
5812 type_comment = NULL;
5813 }
5814 else {
5815 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005816 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5817 goto failed;
5818 }
Victor Stinner74419f02020-07-03 11:35:37 +02005819 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005820 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005821 if (res != 0) goto failed;
5822 Py_CLEAR(tmp);
5823 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005824 *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
5825 type_comment, lineno, col_offset, end_lineno,
5826 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005827 if (*out == NULL) goto failed;
5828 return 0;
5829 }
Victor Stinner74419f02020-07-03 11:35:37 +02005830 tp = state->AsyncFunctionDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005831 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005832 if (isinstance == -1) {
5833 return 1;
5834 }
5835 if (isinstance) {
5836 identifier name;
5837 arguments_ty args;
Pablo Galindoa5634c42020-09-16 19:42:00 +01005838 asdl_stmt_seq* body;
5839 asdl_expr_seq* decorator_list;
Yury Selivanov75445082015-05-11 22:57:16 -04005840 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005841 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005842
Victor Stinner74419f02020-07-03 11:35:37 +02005843 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005844 return 1;
5845 }
5846 if (tmp == NULL) {
5847 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5848 return 1;
5849 }
5850 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005851 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005852 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5853 goto failed;
5854 }
Victor Stinner74419f02020-07-03 11:35:37 +02005855 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005856 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04005857 if (res != 0) goto failed;
5858 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005859 }
Victor Stinner74419f02020-07-03 11:35:37 +02005860 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005861 return 1;
5862 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005863 if (tmp == NULL) {
5864 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5865 return 1;
5866 }
5867 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005868 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005869 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5870 goto failed;
5871 }
Victor Stinner74419f02020-07-03 11:35:37 +02005872 res = obj2ast_arguments(state, tmp, &args, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005873 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04005874 if (res != 0) goto failed;
5875 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005876 }
Victor Stinner74419f02020-07-03 11:35:37 +02005877 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005878 return 1;
5879 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005880 if (tmp == NULL) {
5881 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5882 return 1;
5883 }
5884 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005885 int res;
5886 Py_ssize_t len;
5887 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005888 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005889 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04005890 goto failed;
5891 }
5892 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005893 body = _Py_asdl_stmt_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005894 if (body == NULL) goto failed;
5895 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005896 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005897 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5898 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005899 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5900 goto failed;
5901 }
Victor Stinner74419f02020-07-03 11:35:37 +02005902 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005903 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005904 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005905 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005906 if (len != PyList_GET_SIZE(tmp)) {
5907 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5908 goto failed;
5909 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005910 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005911 }
5912 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005913 }
Victor Stinner74419f02020-07-03 11:35:37 +02005914 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005915 return 1;
5916 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005917 if (tmp == NULL) {
5918 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5919 return 1;
5920 }
5921 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005922 int res;
5923 Py_ssize_t len;
5924 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005925 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005926 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04005927 goto failed;
5928 }
5929 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005930 decorator_list = _Py_asdl_expr_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005931 if (decorator_list == NULL) goto failed;
5932 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005933 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005934 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5935 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005936 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5937 goto failed;
5938 }
Victor Stinner74419f02020-07-03 11:35:37 +02005939 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005940 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005941 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005942 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005943 if (len != PyList_GET_SIZE(tmp)) {
5944 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5945 goto failed;
5946 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005947 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005948 }
5949 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005950 }
Victor Stinner74419f02020-07-03 11:35:37 +02005951 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005952 return 1;
5953 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005954 if (tmp == NULL || tmp == Py_None) {
5955 Py_CLEAR(tmp);
5956 returns = NULL;
5957 }
5958 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005959 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005960 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5961 goto failed;
5962 }
Victor Stinner74419f02020-07-03 11:35:37 +02005963 res = obj2ast_expr(state, tmp, &returns, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005964 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04005965 if (res != 0) goto failed;
5966 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005967 }
Victor Stinner74419f02020-07-03 11:35:37 +02005968 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005969 return 1;
5970 }
5971 if (tmp == NULL || tmp == Py_None) {
5972 Py_CLEAR(tmp);
5973 type_comment = NULL;
5974 }
5975 else {
5976 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005977 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5978 goto failed;
5979 }
Victor Stinner74419f02020-07-03 11:35:37 +02005980 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005981 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005982 if (res != 0) goto failed;
5983 Py_CLEAR(tmp);
5984 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005985 *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
5986 returns, type_comment, lineno,
5987 col_offset, end_lineno, end_col_offset,
5988 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005989 if (*out == NULL) goto failed;
5990 return 0;
5991 }
Victor Stinner74419f02020-07-03 11:35:37 +02005992 tp = state->ClassDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005993 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005994 if (isinstance == -1) {
5995 return 1;
5996 }
5997 if (isinstance) {
5998 identifier name;
Pablo Galindoa5634c42020-09-16 19:42:00 +01005999 asdl_expr_seq* bases;
6000 asdl_keyword_seq* keywords;
6001 asdl_stmt_seq* body;
6002 asdl_expr_seq* decorator_list;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006003
Victor Stinner74419f02020-07-03 11:35:37 +02006004 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006005 return 1;
6006 }
6007 if (tmp == NULL) {
6008 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
6009 return 1;
6010 }
6011 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006012 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006013 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6014 goto failed;
6015 }
Victor Stinner74419f02020-07-03 11:35:37 +02006016 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006017 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006018 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006019 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006020 }
Victor Stinner74419f02020-07-03 11:35:37 +02006021 if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006022 return 1;
6023 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006024 if (tmp == NULL) {
6025 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
6026 return 1;
6027 }
6028 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006029 int res;
6030 Py_ssize_t len;
6031 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006032 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006033 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006034 goto failed;
6035 }
6036 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006037 bases = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006038 if (bases == NULL) goto failed;
6039 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006040 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006041 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6042 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006043 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6044 goto failed;
6045 }
Victor Stinner74419f02020-07-03 11:35:37 +02006046 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006047 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006048 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006049 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006050 if (len != PyList_GET_SIZE(tmp)) {
6051 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
6052 goto failed;
6053 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006054 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006055 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006056 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006057 }
Victor Stinner74419f02020-07-03 11:35:37 +02006058 if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006059 return 1;
6060 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006061 if (tmp == NULL) {
6062 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
6063 return 1;
6064 }
6065 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006066 int res;
6067 Py_ssize_t len;
6068 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006069 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006070 PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006071 goto failed;
6072 }
6073 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006074 keywords = _Py_asdl_keyword_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006075 if (keywords == NULL) goto failed;
6076 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006077 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006078 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6079 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006080 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6081 goto failed;
6082 }
Victor Stinner74419f02020-07-03 11:35:37 +02006083 res = obj2ast_keyword(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006084 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006085 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006086 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006087 if (len != PyList_GET_SIZE(tmp)) {
6088 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
6089 goto failed;
6090 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006091 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006092 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006093 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006094 }
Victor Stinner74419f02020-07-03 11:35:37 +02006095 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006096 return 1;
6097 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006098 if (tmp == NULL) {
6099 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
6100 return 1;
6101 }
6102 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006103 int res;
6104 Py_ssize_t len;
6105 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006106 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006107 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006108 goto failed;
6109 }
6110 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006111 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006112 if (body == NULL) goto failed;
6113 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006114 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006115 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6116 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006117 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6118 goto failed;
6119 }
Victor Stinner74419f02020-07-03 11:35:37 +02006120 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006121 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006122 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006123 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006124 if (len != PyList_GET_SIZE(tmp)) {
6125 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
6126 goto failed;
6127 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006128 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006129 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006130 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006131 }
Victor Stinner74419f02020-07-03 11:35:37 +02006132 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006133 return 1;
6134 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006135 if (tmp == NULL) {
6136 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
6137 return 1;
6138 }
6139 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006140 int res;
6141 Py_ssize_t len;
6142 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006143 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006144 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006145 goto failed;
6146 }
6147 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006148 decorator_list = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006149 if (decorator_list == NULL) goto failed;
6150 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006151 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006152 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6153 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006154 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6155 goto failed;
6156 }
Victor Stinner74419f02020-07-03 11:35:37 +02006157 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006158 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006159 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006160 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006161 if (len != PyList_GET_SIZE(tmp)) {
6162 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
6163 goto failed;
6164 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006165 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006166 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006167 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006168 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006169 *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
6170 lineno, col_offset, end_lineno, end_col_offset,
6171 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006172 if (*out == NULL) goto failed;
6173 return 0;
6174 }
Victor Stinner74419f02020-07-03 11:35:37 +02006175 tp = state->Return_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006176 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006177 if (isinstance == -1) {
6178 return 1;
6179 }
6180 if (isinstance) {
6181 expr_ty value;
6182
Victor Stinner74419f02020-07-03 11:35:37 +02006183 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006184 return 1;
6185 }
6186 if (tmp == NULL || tmp == Py_None) {
6187 Py_CLEAR(tmp);
6188 value = NULL;
6189 }
6190 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006191 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006192 if (Py_EnterRecursiveCall(" while traversing 'Return' node")) {
6193 goto failed;
6194 }
Victor Stinner74419f02020-07-03 11:35:37 +02006195 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006196 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006197 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006198 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006199 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006200 *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
6201 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006202 if (*out == NULL) goto failed;
6203 return 0;
6204 }
Victor Stinner74419f02020-07-03 11:35:37 +02006205 tp = state->Delete_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006206 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006207 if (isinstance == -1) {
6208 return 1;
6209 }
6210 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01006211 asdl_expr_seq* targets;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006212
Victor Stinner74419f02020-07-03 11:35:37 +02006213 if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006214 return 1;
6215 }
6216 if (tmp == NULL) {
6217 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
6218 return 1;
6219 }
6220 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006221 int res;
6222 Py_ssize_t len;
6223 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006224 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006225 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006226 goto failed;
6227 }
6228 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006229 targets = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006230 if (targets == NULL) goto failed;
6231 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006232 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006233 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6234 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006235 if (Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
6236 goto failed;
6237 }
Victor Stinner74419f02020-07-03 11:35:37 +02006238 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006239 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006240 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006241 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006242 if (len != PyList_GET_SIZE(tmp)) {
6243 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
6244 goto failed;
6245 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006246 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006247 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006248 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006249 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006250 *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
6251 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006252 if (*out == NULL) goto failed;
6253 return 0;
6254 }
Victor Stinner74419f02020-07-03 11:35:37 +02006255 tp = state->Assign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006256 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006257 if (isinstance == -1) {
6258 return 1;
6259 }
6260 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01006261 asdl_expr_seq* targets;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006262 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006263 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006264
Victor Stinner74419f02020-07-03 11:35:37 +02006265 if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006266 return 1;
6267 }
6268 if (tmp == NULL) {
6269 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
6270 return 1;
6271 }
6272 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006273 int res;
6274 Py_ssize_t len;
6275 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006276 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006277 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006278 goto failed;
6279 }
6280 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006281 targets = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006282 if (targets == NULL) goto failed;
6283 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006284 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006285 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6286 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006287 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6288 goto failed;
6289 }
Victor Stinner74419f02020-07-03 11:35:37 +02006290 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006291 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006292 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006293 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006294 if (len != PyList_GET_SIZE(tmp)) {
6295 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
6296 goto failed;
6297 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006298 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006299 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006300 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006301 }
Victor Stinner74419f02020-07-03 11:35:37 +02006302 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006303 return 1;
6304 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006305 if (tmp == NULL) {
6306 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
6307 return 1;
6308 }
6309 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006310 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006311 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6312 goto failed;
6313 }
Victor Stinner74419f02020-07-03 11:35:37 +02006314 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006315 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006316 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006317 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006318 }
Victor Stinner74419f02020-07-03 11:35:37 +02006319 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006320 return 1;
6321 }
6322 if (tmp == NULL || tmp == Py_None) {
6323 Py_CLEAR(tmp);
6324 type_comment = NULL;
6325 }
6326 else {
6327 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006328 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6329 goto failed;
6330 }
Victor Stinner74419f02020-07-03 11:35:37 +02006331 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006332 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006333 if (res != 0) goto failed;
6334 Py_CLEAR(tmp);
6335 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006336 *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
6337 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006338 if (*out == NULL) goto failed;
6339 return 0;
6340 }
Victor Stinner74419f02020-07-03 11:35:37 +02006341 tp = state->AugAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006342 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006343 if (isinstance == -1) {
6344 return 1;
6345 }
6346 if (isinstance) {
6347 expr_ty target;
6348 operator_ty op;
6349 expr_ty value;
6350
Victor Stinner74419f02020-07-03 11:35:37 +02006351 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006352 return 1;
6353 }
6354 if (tmp == NULL) {
6355 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6356 return 1;
6357 }
6358 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006359 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006360 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6361 goto failed;
6362 }
Victor Stinner74419f02020-07-03 11:35:37 +02006363 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006364 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006365 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006366 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006367 }
Victor Stinner74419f02020-07-03 11:35:37 +02006368 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006369 return 1;
6370 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006371 if (tmp == NULL) {
6372 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6373 return 1;
6374 }
6375 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006376 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006377 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6378 goto failed;
6379 }
Victor Stinner74419f02020-07-03 11:35:37 +02006380 res = obj2ast_operator(state, tmp, &op, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006381 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006382 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006383 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006384 }
Victor Stinner74419f02020-07-03 11:35:37 +02006385 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006386 return 1;
6387 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006388 if (tmp == NULL) {
6389 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6390 return 1;
6391 }
6392 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006393 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006394 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6395 goto failed;
6396 }
Victor Stinner74419f02020-07-03 11:35:37 +02006397 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006398 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006399 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006400 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006401 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006402 *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
6403 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006404 if (*out == NULL) goto failed;
6405 return 0;
6406 }
Victor Stinner74419f02020-07-03 11:35:37 +02006407 tp = state->AnnAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006408 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006409 if (isinstance == -1) {
6410 return 1;
6411 }
6412 if (isinstance) {
6413 expr_ty target;
6414 expr_ty annotation;
6415 expr_ty value;
6416 int simple;
6417
Victor Stinner74419f02020-07-03 11:35:37 +02006418 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006419 return 1;
6420 }
6421 if (tmp == NULL) {
6422 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6423 return 1;
6424 }
6425 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006426 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006427 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6428 goto failed;
6429 }
Victor Stinner74419f02020-07-03 11:35:37 +02006430 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006431 Py_LeaveRecursiveCall();
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006432 if (res != 0) goto failed;
6433 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006434 }
Victor Stinner74419f02020-07-03 11:35:37 +02006435 if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006436 return 1;
6437 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006438 if (tmp == NULL) {
6439 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6440 return 1;
6441 }
6442 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006443 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006444 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6445 goto failed;
6446 }
Victor Stinner74419f02020-07-03 11:35:37 +02006447 res = obj2ast_expr(state, tmp, &annotation, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006448 Py_LeaveRecursiveCall();
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006449 if (res != 0) goto failed;
6450 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006451 }
Victor Stinner74419f02020-07-03 11:35:37 +02006452 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006453 return 1;
6454 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006455 if (tmp == NULL || tmp == Py_None) {
6456 Py_CLEAR(tmp);
6457 value = NULL;
6458 }
6459 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006460 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006461 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6462 goto failed;
6463 }
Victor Stinner74419f02020-07-03 11:35:37 +02006464 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006465 Py_LeaveRecursiveCall();
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006466 if (res != 0) goto failed;
6467 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006468 }
Victor Stinner74419f02020-07-03 11:35:37 +02006469 if (_PyObject_LookupAttr(obj, state->simple, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006470 return 1;
6471 }
6472 if (tmp == NULL) {
6473 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6474 return 1;
6475 }
6476 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006477 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006478 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6479 goto failed;
6480 }
Victor Stinner74419f02020-07-03 11:35:37 +02006481 res = obj2ast_int(state, tmp, &simple, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006482 Py_LeaveRecursiveCall();
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006483 if (res != 0) goto failed;
6484 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006485 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006486 *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
6487 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006488 if (*out == NULL) goto failed;
6489 return 0;
6490 }
Victor Stinner74419f02020-07-03 11:35:37 +02006491 tp = state->For_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006492 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006493 if (isinstance == -1) {
6494 return 1;
6495 }
6496 if (isinstance) {
6497 expr_ty target;
6498 expr_ty iter;
Pablo Galindoa5634c42020-09-16 19:42:00 +01006499 asdl_stmt_seq* body;
6500 asdl_stmt_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006501 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006502
Victor Stinner74419f02020-07-03 11:35:37 +02006503 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006504 return 1;
6505 }
6506 if (tmp == NULL) {
6507 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6508 return 1;
6509 }
6510 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006511 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006512 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6513 goto failed;
6514 }
Victor Stinner74419f02020-07-03 11:35:37 +02006515 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006516 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006517 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006518 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006519 }
Victor Stinner74419f02020-07-03 11:35:37 +02006520 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006521 return 1;
6522 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006523 if (tmp == NULL) {
6524 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6525 return 1;
6526 }
6527 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006528 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006529 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6530 goto failed;
6531 }
Victor Stinner74419f02020-07-03 11:35:37 +02006532 res = obj2ast_expr(state, tmp, &iter, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006533 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006534 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006535 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006536 }
Victor Stinner74419f02020-07-03 11:35:37 +02006537 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006538 return 1;
6539 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006540 if (tmp == NULL) {
6541 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6542 return 1;
6543 }
6544 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006545 int res;
6546 Py_ssize_t len;
6547 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006548 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006549 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006550 goto failed;
6551 }
6552 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006553 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006554 if (body == NULL) goto failed;
6555 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006556 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006557 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6558 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006559 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6560 goto failed;
6561 }
Victor Stinner74419f02020-07-03 11:35:37 +02006562 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006563 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006564 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006565 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006566 if (len != PyList_GET_SIZE(tmp)) {
6567 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6568 goto failed;
6569 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006570 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006571 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006572 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006573 }
Victor Stinner74419f02020-07-03 11:35:37 +02006574 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006575 return 1;
6576 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006577 if (tmp == NULL) {
6578 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6579 return 1;
6580 }
6581 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006582 int res;
6583 Py_ssize_t len;
6584 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006585 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006586 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006587 goto failed;
6588 }
6589 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006590 orelse = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006591 if (orelse == NULL) goto failed;
6592 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006593 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006594 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6595 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006596 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6597 goto failed;
6598 }
Victor Stinner74419f02020-07-03 11:35:37 +02006599 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006600 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006601 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006602 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006603 if (len != PyList_GET_SIZE(tmp)) {
6604 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6605 goto failed;
6606 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006607 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006608 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006609 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006610 }
Victor Stinner74419f02020-07-03 11:35:37 +02006611 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006612 return 1;
6613 }
6614 if (tmp == NULL || tmp == Py_None) {
6615 Py_CLEAR(tmp);
6616 type_comment = NULL;
6617 }
6618 else {
6619 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006620 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6621 goto failed;
6622 }
Victor Stinner74419f02020-07-03 11:35:37 +02006623 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006624 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006625 if (res != 0) goto failed;
6626 Py_CLEAR(tmp);
6627 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006628 *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
6629 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006630 if (*out == NULL) goto failed;
6631 return 0;
6632 }
Victor Stinner74419f02020-07-03 11:35:37 +02006633 tp = state->AsyncFor_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006634 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006635 if (isinstance == -1) {
6636 return 1;
6637 }
6638 if (isinstance) {
6639 expr_ty target;
6640 expr_ty iter;
Pablo Galindoa5634c42020-09-16 19:42:00 +01006641 asdl_stmt_seq* body;
6642 asdl_stmt_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006643 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006644
Victor Stinner74419f02020-07-03 11:35:37 +02006645 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006646 return 1;
6647 }
6648 if (tmp == NULL) {
6649 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6650 return 1;
6651 }
6652 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006653 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006654 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6655 goto failed;
6656 }
Victor Stinner74419f02020-07-03 11:35:37 +02006657 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006658 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04006659 if (res != 0) goto failed;
6660 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006661 }
Victor Stinner74419f02020-07-03 11:35:37 +02006662 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006663 return 1;
6664 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006665 if (tmp == NULL) {
6666 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6667 return 1;
6668 }
6669 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006670 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006671 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6672 goto failed;
6673 }
Victor Stinner74419f02020-07-03 11:35:37 +02006674 res = obj2ast_expr(state, tmp, &iter, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006675 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04006676 if (res != 0) goto failed;
6677 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006678 }
Victor Stinner74419f02020-07-03 11:35:37 +02006679 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006680 return 1;
6681 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006682 if (tmp == NULL) {
6683 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6684 return 1;
6685 }
6686 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006687 int res;
6688 Py_ssize_t len;
6689 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006690 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006691 PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04006692 goto failed;
6693 }
6694 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006695 body = _Py_asdl_stmt_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006696 if (body == NULL) goto failed;
6697 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006698 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006699 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6700 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006701 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6702 goto failed;
6703 }
Victor Stinner74419f02020-07-03 11:35:37 +02006704 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006705 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006706 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006707 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006708 if (len != PyList_GET_SIZE(tmp)) {
6709 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6710 goto failed;
6711 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006712 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006713 }
6714 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006715 }
Victor Stinner74419f02020-07-03 11:35:37 +02006716 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006717 return 1;
6718 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006719 if (tmp == NULL) {
6720 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6721 return 1;
6722 }
6723 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006724 int res;
6725 Py_ssize_t len;
6726 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006727 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006728 PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04006729 goto failed;
6730 }
6731 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006732 orelse = _Py_asdl_stmt_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006733 if (orelse == NULL) goto failed;
6734 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006735 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006736 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6737 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006738 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6739 goto failed;
6740 }
Victor Stinner74419f02020-07-03 11:35:37 +02006741 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006742 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006743 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006744 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006745 if (len != PyList_GET_SIZE(tmp)) {
6746 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6747 goto failed;
6748 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006749 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006750 }
6751 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006752 }
Victor Stinner74419f02020-07-03 11:35:37 +02006753 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006754 return 1;
6755 }
6756 if (tmp == NULL || tmp == Py_None) {
6757 Py_CLEAR(tmp);
6758 type_comment = NULL;
6759 }
6760 else {
6761 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006762 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6763 goto failed;
6764 }
Victor Stinner74419f02020-07-03 11:35:37 +02006765 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006766 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006767 if (res != 0) goto failed;
6768 Py_CLEAR(tmp);
6769 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006770 *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
6771 lineno, col_offset, end_lineno, end_col_offset,
6772 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006773 if (*out == NULL) goto failed;
6774 return 0;
6775 }
Victor Stinner74419f02020-07-03 11:35:37 +02006776 tp = state->While_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006777 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006778 if (isinstance == -1) {
6779 return 1;
6780 }
6781 if (isinstance) {
6782 expr_ty test;
Pablo Galindoa5634c42020-09-16 19:42:00 +01006783 asdl_stmt_seq* body;
6784 asdl_stmt_seq* orelse;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006785
Victor Stinner74419f02020-07-03 11:35:37 +02006786 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006787 return 1;
6788 }
6789 if (tmp == NULL) {
6790 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6791 return 1;
6792 }
6793 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006794 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006795 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6796 goto failed;
6797 }
Victor Stinner74419f02020-07-03 11:35:37 +02006798 res = obj2ast_expr(state, tmp, &test, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006799 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006800 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006801 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006802 }
Victor Stinner74419f02020-07-03 11:35:37 +02006803 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006804 return 1;
6805 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006806 if (tmp == NULL) {
6807 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6808 return 1;
6809 }
6810 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006811 int res;
6812 Py_ssize_t len;
6813 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006814 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006815 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006816 goto failed;
6817 }
6818 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006819 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006820 if (body == NULL) goto failed;
6821 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006822 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006823 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6824 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006825 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6826 goto failed;
6827 }
Victor Stinner74419f02020-07-03 11:35:37 +02006828 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006829 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006830 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006831 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006832 if (len != PyList_GET_SIZE(tmp)) {
6833 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6834 goto failed;
6835 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006836 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006837 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006838 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006839 }
Victor Stinner74419f02020-07-03 11:35:37 +02006840 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006841 return 1;
6842 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006843 if (tmp == NULL) {
6844 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6845 return 1;
6846 }
6847 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006848 int res;
6849 Py_ssize_t len;
6850 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006851 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006852 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006853 goto failed;
6854 }
6855 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006856 orelse = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006857 if (orelse == NULL) goto failed;
6858 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006859 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006860 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6861 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006862 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6863 goto failed;
6864 }
Victor Stinner74419f02020-07-03 11:35:37 +02006865 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006866 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006867 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006868 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006869 if (len != PyList_GET_SIZE(tmp)) {
6870 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6871 goto failed;
6872 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006873 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006874 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006875 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006876 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006877 *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
6878 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006879 if (*out == NULL) goto failed;
6880 return 0;
6881 }
Victor Stinner74419f02020-07-03 11:35:37 +02006882 tp = state->If_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006883 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006884 if (isinstance == -1) {
6885 return 1;
6886 }
6887 if (isinstance) {
6888 expr_ty test;
Pablo Galindoa5634c42020-09-16 19:42:00 +01006889 asdl_stmt_seq* body;
6890 asdl_stmt_seq* orelse;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006891
Victor Stinner74419f02020-07-03 11:35:37 +02006892 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006893 return 1;
6894 }
6895 if (tmp == NULL) {
6896 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6897 return 1;
6898 }
6899 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006900 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006901 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6902 goto failed;
6903 }
Victor Stinner74419f02020-07-03 11:35:37 +02006904 res = obj2ast_expr(state, tmp, &test, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006905 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006906 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006907 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006908 }
Victor Stinner74419f02020-07-03 11:35:37 +02006909 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006910 return 1;
6911 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006912 if (tmp == NULL) {
6913 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6914 return 1;
6915 }
6916 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006917 int res;
6918 Py_ssize_t len;
6919 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006920 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006921 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006922 goto failed;
6923 }
6924 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006925 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006926 if (body == NULL) goto failed;
6927 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006928 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006929 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6930 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006931 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6932 goto failed;
6933 }
Victor Stinner74419f02020-07-03 11:35:37 +02006934 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006935 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006936 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006937 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006938 if (len != PyList_GET_SIZE(tmp)) {
6939 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6940 goto failed;
6941 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006942 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006943 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006944 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006945 }
Victor Stinner74419f02020-07-03 11:35:37 +02006946 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006947 return 1;
6948 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006949 if (tmp == NULL) {
6950 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6951 return 1;
6952 }
6953 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006954 int res;
6955 Py_ssize_t len;
6956 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006957 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006958 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006959 goto failed;
6960 }
6961 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006962 orelse = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006963 if (orelse == NULL) goto failed;
6964 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006965 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006966 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6967 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006968 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6969 goto failed;
6970 }
Victor Stinner74419f02020-07-03 11:35:37 +02006971 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006972 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006973 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006974 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006975 if (len != PyList_GET_SIZE(tmp)) {
6976 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6977 goto failed;
6978 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006979 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006980 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006981 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006982 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006983 *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
6984 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006985 if (*out == NULL) goto failed;
6986 return 0;
6987 }
Victor Stinner74419f02020-07-03 11:35:37 +02006988 tp = state->With_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006989 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006990 if (isinstance == -1) {
6991 return 1;
6992 }
6993 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01006994 asdl_withitem_seq* items;
6995 asdl_stmt_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006996 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006997
Victor Stinner74419f02020-07-03 11:35:37 +02006998 if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006999 return 1;
7000 }
7001 if (tmp == NULL) {
7002 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
7003 return 1;
7004 }
7005 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007006 int res;
7007 Py_ssize_t len;
7008 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007009 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007010 PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007011 goto failed;
7012 }
7013 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007014 items = _Py_asdl_withitem_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007015 if (items == NULL) goto failed;
7016 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007017 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007018 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7019 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007020 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7021 goto failed;
7022 }
Victor Stinner74419f02020-07-03 11:35:37 +02007023 res = obj2ast_withitem(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007024 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007025 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007026 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007027 if (len != PyList_GET_SIZE(tmp)) {
7028 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
7029 goto failed;
7030 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007031 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007032 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007033 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007034 }
Victor Stinner74419f02020-07-03 11:35:37 +02007035 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007036 return 1;
7037 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007038 if (tmp == NULL) {
7039 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
7040 return 1;
7041 }
7042 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007043 int res;
7044 Py_ssize_t len;
7045 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007046 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007047 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007048 goto failed;
7049 }
7050 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007051 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007052 if (body == NULL) goto failed;
7053 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007054 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007055 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7056 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007057 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7058 goto failed;
7059 }
Victor Stinner74419f02020-07-03 11:35:37 +02007060 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007061 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007062 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007063 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007064 if (len != PyList_GET_SIZE(tmp)) {
7065 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
7066 goto failed;
7067 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007068 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007069 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007070 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007071 }
Victor Stinner74419f02020-07-03 11:35:37 +02007072 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007073 return 1;
7074 }
7075 if (tmp == NULL || tmp == Py_None) {
7076 Py_CLEAR(tmp);
7077 type_comment = NULL;
7078 }
7079 else {
7080 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007081 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7082 goto failed;
7083 }
Victor Stinner74419f02020-07-03 11:35:37 +02007084 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007085 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007086 if (res != 0) goto failed;
7087 Py_CLEAR(tmp);
7088 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007089 *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
7090 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007091 if (*out == NULL) goto failed;
7092 return 0;
7093 }
Victor Stinner74419f02020-07-03 11:35:37 +02007094 tp = state->AsyncWith_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007095 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007096 if (isinstance == -1) {
7097 return 1;
7098 }
7099 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007100 asdl_withitem_seq* items;
7101 asdl_stmt_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007102 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04007103
Victor Stinner74419f02020-07-03 11:35:37 +02007104 if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007105 return 1;
7106 }
7107 if (tmp == NULL) {
7108 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
7109 return 1;
7110 }
7111 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007112 int res;
7113 Py_ssize_t len;
7114 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04007115 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007116 PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04007117 goto failed;
7118 }
7119 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007120 items = _Py_asdl_withitem_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007121 if (items == NULL) goto failed;
7122 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007123 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007124 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7125 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007126 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7127 goto failed;
7128 }
Victor Stinner74419f02020-07-03 11:35:37 +02007129 res = obj2ast_withitem(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007130 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007131 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04007132 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007133 if (len != PyList_GET_SIZE(tmp)) {
7134 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
7135 goto failed;
7136 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007137 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04007138 }
7139 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007140 }
Victor Stinner74419f02020-07-03 11:35:37 +02007141 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04007142 return 1;
7143 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007144 if (tmp == NULL) {
7145 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
7146 return 1;
7147 }
7148 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007149 int res;
7150 Py_ssize_t len;
7151 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04007152 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007153 PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04007154 goto failed;
7155 }
7156 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007157 body = _Py_asdl_stmt_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007158 if (body == NULL) goto failed;
7159 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007160 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007161 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7162 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007163 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7164 goto failed;
7165 }
Victor Stinner74419f02020-07-03 11:35:37 +02007166 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007167 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007168 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04007169 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007170 if (len != PyList_GET_SIZE(tmp)) {
7171 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
7172 goto failed;
7173 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007174 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04007175 }
7176 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007177 }
Victor Stinner74419f02020-07-03 11:35:37 +02007178 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007179 return 1;
7180 }
7181 if (tmp == NULL || tmp == Py_None) {
7182 Py_CLEAR(tmp);
7183 type_comment = NULL;
7184 }
7185 else {
7186 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007187 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7188 goto failed;
7189 }
Victor Stinner74419f02020-07-03 11:35:37 +02007190 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007191 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007192 if (res != 0) goto failed;
7193 Py_CLEAR(tmp);
7194 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007195 *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
7196 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007197 if (*out == NULL) goto failed;
7198 return 0;
7199 }
Brandt Bucher145bf262021-02-26 14:51:55 -08007200 tp = state->Match_type;
7201 isinstance = PyObject_IsInstance(obj, tp);
7202 if (isinstance == -1) {
7203 return 1;
7204 }
7205 if (isinstance) {
7206 expr_ty subject;
7207 asdl_match_case_seq* cases;
7208
7209 if (_PyObject_LookupAttr(obj, state->subject, &tmp) < 0) {
7210 return 1;
7211 }
7212 if (tmp == NULL) {
7213 PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
7214 return 1;
7215 }
7216 else {
7217 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007218 if (Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7219 goto failed;
7220 }
Brandt Bucher145bf262021-02-26 14:51:55 -08007221 res = obj2ast_expr(state, tmp, &subject, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007222 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -08007223 if (res != 0) goto failed;
7224 Py_CLEAR(tmp);
7225 }
7226 if (_PyObject_LookupAttr(obj, state->cases, &tmp) < 0) {
7227 return 1;
7228 }
7229 if (tmp == NULL) {
7230 PyErr_SetString(PyExc_TypeError, "required field \"cases\" missing from Match");
7231 return 1;
7232 }
7233 else {
7234 int res;
7235 Py_ssize_t len;
7236 Py_ssize_t i;
7237 if (!PyList_Check(tmp)) {
7238 PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7239 goto failed;
7240 }
7241 len = PyList_GET_SIZE(tmp);
7242 cases = _Py_asdl_match_case_seq_new(len, arena);
7243 if (cases == NULL) goto failed;
7244 for (i = 0; i < len; i++) {
7245 match_case_ty val;
7246 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7247 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007248 if (Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7249 goto failed;
7250 }
Brandt Bucher145bf262021-02-26 14:51:55 -08007251 res = obj2ast_match_case(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007252 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -08007253 Py_DECREF(tmp2);
7254 if (res != 0) goto failed;
7255 if (len != PyList_GET_SIZE(tmp)) {
7256 PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
7257 goto failed;
7258 }
7259 asdl_seq_SET(cases, i, val);
7260 }
7261 Py_CLEAR(tmp);
7262 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007263 *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
7264 end_col_offset, arena);
Brandt Bucher145bf262021-02-26 14:51:55 -08007265 if (*out == NULL) goto failed;
7266 return 0;
7267 }
Victor Stinner74419f02020-07-03 11:35:37 +02007268 tp = state->Raise_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007269 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007270 if (isinstance == -1) {
7271 return 1;
7272 }
7273 if (isinstance) {
7274 expr_ty exc;
7275 expr_ty cause;
7276
Victor Stinner74419f02020-07-03 11:35:37 +02007277 if (_PyObject_LookupAttr(obj, state->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007278 return 1;
7279 }
7280 if (tmp == NULL || tmp == Py_None) {
7281 Py_CLEAR(tmp);
7282 exc = NULL;
7283 }
7284 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007285 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007286 if (Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7287 goto failed;
7288 }
Victor Stinner74419f02020-07-03 11:35:37 +02007289 res = obj2ast_expr(state, tmp, &exc, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007290 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007291 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007292 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007293 }
Victor Stinner74419f02020-07-03 11:35:37 +02007294 if (_PyObject_LookupAttr(obj, state->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007295 return 1;
7296 }
7297 if (tmp == NULL || tmp == Py_None) {
7298 Py_CLEAR(tmp);
7299 cause = NULL;
7300 }
7301 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007302 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007303 if (Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7304 goto failed;
7305 }
Victor Stinner74419f02020-07-03 11:35:37 +02007306 res = obj2ast_expr(state, tmp, &cause, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007307 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007308 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007309 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007310 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007311 *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
7312 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007313 if (*out == NULL) goto failed;
7314 return 0;
7315 }
Victor Stinner74419f02020-07-03 11:35:37 +02007316 tp = state->Try_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007317 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007318 if (isinstance == -1) {
7319 return 1;
7320 }
7321 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007322 asdl_stmt_seq* body;
7323 asdl_excepthandler_seq* handlers;
7324 asdl_stmt_seq* orelse;
7325 asdl_stmt_seq* finalbody;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007326
Victor Stinner74419f02020-07-03 11:35:37 +02007327 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007328 return 1;
7329 }
7330 if (tmp == NULL) {
7331 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
7332 return 1;
7333 }
7334 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007335 int res;
7336 Py_ssize_t len;
7337 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007338 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007339 PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007340 goto failed;
7341 }
7342 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007343 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007344 if (body == NULL) goto failed;
7345 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007346 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007347 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7348 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007349 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7350 goto failed;
7351 }
Victor Stinner74419f02020-07-03 11:35:37 +02007352 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007353 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007354 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007355 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007356 if (len != PyList_GET_SIZE(tmp)) {
7357 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
7358 goto failed;
7359 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007360 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007361 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007362 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007363 }
Victor Stinner74419f02020-07-03 11:35:37 +02007364 if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007365 return 1;
7366 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007367 if (tmp == NULL) {
7368 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
7369 return 1;
7370 }
7371 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007372 int res;
7373 Py_ssize_t len;
7374 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007375 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007376 PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007377 goto failed;
7378 }
7379 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007380 handlers = _Py_asdl_excepthandler_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007381 if (handlers == NULL) goto failed;
7382 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007383 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007384 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7385 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007386 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7387 goto failed;
7388 }
Victor Stinner74419f02020-07-03 11:35:37 +02007389 res = obj2ast_excepthandler(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007390 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007391 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007392 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007393 if (len != PyList_GET_SIZE(tmp)) {
7394 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
7395 goto failed;
7396 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007397 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007398 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007399 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007400 }
Victor Stinner74419f02020-07-03 11:35:37 +02007401 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007402 return 1;
7403 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007404 if (tmp == NULL) {
7405 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
7406 return 1;
7407 }
7408 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007409 int res;
7410 Py_ssize_t len;
7411 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007412 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007413 PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007414 goto failed;
7415 }
7416 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007417 orelse = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007418 if (orelse == NULL) goto failed;
7419 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007420 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007421 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7422 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007423 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7424 goto failed;
7425 }
Victor Stinner74419f02020-07-03 11:35:37 +02007426 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007427 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007428 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007429 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007430 if (len != PyList_GET_SIZE(tmp)) {
7431 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
7432 goto failed;
7433 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007434 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007435 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007436 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007437 }
Victor Stinner74419f02020-07-03 11:35:37 +02007438 if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007439 return 1;
7440 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007441 if (tmp == NULL) {
7442 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
7443 return 1;
7444 }
7445 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007446 int res;
7447 Py_ssize_t len;
7448 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007449 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007450 PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007451 goto failed;
7452 }
7453 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007454 finalbody = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007455 if (finalbody == NULL) goto failed;
7456 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007457 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007458 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7459 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007460 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7461 goto failed;
7462 }
Victor Stinner74419f02020-07-03 11:35:37 +02007463 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007464 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007465 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007466 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007467 if (len != PyList_GET_SIZE(tmp)) {
7468 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
7469 goto failed;
7470 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007471 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007472 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007473 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007474 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007475 *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
7476 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007477 if (*out == NULL) goto failed;
7478 return 0;
7479 }
Victor Stinner74419f02020-07-03 11:35:37 +02007480 tp = state->Assert_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007481 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007482 if (isinstance == -1) {
7483 return 1;
7484 }
7485 if (isinstance) {
7486 expr_ty test;
7487 expr_ty msg;
7488
Victor Stinner74419f02020-07-03 11:35:37 +02007489 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007490 return 1;
7491 }
7492 if (tmp == NULL) {
7493 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
7494 return 1;
7495 }
7496 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007497 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007498 if (Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
7499 goto failed;
7500 }
Victor Stinner74419f02020-07-03 11:35:37 +02007501 res = obj2ast_expr(state, tmp, &test, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007502 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007503 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007504 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007505 }
Victor Stinner74419f02020-07-03 11:35:37 +02007506 if (_PyObject_LookupAttr(obj, state->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007507 return 1;
7508 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007509 if (tmp == NULL || tmp == Py_None) {
7510 Py_CLEAR(tmp);
7511 msg = NULL;
7512 }
7513 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007514 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007515 if (Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
7516 goto failed;
7517 }
Victor Stinner74419f02020-07-03 11:35:37 +02007518 res = obj2ast_expr(state, tmp, &msg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007519 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007520 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007521 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007522 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007523 *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
7524 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007525 if (*out == NULL) goto failed;
7526 return 0;
7527 }
Victor Stinner74419f02020-07-03 11:35:37 +02007528 tp = state->Import_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007529 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007530 if (isinstance == -1) {
7531 return 1;
7532 }
7533 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007534 asdl_alias_seq* names;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007535
Victor Stinner74419f02020-07-03 11:35:37 +02007536 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007537 return 1;
7538 }
7539 if (tmp == NULL) {
7540 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
7541 return 1;
7542 }
7543 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007544 int res;
7545 Py_ssize_t len;
7546 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007547 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007548 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007549 goto failed;
7550 }
7551 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007552 names = _Py_asdl_alias_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007553 if (names == NULL) goto failed;
7554 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007555 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007556 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7557 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007558 if (Py_EnterRecursiveCall(" while traversing 'Import' node")) {
7559 goto failed;
7560 }
Victor Stinner74419f02020-07-03 11:35:37 +02007561 res = obj2ast_alias(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007562 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007563 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007564 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007565 if (len != PyList_GET_SIZE(tmp)) {
7566 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
7567 goto failed;
7568 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007569 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007570 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007571 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007572 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007573 *out = _PyAST_Import(names, lineno, col_offset, end_lineno,
7574 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007575 if (*out == NULL) goto failed;
7576 return 0;
7577 }
Victor Stinner74419f02020-07-03 11:35:37 +02007578 tp = state->ImportFrom_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007579 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007580 if (isinstance == -1) {
7581 return 1;
7582 }
7583 if (isinstance) {
7584 identifier module;
Pablo Galindoa5634c42020-09-16 19:42:00 +01007585 asdl_alias_seq* names;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007586 int level;
7587
Victor Stinner74419f02020-07-03 11:35:37 +02007588 if (_PyObject_LookupAttr(obj, state->module, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007589 return 1;
7590 }
7591 if (tmp == NULL || tmp == Py_None) {
7592 Py_CLEAR(tmp);
7593 module = NULL;
7594 }
7595 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007596 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007597 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7598 goto failed;
7599 }
Victor Stinner74419f02020-07-03 11:35:37 +02007600 res = obj2ast_identifier(state, tmp, &module, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007601 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007602 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007603 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007604 }
Victor Stinner74419f02020-07-03 11:35:37 +02007605 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007606 return 1;
7607 }
7608 if (tmp == NULL) {
7609 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7610 return 1;
7611 }
7612 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007613 int res;
7614 Py_ssize_t len;
7615 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007616 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007617 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007618 goto failed;
7619 }
7620 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007621 names = _Py_asdl_alias_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007622 if (names == NULL) goto failed;
7623 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007624 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007625 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7626 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007627 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7628 goto failed;
7629 }
Victor Stinner74419f02020-07-03 11:35:37 +02007630 res = obj2ast_alias(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007631 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007632 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007633 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007634 if (len != PyList_GET_SIZE(tmp)) {
7635 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7636 goto failed;
7637 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007638 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007639 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007640 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007641 }
Victor Stinner74419f02020-07-03 11:35:37 +02007642 if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007643 return 1;
7644 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007645 if (tmp == NULL || tmp == Py_None) {
7646 Py_CLEAR(tmp);
7647 level = 0;
7648 }
7649 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007650 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007651 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7652 goto failed;
7653 }
Victor Stinner74419f02020-07-03 11:35:37 +02007654 res = obj2ast_int(state, tmp, &level, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007655 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007656 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007657 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007658 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007659 *out = _PyAST_ImportFrom(module, names, level, lineno, col_offset,
7660 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007661 if (*out == NULL) goto failed;
7662 return 0;
7663 }
Victor Stinner74419f02020-07-03 11:35:37 +02007664 tp = state->Global_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007665 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007666 if (isinstance == -1) {
7667 return 1;
7668 }
7669 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007670 asdl_identifier_seq* names;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007671
Victor Stinner74419f02020-07-03 11:35:37 +02007672 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007673 return 1;
7674 }
7675 if (tmp == NULL) {
7676 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7677 return 1;
7678 }
7679 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007680 int res;
7681 Py_ssize_t len;
7682 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007683 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007684 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007685 goto failed;
7686 }
7687 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007688 names = _Py_asdl_identifier_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007689 if (names == NULL) goto failed;
7690 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007691 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007692 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7693 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007694 if (Py_EnterRecursiveCall(" while traversing 'Global' node")) {
7695 goto failed;
7696 }
Victor Stinner74419f02020-07-03 11:35:37 +02007697 res = obj2ast_identifier(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007698 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007699 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007700 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007701 if (len != PyList_GET_SIZE(tmp)) {
7702 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7703 goto failed;
7704 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007705 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007706 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007707 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007708 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007709 *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
7710 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007711 if (*out == NULL) goto failed;
7712 return 0;
7713 }
Victor Stinner74419f02020-07-03 11:35:37 +02007714 tp = state->Nonlocal_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007715 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007716 if (isinstance == -1) {
7717 return 1;
7718 }
7719 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007720 asdl_identifier_seq* names;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007721
Victor Stinner74419f02020-07-03 11:35:37 +02007722 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007723 return 1;
7724 }
7725 if (tmp == NULL) {
7726 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7727 return 1;
7728 }
7729 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007730 int res;
7731 Py_ssize_t len;
7732 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007733 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007734 PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007735 goto failed;
7736 }
7737 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007738 names = _Py_asdl_identifier_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007739 if (names == NULL) goto failed;
7740 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007741 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007742 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7743 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007744 if (Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
7745 goto failed;
7746 }
Victor Stinner74419f02020-07-03 11:35:37 +02007747 res = obj2ast_identifier(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007748 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007749 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007750 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007751 if (len != PyList_GET_SIZE(tmp)) {
7752 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7753 goto failed;
7754 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007755 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007756 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007757 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007758 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007759 *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
7760 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007761 if (*out == NULL) goto failed;
7762 return 0;
7763 }
Victor Stinner74419f02020-07-03 11:35:37 +02007764 tp = state->Expr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007765 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007766 if (isinstance == -1) {
7767 return 1;
7768 }
7769 if (isinstance) {
7770 expr_ty value;
7771
Victor Stinner74419f02020-07-03 11:35:37 +02007772 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007773 return 1;
7774 }
7775 if (tmp == NULL) {
7776 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7777 return 1;
7778 }
7779 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007780 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007781 if (Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
7782 goto failed;
7783 }
Victor Stinner74419f02020-07-03 11:35:37 +02007784 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007785 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007786 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007787 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007788 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007789 *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
7790 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007791 if (*out == NULL) goto failed;
7792 return 0;
7793 }
Victor Stinner74419f02020-07-03 11:35:37 +02007794 tp = state->Pass_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007795 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007796 if (isinstance == -1) {
7797 return 1;
7798 }
7799 if (isinstance) {
7800
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007801 *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
7802 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007803 if (*out == NULL) goto failed;
7804 return 0;
7805 }
Victor Stinner74419f02020-07-03 11:35:37 +02007806 tp = state->Break_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007807 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007808 if (isinstance == -1) {
7809 return 1;
7810 }
7811 if (isinstance) {
7812
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007813 *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
7814 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007815 if (*out == NULL) goto failed;
7816 return 0;
7817 }
Victor Stinner74419f02020-07-03 11:35:37 +02007818 tp = state->Continue_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007819 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007820 if (isinstance == -1) {
7821 return 1;
7822 }
7823 if (isinstance) {
7824
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007825 *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
7826 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007827 if (*out == NULL) goto failed;
7828 return 0;
7829 }
7830
7831 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7832 failed:
7833 Py_XDECREF(tmp);
7834 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007835}
7836
7837int
Victor Stinner5cf47822020-11-02 22:03:28 +01007838obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
7839 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007840{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007841 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007842
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007843 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007844 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007845 int lineno;
7846 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007847 int end_lineno;
7848 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007849
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007850 if (obj == Py_None) {
7851 *out = NULL;
7852 return 0;
7853 }
Victor Stinner74419f02020-07-03 11:35:37 +02007854 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007855 return 1;
7856 }
7857 if (tmp == NULL) {
7858 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7859 return 1;
7860 }
7861 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007862 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007863 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7864 goto failed;
7865 }
Victor Stinner74419f02020-07-03 11:35:37 +02007866 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007867 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007868 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007869 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007870 }
Victor Stinner74419f02020-07-03 11:35:37 +02007871 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007872 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007873 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007874 if (tmp == NULL) {
7875 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7876 return 1;
7877 }
7878 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007879 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007880 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7881 goto failed;
7882 }
Victor Stinner74419f02020-07-03 11:35:37 +02007883 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007884 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007885 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007886 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007887 }
Victor Stinner74419f02020-07-03 11:35:37 +02007888 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007889 return 1;
7890 }
7891 if (tmp == NULL || tmp == Py_None) {
7892 Py_CLEAR(tmp);
7893 end_lineno = 0;
7894 }
7895 else {
7896 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007897 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7898 goto failed;
7899 }
Victor Stinner74419f02020-07-03 11:35:37 +02007900 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007901 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007902 if (res != 0) goto failed;
7903 Py_CLEAR(tmp);
7904 }
Victor Stinner74419f02020-07-03 11:35:37 +02007905 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007906 return 1;
7907 }
7908 if (tmp == NULL || tmp == Py_None) {
7909 Py_CLEAR(tmp);
7910 end_col_offset = 0;
7911 }
7912 else {
7913 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007914 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7915 goto failed;
7916 }
Victor Stinner74419f02020-07-03 11:35:37 +02007917 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007918 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007919 if (res != 0) goto failed;
7920 Py_CLEAR(tmp);
7921 }
Victor Stinner74419f02020-07-03 11:35:37 +02007922 tp = state->BoolOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007923 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007924 if (isinstance == -1) {
7925 return 1;
7926 }
7927 if (isinstance) {
7928 boolop_ty op;
Pablo Galindoa5634c42020-09-16 19:42:00 +01007929 asdl_expr_seq* values;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007930
Victor Stinner74419f02020-07-03 11:35:37 +02007931 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007932 return 1;
7933 }
7934 if (tmp == NULL) {
7935 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7936 return 1;
7937 }
7938 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007939 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007940 if (Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
7941 goto failed;
7942 }
Victor Stinner74419f02020-07-03 11:35:37 +02007943 res = obj2ast_boolop(state, tmp, &op, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007944 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007945 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007946 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007947 }
Victor Stinner74419f02020-07-03 11:35:37 +02007948 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007949 return 1;
7950 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007951 if (tmp == NULL) {
7952 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7953 return 1;
7954 }
7955 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007956 int res;
7957 Py_ssize_t len;
7958 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007959 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007960 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007961 goto failed;
7962 }
7963 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007964 values = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007965 if (values == NULL) goto failed;
7966 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007967 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007968 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7969 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007970 if (Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
7971 goto failed;
7972 }
Victor Stinner74419f02020-07-03 11:35:37 +02007973 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007974 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007975 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007976 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007977 if (len != PyList_GET_SIZE(tmp)) {
7978 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7979 goto failed;
7980 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007981 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007982 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007983 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007984 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007985 *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
7986 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007987 if (*out == NULL) goto failed;
7988 return 0;
7989 }
Victor Stinner74419f02020-07-03 11:35:37 +02007990 tp = state->NamedExpr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007991 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007992 if (isinstance == -1) {
7993 return 1;
7994 }
7995 if (isinstance) {
7996 expr_ty target;
7997 expr_ty value;
7998
Victor Stinner74419f02020-07-03 11:35:37 +02007999 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008000 return 1;
8001 }
8002 if (tmp == NULL) {
8003 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
8004 return 1;
8005 }
8006 else {
8007 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008008 if (Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8009 goto failed;
8010 }
Victor Stinner74419f02020-07-03 11:35:37 +02008011 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008012 Py_LeaveRecursiveCall();
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008013 if (res != 0) goto failed;
8014 Py_CLEAR(tmp);
8015 }
Victor Stinner74419f02020-07-03 11:35:37 +02008016 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008017 return 1;
8018 }
8019 if (tmp == NULL) {
8020 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
8021 return 1;
8022 }
8023 else {
8024 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008025 if (Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8026 goto failed;
8027 }
Victor Stinner74419f02020-07-03 11:35:37 +02008028 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008029 Py_LeaveRecursiveCall();
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008030 if (res != 0) goto failed;
8031 Py_CLEAR(tmp);
8032 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008033 *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
8034 end_col_offset, arena);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008035 if (*out == NULL) goto failed;
8036 return 0;
8037 }
Victor Stinner74419f02020-07-03 11:35:37 +02008038 tp = state->BinOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008039 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008040 if (isinstance == -1) {
8041 return 1;
8042 }
8043 if (isinstance) {
8044 expr_ty left;
8045 operator_ty op;
8046 expr_ty right;
8047
Victor Stinner74419f02020-07-03 11:35:37 +02008048 if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008049 return 1;
8050 }
8051 if (tmp == NULL) {
8052 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
8053 return 1;
8054 }
8055 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008056 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008057 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8058 goto failed;
8059 }
Victor Stinner74419f02020-07-03 11:35:37 +02008060 res = obj2ast_expr(state, tmp, &left, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008061 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008062 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008063 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008064 }
Victor Stinner74419f02020-07-03 11:35:37 +02008065 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008066 return 1;
8067 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008068 if (tmp == NULL) {
8069 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
8070 return 1;
8071 }
8072 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008073 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008074 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8075 goto failed;
8076 }
Victor Stinner74419f02020-07-03 11:35:37 +02008077 res = obj2ast_operator(state, tmp, &op, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008078 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008079 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008080 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008081 }
Victor Stinner74419f02020-07-03 11:35:37 +02008082 if (_PyObject_LookupAttr(obj, state->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008083 return 1;
8084 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008085 if (tmp == NULL) {
8086 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
8087 return 1;
8088 }
8089 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008090 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008091 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8092 goto failed;
8093 }
Victor Stinner74419f02020-07-03 11:35:37 +02008094 res = obj2ast_expr(state, tmp, &right, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008095 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008096 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008097 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008098 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008099 *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
8100 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008101 if (*out == NULL) goto failed;
8102 return 0;
8103 }
Victor Stinner74419f02020-07-03 11:35:37 +02008104 tp = state->UnaryOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008105 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008106 if (isinstance == -1) {
8107 return 1;
8108 }
8109 if (isinstance) {
8110 unaryop_ty op;
8111 expr_ty operand;
8112
Victor Stinner74419f02020-07-03 11:35:37 +02008113 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008114 return 1;
8115 }
8116 if (tmp == NULL) {
8117 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
8118 return 1;
8119 }
8120 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008121 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008122 if (Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8123 goto failed;
8124 }
Victor Stinner74419f02020-07-03 11:35:37 +02008125 res = obj2ast_unaryop(state, tmp, &op, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008126 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008127 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008128 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008129 }
Victor Stinner74419f02020-07-03 11:35:37 +02008130 if (_PyObject_LookupAttr(obj, state->operand, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008131 return 1;
8132 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008133 if (tmp == NULL) {
8134 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
8135 return 1;
8136 }
8137 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008138 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008139 if (Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8140 goto failed;
8141 }
Victor Stinner74419f02020-07-03 11:35:37 +02008142 res = obj2ast_expr(state, tmp, &operand, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008143 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008144 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008145 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008146 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008147 *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
8148 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008149 if (*out == NULL) goto failed;
8150 return 0;
8151 }
Victor Stinner74419f02020-07-03 11:35:37 +02008152 tp = state->Lambda_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008153 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008154 if (isinstance == -1) {
8155 return 1;
8156 }
8157 if (isinstance) {
8158 arguments_ty args;
8159 expr_ty body;
8160
Victor Stinner74419f02020-07-03 11:35:37 +02008161 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008162 return 1;
8163 }
8164 if (tmp == NULL) {
8165 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
8166 return 1;
8167 }
8168 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008169 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008170 if (Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8171 goto failed;
8172 }
Victor Stinner74419f02020-07-03 11:35:37 +02008173 res = obj2ast_arguments(state, tmp, &args, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008174 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008175 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008176 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008177 }
Victor Stinner74419f02020-07-03 11:35:37 +02008178 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008179 return 1;
8180 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008181 if (tmp == NULL) {
8182 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
8183 return 1;
8184 }
8185 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008186 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008187 if (Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8188 goto failed;
8189 }
Victor Stinner74419f02020-07-03 11:35:37 +02008190 res = obj2ast_expr(state, tmp, &body, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008191 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008192 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008193 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008194 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008195 *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
8196 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008197 if (*out == NULL) goto failed;
8198 return 0;
8199 }
Victor Stinner74419f02020-07-03 11:35:37 +02008200 tp = state->IfExp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008201 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008202 if (isinstance == -1) {
8203 return 1;
8204 }
8205 if (isinstance) {
8206 expr_ty test;
8207 expr_ty body;
8208 expr_ty orelse;
8209
Victor Stinner74419f02020-07-03 11:35:37 +02008210 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008211 return 1;
8212 }
8213 if (tmp == NULL) {
8214 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
8215 return 1;
8216 }
8217 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008218 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008219 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8220 goto failed;
8221 }
Victor Stinner74419f02020-07-03 11:35:37 +02008222 res = obj2ast_expr(state, tmp, &test, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008223 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008224 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008225 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008226 }
Victor Stinner74419f02020-07-03 11:35:37 +02008227 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008228 return 1;
8229 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008230 if (tmp == NULL) {
8231 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
8232 return 1;
8233 }
8234 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008235 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008236 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8237 goto failed;
8238 }
Victor Stinner74419f02020-07-03 11:35:37 +02008239 res = obj2ast_expr(state, tmp, &body, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008240 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008241 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008242 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008243 }
Victor Stinner74419f02020-07-03 11:35:37 +02008244 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008245 return 1;
8246 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008247 if (tmp == NULL) {
8248 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
8249 return 1;
8250 }
8251 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008252 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008253 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8254 goto failed;
8255 }
Victor Stinner74419f02020-07-03 11:35:37 +02008256 res = obj2ast_expr(state, tmp, &orelse, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008257 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008258 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008259 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008260 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008261 *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
8262 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008263 if (*out == NULL) goto failed;
8264 return 0;
8265 }
Victor Stinner74419f02020-07-03 11:35:37 +02008266 tp = state->Dict_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008267 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008268 if (isinstance == -1) {
8269 return 1;
8270 }
8271 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01008272 asdl_expr_seq* keys;
8273 asdl_expr_seq* values;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008274
Victor Stinner74419f02020-07-03 11:35:37 +02008275 if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008276 return 1;
8277 }
8278 if (tmp == NULL) {
8279 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
8280 return 1;
8281 }
8282 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008283 int res;
8284 Py_ssize_t len;
8285 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008286 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008287 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008288 goto failed;
8289 }
8290 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008291 keys = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008292 if (keys == NULL) goto failed;
8293 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008294 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008295 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8296 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008297 if (Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
8298 goto failed;
8299 }
Victor Stinner74419f02020-07-03 11:35:37 +02008300 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008301 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008302 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008303 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008304 if (len != PyList_GET_SIZE(tmp)) {
8305 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
8306 goto failed;
8307 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008308 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008309 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008310 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008311 }
Victor Stinner74419f02020-07-03 11:35:37 +02008312 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008313 return 1;
8314 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008315 if (tmp == NULL) {
8316 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
8317 return 1;
8318 }
8319 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008320 int res;
8321 Py_ssize_t len;
8322 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008323 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008324 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008325 goto failed;
8326 }
8327 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008328 values = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008329 if (values == NULL) goto failed;
8330 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008331 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008332 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8333 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008334 if (Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
8335 goto failed;
8336 }
Victor Stinner74419f02020-07-03 11:35:37 +02008337 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008338 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008339 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008340 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008341 if (len != PyList_GET_SIZE(tmp)) {
8342 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
8343 goto failed;
8344 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008345 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008346 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008347 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008348 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008349 *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
8350 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008351 if (*out == NULL) goto failed;
8352 return 0;
8353 }
Victor Stinner74419f02020-07-03 11:35:37 +02008354 tp = state->Set_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008355 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008356 if (isinstance == -1) {
8357 return 1;
8358 }
8359 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01008360 asdl_expr_seq* elts;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008361
Victor Stinner74419f02020-07-03 11:35:37 +02008362 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008363 return 1;
8364 }
8365 if (tmp == NULL) {
8366 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
8367 return 1;
8368 }
8369 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008370 int res;
8371 Py_ssize_t len;
8372 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008373 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008374 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008375 goto failed;
8376 }
8377 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008378 elts = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008379 if (elts == NULL) goto failed;
8380 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008381 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008382 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8383 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008384 if (Py_EnterRecursiveCall(" while traversing 'Set' node")) {
8385 goto failed;
8386 }
Victor Stinner74419f02020-07-03 11:35:37 +02008387 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008388 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008389 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008390 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008391 if (len != PyList_GET_SIZE(tmp)) {
8392 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
8393 goto failed;
8394 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008395 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008396 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008397 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008398 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008399 *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
8400 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008401 if (*out == NULL) goto failed;
8402 return 0;
8403 }
Victor Stinner74419f02020-07-03 11:35:37 +02008404 tp = state->ListComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008405 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008406 if (isinstance == -1) {
8407 return 1;
8408 }
8409 if (isinstance) {
8410 expr_ty elt;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008411 asdl_comprehension_seq* generators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008412
Victor Stinner74419f02020-07-03 11:35:37 +02008413 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008414 return 1;
8415 }
8416 if (tmp == NULL) {
8417 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
8418 return 1;
8419 }
8420 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008421 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008422 if (Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
8423 goto failed;
8424 }
Victor Stinner74419f02020-07-03 11:35:37 +02008425 res = obj2ast_expr(state, tmp, &elt, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008426 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008427 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008428 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008429 }
Victor Stinner74419f02020-07-03 11:35:37 +02008430 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008431 return 1;
8432 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008433 if (tmp == NULL) {
8434 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
8435 return 1;
8436 }
8437 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008438 int res;
8439 Py_ssize_t len;
8440 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008441 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008442 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008443 goto failed;
8444 }
8445 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008446 generators = _Py_asdl_comprehension_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008447 if (generators == NULL) goto failed;
8448 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008449 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008450 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8451 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008452 if (Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
8453 goto failed;
8454 }
Victor Stinner74419f02020-07-03 11:35:37 +02008455 res = obj2ast_comprehension(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008456 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008457 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008458 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008459 if (len != PyList_GET_SIZE(tmp)) {
8460 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
8461 goto failed;
8462 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008463 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008464 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008465 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008466 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008467 *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
8468 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008469 if (*out == NULL) goto failed;
8470 return 0;
8471 }
Victor Stinner74419f02020-07-03 11:35:37 +02008472 tp = state->SetComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008473 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008474 if (isinstance == -1) {
8475 return 1;
8476 }
8477 if (isinstance) {
8478 expr_ty elt;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008479 asdl_comprehension_seq* generators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008480
Victor Stinner74419f02020-07-03 11:35:37 +02008481 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008482 return 1;
8483 }
8484 if (tmp == NULL) {
8485 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
8486 return 1;
8487 }
8488 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008489 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008490 if (Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
8491 goto failed;
8492 }
Victor Stinner74419f02020-07-03 11:35:37 +02008493 res = obj2ast_expr(state, tmp, &elt, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008494 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008495 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008496 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008497 }
Victor Stinner74419f02020-07-03 11:35:37 +02008498 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008499 return 1;
8500 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008501 if (tmp == NULL) {
8502 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
8503 return 1;
8504 }
8505 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008506 int res;
8507 Py_ssize_t len;
8508 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008509 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008510 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008511 goto failed;
8512 }
8513 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008514 generators = _Py_asdl_comprehension_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008515 if (generators == NULL) goto failed;
8516 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008517 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008518 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8519 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008520 if (Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
8521 goto failed;
8522 }
Victor Stinner74419f02020-07-03 11:35:37 +02008523 res = obj2ast_comprehension(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008524 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008525 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008526 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008527 if (len != PyList_GET_SIZE(tmp)) {
8528 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
8529 goto failed;
8530 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008531 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008532 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008533 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008534 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008535 *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
8536 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008537 if (*out == NULL) goto failed;
8538 return 0;
8539 }
Victor Stinner74419f02020-07-03 11:35:37 +02008540 tp = state->DictComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008541 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008542 if (isinstance == -1) {
8543 return 1;
8544 }
8545 if (isinstance) {
8546 expr_ty key;
8547 expr_ty value;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008548 asdl_comprehension_seq* generators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008549
Victor Stinner74419f02020-07-03 11:35:37 +02008550 if (_PyObject_LookupAttr(obj, state->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008551 return 1;
8552 }
8553 if (tmp == NULL) {
8554 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
8555 return 1;
8556 }
8557 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008558 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008559 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8560 goto failed;
8561 }
Victor Stinner74419f02020-07-03 11:35:37 +02008562 res = obj2ast_expr(state, tmp, &key, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008563 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008564 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008565 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008566 }
Victor Stinner74419f02020-07-03 11:35:37 +02008567 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008568 return 1;
8569 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008570 if (tmp == NULL) {
8571 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
8572 return 1;
8573 }
8574 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008575 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008576 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8577 goto failed;
8578 }
Victor Stinner74419f02020-07-03 11:35:37 +02008579 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008580 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008581 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008582 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008583 }
Victor Stinner74419f02020-07-03 11:35:37 +02008584 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008585 return 1;
8586 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008587 if (tmp == NULL) {
8588 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
8589 return 1;
8590 }
8591 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008592 int res;
8593 Py_ssize_t len;
8594 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008595 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008596 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008597 goto failed;
8598 }
8599 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008600 generators = _Py_asdl_comprehension_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008601 if (generators == NULL) goto failed;
8602 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008603 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008604 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8605 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008606 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8607 goto failed;
8608 }
Victor Stinner74419f02020-07-03 11:35:37 +02008609 res = obj2ast_comprehension(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008610 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008611 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008612 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008613 if (len != PyList_GET_SIZE(tmp)) {
8614 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
8615 goto failed;
8616 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008617 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008618 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008619 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008620 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008621 *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
8622 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008623 if (*out == NULL) goto failed;
8624 return 0;
8625 }
Victor Stinner74419f02020-07-03 11:35:37 +02008626 tp = state->GeneratorExp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008627 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008628 if (isinstance == -1) {
8629 return 1;
8630 }
8631 if (isinstance) {
8632 expr_ty elt;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008633 asdl_comprehension_seq* generators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008634
Victor Stinner74419f02020-07-03 11:35:37 +02008635 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008636 return 1;
8637 }
8638 if (tmp == NULL) {
8639 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
8640 return 1;
8641 }
8642 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008643 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008644 if (Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
8645 goto failed;
8646 }
Victor Stinner74419f02020-07-03 11:35:37 +02008647 res = obj2ast_expr(state, tmp, &elt, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008648 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008649 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008650 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008651 }
Victor Stinner74419f02020-07-03 11:35:37 +02008652 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008653 return 1;
8654 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008655 if (tmp == NULL) {
8656 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
8657 return 1;
8658 }
8659 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008660 int res;
8661 Py_ssize_t len;
8662 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008663 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008664 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008665 goto failed;
8666 }
8667 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008668 generators = _Py_asdl_comprehension_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008669 if (generators == NULL) goto failed;
8670 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008671 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008672 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8673 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008674 if (Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
8675 goto failed;
8676 }
Victor Stinner74419f02020-07-03 11:35:37 +02008677 res = obj2ast_comprehension(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008678 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008679 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008680 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008681 if (len != PyList_GET_SIZE(tmp)) {
8682 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
8683 goto failed;
8684 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008685 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008686 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008687 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008688 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008689 *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
8690 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008691 if (*out == NULL) goto failed;
8692 return 0;
8693 }
Victor Stinner74419f02020-07-03 11:35:37 +02008694 tp = state->Await_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008695 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04008696 if (isinstance == -1) {
8697 return 1;
8698 }
8699 if (isinstance) {
8700 expr_ty value;
8701
Victor Stinner74419f02020-07-03 11:35:37 +02008702 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008703 return 1;
8704 }
8705 if (tmp == NULL) {
8706 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
8707 return 1;
8708 }
8709 else {
Yury Selivanov75445082015-05-11 22:57:16 -04008710 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008711 if (Py_EnterRecursiveCall(" while traversing 'Await' node")) {
8712 goto failed;
8713 }
Victor Stinner74419f02020-07-03 11:35:37 +02008714 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008715 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04008716 if (res != 0) goto failed;
8717 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04008718 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008719 *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
8720 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04008721 if (*out == NULL) goto failed;
8722 return 0;
8723 }
Victor Stinner74419f02020-07-03 11:35:37 +02008724 tp = state->Yield_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008725 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008726 if (isinstance == -1) {
8727 return 1;
8728 }
8729 if (isinstance) {
8730 expr_ty value;
8731
Victor Stinner74419f02020-07-03 11:35:37 +02008732 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008733 return 1;
8734 }
8735 if (tmp == NULL || tmp == Py_None) {
8736 Py_CLEAR(tmp);
8737 value = NULL;
8738 }
8739 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008740 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008741 if (Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
8742 goto failed;
8743 }
Victor Stinner74419f02020-07-03 11:35:37 +02008744 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008745 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008746 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008747 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008748 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008749 *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
8750 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008751 if (*out == NULL) goto failed;
8752 return 0;
8753 }
Victor Stinner74419f02020-07-03 11:35:37 +02008754 tp = state->YieldFrom_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008755 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008756 if (isinstance == -1) {
8757 return 1;
8758 }
8759 if (isinstance) {
8760 expr_ty value;
8761
Victor Stinner74419f02020-07-03 11:35:37 +02008762 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008763 return 1;
8764 }
8765 if (tmp == NULL) {
8766 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8767 return 1;
8768 }
8769 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008770 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008771 if (Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
8772 goto failed;
8773 }
Victor Stinner74419f02020-07-03 11:35:37 +02008774 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008775 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008776 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008777 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008778 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008779 *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
8780 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008781 if (*out == NULL) goto failed;
8782 return 0;
8783 }
Victor Stinner74419f02020-07-03 11:35:37 +02008784 tp = state->Compare_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008785 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008786 if (isinstance == -1) {
8787 return 1;
8788 }
8789 if (isinstance) {
8790 expr_ty left;
8791 asdl_int_seq* ops;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008792 asdl_expr_seq* comparators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008793
Victor Stinner74419f02020-07-03 11:35:37 +02008794 if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008795 return 1;
8796 }
8797 if (tmp == NULL) {
8798 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8799 return 1;
8800 }
8801 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008802 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008803 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8804 goto failed;
8805 }
Victor Stinner74419f02020-07-03 11:35:37 +02008806 res = obj2ast_expr(state, tmp, &left, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008807 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008808 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008809 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008810 }
Victor Stinner74419f02020-07-03 11:35:37 +02008811 if (_PyObject_LookupAttr(obj, state->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008812 return 1;
8813 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008814 if (tmp == NULL) {
8815 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8816 return 1;
8817 }
8818 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008819 int res;
8820 Py_ssize_t len;
8821 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008822 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008823 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008824 goto failed;
8825 }
8826 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008827 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008828 if (ops == NULL) goto failed;
8829 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008830 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008831 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8832 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008833 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8834 goto failed;
8835 }
Victor Stinner74419f02020-07-03 11:35:37 +02008836 res = obj2ast_cmpop(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008837 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008838 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008839 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008840 if (len != PyList_GET_SIZE(tmp)) {
8841 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8842 goto failed;
8843 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008844 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008845 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008846 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008847 }
Victor Stinner74419f02020-07-03 11:35:37 +02008848 if (_PyObject_LookupAttr(obj, state->comparators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008849 return 1;
8850 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008851 if (tmp == NULL) {
8852 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8853 return 1;
8854 }
8855 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008856 int res;
8857 Py_ssize_t len;
8858 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008859 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008860 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008861 goto failed;
8862 }
8863 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008864 comparators = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008865 if (comparators == NULL) goto failed;
8866 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008867 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008868 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8869 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008870 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8871 goto failed;
8872 }
Victor Stinner74419f02020-07-03 11:35:37 +02008873 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008874 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008875 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008876 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008877 if (len != PyList_GET_SIZE(tmp)) {
8878 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8879 goto failed;
8880 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008881 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008882 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008883 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008884 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008885 *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
8886 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008887 if (*out == NULL) goto failed;
8888 return 0;
8889 }
Victor Stinner74419f02020-07-03 11:35:37 +02008890 tp = state->Call_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008891 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008892 if (isinstance == -1) {
8893 return 1;
8894 }
8895 if (isinstance) {
8896 expr_ty func;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008897 asdl_expr_seq* args;
8898 asdl_keyword_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008899
Victor Stinner74419f02020-07-03 11:35:37 +02008900 if (_PyObject_LookupAttr(obj, state->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008901 return 1;
8902 }
8903 if (tmp == NULL) {
8904 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8905 return 1;
8906 }
8907 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008908 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008909 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8910 goto failed;
8911 }
Victor Stinner74419f02020-07-03 11:35:37 +02008912 res = obj2ast_expr(state, tmp, &func, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008913 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008914 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008915 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008916 }
Victor Stinner74419f02020-07-03 11:35:37 +02008917 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008918 return 1;
8919 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008920 if (tmp == NULL) {
8921 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8922 return 1;
8923 }
8924 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008925 int res;
8926 Py_ssize_t len;
8927 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008928 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008929 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008930 goto failed;
8931 }
8932 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008933 args = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008934 if (args == NULL) goto failed;
8935 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008936 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008937 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8938 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008939 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8940 goto failed;
8941 }
Victor Stinner74419f02020-07-03 11:35:37 +02008942 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008943 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008944 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008945 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008946 if (len != PyList_GET_SIZE(tmp)) {
8947 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8948 goto failed;
8949 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008950 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008951 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008952 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008953 }
Victor Stinner74419f02020-07-03 11:35:37 +02008954 if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008955 return 1;
8956 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008957 if (tmp == NULL) {
8958 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8959 return 1;
8960 }
8961 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008962 int res;
8963 Py_ssize_t len;
8964 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008965 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008966 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008967 goto failed;
8968 }
8969 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008970 keywords = _Py_asdl_keyword_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008971 if (keywords == NULL) goto failed;
8972 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008973 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008974 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8975 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008976 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8977 goto failed;
8978 }
Victor Stinner74419f02020-07-03 11:35:37 +02008979 res = obj2ast_keyword(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008980 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008981 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008982 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008983 if (len != PyList_GET_SIZE(tmp)) {
8984 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8985 goto failed;
8986 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008987 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008988 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008989 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008990 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008991 *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
8992 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008993 if (*out == NULL) goto failed;
8994 return 0;
8995 }
Victor Stinner74419f02020-07-03 11:35:37 +02008996 tp = state->FormattedValue_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008997 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008998 if (isinstance == -1) {
8999 return 1;
9000 }
9001 if (isinstance) {
9002 expr_ty value;
9003 int conversion;
9004 expr_ty format_spec;
9005
Victor Stinner74419f02020-07-03 11:35:37 +02009006 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009007 return 1;
9008 }
9009 if (tmp == NULL) {
9010 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
9011 return 1;
9012 }
9013 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009014 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009015 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9016 goto failed;
9017 }
Victor Stinner74419f02020-07-03 11:35:37 +02009018 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009019 Py_LeaveRecursiveCall();
Eric V. Smith235a6f02015-09-19 14:51:32 -04009020 if (res != 0) goto failed;
9021 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009022 }
Victor Stinner74419f02020-07-03 11:35:37 +02009023 if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009024 return 1;
9025 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009026 if (tmp == NULL || tmp == Py_None) {
9027 Py_CLEAR(tmp);
9028 conversion = 0;
9029 }
9030 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009031 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009032 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9033 goto failed;
9034 }
Victor Stinner74419f02020-07-03 11:35:37 +02009035 res = obj2ast_int(state, tmp, &conversion, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009036 Py_LeaveRecursiveCall();
Eric V. Smith235a6f02015-09-19 14:51:32 -04009037 if (res != 0) goto failed;
9038 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009039 }
Victor Stinner74419f02020-07-03 11:35:37 +02009040 if (_PyObject_LookupAttr(obj, state->format_spec, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009041 return 1;
9042 }
9043 if (tmp == NULL || tmp == Py_None) {
9044 Py_CLEAR(tmp);
9045 format_spec = NULL;
9046 }
9047 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009048 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009049 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9050 goto failed;
9051 }
Victor Stinner74419f02020-07-03 11:35:37 +02009052 res = obj2ast_expr(state, tmp, &format_spec, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009053 Py_LeaveRecursiveCall();
Eric V. Smith235a6f02015-09-19 14:51:32 -04009054 if (res != 0) goto failed;
9055 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009056 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009057 *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
9058 col_offset, end_lineno, end_col_offset,
9059 arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009060 if (*out == NULL) goto failed;
9061 return 0;
9062 }
Victor Stinner74419f02020-07-03 11:35:37 +02009063 tp = state->JoinedStr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009064 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009065 if (isinstance == -1) {
9066 return 1;
9067 }
9068 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01009069 asdl_expr_seq* values;
Eric V. Smith235a6f02015-09-19 14:51:32 -04009070
Victor Stinner74419f02020-07-03 11:35:37 +02009071 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009072 return 1;
9073 }
9074 if (tmp == NULL) {
9075 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
9076 return 1;
9077 }
9078 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009079 int res;
9080 Py_ssize_t len;
9081 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04009082 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009083 PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Eric V. Smith235a6f02015-09-19 14:51:32 -04009084 goto failed;
9085 }
9086 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01009087 values = _Py_asdl_expr_seq_new(len, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009088 if (values == NULL) goto failed;
9089 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009090 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009091 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9092 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009093 if (Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
9094 goto failed;
9095 }
Victor Stinner74419f02020-07-03 11:35:37 +02009096 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009097 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009098 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009099 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03009100 if (len != PyList_GET_SIZE(tmp)) {
9101 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
9102 goto failed;
9103 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009104 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009105 }
9106 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009107 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009108 *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
9109 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009110 if (*out == NULL) goto failed;
9111 return 0;
9112 }
Victor Stinner74419f02020-07-03 11:35:37 +02009113 tp = state->Constant_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009114 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009115 if (isinstance == -1) {
9116 return 1;
9117 }
9118 if (isinstance) {
9119 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07009120 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009121
Victor Stinner74419f02020-07-03 11:35:37 +02009122 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009123 return 1;
9124 }
9125 if (tmp == NULL) {
9126 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
9127 return 1;
9128 }
9129 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009130 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009131 if (Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9132 goto failed;
9133 }
Victor Stinner74419f02020-07-03 11:35:37 +02009134 res = obj2ast_constant(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009135 Py_LeaveRecursiveCall();
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009136 if (res != 0) goto failed;
9137 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009138 }
Victor Stinner74419f02020-07-03 11:35:37 +02009139 if (_PyObject_LookupAttr(obj, state->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07009140 return 1;
9141 }
9142 if (tmp == NULL || tmp == Py_None) {
9143 Py_CLEAR(tmp);
9144 kind = NULL;
9145 }
9146 else {
9147 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009148 if (Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9149 goto failed;
9150 }
Victor Stinner74419f02020-07-03 11:35:37 +02009151 res = obj2ast_string(state, tmp, &kind, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009152 Py_LeaveRecursiveCall();
Guido van Rossum10f8ce62019-03-13 13:00:46 -07009153 if (res != 0) goto failed;
9154 Py_CLEAR(tmp);
9155 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009156 *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
9157 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009158 if (*out == NULL) goto failed;
9159 return 0;
9160 }
Victor Stinner74419f02020-07-03 11:35:37 +02009161 tp = state->Attribute_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009162 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009163 if (isinstance == -1) {
9164 return 1;
9165 }
9166 if (isinstance) {
9167 expr_ty value;
9168 identifier attr;
9169 expr_context_ty ctx;
9170
Victor Stinner74419f02020-07-03 11:35:37 +02009171 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009172 return 1;
9173 }
9174 if (tmp == NULL) {
9175 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
9176 return 1;
9177 }
9178 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009179 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009180 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9181 goto failed;
9182 }
Victor Stinner74419f02020-07-03 11:35:37 +02009183 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009184 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009185 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009186 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009187 }
Victor Stinner74419f02020-07-03 11:35:37 +02009188 if (_PyObject_LookupAttr(obj, state->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009189 return 1;
9190 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009191 if (tmp == NULL) {
9192 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
9193 return 1;
9194 }
9195 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009196 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009197 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9198 goto failed;
9199 }
Victor Stinner74419f02020-07-03 11:35:37 +02009200 res = obj2ast_identifier(state, tmp, &attr, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009201 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009202 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009203 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009204 }
Victor Stinner74419f02020-07-03 11:35:37 +02009205 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009206 return 1;
9207 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009208 if (tmp == NULL) {
9209 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
9210 return 1;
9211 }
9212 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009213 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009214 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9215 goto failed;
9216 }
Victor Stinner74419f02020-07-03 11:35:37 +02009217 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009218 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009219 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009220 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009221 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009222 *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
9223 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009224 if (*out == NULL) goto failed;
9225 return 0;
9226 }
Victor Stinner74419f02020-07-03 11:35:37 +02009227 tp = state->Subscript_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009228 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009229 if (isinstance == -1) {
9230 return 1;
9231 }
9232 if (isinstance) {
9233 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009234 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009235 expr_context_ty ctx;
9236
Victor Stinner74419f02020-07-03 11:35:37 +02009237 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009238 return 1;
9239 }
9240 if (tmp == NULL) {
9241 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
9242 return 1;
9243 }
9244 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009245 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009246 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9247 goto failed;
9248 }
Victor Stinner74419f02020-07-03 11:35:37 +02009249 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009250 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009251 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009252 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009253 }
Victor Stinner74419f02020-07-03 11:35:37 +02009254 if (_PyObject_LookupAttr(obj, state->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009255 return 1;
9256 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009257 if (tmp == NULL) {
9258 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
9259 return 1;
9260 }
9261 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009262 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009263 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9264 goto failed;
9265 }
Victor Stinner74419f02020-07-03 11:35:37 +02009266 res = obj2ast_expr(state, tmp, &slice, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009267 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009268 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009269 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009270 }
Victor Stinner74419f02020-07-03 11:35:37 +02009271 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009272 return 1;
9273 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009274 if (tmp == NULL) {
9275 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
9276 return 1;
9277 }
9278 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009279 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009280 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9281 goto failed;
9282 }
Victor Stinner74419f02020-07-03 11:35:37 +02009283 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009284 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009285 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009286 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009287 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009288 *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
9289 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009290 if (*out == NULL) goto failed;
9291 return 0;
9292 }
Victor Stinner74419f02020-07-03 11:35:37 +02009293 tp = state->Starred_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009294 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009295 if (isinstance == -1) {
9296 return 1;
9297 }
9298 if (isinstance) {
9299 expr_ty value;
9300 expr_context_ty ctx;
9301
Victor Stinner74419f02020-07-03 11:35:37 +02009302 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009303 return 1;
9304 }
9305 if (tmp == NULL) {
9306 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
9307 return 1;
9308 }
9309 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009310 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009311 if (Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
9312 goto failed;
9313 }
Victor Stinner74419f02020-07-03 11:35:37 +02009314 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009315 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009316 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009317 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009318 }
Victor Stinner74419f02020-07-03 11:35:37 +02009319 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009320 return 1;
9321 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009322 if (tmp == NULL) {
9323 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
9324 return 1;
9325 }
9326 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009327 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009328 if (Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
9329 goto failed;
9330 }
Victor Stinner74419f02020-07-03 11:35:37 +02009331 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009332 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009333 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009334 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009335 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009336 *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
9337 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009338 if (*out == NULL) goto failed;
9339 return 0;
9340 }
Victor Stinner74419f02020-07-03 11:35:37 +02009341 tp = state->Name_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009342 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009343 if (isinstance == -1) {
9344 return 1;
9345 }
9346 if (isinstance) {
9347 identifier id;
9348 expr_context_ty ctx;
9349
Victor Stinner74419f02020-07-03 11:35:37 +02009350 if (_PyObject_LookupAttr(obj, state->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009351 return 1;
9352 }
9353 if (tmp == NULL) {
9354 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
9355 return 1;
9356 }
9357 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009358 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009359 if (Py_EnterRecursiveCall(" while traversing 'Name' node")) {
9360 goto failed;
9361 }
Victor Stinner74419f02020-07-03 11:35:37 +02009362 res = obj2ast_identifier(state, tmp, &id, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009363 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009364 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009365 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009366 }
Victor Stinner74419f02020-07-03 11:35:37 +02009367 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009368 return 1;
9369 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009370 if (tmp == NULL) {
9371 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
9372 return 1;
9373 }
9374 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009375 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009376 if (Py_EnterRecursiveCall(" while traversing 'Name' node")) {
9377 goto failed;
9378 }
Victor Stinner74419f02020-07-03 11:35:37 +02009379 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009380 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009381 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009382 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009383 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009384 *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
9385 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009386 if (*out == NULL) goto failed;
9387 return 0;
9388 }
Victor Stinner74419f02020-07-03 11:35:37 +02009389 tp = state->List_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009390 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009391 if (isinstance == -1) {
9392 return 1;
9393 }
9394 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01009395 asdl_expr_seq* elts;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009396 expr_context_ty ctx;
9397
Victor Stinner74419f02020-07-03 11:35:37 +02009398 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009399 return 1;
9400 }
9401 if (tmp == NULL) {
9402 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
9403 return 1;
9404 }
9405 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009406 int res;
9407 Py_ssize_t len;
9408 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009409 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009410 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009411 goto failed;
9412 }
9413 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01009414 elts = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009415 if (elts == NULL) goto failed;
9416 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009417 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009418 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9419 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009420 if (Py_EnterRecursiveCall(" while traversing 'List' node")) {
9421 goto failed;
9422 }
Victor Stinner74419f02020-07-03 11:35:37 +02009423 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009424 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009425 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009426 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009427 if (len != PyList_GET_SIZE(tmp)) {
9428 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
9429 goto failed;
9430 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009431 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009432 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009433 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009434 }
Victor Stinner74419f02020-07-03 11:35:37 +02009435 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009436 return 1;
9437 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009438 if (tmp == NULL) {
9439 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
9440 return 1;
9441 }
9442 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009443 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009444 if (Py_EnterRecursiveCall(" while traversing 'List' node")) {
9445 goto failed;
9446 }
Victor Stinner74419f02020-07-03 11:35:37 +02009447 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009448 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009449 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009450 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009451 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009452 *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
9453 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009454 if (*out == NULL) goto failed;
9455 return 0;
9456 }
Victor Stinner74419f02020-07-03 11:35:37 +02009457 tp = state->Tuple_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009458 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009459 if (isinstance == -1) {
9460 return 1;
9461 }
9462 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01009463 asdl_expr_seq* elts;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009464 expr_context_ty ctx;
9465
Victor Stinner74419f02020-07-03 11:35:37 +02009466 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009467 return 1;
9468 }
9469 if (tmp == NULL) {
9470 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
9471 return 1;
9472 }
9473 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009474 int res;
9475 Py_ssize_t len;
9476 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009477 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009478 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009479 goto failed;
9480 }
9481 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01009482 elts = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009483 if (elts == NULL) goto failed;
9484 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009485 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009486 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9487 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009488 if (Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
9489 goto failed;
9490 }
Victor Stinner74419f02020-07-03 11:35:37 +02009491 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009492 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009493 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009494 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009495 if (len != PyList_GET_SIZE(tmp)) {
9496 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
9497 goto failed;
9498 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009499 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009500 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009501 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009502 }
Victor Stinner74419f02020-07-03 11:35:37 +02009503 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009504 return 1;
9505 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009506 if (tmp == NULL) {
9507 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
9508 return 1;
9509 }
9510 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009511 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009512 if (Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
9513 goto failed;
9514 }
Victor Stinner74419f02020-07-03 11:35:37 +02009515 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009516 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009517 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009518 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009519 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009520 *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
9521 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009522 if (*out == NULL) goto failed;
9523 return 0;
9524 }
Victor Stinner74419f02020-07-03 11:35:37 +02009525 tp = state->Slice_type;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009526 isinstance = PyObject_IsInstance(obj, tp);
9527 if (isinstance == -1) {
9528 return 1;
9529 }
9530 if (isinstance) {
9531 expr_ty lower;
9532 expr_ty upper;
9533 expr_ty step;
9534
Victor Stinner74419f02020-07-03 11:35:37 +02009535 if (_PyObject_LookupAttr(obj, state->lower, &tmp) < 0) {
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009536 return 1;
9537 }
9538 if (tmp == NULL || tmp == Py_None) {
9539 Py_CLEAR(tmp);
9540 lower = NULL;
9541 }
9542 else {
9543 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009544 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9545 goto failed;
9546 }
Victor Stinner74419f02020-07-03 11:35:37 +02009547 res = obj2ast_expr(state, tmp, &lower, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009548 Py_LeaveRecursiveCall();
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009549 if (res != 0) goto failed;
9550 Py_CLEAR(tmp);
9551 }
Victor Stinner74419f02020-07-03 11:35:37 +02009552 if (_PyObject_LookupAttr(obj, state->upper, &tmp) < 0) {
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009553 return 1;
9554 }
9555 if (tmp == NULL || tmp == Py_None) {
9556 Py_CLEAR(tmp);
9557 upper = NULL;
9558 }
9559 else {
9560 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009561 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9562 goto failed;
9563 }
Victor Stinner74419f02020-07-03 11:35:37 +02009564 res = obj2ast_expr(state, tmp, &upper, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009565 Py_LeaveRecursiveCall();
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009566 if (res != 0) goto failed;
9567 Py_CLEAR(tmp);
9568 }
Victor Stinner74419f02020-07-03 11:35:37 +02009569 if (_PyObject_LookupAttr(obj, state->step, &tmp) < 0) {
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009570 return 1;
9571 }
9572 if (tmp == NULL || tmp == Py_None) {
9573 Py_CLEAR(tmp);
9574 step = NULL;
9575 }
9576 else {
9577 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009578 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9579 goto failed;
9580 }
Victor Stinner74419f02020-07-03 11:35:37 +02009581 res = obj2ast_expr(state, tmp, &step, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009582 Py_LeaveRecursiveCall();
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009583 if (res != 0) goto failed;
9584 Py_CLEAR(tmp);
9585 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009586 *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
9587 end_col_offset, arena);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009588 if (*out == NULL) goto failed;
9589 return 0;
9590 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009591
9592 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
9593 failed:
9594 Py_XDECREF(tmp);
9595 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009596}
9597
9598int
Victor Stinner5cf47822020-11-02 22:03:28 +01009599obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
Victor Stinner74419f02020-07-03 11:35:37 +02009600 out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009601{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009602 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009603
Victor Stinner74419f02020-07-03 11:35:37 +02009604 isinstance = PyObject_IsInstance(obj, state->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009605 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009606 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009607 }
9608 if (isinstance) {
9609 *out = Load;
9610 return 0;
9611 }
Victor Stinner74419f02020-07-03 11:35:37 +02009612 isinstance = PyObject_IsInstance(obj, state->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009613 if (isinstance == -1) {
9614 return 1;
9615 }
9616 if (isinstance) {
9617 *out = Store;
9618 return 0;
9619 }
Victor Stinner74419f02020-07-03 11:35:37 +02009620 isinstance = PyObject_IsInstance(obj, state->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009621 if (isinstance == -1) {
9622 return 1;
9623 }
9624 if (isinstance) {
9625 *out = Del;
9626 return 0;
9627 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009628
9629 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
9630 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009631}
9632
9633int
Victor Stinner5cf47822020-11-02 22:03:28 +01009634obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
Victor Stinner74419f02020-07-03 11:35:37 +02009635 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009636{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009637 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009638
Victor Stinner74419f02020-07-03 11:35:37 +02009639 isinstance = PyObject_IsInstance(obj, state->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009640 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009641 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009642 }
9643 if (isinstance) {
9644 *out = And;
9645 return 0;
9646 }
Victor Stinner74419f02020-07-03 11:35:37 +02009647 isinstance = PyObject_IsInstance(obj, state->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009648 if (isinstance == -1) {
9649 return 1;
9650 }
9651 if (isinstance) {
9652 *out = Or;
9653 return 0;
9654 }
9655
9656 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
9657 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009658}
9659
9660int
Victor Stinner5cf47822020-11-02 22:03:28 +01009661obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02009662 PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009663{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009664 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009665
Victor Stinner74419f02020-07-03 11:35:37 +02009666 isinstance = PyObject_IsInstance(obj, state->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009667 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009668 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009669 }
9670 if (isinstance) {
9671 *out = Add;
9672 return 0;
9673 }
Victor Stinner74419f02020-07-03 11:35:37 +02009674 isinstance = PyObject_IsInstance(obj, state->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009675 if (isinstance == -1) {
9676 return 1;
9677 }
9678 if (isinstance) {
9679 *out = Sub;
9680 return 0;
9681 }
Victor Stinner74419f02020-07-03 11:35:37 +02009682 isinstance = PyObject_IsInstance(obj, state->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009683 if (isinstance == -1) {
9684 return 1;
9685 }
9686 if (isinstance) {
9687 *out = Mult;
9688 return 0;
9689 }
Victor Stinner74419f02020-07-03 11:35:37 +02009690 isinstance = PyObject_IsInstance(obj, state->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04009691 if (isinstance == -1) {
9692 return 1;
9693 }
9694 if (isinstance) {
9695 *out = MatMult;
9696 return 0;
9697 }
Victor Stinner74419f02020-07-03 11:35:37 +02009698 isinstance = PyObject_IsInstance(obj, state->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009699 if (isinstance == -1) {
9700 return 1;
9701 }
9702 if (isinstance) {
9703 *out = Div;
9704 return 0;
9705 }
Victor Stinner74419f02020-07-03 11:35:37 +02009706 isinstance = PyObject_IsInstance(obj, state->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009707 if (isinstance == -1) {
9708 return 1;
9709 }
9710 if (isinstance) {
9711 *out = Mod;
9712 return 0;
9713 }
Victor Stinner74419f02020-07-03 11:35:37 +02009714 isinstance = PyObject_IsInstance(obj, state->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009715 if (isinstance == -1) {
9716 return 1;
9717 }
9718 if (isinstance) {
9719 *out = Pow;
9720 return 0;
9721 }
Victor Stinner74419f02020-07-03 11:35:37 +02009722 isinstance = PyObject_IsInstance(obj, state->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009723 if (isinstance == -1) {
9724 return 1;
9725 }
9726 if (isinstance) {
9727 *out = LShift;
9728 return 0;
9729 }
Victor Stinner74419f02020-07-03 11:35:37 +02009730 isinstance = PyObject_IsInstance(obj, state->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009731 if (isinstance == -1) {
9732 return 1;
9733 }
9734 if (isinstance) {
9735 *out = RShift;
9736 return 0;
9737 }
Victor Stinner74419f02020-07-03 11:35:37 +02009738 isinstance = PyObject_IsInstance(obj, state->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009739 if (isinstance == -1) {
9740 return 1;
9741 }
9742 if (isinstance) {
9743 *out = BitOr;
9744 return 0;
9745 }
Victor Stinner74419f02020-07-03 11:35:37 +02009746 isinstance = PyObject_IsInstance(obj, state->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009747 if (isinstance == -1) {
9748 return 1;
9749 }
9750 if (isinstance) {
9751 *out = BitXor;
9752 return 0;
9753 }
Victor Stinner74419f02020-07-03 11:35:37 +02009754 isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009755 if (isinstance == -1) {
9756 return 1;
9757 }
9758 if (isinstance) {
9759 *out = BitAnd;
9760 return 0;
9761 }
Victor Stinner74419f02020-07-03 11:35:37 +02009762 isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009763 if (isinstance == -1) {
9764 return 1;
9765 }
9766 if (isinstance) {
9767 *out = FloorDiv;
9768 return 0;
9769 }
9770
9771 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
9772 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009773}
9774
9775int
Victor Stinner5cf47822020-11-02 22:03:28 +01009776obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
9777 PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009778{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009779 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009780
Victor Stinner74419f02020-07-03 11:35:37 +02009781 isinstance = PyObject_IsInstance(obj, state->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009782 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009783 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009784 }
9785 if (isinstance) {
9786 *out = Invert;
9787 return 0;
9788 }
Victor Stinner74419f02020-07-03 11:35:37 +02009789 isinstance = PyObject_IsInstance(obj, state->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009790 if (isinstance == -1) {
9791 return 1;
9792 }
9793 if (isinstance) {
9794 *out = Not;
9795 return 0;
9796 }
Victor Stinner74419f02020-07-03 11:35:37 +02009797 isinstance = PyObject_IsInstance(obj, state->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009798 if (isinstance == -1) {
9799 return 1;
9800 }
9801 if (isinstance) {
9802 *out = UAdd;
9803 return 0;
9804 }
Victor Stinner74419f02020-07-03 11:35:37 +02009805 isinstance = PyObject_IsInstance(obj, state->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009806 if (isinstance == -1) {
9807 return 1;
9808 }
9809 if (isinstance) {
9810 *out = USub;
9811 return 0;
9812 }
9813
9814 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9815 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009816}
9817
9818int
Victor Stinner5cf47822020-11-02 22:03:28 +01009819obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
Victor Stinner74419f02020-07-03 11:35:37 +02009820 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009821{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009822 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009823
Victor Stinner74419f02020-07-03 11:35:37 +02009824 isinstance = PyObject_IsInstance(obj, state->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009825 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009826 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009827 }
9828 if (isinstance) {
9829 *out = Eq;
9830 return 0;
9831 }
Victor Stinner74419f02020-07-03 11:35:37 +02009832 isinstance = PyObject_IsInstance(obj, state->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009833 if (isinstance == -1) {
9834 return 1;
9835 }
9836 if (isinstance) {
9837 *out = NotEq;
9838 return 0;
9839 }
Victor Stinner74419f02020-07-03 11:35:37 +02009840 isinstance = PyObject_IsInstance(obj, state->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009841 if (isinstance == -1) {
9842 return 1;
9843 }
9844 if (isinstance) {
9845 *out = Lt;
9846 return 0;
9847 }
Victor Stinner74419f02020-07-03 11:35:37 +02009848 isinstance = PyObject_IsInstance(obj, state->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009849 if (isinstance == -1) {
9850 return 1;
9851 }
9852 if (isinstance) {
9853 *out = LtE;
9854 return 0;
9855 }
Victor Stinner74419f02020-07-03 11:35:37 +02009856 isinstance = PyObject_IsInstance(obj, state->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009857 if (isinstance == -1) {
9858 return 1;
9859 }
9860 if (isinstance) {
9861 *out = Gt;
9862 return 0;
9863 }
Victor Stinner74419f02020-07-03 11:35:37 +02009864 isinstance = PyObject_IsInstance(obj, state->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009865 if (isinstance == -1) {
9866 return 1;
9867 }
9868 if (isinstance) {
9869 *out = GtE;
9870 return 0;
9871 }
Victor Stinner74419f02020-07-03 11:35:37 +02009872 isinstance = PyObject_IsInstance(obj, state->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009873 if (isinstance == -1) {
9874 return 1;
9875 }
9876 if (isinstance) {
9877 *out = Is;
9878 return 0;
9879 }
Victor Stinner74419f02020-07-03 11:35:37 +02009880 isinstance = PyObject_IsInstance(obj, state->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009881 if (isinstance == -1) {
9882 return 1;
9883 }
9884 if (isinstance) {
9885 *out = IsNot;
9886 return 0;
9887 }
Victor Stinner74419f02020-07-03 11:35:37 +02009888 isinstance = PyObject_IsInstance(obj, state->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009889 if (isinstance == -1) {
9890 return 1;
9891 }
9892 if (isinstance) {
9893 *out = In;
9894 return 0;
9895 }
Victor Stinner74419f02020-07-03 11:35:37 +02009896 isinstance = PyObject_IsInstance(obj, state->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009897 if (isinstance == -1) {
9898 return 1;
9899 }
9900 if (isinstance) {
9901 *out = NotIn;
9902 return 0;
9903 }
9904
9905 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9906 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009907}
9908
9909int
Victor Stinner5cf47822020-11-02 22:03:28 +01009910obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
Victor Stinner74419f02020-07-03 11:35:37 +02009911 out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009912{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009913 PyObject* tmp = NULL;
9914 expr_ty target;
9915 expr_ty iter;
Pablo Galindoa5634c42020-09-16 19:42:00 +01009916 asdl_expr_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009917 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009918
Victor Stinner74419f02020-07-03 11:35:37 +02009919 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009920 return 1;
9921 }
9922 if (tmp == NULL) {
9923 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9924 return 1;
9925 }
9926 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009927 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009928 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9929 goto failed;
9930 }
Victor Stinner74419f02020-07-03 11:35:37 +02009931 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009932 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009933 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009934 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009935 }
Victor Stinner74419f02020-07-03 11:35:37 +02009936 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009937 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009938 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009939 if (tmp == NULL) {
9940 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9941 return 1;
9942 }
9943 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009944 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009945 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9946 goto failed;
9947 }
Victor Stinner74419f02020-07-03 11:35:37 +02009948 res = obj2ast_expr(state, tmp, &iter, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009949 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009950 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009951 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009952 }
Victor Stinner74419f02020-07-03 11:35:37 +02009953 if (_PyObject_LookupAttr(obj, state->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009954 return 1;
9955 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009956 if (tmp == NULL) {
9957 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9958 return 1;
9959 }
9960 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009961 int res;
9962 Py_ssize_t len;
9963 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009964 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009965 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009966 goto failed;
9967 }
9968 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01009969 ifs = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009970 if (ifs == NULL) goto failed;
9971 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009972 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009973 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9974 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009975 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9976 goto failed;
9977 }
Victor Stinner74419f02020-07-03 11:35:37 +02009978 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009979 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009980 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009981 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009982 if (len != PyList_GET_SIZE(tmp)) {
9983 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9984 goto failed;
9985 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009986 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009987 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009988 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009989 }
Victor Stinner74419f02020-07-03 11:35:37 +02009990 if (_PyObject_LookupAttr(obj, state->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009991 return 1;
9992 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009993 if (tmp == NULL) {
9994 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9995 return 1;
9996 }
9997 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009998 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009999 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
10000 goto failed;
10001 }
Victor Stinner74419f02020-07-03 11:35:37 +020010002 res = obj2ast_int(state, tmp, &is_async, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010003 Py_LeaveRecursiveCall();
Yury Selivanov52c4e7c2016-09-09 10:36:01 -070010004 if (res != 0) goto failed;
10005 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -070010006 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010007 *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010008 return 0;
10009failed:
10010 Py_XDECREF(tmp);
10011 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010012}
10013
10014int
Victor Stinner5cf47822020-11-02 22:03:28 +010010015obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
Victor Stinner74419f02020-07-03 11:35:37 +020010016 out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010017{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010018 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +000010019
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010020 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010021 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010022 int lineno;
10023 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010024 int end_lineno;
10025 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010026
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010027 if (obj == Py_None) {
10028 *out = NULL;
10029 return 0;
10030 }
Victor Stinner74419f02020-07-03 11:35:37 +020010031 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010032 return 1;
10033 }
10034 if (tmp == NULL) {
10035 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
10036 return 1;
10037 }
10038 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010039 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010040 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10041 goto failed;
10042 }
Victor Stinner74419f02020-07-03 11:35:37 +020010043 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010044 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010045 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010046 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010047 }
Victor Stinner74419f02020-07-03 11:35:37 +020010048 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010049 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010050 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010051 if (tmp == NULL) {
10052 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
10053 return 1;
10054 }
10055 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010056 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010057 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10058 goto failed;
10059 }
Victor Stinner74419f02020-07-03 11:35:37 +020010060 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010061 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010062 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010063 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010064 }
Victor Stinner74419f02020-07-03 11:35:37 +020010065 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010066 return 1;
10067 }
10068 if (tmp == NULL || tmp == Py_None) {
10069 Py_CLEAR(tmp);
10070 end_lineno = 0;
10071 }
10072 else {
10073 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010074 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10075 goto failed;
10076 }
Victor Stinner74419f02020-07-03 11:35:37 +020010077 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010078 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010079 if (res != 0) goto failed;
10080 Py_CLEAR(tmp);
10081 }
Victor Stinner74419f02020-07-03 11:35:37 +020010082 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010083 return 1;
10084 }
10085 if (tmp == NULL || tmp == Py_None) {
10086 Py_CLEAR(tmp);
10087 end_col_offset = 0;
10088 }
10089 else {
10090 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010091 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10092 goto failed;
10093 }
Victor Stinner74419f02020-07-03 11:35:37 +020010094 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010095 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010096 if (res != 0) goto failed;
10097 Py_CLEAR(tmp);
10098 }
Victor Stinner74419f02020-07-03 11:35:37 +020010099 tp = state->ExceptHandler_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010100 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010101 if (isinstance == -1) {
10102 return 1;
10103 }
10104 if (isinstance) {
10105 expr_ty type;
10106 identifier name;
Pablo Galindoa5634c42020-09-16 19:42:00 +010010107 asdl_stmt_seq* body;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010108
Victor Stinner74419f02020-07-03 11:35:37 +020010109 if (_PyObject_LookupAttr(obj, state->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010110 return 1;
10111 }
10112 if (tmp == NULL || tmp == Py_None) {
10113 Py_CLEAR(tmp);
10114 type = NULL;
10115 }
10116 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010117 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010118 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10119 goto failed;
10120 }
Victor Stinner74419f02020-07-03 11:35:37 +020010121 res = obj2ast_expr(state, tmp, &type, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010122 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010123 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010124 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010125 }
Victor Stinner74419f02020-07-03 11:35:37 +020010126 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010127 return 1;
10128 }
10129 if (tmp == NULL || tmp == Py_None) {
10130 Py_CLEAR(tmp);
10131 name = NULL;
10132 }
10133 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010134 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010135 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10136 goto failed;
10137 }
Victor Stinner74419f02020-07-03 11:35:37 +020010138 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010139 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010140 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010141 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010142 }
Victor Stinner74419f02020-07-03 11:35:37 +020010143 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010144 return 1;
10145 }
10146 if (tmp == NULL) {
10147 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
10148 return 1;
10149 }
10150 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010151 int res;
10152 Py_ssize_t len;
10153 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010154 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010155 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010156 goto failed;
10157 }
10158 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010159 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010160 if (body == NULL) goto failed;
10161 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010162 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010163 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10164 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010165 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10166 goto failed;
10167 }
Victor Stinner74419f02020-07-03 11:35:37 +020010168 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010169 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010170 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010171 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +030010172 if (len != PyList_GET_SIZE(tmp)) {
10173 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
10174 goto failed;
10175 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010176 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010177 }
Victor Stinner1acc1292013-07-27 00:03:47 +020010178 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010179 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010180 *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
10181 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010182 if (*out == NULL) goto failed;
10183 return 0;
10184 }
10185
10186 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
10187 failed:
10188 Py_XDECREF(tmp);
10189 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010190}
10191
10192int
Victor Stinner5cf47822020-11-02 22:03:28 +010010193obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +020010194 PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010195{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010196 PyObject* tmp = NULL;
Pablo Galindoa5634c42020-09-16 19:42:00 +010010197 asdl_arg_seq* posonlyargs;
10198 asdl_arg_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +020010199 arg_ty vararg;
Pablo Galindoa5634c42020-09-16 19:42:00 +010010200 asdl_arg_seq* kwonlyargs;
10201 asdl_expr_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +020010202 arg_ty kwarg;
Pablo Galindoa5634c42020-09-16 19:42:00 +010010203 asdl_expr_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010204
Victor Stinner74419f02020-07-03 11:35:37 +020010205 if (_PyObject_LookupAttr(obj, state->posonlyargs, &tmp) < 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +010010206 return 1;
10207 }
10208 if (tmp == NULL) {
10209 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
10210 return 1;
10211 }
10212 else {
10213 int res;
10214 Py_ssize_t len;
10215 Py_ssize_t i;
10216 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010217 PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Pablo Galindo8c77b8c2019-04-29 13:36:57 +010010218 goto failed;
10219 }
10220 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010221 posonlyargs = _Py_asdl_arg_seq_new(len, arena);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +010010222 if (posonlyargs == NULL) goto failed;
10223 for (i = 0; i < len; i++) {
10224 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010225 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10226 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010227 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10228 goto failed;
10229 }
Victor Stinner74419f02020-07-03 11:35:37 +020010230 res = obj2ast_arg(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010231 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010232 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +010010233 if (res != 0) goto failed;
10234 if (len != PyList_GET_SIZE(tmp)) {
10235 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
10236 goto failed;
10237 }
10238 asdl_seq_SET(posonlyargs, i, val);
10239 }
10240 Py_CLEAR(tmp);
10241 }
Victor Stinner74419f02020-07-03 11:35:37 +020010242 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +020010243 return 1;
10244 }
10245 if (tmp == NULL) {
10246 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
10247 return 1;
10248 }
10249 else {
10250 int res;
10251 Py_ssize_t len;
10252 Py_ssize_t i;
10253 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010254 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Pablo Galindocd6e83b2019-07-15 01:32:18 +020010255 goto failed;
10256 }
10257 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010258 args = _Py_asdl_arg_seq_new(len, arena);
Pablo Galindocd6e83b2019-07-15 01:32:18 +020010259 if (args == NULL) goto failed;
10260 for (i = 0; i < len; i++) {
10261 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010262 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10263 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010264 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10265 goto failed;
10266 }
Victor Stinner74419f02020-07-03 11:35:37 +020010267 res = obj2ast_arg(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010268 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010269 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +020010270 if (res != 0) goto failed;
10271 if (len != PyList_GET_SIZE(tmp)) {
10272 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
10273 goto failed;
10274 }
10275 asdl_seq_SET(args, i, val);
10276 }
10277 Py_CLEAR(tmp);
10278 }
Victor Stinner74419f02020-07-03 11:35:37 +020010279 if (_PyObject_LookupAttr(obj, state->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010280 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010281 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010282 if (tmp == NULL || tmp == Py_None) {
10283 Py_CLEAR(tmp);
10284 vararg = NULL;
10285 }
10286 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010287 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010288 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10289 goto failed;
10290 }
Victor Stinner74419f02020-07-03 11:35:37 +020010291 res = obj2ast_arg(state, tmp, &vararg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010292 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010293 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010294 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010295 }
Victor Stinner74419f02020-07-03 11:35:37 +020010296 if (_PyObject_LookupAttr(obj, state->kwonlyargs, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010297 return 1;
10298 }
10299 if (tmp == NULL) {
10300 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
10301 return 1;
10302 }
10303 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010304 int res;
10305 Py_ssize_t len;
10306 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010307 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010308 PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010309 goto failed;
10310 }
10311 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010312 kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010313 if (kwonlyargs == NULL) goto failed;
10314 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010315 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010316 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10317 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010318 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10319 goto failed;
10320 }
Victor Stinner74419f02020-07-03 11:35:37 +020010321 res = obj2ast_arg(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010322 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010323 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010324 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +030010325 if (len != PyList_GET_SIZE(tmp)) {
10326 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
10327 goto failed;
10328 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010329 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010330 }
Victor Stinner1acc1292013-07-27 00:03:47 +020010331 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010332 }
Victor Stinner74419f02020-07-03 11:35:37 +020010333 if (_PyObject_LookupAttr(obj, state->kw_defaults, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010334 return 1;
10335 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010336 if (tmp == NULL) {
10337 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
10338 return 1;
10339 }
10340 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010341 int res;
10342 Py_ssize_t len;
10343 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010344 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010345 PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010346 goto failed;
10347 }
10348 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010349 kw_defaults = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010350 if (kw_defaults == NULL) goto failed;
10351 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010352 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010353 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10354 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010355 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10356 goto failed;
10357 }
Victor Stinner74419f02020-07-03 11:35:37 +020010358 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010359 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010360 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010361 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +030010362 if (len != PyList_GET_SIZE(tmp)) {
10363 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
10364 goto failed;
10365 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010366 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010367 }
Victor Stinner1acc1292013-07-27 00:03:47 +020010368 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010369 }
Victor Stinner74419f02020-07-03 11:35:37 +020010370 if (_PyObject_LookupAttr(obj, state->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010371 return 1;
10372 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010373 if (tmp == NULL || tmp == Py_None) {
10374 Py_CLEAR(tmp);
10375 kwarg = NULL;
10376 }
10377 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +020010378 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010379 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10380 goto failed;
10381 }
Victor Stinner74419f02020-07-03 11:35:37 +020010382 res = obj2ast_arg(state, tmp, &kwarg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010383 Py_LeaveRecursiveCall();
Victor Stinneree4b59c2013-07-27 00:01:35 +020010384 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +020010385 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010386 }
Victor Stinner74419f02020-07-03 11:35:37 +020010387 if (_PyObject_LookupAttr(obj, state->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010388 return 1;
10389 }
10390 if (tmp == NULL) {
10391 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
10392 return 1;
10393 }
10394 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +020010395 int res;
10396 Py_ssize_t len;
10397 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +020010398 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010399 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinneree4b59c2013-07-27 00:01:35 +020010400 goto failed;
10401 }
10402 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010403 defaults = _Py_asdl_expr_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010404 if (defaults == NULL) goto failed;
10405 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010406 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010407 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10408 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010409 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10410 goto failed;
10411 }
Victor Stinner74419f02020-07-03 11:35:37 +020010412 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010413 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010414 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010415 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +030010416 if (len != PyList_GET_SIZE(tmp)) {
10417 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
10418 goto failed;
10419 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010420 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010421 }
Victor Stinnerb3189902013-07-27 00:04:42 +020010422 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010423 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010424 *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
10425 kwarg, defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010426 return 0;
10427failed:
10428 Py_XDECREF(tmp);
10429 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010430}
10431
10432int
Victor Stinner5cf47822020-11-02 22:03:28 +010010433obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010434{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010435 PyObject* tmp = NULL;
10436 identifier arg;
10437 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -080010438 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +010010439 int lineno;
10440 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010441 int end_lineno;
10442 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010443
Victor Stinner74419f02020-07-03 11:35:37 +020010444 if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010445 return 1;
10446 }
10447 if (tmp == NULL) {
10448 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
10449 return 1;
10450 }
10451 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010452 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010453 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10454 goto failed;
10455 }
Victor Stinner74419f02020-07-03 11:35:37 +020010456 res = obj2ast_identifier(state, tmp, &arg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010457 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010458 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010459 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010460 }
Victor Stinner74419f02020-07-03 11:35:37 +020010461 if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010462 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010463 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010464 if (tmp == NULL || tmp == Py_None) {
10465 Py_CLEAR(tmp);
10466 annotation = NULL;
10467 }
10468 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010469 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010470 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10471 goto failed;
10472 }
Victor Stinner74419f02020-07-03 11:35:37 +020010473 res = obj2ast_expr(state, tmp, &annotation, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010474 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010475 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010476 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010477 }
Victor Stinner74419f02020-07-03 11:35:37 +020010478 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -080010479 return 1;
10480 }
10481 if (tmp == NULL || tmp == Py_None) {
10482 Py_CLEAR(tmp);
10483 type_comment = NULL;
10484 }
10485 else {
10486 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010487 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10488 goto failed;
10489 }
Victor Stinner74419f02020-07-03 11:35:37 +020010490 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010491 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -080010492 if (res != 0) goto failed;
10493 Py_CLEAR(tmp);
10494 }
Victor Stinner74419f02020-07-03 11:35:37 +020010495 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010496 return 1;
10497 }
10498 if (tmp == NULL) {
10499 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
10500 return 1;
10501 }
10502 else {
Victor Stinnerc106c682015-11-06 17:01:48 +010010503 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010504 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10505 goto failed;
10506 }
Victor Stinner74419f02020-07-03 11:35:37 +020010507 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010508 Py_LeaveRecursiveCall();
Victor Stinnerc106c682015-11-06 17:01:48 +010010509 if (res != 0) goto failed;
10510 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010511 }
Victor Stinner74419f02020-07-03 11:35:37 +020010512 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Victor Stinnerc106c682015-11-06 17:01:48 +010010513 return 1;
10514 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010515 if (tmp == NULL) {
10516 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
10517 return 1;
10518 }
10519 else {
Victor Stinnerc106c682015-11-06 17:01:48 +010010520 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010521 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10522 goto failed;
10523 }
Victor Stinner74419f02020-07-03 11:35:37 +020010524 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010525 Py_LeaveRecursiveCall();
Victor Stinnerc106c682015-11-06 17:01:48 +010010526 if (res != 0) goto failed;
10527 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +010010528 }
Victor Stinner74419f02020-07-03 11:35:37 +020010529 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010530 return 1;
10531 }
10532 if (tmp == NULL || tmp == Py_None) {
10533 Py_CLEAR(tmp);
10534 end_lineno = 0;
10535 }
10536 else {
10537 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010538 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10539 goto failed;
10540 }
Victor Stinner74419f02020-07-03 11:35:37 +020010541 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010542 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010543 if (res != 0) goto failed;
10544 Py_CLEAR(tmp);
10545 }
Victor Stinner74419f02020-07-03 11:35:37 +020010546 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010547 return 1;
10548 }
10549 if (tmp == NULL || tmp == Py_None) {
10550 Py_CLEAR(tmp);
10551 end_col_offset = 0;
10552 }
10553 else {
10554 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010555 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10556 goto failed;
10557 }
Victor Stinner74419f02020-07-03 11:35:37 +020010558 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010559 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010560 if (res != 0) goto failed;
10561 Py_CLEAR(tmp);
10562 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010563 *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
10564 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010565 return 0;
10566failed:
10567 Py_XDECREF(tmp);
10568 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010569}
10570
10571int
Victor Stinner5cf47822020-11-02 22:03:28 +010010572obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
10573 PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010574{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010575 PyObject* tmp = NULL;
10576 identifier arg;
10577 expr_ty value;
Pablo Galindo168660b2020-04-02 00:47:39 +010010578 int lineno;
10579 int col_offset;
10580 int end_lineno;
10581 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010582
Victor Stinner74419f02020-07-03 11:35:37 +020010583 if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010584 return 1;
10585 }
10586 if (tmp == NULL || tmp == Py_None) {
10587 Py_CLEAR(tmp);
10588 arg = NULL;
10589 }
10590 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010591 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010592 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10593 goto failed;
10594 }
Victor Stinner74419f02020-07-03 11:35:37 +020010595 res = obj2ast_identifier(state, tmp, &arg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010596 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010597 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010598 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010599 }
Victor Stinner74419f02020-07-03 11:35:37 +020010600 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010601 return 1;
10602 }
10603 if (tmp == NULL) {
10604 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
10605 return 1;
10606 }
10607 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010608 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010609 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10610 goto failed;
10611 }
Victor Stinner74419f02020-07-03 11:35:37 +020010612 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010613 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010614 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010615 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010616 }
Victor Stinner74419f02020-07-03 11:35:37 +020010617 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Pablo Galindo168660b2020-04-02 00:47:39 +010010618 return 1;
10619 }
10620 if (tmp == NULL) {
10621 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
10622 return 1;
10623 }
10624 else {
10625 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010626 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10627 goto failed;
10628 }
Victor Stinner74419f02020-07-03 11:35:37 +020010629 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010630 Py_LeaveRecursiveCall();
Pablo Galindo168660b2020-04-02 00:47:39 +010010631 if (res != 0) goto failed;
10632 Py_CLEAR(tmp);
10633 }
Victor Stinner74419f02020-07-03 11:35:37 +020010634 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Pablo Galindo168660b2020-04-02 00:47:39 +010010635 return 1;
10636 }
10637 if (tmp == NULL) {
10638 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
10639 return 1;
10640 }
10641 else {
10642 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010643 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10644 goto failed;
10645 }
Victor Stinner74419f02020-07-03 11:35:37 +020010646 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010647 Py_LeaveRecursiveCall();
Pablo Galindo168660b2020-04-02 00:47:39 +010010648 if (res != 0) goto failed;
10649 Py_CLEAR(tmp);
10650 }
Victor Stinner74419f02020-07-03 11:35:37 +020010651 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Pablo Galindo168660b2020-04-02 00:47:39 +010010652 return 1;
10653 }
10654 if (tmp == NULL || tmp == Py_None) {
10655 Py_CLEAR(tmp);
10656 end_lineno = 0;
10657 }
10658 else {
10659 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010660 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10661 goto failed;
10662 }
Victor Stinner74419f02020-07-03 11:35:37 +020010663 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010664 Py_LeaveRecursiveCall();
Pablo Galindo168660b2020-04-02 00:47:39 +010010665 if (res != 0) goto failed;
10666 Py_CLEAR(tmp);
10667 }
Victor Stinner74419f02020-07-03 11:35:37 +020010668 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Pablo Galindo168660b2020-04-02 00:47:39 +010010669 return 1;
10670 }
10671 if (tmp == NULL || tmp == Py_None) {
10672 Py_CLEAR(tmp);
10673 end_col_offset = 0;
10674 }
10675 else {
10676 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010677 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10678 goto failed;
10679 }
Victor Stinner74419f02020-07-03 11:35:37 +020010680 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010681 Py_LeaveRecursiveCall();
Pablo Galindo168660b2020-04-02 00:47:39 +010010682 if (res != 0) goto failed;
10683 Py_CLEAR(tmp);
10684 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010685 *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
10686 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010687 return 0;
10688failed:
10689 Py_XDECREF(tmp);
10690 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010691}
10692
10693int
Victor Stinner5cf47822020-11-02 22:03:28 +010010694obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
Victor Stinner74419f02020-07-03 11:35:37 +020010695 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010696{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010697 PyObject* tmp = NULL;
10698 identifier name;
10699 identifier asname;
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010700 int lineno;
10701 int col_offset;
10702 int end_lineno;
10703 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010704
Victor Stinner74419f02020-07-03 11:35:37 +020010705 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010706 return 1;
10707 }
10708 if (tmp == NULL) {
10709 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
10710 return 1;
10711 }
10712 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010713 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010714 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10715 goto failed;
10716 }
Victor Stinner74419f02020-07-03 11:35:37 +020010717 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010718 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010719 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010720 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010721 }
Victor Stinner74419f02020-07-03 11:35:37 +020010722 if (_PyObject_LookupAttr(obj, state->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010723 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010724 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010725 if (tmp == NULL || tmp == Py_None) {
10726 Py_CLEAR(tmp);
10727 asname = NULL;
10728 }
10729 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010730 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010731 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10732 goto failed;
10733 }
Victor Stinner74419f02020-07-03 11:35:37 +020010734 res = obj2ast_identifier(state, tmp, &asname, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010735 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010736 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010737 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010738 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010739 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10740 return 1;
10741 }
10742 if (tmp == NULL) {
10743 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
10744 return 1;
10745 }
10746 else {
10747 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010748 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10749 goto failed;
10750 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010751 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010752 Py_LeaveRecursiveCall();
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010753 if (res != 0) goto failed;
10754 Py_CLEAR(tmp);
10755 }
10756 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10757 return 1;
10758 }
10759 if (tmp == NULL) {
10760 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
10761 return 1;
10762 }
10763 else {
10764 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010765 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10766 goto failed;
10767 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010768 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010769 Py_LeaveRecursiveCall();
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010770 if (res != 0) goto failed;
10771 Py_CLEAR(tmp);
10772 }
10773 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10774 return 1;
10775 }
10776 if (tmp == NULL || tmp == Py_None) {
10777 Py_CLEAR(tmp);
10778 end_lineno = 0;
10779 }
10780 else {
10781 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010782 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10783 goto failed;
10784 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010785 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010786 Py_LeaveRecursiveCall();
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010787 if (res != 0) goto failed;
10788 Py_CLEAR(tmp);
10789 }
10790 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10791 return 1;
10792 }
10793 if (tmp == NULL || tmp == Py_None) {
10794 Py_CLEAR(tmp);
10795 end_col_offset = 0;
10796 }
10797 else {
10798 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010799 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10800 goto failed;
10801 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010802 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010803 Py_LeaveRecursiveCall();
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010804 if (res != 0) goto failed;
10805 Py_CLEAR(tmp);
10806 }
10807 *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
10808 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010809 return 0;
10810failed:
10811 Py_XDECREF(tmp);
10812 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010813}
10814
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010815int
Victor Stinner5cf47822020-11-02 22:03:28 +010010816obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +020010817 PyArena* arena)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010818{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010819 PyObject* tmp = NULL;
10820 expr_ty context_expr;
10821 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010822
Victor Stinner74419f02020-07-03 11:35:37 +020010823 if (_PyObject_LookupAttr(obj, state->context_expr, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010824 return 1;
10825 }
10826 if (tmp == NULL) {
10827 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
10828 return 1;
10829 }
10830 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010831 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010832 if (Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
10833 goto failed;
10834 }
Victor Stinner74419f02020-07-03 11:35:37 +020010835 res = obj2ast_expr(state, tmp, &context_expr, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010836 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010837 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010838 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010839 }
Victor Stinner74419f02020-07-03 11:35:37 +020010840 if (_PyObject_LookupAttr(obj, state->optional_vars, &tmp) < 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010841 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010842 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010843 if (tmp == NULL || tmp == Py_None) {
10844 Py_CLEAR(tmp);
10845 optional_vars = NULL;
10846 }
10847 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010848 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010849 if (Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
10850 goto failed;
10851 }
Victor Stinner74419f02020-07-03 11:35:37 +020010852 res = obj2ast_expr(state, tmp, &optional_vars, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010853 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010854 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010855 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010856 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010857 *out = _PyAST_withitem(context_expr, optional_vars, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010858 return 0;
10859failed:
10860 Py_XDECREF(tmp);
10861 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010862}
10863
Guido van Rossumdcfcd142019-01-31 03:40:27 -080010864int
Brandt Bucher145bf262021-02-26 14:51:55 -080010865obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
10866 PyArena* arena)
10867{
10868 PyObject* tmp = NULL;
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010869 pattern_ty pattern;
Brandt Bucher145bf262021-02-26 14:51:55 -080010870 expr_ty guard;
10871 asdl_stmt_seq* body;
10872
10873 if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
10874 return 1;
10875 }
10876 if (tmp == NULL) {
10877 PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
10878 return 1;
10879 }
10880 else {
10881 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010882 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10883 goto failed;
10884 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010885 res = obj2ast_pattern(state, tmp, &pattern, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010886 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -080010887 if (res != 0) goto failed;
10888 Py_CLEAR(tmp);
10889 }
10890 if (_PyObject_LookupAttr(obj, state->guard, &tmp) < 0) {
10891 return 1;
10892 }
10893 if (tmp == NULL || tmp == Py_None) {
10894 Py_CLEAR(tmp);
10895 guard = NULL;
10896 }
10897 else {
10898 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010899 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10900 goto failed;
10901 }
Brandt Bucher145bf262021-02-26 14:51:55 -080010902 res = obj2ast_expr(state, tmp, &guard, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010903 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -080010904 if (res != 0) goto failed;
10905 Py_CLEAR(tmp);
10906 }
10907 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
10908 return 1;
10909 }
10910 if (tmp == NULL) {
10911 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from match_case");
10912 return 1;
10913 }
10914 else {
10915 int res;
10916 Py_ssize_t len;
10917 Py_ssize_t i;
10918 if (!PyList_Check(tmp)) {
10919 PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10920 goto failed;
10921 }
10922 len = PyList_GET_SIZE(tmp);
10923 body = _Py_asdl_stmt_seq_new(len, arena);
10924 if (body == NULL) goto failed;
10925 for (i = 0; i < len; i++) {
10926 stmt_ty val;
10927 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10928 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010929 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10930 goto failed;
10931 }
Brandt Bucher145bf262021-02-26 14:51:55 -080010932 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010933 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -080010934 Py_DECREF(tmp2);
10935 if (res != 0) goto failed;
10936 if (len != PyList_GET_SIZE(tmp)) {
10937 PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
10938 goto failed;
10939 }
10940 asdl_seq_SET(body, i, val);
10941 }
10942 Py_CLEAR(tmp);
10943 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010944 *out = _PyAST_match_case(pattern, guard, body, arena);
Brandt Bucher145bf262021-02-26 14:51:55 -080010945 return 0;
10946failed:
10947 Py_XDECREF(tmp);
10948 return 1;
10949}
10950
10951int
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010952obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
10953 PyArena* arena)
10954{
10955 int isinstance;
10956
10957 PyObject *tmp = NULL;
10958 PyObject *tp;
10959 int lineno;
10960 int col_offset;
10961 int end_lineno;
10962 int end_col_offset;
10963
10964 if (obj == Py_None) {
10965 *out = NULL;
10966 return 0;
10967 }
10968 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10969 return 1;
10970 }
10971 if (tmp == NULL) {
10972 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
10973 return 1;
10974 }
10975 else {
10976 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010977 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
10978 goto failed;
10979 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010980 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010981 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010982 if (res != 0) goto failed;
10983 Py_CLEAR(tmp);
10984 }
10985 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10986 return 1;
10987 }
10988 if (tmp == NULL) {
10989 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
10990 return 1;
10991 }
10992 else {
10993 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010994 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
10995 goto failed;
10996 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010997 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010998 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010999 if (res != 0) goto failed;
11000 Py_CLEAR(tmp);
11001 }
11002 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11003 return 1;
11004 }
11005 if (tmp == NULL) {
11006 PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
11007 return 1;
11008 }
11009 else {
11010 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011011 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11012 goto failed;
11013 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011014 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011015 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011016 if (res != 0) goto failed;
11017 Py_CLEAR(tmp);
11018 }
11019 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11020 return 1;
11021 }
11022 if (tmp == NULL) {
11023 PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
11024 return 1;
11025 }
11026 else {
11027 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011028 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11029 goto failed;
11030 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011031 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011032 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011033 if (res != 0) goto failed;
11034 Py_CLEAR(tmp);
11035 }
11036 tp = state->MatchValue_type;
11037 isinstance = PyObject_IsInstance(obj, tp);
11038 if (isinstance == -1) {
11039 return 1;
11040 }
11041 if (isinstance) {
11042 expr_ty value;
11043
11044 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11045 return 1;
11046 }
11047 if (tmp == NULL) {
11048 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
11049 return 1;
11050 }
11051 else {
11052 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011053 if (Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
11054 goto failed;
11055 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011056 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011057 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011058 if (res != 0) goto failed;
11059 Py_CLEAR(tmp);
11060 }
11061 *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
11062 end_col_offset, arena);
11063 if (*out == NULL) goto failed;
11064 return 0;
11065 }
11066 tp = state->MatchSingleton_type;
11067 isinstance = PyObject_IsInstance(obj, tp);
11068 if (isinstance == -1) {
11069 return 1;
11070 }
11071 if (isinstance) {
11072 constant value;
11073
11074 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11075 return 1;
11076 }
11077 if (tmp == NULL) {
11078 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
11079 return 1;
11080 }
11081 else {
11082 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011083 if (Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
11084 goto failed;
11085 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011086 res = obj2ast_constant(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011087 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011088 if (res != 0) goto failed;
11089 Py_CLEAR(tmp);
11090 }
11091 *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
11092 end_col_offset, arena);
11093 if (*out == NULL) goto failed;
11094 return 0;
11095 }
11096 tp = state->MatchSequence_type;
11097 isinstance = PyObject_IsInstance(obj, tp);
11098 if (isinstance == -1) {
11099 return 1;
11100 }
11101 if (isinstance) {
11102 asdl_pattern_seq* patterns;
11103
11104 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11105 return 1;
11106 }
11107 if (tmp == NULL) {
11108 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchSequence");
11109 return 1;
11110 }
11111 else {
11112 int res;
11113 Py_ssize_t len;
11114 Py_ssize_t i;
11115 if (!PyList_Check(tmp)) {
11116 PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11117 goto failed;
11118 }
11119 len = PyList_GET_SIZE(tmp);
11120 patterns = _Py_asdl_pattern_seq_new(len, arena);
11121 if (patterns == NULL) goto failed;
11122 for (i = 0; i < len; i++) {
11123 pattern_ty val;
11124 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11125 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011126 if (Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
11127 goto failed;
11128 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011129 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011130 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011131 Py_DECREF(tmp2);
11132 if (res != 0) goto failed;
11133 if (len != PyList_GET_SIZE(tmp)) {
11134 PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
11135 goto failed;
11136 }
11137 asdl_seq_SET(patterns, i, val);
11138 }
11139 Py_CLEAR(tmp);
11140 }
11141 *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
11142 end_col_offset, arena);
11143 if (*out == NULL) goto failed;
11144 return 0;
11145 }
11146 tp = state->MatchMapping_type;
11147 isinstance = PyObject_IsInstance(obj, tp);
11148 if (isinstance == -1) {
11149 return 1;
11150 }
11151 if (isinstance) {
11152 asdl_expr_seq* keys;
11153 asdl_pattern_seq* patterns;
11154 identifier rest;
11155
11156 if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
11157 return 1;
11158 }
11159 if (tmp == NULL) {
11160 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from MatchMapping");
11161 return 1;
11162 }
11163 else {
11164 int res;
11165 Py_ssize_t len;
11166 Py_ssize_t i;
11167 if (!PyList_Check(tmp)) {
11168 PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11169 goto failed;
11170 }
11171 len = PyList_GET_SIZE(tmp);
11172 keys = _Py_asdl_expr_seq_new(len, arena);
11173 if (keys == NULL) goto failed;
11174 for (i = 0; i < len; i++) {
11175 expr_ty val;
11176 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11177 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011178 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11179 goto failed;
11180 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011181 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011182 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011183 Py_DECREF(tmp2);
11184 if (res != 0) goto failed;
11185 if (len != PyList_GET_SIZE(tmp)) {
11186 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
11187 goto failed;
11188 }
11189 asdl_seq_SET(keys, i, val);
11190 }
11191 Py_CLEAR(tmp);
11192 }
11193 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11194 return 1;
11195 }
11196 if (tmp == NULL) {
11197 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchMapping");
11198 return 1;
11199 }
11200 else {
11201 int res;
11202 Py_ssize_t len;
11203 Py_ssize_t i;
11204 if (!PyList_Check(tmp)) {
11205 PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11206 goto failed;
11207 }
11208 len = PyList_GET_SIZE(tmp);
11209 patterns = _Py_asdl_pattern_seq_new(len, arena);
11210 if (patterns == NULL) goto failed;
11211 for (i = 0; i < len; i++) {
11212 pattern_ty val;
11213 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11214 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011215 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11216 goto failed;
11217 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011218 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011219 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011220 Py_DECREF(tmp2);
11221 if (res != 0) goto failed;
11222 if (len != PyList_GET_SIZE(tmp)) {
11223 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
11224 goto failed;
11225 }
11226 asdl_seq_SET(patterns, i, val);
11227 }
11228 Py_CLEAR(tmp);
11229 }
11230 if (_PyObject_LookupAttr(obj, state->rest, &tmp) < 0) {
11231 return 1;
11232 }
11233 if (tmp == NULL || tmp == Py_None) {
11234 Py_CLEAR(tmp);
11235 rest = NULL;
11236 }
11237 else {
11238 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011239 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11240 goto failed;
11241 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011242 res = obj2ast_identifier(state, tmp, &rest, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011243 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011244 if (res != 0) goto failed;
11245 Py_CLEAR(tmp);
11246 }
11247 *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
11248 end_lineno, end_col_offset, arena);
11249 if (*out == NULL) goto failed;
11250 return 0;
11251 }
11252 tp = state->MatchClass_type;
11253 isinstance = PyObject_IsInstance(obj, tp);
11254 if (isinstance == -1) {
11255 return 1;
11256 }
11257 if (isinstance) {
11258 expr_ty cls;
11259 asdl_pattern_seq* patterns;
11260 asdl_identifier_seq* kwd_attrs;
11261 asdl_pattern_seq* kwd_patterns;
11262
11263 if (_PyObject_LookupAttr(obj, state->cls, &tmp) < 0) {
11264 return 1;
11265 }
11266 if (tmp == NULL) {
11267 PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
11268 return 1;
11269 }
11270 else {
11271 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011272 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11273 goto failed;
11274 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011275 res = obj2ast_expr(state, tmp, &cls, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011276 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011277 if (res != 0) goto failed;
11278 Py_CLEAR(tmp);
11279 }
11280 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11281 return 1;
11282 }
11283 if (tmp == NULL) {
11284 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchClass");
11285 return 1;
11286 }
11287 else {
11288 int res;
11289 Py_ssize_t len;
11290 Py_ssize_t i;
11291 if (!PyList_Check(tmp)) {
11292 PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11293 goto failed;
11294 }
11295 len = PyList_GET_SIZE(tmp);
11296 patterns = _Py_asdl_pattern_seq_new(len, arena);
11297 if (patterns == NULL) goto failed;
11298 for (i = 0; i < len; i++) {
11299 pattern_ty val;
11300 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11301 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011302 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11303 goto failed;
11304 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011305 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011306 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011307 Py_DECREF(tmp2);
11308 if (res != 0) goto failed;
11309 if (len != PyList_GET_SIZE(tmp)) {
11310 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
11311 goto failed;
11312 }
11313 asdl_seq_SET(patterns, i, val);
11314 }
11315 Py_CLEAR(tmp);
11316 }
11317 if (_PyObject_LookupAttr(obj, state->kwd_attrs, &tmp) < 0) {
11318 return 1;
11319 }
11320 if (tmp == NULL) {
11321 PyErr_SetString(PyExc_TypeError, "required field \"kwd_attrs\" missing from MatchClass");
11322 return 1;
11323 }
11324 else {
11325 int res;
11326 Py_ssize_t len;
11327 Py_ssize_t i;
11328 if (!PyList_Check(tmp)) {
11329 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11330 goto failed;
11331 }
11332 len = PyList_GET_SIZE(tmp);
11333 kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
11334 if (kwd_attrs == NULL) goto failed;
11335 for (i = 0; i < len; i++) {
11336 identifier val;
11337 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11338 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011339 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11340 goto failed;
11341 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011342 res = obj2ast_identifier(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011343 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011344 Py_DECREF(tmp2);
11345 if (res != 0) goto failed;
11346 if (len != PyList_GET_SIZE(tmp)) {
11347 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
11348 goto failed;
11349 }
11350 asdl_seq_SET(kwd_attrs, i, val);
11351 }
11352 Py_CLEAR(tmp);
11353 }
11354 if (_PyObject_LookupAttr(obj, state->kwd_patterns, &tmp) < 0) {
11355 return 1;
11356 }
11357 if (tmp == NULL) {
11358 PyErr_SetString(PyExc_TypeError, "required field \"kwd_patterns\" missing from MatchClass");
11359 return 1;
11360 }
11361 else {
11362 int res;
11363 Py_ssize_t len;
11364 Py_ssize_t i;
11365 if (!PyList_Check(tmp)) {
11366 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11367 goto failed;
11368 }
11369 len = PyList_GET_SIZE(tmp);
11370 kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
11371 if (kwd_patterns == NULL) goto failed;
11372 for (i = 0; i < len; i++) {
11373 pattern_ty val;
11374 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11375 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011376 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11377 goto failed;
11378 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011379 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011380 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011381 Py_DECREF(tmp2);
11382 if (res != 0) goto failed;
11383 if (len != PyList_GET_SIZE(tmp)) {
11384 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
11385 goto failed;
11386 }
11387 asdl_seq_SET(kwd_patterns, i, val);
11388 }
11389 Py_CLEAR(tmp);
11390 }
11391 *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
11392 lineno, col_offset, end_lineno,
11393 end_col_offset, arena);
11394 if (*out == NULL) goto failed;
11395 return 0;
11396 }
11397 tp = state->MatchStar_type;
11398 isinstance = PyObject_IsInstance(obj, tp);
11399 if (isinstance == -1) {
11400 return 1;
11401 }
11402 if (isinstance) {
11403 identifier name;
11404
11405 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11406 return 1;
11407 }
11408 if (tmp == NULL || tmp == Py_None) {
11409 Py_CLEAR(tmp);
11410 name = NULL;
11411 }
11412 else {
11413 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011414 if (Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
11415 goto failed;
11416 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011417 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011418 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011419 if (res != 0) goto failed;
11420 Py_CLEAR(tmp);
11421 }
11422 *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
11423 end_col_offset, arena);
11424 if (*out == NULL) goto failed;
11425 return 0;
11426 }
11427 tp = state->MatchAs_type;
11428 isinstance = PyObject_IsInstance(obj, tp);
11429 if (isinstance == -1) {
11430 return 1;
11431 }
11432 if (isinstance) {
11433 pattern_ty pattern;
11434 identifier name;
11435
11436 if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
11437 return 1;
11438 }
11439 if (tmp == NULL || tmp == Py_None) {
11440 Py_CLEAR(tmp);
11441 pattern = NULL;
11442 }
11443 else {
11444 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011445 if (Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
11446 goto failed;
11447 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011448 res = obj2ast_pattern(state, tmp, &pattern, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011449 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011450 if (res != 0) goto failed;
11451 Py_CLEAR(tmp);
11452 }
11453 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11454 return 1;
11455 }
11456 if (tmp == NULL || tmp == Py_None) {
11457 Py_CLEAR(tmp);
11458 name = NULL;
11459 }
11460 else {
11461 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011462 if (Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
11463 goto failed;
11464 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011465 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011466 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011467 if (res != 0) goto failed;
11468 Py_CLEAR(tmp);
11469 }
11470 *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
11471 end_col_offset, arena);
11472 if (*out == NULL) goto failed;
11473 return 0;
11474 }
11475 tp = state->MatchOr_type;
11476 isinstance = PyObject_IsInstance(obj, tp);
11477 if (isinstance == -1) {
11478 return 1;
11479 }
11480 if (isinstance) {
11481 asdl_pattern_seq* patterns;
11482
11483 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11484 return 1;
11485 }
11486 if (tmp == NULL) {
11487 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchOr");
11488 return 1;
11489 }
11490 else {
11491 int res;
11492 Py_ssize_t len;
11493 Py_ssize_t i;
11494 if (!PyList_Check(tmp)) {
11495 PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11496 goto failed;
11497 }
11498 len = PyList_GET_SIZE(tmp);
11499 patterns = _Py_asdl_pattern_seq_new(len, arena);
11500 if (patterns == NULL) goto failed;
11501 for (i = 0; i < len; i++) {
11502 pattern_ty val;
11503 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11504 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011505 if (Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
11506 goto failed;
11507 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011508 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011509 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011510 Py_DECREF(tmp2);
11511 if (res != 0) goto failed;
11512 if (len != PyList_GET_SIZE(tmp)) {
11513 PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
11514 goto failed;
11515 }
11516 asdl_seq_SET(patterns, i, val);
11517 }
11518 Py_CLEAR(tmp);
11519 }
11520 *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
11521 end_col_offset, arena);
11522 if (*out == NULL) goto failed;
11523 return 0;
11524 }
11525
11526 PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
11527 failed:
11528 Py_XDECREF(tmp);
11529 return 1;
11530}
11531
11532int
Victor Stinner5cf47822020-11-02 22:03:28 +010011533obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
11534 out, PyArena* arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011535{
11536 int isinstance;
11537
11538 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -070011539 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011540
11541 if (obj == Py_None) {
11542 *out = NULL;
11543 return 0;
11544 }
Victor Stinner74419f02020-07-03 11:35:37 +020011545 tp = state->TypeIgnore_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070011546 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011547 if (isinstance == -1) {
11548 return 1;
11549 }
11550 if (isinstance) {
11551 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -070011552 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011553
Victor Stinner74419f02020-07-03 11:35:37 +020011554 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011555 return 1;
11556 }
11557 if (tmp == NULL) {
11558 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
11559 return 1;
11560 }
11561 else {
11562 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011563 if (Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
11564 goto failed;
11565 }
Victor Stinner74419f02020-07-03 11:35:37 +020011566 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011567 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011568 if (res != 0) goto failed;
11569 Py_CLEAR(tmp);
11570 }
Victor Stinner74419f02020-07-03 11:35:37 +020011571 if (_PyObject_LookupAttr(obj, state->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -070011572 return 1;
11573 }
11574 if (tmp == NULL) {
11575 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
11576 return 1;
11577 }
11578 else {
11579 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011580 if (Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
11581 goto failed;
11582 }
Victor Stinner74419f02020-07-03 11:35:37 +020011583 res = obj2ast_string(state, tmp, &tag, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011584 Py_LeaveRecursiveCall();
Michael J. Sullivan933e1502019-05-22 07:54:20 -070011585 if (res != 0) goto failed;
11586 Py_CLEAR(tmp);
11587 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020011588 *out = _PyAST_TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011589 if (*out == NULL) goto failed;
11590 return 0;
11591 }
11592
11593 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
11594 failed:
11595 Py_XDECREF(tmp);
11596 return 1;
11597}
11598
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000011599
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011600static int
11601astmodule_exec(PyObject *m)
Martin v. Löwis577b5b92006-02-27 15:23:19 +000011602{
Victor Stinner5cf47822020-11-02 22:03:28 +010011603 struct ast_state *state = get_ast_state();
11604 if (state == NULL) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011605 return -1;
Victor Stinner91e1bc12020-07-03 14:15:53 +020011606 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011607 if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011608 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011609 }
Brandt Bucherd2f96672020-02-06 06:45:46 -080011610 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011611 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011612 }
11613 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011614 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011615 }
11616 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011617 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011618 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011619 if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011620 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011621 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011622 if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011623 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011624 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011625 if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011626 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011627 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011628 if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011629 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011630 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011631 if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
11632 {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011633 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011634 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011635 if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011636 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011637 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011638 if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011639 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011640 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011641 if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
11642 state->AsyncFunctionDef_type) < 0) {
11643 return -1;
11644 }
11645 if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
11646 return -1;
11647 }
11648 if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
11649 return -1;
11650 }
11651 if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
11652 return -1;
11653 }
11654 if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
11655 return -1;
11656 }
11657 if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
11658 return -1;
11659 }
11660 if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
11661 return -1;
11662 }
11663 if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
11664 return -1;
11665 }
11666 if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
11667 return -1;
11668 }
11669 if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
11670 return -1;
11671 }
11672 if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
11673 return -1;
11674 }
11675 if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
11676 return -1;
11677 }
11678 if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
11679 return -1;
11680 }
Brandt Bucher145bf262021-02-26 14:51:55 -080011681 if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
11682 return -1;
11683 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011684 if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
11685 return -1;
11686 }
11687 if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
11688 return -1;
11689 }
11690 if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
11691 return -1;
11692 }
11693 if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
11694 return -1;
11695 }
11696 if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
11697 return -1;
11698 }
11699 if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
11700 return -1;
11701 }
11702 if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
11703 return -1;
11704 }
11705 if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
11706 return -1;
11707 }
11708 if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
11709 return -1;
11710 }
11711 if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
11712 return -1;
11713 }
11714 if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
11715 return -1;
11716 }
11717 if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
11718 return -1;
11719 }
11720 if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
11721 return -1;
11722 }
11723 if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
11724 return -1;
11725 }
11726 if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
11727 return -1;
11728 }
11729 if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
11730 return -1;
11731 }
11732 if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
11733 return -1;
11734 }
11735 if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
11736 return -1;
11737 }
11738 if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
11739 return -1;
11740 }
11741 if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
11742 return -1;
11743 }
11744 if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
11745 return -1;
11746 }
11747 if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
11748 return -1;
11749 }
11750 if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
11751 return -1;
11752 }
11753 if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
11754 {
11755 return -1;
11756 }
11757 if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
11758 return -1;
11759 }
11760 if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
11761 return -1;
11762 }
11763 if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
11764 return -1;
11765 }
11766 if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
11767 return -1;
11768 }
11769 if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
11770 return -1;
11771 }
11772 if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080011773 < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011774 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011775 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011776 if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011777 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011778 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011779 if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011780 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011781 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011782 if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011783 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011784 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011785 if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011786 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011787 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011788 if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011789 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011790 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011791 if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011792 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011793 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011794 if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011795 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011796 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011797 if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011798 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011799 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011800 if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011801 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011802 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011803 if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
11804 {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011805 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011806 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011807 if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011808 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011809 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011810 if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011811 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011812 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011813 if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011814 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011815 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011816 if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011817 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011818 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011819 if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011820 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011821 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011822 if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011823 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011824 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011825 if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011826 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011827 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011828 if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011829 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011830 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011831 if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011832 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011833 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011834 if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011835 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011836 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011837 if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011838 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011839 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011840 if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011841 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011842 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011843 if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011844 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011845 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011846 if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011847 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011848 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011849 if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011850 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011851 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011852 if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011853 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011854 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011855 if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011856 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011857 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011858 if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011859 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011860 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011861 if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011862 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011863 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011864 if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011865 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011866 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011867 if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011868 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011869 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011870 if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011871 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011872 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011873 if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011874 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011875 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011876 if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011877 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011878 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011879 if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011880 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011881 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011882 if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011883 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011884 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011885 if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011886 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011887 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011888 if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011889 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011890 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011891 if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011892 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011893 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011894 if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011895 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011896 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011897 if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011898 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011899 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011900 if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
11901 return -1;
11902 }
11903 if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
11904 return -1;
11905 }
11906 if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
11907 return -1;
11908 }
11909 if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
11910 return -1;
11911 }
11912 if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
11913 return -1;
11914 }
11915 if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080011916 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011917 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011918 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011919 if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
11920 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011921 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011922 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011923 if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
11924 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011925 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011926 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011927 if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011928 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011929 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011930 if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011931 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011932 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011933 if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011934 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011935 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011936 if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011937 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011938 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011939 if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011940 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011941 }
Brandt Bucher145bf262021-02-26 14:51:55 -080011942 if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
11943 return -1;
11944 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011945 if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
11946 return -1;
11947 }
11948 if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
11949 return -1;
11950 }
11951 if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
11952 < 0) {
11953 return -1;
11954 }
11955 if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
11956 0) {
11957 return -1;
11958 }
11959 if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
11960 {
11961 return -1;
11962 }
11963 if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
11964 return -1;
11965 }
11966 if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
11967 return -1;
11968 }
11969 if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
11970 return -1;
11971 }
11972 if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
11973 return -1;
11974 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011975 if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011976 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011977 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011978 if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011979 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011980 }
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011981 return 0;
11982}
Victor Stinner91e1bc12020-07-03 14:15:53 +020011983
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011984static PyModuleDef_Slot astmodule_slots[] = {
11985 {Py_mod_exec, astmodule_exec},
11986 {0, NULL}
11987};
11988
11989static struct PyModuleDef _astmodule = {
11990 PyModuleDef_HEAD_INIT,
11991 .m_name = "_ast",
Victor Stinner5cf47822020-11-02 22:03:28 +010011992 // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
Victor Stinnere5fbe0c2020-09-15 18:03:34 +020011993 .m_size = 0,
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011994 .m_slots = astmodule_slots,
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011995};
11996
11997PyMODINIT_FUNC
11998PyInit__ast(void)
11999{
12000 return PyModuleDef_Init(&_astmodule);
Martin v. Löwis577b5b92006-02-27 15:23:19 +000012001}
12002
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000012003
Martin v. Löwisbd260da2006-02-26 19:42:26 +000012004PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000012005{
Victor Stinner5cf47822020-11-02 22:03:28 +010012006 struct ast_state *state = get_ast_state();
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020012007 if (state == NULL) {
Victor Stinnerbdf630c2013-07-17 00:17:15 +020012008 return NULL;
Victor Stinner91e1bc12020-07-03 14:15:53 +020012009 }
Victor Stinner74419f02020-07-03 11:35:37 +020012010 return ast2obj_mod(state, t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000012011}
Martin v. Löwis5b222132007-06-10 09:51:05 +000012012
Neal Norwitzdb4115f2008-03-31 04:20:05 +000012013/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
12014mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000012015{
Serhiy Storchaka43c97312019-09-10 13:02:30 +030012016 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000012017 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050012018
Steve Dowerb82e17e2019-05-23 08:45:22 -070012019 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
12020 return NULL;
12021 }
12022
Victor Stinner5cf47822020-11-02 22:03:28 +010012023 struct ast_state *state = get_ast_state();
12024 if (state == NULL) {
12025 return NULL;
12026 }
12027
Victor Stinner74419f02020-07-03 11:35:37 +020012028 PyObject *req_type[3];
12029 req_type[0] = state->Module_type;
12030 req_type[1] = state->Expression_type;
12031 req_type[2] = state->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050012032
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080012033 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000012034
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000012035 isinstance = PyObject_IsInstance(ast, req_type[mode]);
12036 if (isinstance == -1)
12037 return NULL;
12038 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000012039 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070012040 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000012041 return NULL;
12042 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090012043
12044 mod_ty res = NULL;
Victor Stinner74419f02020-07-03 11:35:37 +020012045 if (obj2ast_mod(state, ast, &res, arena) != 0)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000012046 return NULL;
12047 else
12048 return res;
12049}
12050
12051int PyAST_Check(PyObject* obj)
12052{
Victor Stinner5cf47822020-11-02 22:03:28 +010012053 struct ast_state *state = get_ast_state();
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020012054 if (state == NULL) {
Victor Stinnerbdf630c2013-07-17 00:17:15 +020012055 return -1;
Victor Stinner91e1bc12020-07-03 14:15:53 +020012056 }
Victor Stinner74419f02020-07-03 11:35:37 +020012057 return PyObject_IsInstance(obj, state->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000012058}
12059
Martin v. Löwis5b222132007-06-10 09:51:05 +000012060