blob: 2f84cad7749dd885990c91e537c587a338106d66 [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"
Miss Islington (bot)bea3f422022-01-07 14:30:18 -08001315 " | FormattedValue(expr value, int conversion, expr? format_spec)\n"
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001316 " | 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,
Miss Islington (bot)bea3f422022-01-07 14:30:18 -08001405 "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->format_spec,
1408 Py_None) == -1)
1409 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001410 state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001411 JoinedStr_fields, 1,
1412 "JoinedStr(expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001413 if (!state->JoinedStr_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001414 state->Constant_type = make_type(state, "Constant", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001415 Constant_fields, 2,
1416 "Constant(constant value, string? kind)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001417 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001418 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1419 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001420 state->Attribute_type = make_type(state, "Attribute", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001421 Attribute_fields, 3,
1422 "Attribute(expr value, identifier attr, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001423 if (!state->Attribute_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001424 state->Subscript_type = make_type(state, "Subscript", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001425 Subscript_fields, 3,
1426 "Subscript(expr value, expr slice, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001427 if (!state->Subscript_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001428 state->Starred_type = make_type(state, "Starred", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001429 Starred_fields, 2,
1430 "Starred(expr value, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001431 if (!state->Starred_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001432 state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
1433 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001434 "Name(identifier id, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001435 if (!state->Name_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001436 state->List_type = make_type(state, "List", state->expr_type, List_fields,
1437 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001438 "List(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001439 if (!state->List_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001440 state->Tuple_type = make_type(state, "Tuple", state->expr_type,
1441 Tuple_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001442 "Tuple(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001443 if (!state->Tuple_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001444 state->Slice_type = make_type(state, "Slice", state->expr_type,
1445 Slice_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001446 "Slice(expr? lower, expr? upper, expr? step)");
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001447 if (!state->Slice_type) return 0;
1448 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1449 return 0;
1450 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1451 return 0;
1452 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1453 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001454 state->expr_context_type = make_type(state, "expr_context",
1455 state->AST_type, NULL, 0,
Serhiy Storchaka6b975982020-03-17 23:41:08 +02001456 "expr_context = Load | Store | Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001457 if (!state->expr_context_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001458 if (!add_attributes(state, state->expr_context_type, NULL, 0)) return 0;
1459 state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
1460 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001461 "Load");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001462 if (!state->Load_type) return 0;
1463 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1464 NULL, NULL);
1465 if (!state->Load_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001466 state->Store_type = make_type(state, "Store", state->expr_context_type,
1467 NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001468 "Store");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001469 if (!state->Store_type) return 0;
1470 state->Store_singleton = PyType_GenericNew((PyTypeObject
1471 *)state->Store_type, NULL, NULL);
1472 if (!state->Store_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001473 state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001474 "Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001475 if (!state->Del_type) return 0;
1476 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1477 NULL, NULL);
1478 if (!state->Del_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001479 state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001480 "boolop = And | Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001481 if (!state->boolop_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001482 if (!add_attributes(state, state->boolop_type, NULL, 0)) return 0;
1483 state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001484 "And");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001485 if (!state->And_type) return 0;
1486 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1487 NULL, NULL);
1488 if (!state->And_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001489 state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001490 "Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001491 if (!state->Or_type) return 0;
1492 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1493 NULL, NULL);
1494 if (!state->Or_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001495 state->operator_type = make_type(state, "operator", state->AST_type, NULL,
1496 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001497 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001498 if (!state->operator_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001499 if (!add_attributes(state, state->operator_type, NULL, 0)) return 0;
1500 state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001501 "Add");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001502 if (!state->Add_type) return 0;
1503 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1504 NULL, NULL);
1505 if (!state->Add_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001506 state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001507 "Sub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001508 if (!state->Sub_type) return 0;
1509 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1510 NULL, NULL);
1511 if (!state->Sub_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001512 state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001513 "Mult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001514 if (!state->Mult_type) return 0;
1515 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1516 NULL, NULL);
1517 if (!state->Mult_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001518 state->MatMult_type = make_type(state, "MatMult", state->operator_type,
1519 NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001520 "MatMult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001521 if (!state->MatMult_type) return 0;
1522 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1523 *)state->MatMult_type, NULL,
1524 NULL);
1525 if (!state->MatMult_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001526 state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001527 "Div");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001528 if (!state->Div_type) return 0;
1529 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1530 NULL, NULL);
1531 if (!state->Div_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001532 state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001533 "Mod");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001534 if (!state->Mod_type) return 0;
1535 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1536 NULL, NULL);
1537 if (!state->Mod_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001538 state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001539 "Pow");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001540 if (!state->Pow_type) return 0;
1541 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1542 NULL, NULL);
1543 if (!state->Pow_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001544 state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
1545 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001546 "LShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001547 if (!state->LShift_type) return 0;
1548 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1549 *)state->LShift_type, NULL,
1550 NULL);
1551 if (!state->LShift_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001552 state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
1553 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001554 "RShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001555 if (!state->RShift_type) return 0;
1556 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1557 *)state->RShift_type, NULL,
1558 NULL);
1559 if (!state->RShift_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001560 state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001561 "BitOr");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001562 if (!state->BitOr_type) return 0;
1563 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1564 *)state->BitOr_type, NULL, NULL);
1565 if (!state->BitOr_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001566 state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
1567 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001568 "BitXor");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001569 if (!state->BitXor_type) return 0;
1570 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1571 *)state->BitXor_type, NULL,
1572 NULL);
1573 if (!state->BitXor_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001574 state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
1575 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001576 "BitAnd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001577 if (!state->BitAnd_type) return 0;
1578 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1579 *)state->BitAnd_type, NULL,
1580 NULL);
1581 if (!state->BitAnd_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001582 state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
1583 NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001584 "FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001585 if (!state->FloorDiv_type) return 0;
1586 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1587 *)state->FloorDiv_type, NULL,
1588 NULL);
1589 if (!state->FloorDiv_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001590 state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001591 "unaryop = Invert | Not | UAdd | USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001592 if (!state->unaryop_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001593 if (!add_attributes(state, state->unaryop_type, NULL, 0)) return 0;
1594 state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
1595 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001596 "Invert");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001597 if (!state->Invert_type) return 0;
1598 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1599 *)state->Invert_type, NULL,
1600 NULL);
1601 if (!state->Invert_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001602 state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001603 "Not");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001604 if (!state->Not_type) return 0;
1605 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1606 NULL, NULL);
1607 if (!state->Not_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001608 state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001609 "UAdd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001610 if (!state->UAdd_type) return 0;
1611 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1612 NULL, NULL);
1613 if (!state->UAdd_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001614 state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001615 "USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001616 if (!state->USub_type) return 0;
1617 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1618 NULL, NULL);
1619 if (!state->USub_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001620 state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001621 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001622 if (!state->cmpop_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001623 if (!add_attributes(state, state->cmpop_type, NULL, 0)) return 0;
1624 state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001625 "Eq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001626 if (!state->Eq_type) return 0;
1627 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1628 NULL, NULL);
1629 if (!state->Eq_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001630 state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001631 "NotEq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001632 if (!state->NotEq_type) return 0;
1633 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1634 *)state->NotEq_type, NULL, NULL);
1635 if (!state->NotEq_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001636 state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001637 "Lt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001638 if (!state->Lt_type) return 0;
1639 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1640 NULL, NULL);
1641 if (!state->Lt_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001642 state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001643 "LtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001644 if (!state->LtE_type) return 0;
1645 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1646 NULL, NULL);
1647 if (!state->LtE_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001648 state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001649 "Gt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001650 if (!state->Gt_type) return 0;
1651 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1652 NULL, NULL);
1653 if (!state->Gt_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001654 state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001655 "GtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001656 if (!state->GtE_type) return 0;
1657 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1658 NULL, NULL);
1659 if (!state->GtE_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001660 state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001661 "Is");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001662 if (!state->Is_type) return 0;
1663 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1664 NULL, NULL);
1665 if (!state->Is_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001666 state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001667 "IsNot");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001668 if (!state->IsNot_type) return 0;
1669 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1670 *)state->IsNot_type, NULL, NULL);
1671 if (!state->IsNot_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001672 state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001673 "In");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001674 if (!state->In_type) return 0;
1675 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1676 NULL, NULL);
1677 if (!state->In_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001678 state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001679 "NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001680 if (!state->NotIn_type) return 0;
1681 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1682 *)state->NotIn_type, NULL, NULL);
1683 if (!state->NotIn_singleton) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001684 state->comprehension_type = make_type(state, "comprehension",
1685 state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001686 comprehension_fields, 4,
1687 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001688 if (!state->comprehension_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001689 if (!add_attributes(state, state->comprehension_type, NULL, 0)) return 0;
1690 state->excepthandler_type = make_type(state, "excepthandler",
1691 state->AST_type, NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001692 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001693 if (!state->excepthandler_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001694 if (!add_attributes(state, state->excepthandler_type,
1695 excepthandler_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001696 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1697 == -1)
1698 return 0;
1699 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1700 Py_None) == -1)
1701 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001702 state->ExceptHandler_type = make_type(state, "ExceptHandler",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001703 state->excepthandler_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001704 ExceptHandler_fields, 3,
1705 "ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001706 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001707 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1708 return 0;
1709 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1710 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001711 state->arguments_type = make_type(state, "arguments", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001712 arguments_fields, 7,
1713 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001714 if (!state->arguments_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001715 if (!add_attributes(state, state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001716 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1717 return 0;
1718 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1719 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001720 state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001721 "arg(identifier arg, expr? annotation, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001722 if (!state->arg_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001723 if (!add_attributes(state, state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001724 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1725 return 0;
1726 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1727 return 0;
1728 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1729 return 0;
1730 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1731 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001732 state->keyword_type = make_type(state, "keyword", state->AST_type,
1733 keyword_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001734 "keyword(identifier? arg, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001735 if (!state->keyword_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001736 if (!add_attributes(state, state->keyword_type, keyword_attributes, 4))
1737 return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001738 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1739 return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01001740 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
1741 return 0;
1742 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
1743 == -1)
1744 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001745 state->alias_type = make_type(state, "alias", state->AST_type,
1746 alias_fields, 2,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001747 "alias(identifier name, identifier? asname)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001748 if (!state->alias_type) return 0;
Matthew Suozzo75a06f02021-04-10 16:56:28 -04001749 if (!add_attributes(state, state->alias_type, alias_attributes, 4)) return
1750 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001751 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
1752 return 0;
Matthew Suozzo75a06f02021-04-10 16:56:28 -04001753 if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
1754 return 0;
1755 if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
1756 -1)
1757 return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001758 state->withitem_type = make_type(state, "withitem", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001759 withitem_fields, 2,
1760 "withitem(expr context_expr, expr? optional_vars)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001761 if (!state->withitem_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001762 if (!add_attributes(state, state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001763 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
1764 == -1)
1765 return 0;
Brandt Bucher145bf262021-02-26 14:51:55 -08001766 state->match_case_type = make_type(state, "match_case", state->AST_type,
1767 match_case_fields, 3,
Nick Coghlan1e7b8582021-04-29 15:58:44 +10001768 "match_case(pattern pattern, expr? guard, stmt* body)");
Brandt Bucher145bf262021-02-26 14:51:55 -08001769 if (!state->match_case_type) return 0;
1770 if (!add_attributes(state, state->match_case_type, NULL, 0)) return 0;
1771 if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
1772 return 0;
Nick Coghlan1e7b8582021-04-29 15:58:44 +10001773 state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
1774 "pattern = MatchValue(expr value)\n"
1775 " | MatchSingleton(constant value)\n"
1776 " | MatchSequence(pattern* patterns)\n"
1777 " | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
1778 " | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
1779 " | MatchStar(identifier? name)\n"
1780 " | MatchAs(pattern? pattern, identifier? name)\n"
1781 " | MatchOr(pattern* patterns)");
1782 if (!state->pattern_type) return 0;
1783 if (!add_attributes(state, state->pattern_type, pattern_attributes, 4))
1784 return 0;
1785 state->MatchValue_type = make_type(state, "MatchValue",
1786 state->pattern_type, MatchValue_fields,
1787 1,
1788 "MatchValue(expr value)");
1789 if (!state->MatchValue_type) return 0;
1790 state->MatchSingleton_type = make_type(state, "MatchSingleton",
1791 state->pattern_type,
1792 MatchSingleton_fields, 1,
1793 "MatchSingleton(constant value)");
1794 if (!state->MatchSingleton_type) return 0;
1795 state->MatchSequence_type = make_type(state, "MatchSequence",
1796 state->pattern_type,
1797 MatchSequence_fields, 1,
1798 "MatchSequence(pattern* patterns)");
1799 if (!state->MatchSequence_type) return 0;
1800 state->MatchMapping_type = make_type(state, "MatchMapping",
1801 state->pattern_type,
1802 MatchMapping_fields, 3,
1803 "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
1804 if (!state->MatchMapping_type) return 0;
1805 if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
1806 return 0;
1807 state->MatchClass_type = make_type(state, "MatchClass",
1808 state->pattern_type, MatchClass_fields,
1809 4,
1810 "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
1811 if (!state->MatchClass_type) return 0;
1812 state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
1813 MatchStar_fields, 1,
1814 "MatchStar(identifier? name)");
1815 if (!state->MatchStar_type) return 0;
1816 if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
1817 return 0;
1818 state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
1819 MatchAs_fields, 2,
1820 "MatchAs(pattern? pattern, identifier? name)");
1821 if (!state->MatchAs_type) return 0;
1822 if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
1823 return 0;
1824 if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
1825 return 0;
1826 state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
1827 MatchOr_fields, 1,
1828 "MatchOr(pattern* patterns)");
1829 if (!state->MatchOr_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001830 state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
1831 NULL, 0,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001832 "type_ignore = TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001833 if (!state->type_ignore_type) return 0;
Victor Stinner74419f02020-07-03 11:35:37 +02001834 if (!add_attributes(state, state->type_ignore_type, NULL, 0)) return 0;
1835 state->TypeIgnore_type = make_type(state, "TypeIgnore",
1836 state->type_ignore_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001837 TypeIgnore_fields, 2,
1838 "TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001839 if (!state->TypeIgnore_type) return 0;
Victor Stinnerfd957c12020-11-03 18:07:15 +01001840
Dino Viehlandac46eb42019-09-11 10:16:34 -07001841 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001842 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001843}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001844
Victor Stinner5cf47822020-11-02 22:03:28 +01001845static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001846 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001847static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001848 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001849static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001850 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001851static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001852 expr_context_ty* out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001853static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
1854 out, PyArena* arena);
1855static int obj2ast_operator(struct ast_state *state, PyObject* obj,
1856 operator_ty* out, PyArena* arena);
1857static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
Victor Stinner74419f02020-07-03 11:35:37 +02001858 out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001859static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001860 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001861static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001862 comprehension_ty* out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001863static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001864 excepthandler_ty* out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001865static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001866 arguments_ty* out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001867static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001868 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001869static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
Victor Stinner74419f02020-07-03 11:35:37 +02001870 out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001871static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02001872 PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001873static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
1874 withitem_ty* out, PyArena* arena);
Brandt Bucher145bf262021-02-26 14:51:55 -08001875static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
1876 match_case_ty* out, PyArena* arena);
Nick Coghlan1e7b8582021-04-29 15:58:44 +10001877static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
1878 out, PyArena* arena);
Victor Stinner5cf47822020-11-02 22:03:28 +01001879static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
Victor Stinner74419f02020-07-03 11:35:37 +02001880 type_ignore_ty* out, PyArena* arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001881
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001882mod_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001883_PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
1884 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001885{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001886 mod_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01001887 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001888 if (!p)
1889 return NULL;
1890 p->kind = Module_kind;
1891 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001892 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001893 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001894}
1895
1896mod_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001897_PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001898{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001899 mod_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01001900 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001901 if (!p)
1902 return NULL;
1903 p->kind = Interactive_kind;
1904 p->v.Interactive.body = body;
1905 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001906}
1907
1908mod_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001909_PyAST_Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001910{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001911 mod_ty p;
1912 if (!body) {
1913 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001914 "field 'body' is required for Expression");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001915 return NULL;
1916 }
Victor Stinner8370e072021-03-24 02:23:01 +01001917 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001918 if (!p)
1919 return NULL;
1920 p->kind = Expression_kind;
1921 p->v.Expression.body = body;
1922 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001923}
1924
1925mod_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001926_PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001927{
1928 mod_ty p;
1929 if (!returns) {
1930 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001931 "field 'returns' is required for FunctionType");
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001932 return NULL;
1933 }
Victor Stinner8370e072021-03-24 02:23:01 +01001934 p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001935 if (!p)
1936 return NULL;
1937 p->kind = FunctionType_kind;
1938 p->v.FunctionType.argtypes = argtypes;
1939 p->v.FunctionType.returns = returns;
1940 return p;
1941}
1942
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001943stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001944_PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
1945 asdl_expr_seq * decorator_list, expr_ty returns, string
1946 type_comment, int lineno, int col_offset, int end_lineno,
1947 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001948{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001949 stmt_ty p;
1950 if (!name) {
1951 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001952 "field 'name' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001953 return NULL;
1954 }
1955 if (!args) {
1956 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001957 "field 'args' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001958 return NULL;
1959 }
Victor Stinner8370e072021-03-24 02:23:01 +01001960 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001961 if (!p)
1962 return NULL;
1963 p->kind = FunctionDef_kind;
1964 p->v.FunctionDef.name = name;
1965 p->v.FunctionDef.args = args;
1966 p->v.FunctionDef.body = body;
1967 p->v.FunctionDef.decorator_list = decorator_list;
1968 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001969 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001970 p->lineno = lineno;
1971 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001972 p->end_lineno = end_lineno;
1973 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001974 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001975}
1976
1977stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02001978_PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
1979 body, asdl_expr_seq * decorator_list, expr_ty returns,
1980 string type_comment, int lineno, int col_offset, int
1981 end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04001982{
1983 stmt_ty p;
1984 if (!name) {
1985 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001986 "field 'name' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04001987 return NULL;
1988 }
1989 if (!args) {
1990 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001991 "field 'args' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04001992 return NULL;
1993 }
Victor Stinner8370e072021-03-24 02:23:01 +01001994 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanov75445082015-05-11 22:57:16 -04001995 if (!p)
1996 return NULL;
1997 p->kind = AsyncFunctionDef_kind;
1998 p->v.AsyncFunctionDef.name = name;
1999 p->v.AsyncFunctionDef.args = args;
2000 p->v.AsyncFunctionDef.body = body;
2001 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2002 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002003 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002004 p->lineno = lineno;
2005 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002006 p->end_lineno = end_lineno;
2007 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002008 return p;
2009}
2010
2011stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002012_PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
2013 keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
2014 int lineno, int col_offset, int end_lineno, int end_col_offset,
2015 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002016{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002017 stmt_ty p;
2018 if (!name) {
2019 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002020 "field 'name' is required for ClassDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002021 return NULL;
2022 }
Victor Stinner8370e072021-03-24 02:23:01 +01002023 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002024 if (!p)
2025 return NULL;
2026 p->kind = ClassDef_kind;
2027 p->v.ClassDef.name = name;
2028 p->v.ClassDef.bases = bases;
2029 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002030 p->v.ClassDef.body = body;
2031 p->v.ClassDef.decorator_list = decorator_list;
2032 p->lineno = lineno;
2033 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002034 p->end_lineno = end_lineno;
2035 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002036 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002037}
2038
2039stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002040_PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2041 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002042{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002043 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002044 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002045 if (!p)
2046 return NULL;
2047 p->kind = Return_kind;
2048 p->v.Return.value = value;
2049 p->lineno = lineno;
2050 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002051 p->end_lineno = end_lineno;
2052 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002053 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002054}
2055
2056stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002057_PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
2058 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002059{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002060 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002061 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002062 if (!p)
2063 return NULL;
2064 p->kind = Delete_kind;
2065 p->v.Delete.targets = targets;
2066 p->lineno = lineno;
2067 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002068 p->end_lineno = end_lineno;
2069 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002070 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002071}
2072
2073stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002074_PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
2075 lineno, int col_offset, int end_lineno, int end_col_offset,
2076 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002077{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002078 stmt_ty p;
2079 if (!value) {
2080 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002081 "field 'value' is required for Assign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002082 return NULL;
2083 }
Victor Stinner8370e072021-03-24 02:23:01 +01002084 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002085 if (!p)
2086 return NULL;
2087 p->kind = Assign_kind;
2088 p->v.Assign.targets = targets;
2089 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002090 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002091 p->lineno = lineno;
2092 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002093 p->end_lineno = end_lineno;
2094 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002095 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002096}
2097
2098stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002099_PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
2100 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002101{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002102 stmt_ty p;
2103 if (!target) {
2104 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002105 "field 'target' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002106 return NULL;
2107 }
2108 if (!op) {
2109 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002110 "field 'op' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002111 return NULL;
2112 }
2113 if (!value) {
2114 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002115 "field 'value' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002116 return NULL;
2117 }
Victor Stinner8370e072021-03-24 02:23:01 +01002118 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002119 if (!p)
2120 return NULL;
2121 p->kind = AugAssign_kind;
2122 p->v.AugAssign.target = target;
2123 p->v.AugAssign.op = op;
2124 p->v.AugAssign.value = value;
2125 p->lineno = lineno;
2126 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002127 p->end_lineno = end_lineno;
2128 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002129 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002130}
2131
2132stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002133_PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
2134 int lineno, int col_offset, int end_lineno, int
2135 end_col_offset, PyArena *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002136{
2137 stmt_ty p;
2138 if (!target) {
2139 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002140 "field 'target' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002141 return NULL;
2142 }
2143 if (!annotation) {
2144 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002145 "field 'annotation' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002146 return NULL;
2147 }
Victor Stinner8370e072021-03-24 02:23:01 +01002148 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002149 if (!p)
2150 return NULL;
2151 p->kind = AnnAssign_kind;
2152 p->v.AnnAssign.target = target;
2153 p->v.AnnAssign.annotation = annotation;
2154 p->v.AnnAssign.value = value;
2155 p->v.AnnAssign.simple = simple;
2156 p->lineno = lineno;
2157 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002158 p->end_lineno = end_lineno;
2159 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002160 return p;
2161}
2162
2163stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002164_PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
2165 orelse, string type_comment, int lineno, int col_offset, int
2166 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002167{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002168 stmt_ty p;
2169 if (!target) {
2170 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002171 "field 'target' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002172 return NULL;
2173 }
2174 if (!iter) {
2175 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002176 "field 'iter' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002177 return NULL;
2178 }
Victor Stinner8370e072021-03-24 02:23:01 +01002179 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002180 if (!p)
2181 return NULL;
2182 p->kind = For_kind;
2183 p->v.For.target = target;
2184 p->v.For.iter = iter;
2185 p->v.For.body = body;
2186 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002187 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002188 p->lineno = lineno;
2189 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002190 p->end_lineno = end_lineno;
2191 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002192 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002193}
2194
2195stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002196_PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
2197 asdl_stmt_seq * orelse, string type_comment, int lineno, int
2198 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002199{
2200 stmt_ty p;
2201 if (!target) {
2202 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002203 "field 'target' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002204 return NULL;
2205 }
2206 if (!iter) {
2207 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002208 "field 'iter' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002209 return NULL;
2210 }
Victor Stinner8370e072021-03-24 02:23:01 +01002211 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanov75445082015-05-11 22:57:16 -04002212 if (!p)
2213 return NULL;
2214 p->kind = AsyncFor_kind;
2215 p->v.AsyncFor.target = target;
2216 p->v.AsyncFor.iter = iter;
2217 p->v.AsyncFor.body = body;
2218 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002219 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002220 p->lineno = lineno;
2221 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002222 p->end_lineno = end_lineno;
2223 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002224 return p;
2225}
2226
2227stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002228_PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2229 lineno, int col_offset, int end_lineno, int end_col_offset,
2230 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002231{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002232 stmt_ty p;
2233 if (!test) {
2234 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002235 "field 'test' is required for While");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002236 return NULL;
2237 }
Victor Stinner8370e072021-03-24 02:23:01 +01002238 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002239 if (!p)
2240 return NULL;
2241 p->kind = While_kind;
2242 p->v.While.test = test;
2243 p->v.While.body = body;
2244 p->v.While.orelse = orelse;
2245 p->lineno = lineno;
2246 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002247 p->end_lineno = end_lineno;
2248 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002249 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002250}
2251
2252stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002253_PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
2254 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2255 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002256{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002257 stmt_ty p;
2258 if (!test) {
2259 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002260 "field 'test' is required for If");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002261 return NULL;
2262 }
Victor Stinner8370e072021-03-24 02:23:01 +01002263 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002264 if (!p)
2265 return NULL;
2266 p->kind = If_kind;
2267 p->v.If.test = test;
2268 p->v.If.body = body;
2269 p->v.If.orelse = orelse;
2270 p->lineno = lineno;
2271 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002272 p->end_lineno = end_lineno;
2273 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002274 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002275}
2276
2277stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002278_PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2279 type_comment, int lineno, int col_offset, int end_lineno, int
2280 end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002281{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002282 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002283 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002284 if (!p)
2285 return NULL;
2286 p->kind = With_kind;
2287 p->v.With.items = items;
2288 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002289 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002290 p->lineno = lineno;
2291 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002292 p->end_lineno = end_lineno;
2293 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002294 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002295}
2296
2297stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002298_PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
2299 type_comment, int lineno, int col_offset, int end_lineno, int
2300 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002301{
2302 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002303 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanov75445082015-05-11 22:57:16 -04002304 if (!p)
2305 return NULL;
2306 p->kind = AsyncWith_kind;
2307 p->v.AsyncWith.items = items;
2308 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002309 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002310 p->lineno = lineno;
2311 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002312 p->end_lineno = end_lineno;
2313 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002314 return p;
2315}
2316
2317stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002318_PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
2319 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Brandt Bucher145bf262021-02-26 14:51:55 -08002320{
2321 stmt_ty p;
2322 if (!subject) {
2323 PyErr_SetString(PyExc_ValueError,
2324 "field 'subject' is required for Match");
2325 return NULL;
2326 }
Victor Stinner8370e072021-03-24 02:23:01 +01002327 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Brandt Bucher145bf262021-02-26 14:51:55 -08002328 if (!p)
2329 return NULL;
2330 p->kind = Match_kind;
2331 p->v.Match.subject = subject;
2332 p->v.Match.cases = cases;
2333 p->lineno = lineno;
2334 p->col_offset = col_offset;
2335 p->end_lineno = end_lineno;
2336 p->end_col_offset = end_col_offset;
2337 return p;
2338}
2339
2340stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002341_PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
2342 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002343{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002344 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002345 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002346 if (!p)
2347 return NULL;
2348 p->kind = Raise_kind;
2349 p->v.Raise.exc = exc;
2350 p->v.Raise.cause = cause;
2351 p->lineno = lineno;
2352 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002353 p->end_lineno = end_lineno;
2354 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002355 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002356}
2357
2358stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002359_PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
2360 asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
2361 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002362{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002363 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002364 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002365 if (!p)
2366 return NULL;
2367 p->kind = Try_kind;
2368 p->v.Try.body = body;
2369 p->v.Try.handlers = handlers;
2370 p->v.Try.orelse = orelse;
2371 p->v.Try.finalbody = finalbody;
2372 p->lineno = lineno;
2373 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002374 p->end_lineno = end_lineno;
2375 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002376 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002377}
2378
2379stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002380_PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
2381 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002382{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002383 stmt_ty p;
2384 if (!test) {
2385 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002386 "field 'test' is required for Assert");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002387 return NULL;
2388 }
Victor Stinner8370e072021-03-24 02:23:01 +01002389 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002390 if (!p)
2391 return NULL;
2392 p->kind = Assert_kind;
2393 p->v.Assert.test = test;
2394 p->v.Assert.msg = msg;
2395 p->lineno = lineno;
2396 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002397 p->end_lineno = end_lineno;
2398 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002399 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002400}
2401
2402stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002403_PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
2404 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002405{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002406 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002407 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002408 if (!p)
2409 return NULL;
2410 p->kind = Import_kind;
2411 p->v.Import.names = names;
2412 p->lineno = lineno;
2413 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002414 p->end_lineno = end_lineno;
2415 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002416 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002417}
2418
2419stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002420_PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
2421 lineno, int col_offset, int end_lineno, int end_col_offset,
2422 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002423{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002424 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002425 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002426 if (!p)
2427 return NULL;
2428 p->kind = ImportFrom_kind;
2429 p->v.ImportFrom.module = module;
2430 p->v.ImportFrom.names = names;
2431 p->v.ImportFrom.level = level;
2432 p->lineno = lineno;
2433 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002434 p->end_lineno = end_lineno;
2435 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002436 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002437}
2438
2439stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002440_PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
2441 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002442{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002443 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002444 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002445 if (!p)
2446 return NULL;
2447 p->kind = Global_kind;
2448 p->v.Global.names = names;
2449 p->lineno = lineno;
2450 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002451 p->end_lineno = end_lineno;
2452 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002453 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002454}
2455
2456stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002457_PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
2458 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002459{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002460 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002461 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002462 if (!p)
2463 return NULL;
2464 p->kind = Nonlocal_kind;
2465 p->v.Nonlocal.names = names;
2466 p->lineno = lineno;
2467 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002468 p->end_lineno = end_lineno;
2469 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002470 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002471}
2472
2473stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002474_PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2475 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002476{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002477 stmt_ty p;
2478 if (!value) {
2479 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002480 "field 'value' is required for Expr");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002481 return NULL;
2482 }
Victor Stinner8370e072021-03-24 02:23:01 +01002483 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002484 if (!p)
2485 return NULL;
2486 p->kind = Expr_kind;
2487 p->v.Expr.value = value;
2488 p->lineno = lineno;
2489 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002490 p->end_lineno = end_lineno;
2491 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002492 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002493}
2494
2495stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002496_PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
2497 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002498{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002499 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002500 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002501 if (!p)
2502 return NULL;
2503 p->kind = Pass_kind;
2504 p->lineno = lineno;
2505 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002506 p->end_lineno = end_lineno;
2507 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002508 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002509}
2510
2511stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002512_PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
2513 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002514{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002515 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002516 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002517 if (!p)
2518 return NULL;
2519 p->kind = Break_kind;
2520 p->lineno = lineno;
2521 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002522 p->end_lineno = end_lineno;
2523 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002524 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002525}
2526
2527stmt_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002528_PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2529 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002530{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002531 stmt_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002532 p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002533 if (!p)
2534 return NULL;
2535 p->kind = Continue_kind;
2536 p->lineno = lineno;
2537 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002538 p->end_lineno = end_lineno;
2539 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002540 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002541}
2542
2543expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002544_PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
2545 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002546{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002547 expr_ty p;
2548 if (!op) {
2549 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002550 "field 'op' is required for BoolOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002551 return NULL;
2552 }
Victor Stinner8370e072021-03-24 02:23:01 +01002553 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002554 if (!p)
2555 return NULL;
2556 p->kind = BoolOp_kind;
2557 p->v.BoolOp.op = op;
2558 p->v.BoolOp.values = values;
2559 p->lineno = lineno;
2560 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002561 p->end_lineno = end_lineno;
2562 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002563 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002564}
2565
2566expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002567_PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2568 end_lineno, int end_col_offset, PyArena *arena)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002569{
2570 expr_ty p;
2571 if (!target) {
2572 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002573 "field 'target' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002574 return NULL;
2575 }
2576 if (!value) {
2577 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002578 "field 'value' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002579 return NULL;
2580 }
Victor Stinner8370e072021-03-24 02:23:01 +01002581 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002582 if (!p)
2583 return NULL;
2584 p->kind = NamedExpr_kind;
2585 p->v.NamedExpr.target = target;
2586 p->v.NamedExpr.value = value;
2587 p->lineno = lineno;
2588 p->col_offset = col_offset;
2589 p->end_lineno = end_lineno;
2590 p->end_col_offset = end_col_offset;
2591 return p;
2592}
2593
2594expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002595_PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
2596 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002597{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002598 expr_ty p;
2599 if (!left) {
2600 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002601 "field 'left' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002602 return NULL;
2603 }
2604 if (!op) {
2605 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002606 "field 'op' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002607 return NULL;
2608 }
2609 if (!right) {
2610 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002611 "field 'right' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002612 return NULL;
2613 }
Victor Stinner8370e072021-03-24 02:23:01 +01002614 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002615 if (!p)
2616 return NULL;
2617 p->kind = BinOp_kind;
2618 p->v.BinOp.left = left;
2619 p->v.BinOp.op = op;
2620 p->v.BinOp.right = right;
2621 p->lineno = lineno;
2622 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002623 p->end_lineno = end_lineno;
2624 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002625 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002626}
2627
2628expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002629_PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2630 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002631{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002632 expr_ty p;
2633 if (!op) {
2634 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002635 "field 'op' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002636 return NULL;
2637 }
2638 if (!operand) {
2639 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002640 "field 'operand' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002641 return NULL;
2642 }
Victor Stinner8370e072021-03-24 02:23:01 +01002643 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002644 if (!p)
2645 return NULL;
2646 p->kind = UnaryOp_kind;
2647 p->v.UnaryOp.op = op;
2648 p->v.UnaryOp.operand = operand;
2649 p->lineno = lineno;
2650 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002651 p->end_lineno = end_lineno;
2652 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002653 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002654}
2655
2656expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002657_PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2658 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002659{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002660 expr_ty p;
2661 if (!args) {
2662 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002663 "field 'args' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002664 return NULL;
2665 }
2666 if (!body) {
2667 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002668 "field 'body' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002669 return NULL;
2670 }
Victor Stinner8370e072021-03-24 02:23:01 +01002671 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002672 if (!p)
2673 return NULL;
2674 p->kind = Lambda_kind;
2675 p->v.Lambda.args = args;
2676 p->v.Lambda.body = body;
2677 p->lineno = lineno;
2678 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002679 p->end_lineno = end_lineno;
2680 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002681 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002682}
2683
2684expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002685_PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
2686 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002687{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002688 expr_ty p;
2689 if (!test) {
2690 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002691 "field 'test' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002692 return NULL;
2693 }
2694 if (!body) {
2695 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002696 "field 'body' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002697 return NULL;
2698 }
2699 if (!orelse) {
2700 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002701 "field 'orelse' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002702 return NULL;
2703 }
Victor Stinner8370e072021-03-24 02:23:01 +01002704 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002705 if (!p)
2706 return NULL;
2707 p->kind = IfExp_kind;
2708 p->v.IfExp.test = test;
2709 p->v.IfExp.body = body;
2710 p->v.IfExp.orelse = orelse;
2711 p->lineno = lineno;
2712 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002713 p->end_lineno = end_lineno;
2714 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002715 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002716}
2717
2718expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002719_PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
2720 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002721{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002722 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002723 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002724 if (!p)
2725 return NULL;
2726 p->kind = Dict_kind;
2727 p->v.Dict.keys = keys;
2728 p->v.Dict.values = values;
2729 p->lineno = lineno;
2730 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002731 p->end_lineno = end_lineno;
2732 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002733 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002734}
2735
2736expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002737_PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
2738 int end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002739{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002740 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002741 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002742 if (!p)
2743 return NULL;
2744 p->kind = Set_kind;
2745 p->v.Set.elts = elts;
2746 p->lineno = lineno;
2747 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002748 p->end_lineno = end_lineno;
2749 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002750 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002751}
2752
2753expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002754_PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2755 int col_offset, int end_lineno, int end_col_offset, PyArena
2756 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002757{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002758 expr_ty p;
2759 if (!elt) {
2760 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002761 "field 'elt' is required for ListComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002762 return NULL;
2763 }
Victor Stinner8370e072021-03-24 02:23:01 +01002764 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002765 if (!p)
2766 return NULL;
2767 p->kind = ListComp_kind;
2768 p->v.ListComp.elt = elt;
2769 p->v.ListComp.generators = generators;
2770 p->lineno = lineno;
2771 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002772 p->end_lineno = end_lineno;
2773 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002774 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002775}
2776
2777expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002778_PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
2779 int col_offset, int end_lineno, int end_col_offset, PyArena
2780 *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002781{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002782 expr_ty p;
2783 if (!elt) {
2784 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002785 "field 'elt' is required for SetComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002786 return NULL;
2787 }
Victor Stinner8370e072021-03-24 02:23:01 +01002788 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002789 if (!p)
2790 return NULL;
2791 p->kind = SetComp_kind;
2792 p->v.SetComp.elt = elt;
2793 p->v.SetComp.generators = generators;
2794 p->lineno = lineno;
2795 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002796 p->end_lineno = end_lineno;
2797 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002798 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002799}
2800
2801expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002802_PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
2803 generators, int lineno, int col_offset, int end_lineno, int
2804 end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002805{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002806 expr_ty p;
2807 if (!key) {
2808 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002809 "field 'key' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002810 return NULL;
2811 }
2812 if (!value) {
2813 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002814 "field 'value' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002815 return NULL;
2816 }
Victor Stinner8370e072021-03-24 02:23:01 +01002817 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002818 if (!p)
2819 return NULL;
2820 p->kind = DictComp_kind;
2821 p->v.DictComp.key = key;
2822 p->v.DictComp.value = value;
2823 p->v.DictComp.generators = generators;
2824 p->lineno = lineno;
2825 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002826 p->end_lineno = end_lineno;
2827 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002828 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002829}
2830
2831expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002832_PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
2833 lineno, int col_offset, int end_lineno, int end_col_offset,
2834 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002835{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002836 expr_ty p;
2837 if (!elt) {
2838 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002839 "field 'elt' is required for GeneratorExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002840 return NULL;
2841 }
Victor Stinner8370e072021-03-24 02:23:01 +01002842 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002843 if (!p)
2844 return NULL;
2845 p->kind = GeneratorExp_kind;
2846 p->v.GeneratorExp.elt = elt;
2847 p->v.GeneratorExp.generators = generators;
2848 p->lineno = lineno;
2849 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002850 p->end_lineno = end_lineno;
2851 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002852 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002853}
2854
2855expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002856_PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2857 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002858{
2859 expr_ty p;
2860 if (!value) {
2861 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002862 "field 'value' is required for Await");
Yury Selivanov75445082015-05-11 22:57:16 -04002863 return NULL;
2864 }
Victor Stinner8370e072021-03-24 02:23:01 +01002865 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Yury Selivanov75445082015-05-11 22:57:16 -04002866 if (!p)
2867 return NULL;
2868 p->kind = Await_kind;
2869 p->v.Await.value = value;
2870 p->lineno = lineno;
2871 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002872 p->end_lineno = end_lineno;
2873 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002874 return p;
2875}
2876
2877expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002878_PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2879 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002880{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002881 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002882 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002883 if (!p)
2884 return NULL;
2885 p->kind = Yield_kind;
2886 p->v.Yield.value = value;
2887 p->lineno = lineno;
2888 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002889 p->end_lineno = end_lineno;
2890 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002891 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002892}
2893
2894expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002895_PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2896 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002897{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002898 expr_ty p;
2899 if (!value) {
2900 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002901 "field 'value' is required for YieldFrom");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002902 return NULL;
2903 }
Victor Stinner8370e072021-03-24 02:23:01 +01002904 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002905 if (!p)
2906 return NULL;
2907 p->kind = YieldFrom_kind;
2908 p->v.YieldFrom.value = value;
2909 p->lineno = lineno;
2910 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002911 p->end_lineno = end_lineno;
2912 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002913 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002914}
2915
2916expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002917_PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
2918 int lineno, int col_offset, int end_lineno, int end_col_offset,
2919 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002920{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002921 expr_ty p;
2922 if (!left) {
2923 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002924 "field 'left' is required for Compare");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002925 return NULL;
2926 }
Victor Stinner8370e072021-03-24 02:23:01 +01002927 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002928 if (!p)
2929 return NULL;
2930 p->kind = Compare_kind;
2931 p->v.Compare.left = left;
2932 p->v.Compare.ops = ops;
2933 p->v.Compare.comparators = comparators;
2934 p->lineno = lineno;
2935 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002936 p->end_lineno = end_lineno;
2937 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002938 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002939}
2940
2941expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002942_PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
2943 int lineno, int col_offset, int end_lineno, int end_col_offset,
2944 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002945{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002946 expr_ty p;
2947 if (!func) {
2948 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002949 "field 'func' is required for Call");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002950 return NULL;
2951 }
Victor Stinner8370e072021-03-24 02:23:01 +01002952 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002953 if (!p)
2954 return NULL;
2955 p->kind = Call_kind;
2956 p->v.Call.func = func;
2957 p->v.Call.args = args;
2958 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002959 p->lineno = lineno;
2960 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002961 p->end_lineno = end_lineno;
2962 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002963 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002964}
2965
2966expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002967_PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
2968 lineno, int col_offset, int end_lineno, int
2969 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002970{
2971 expr_ty p;
2972 if (!value) {
2973 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002974 "field 'value' is required for FormattedValue");
Eric V. Smith235a6f02015-09-19 14:51:32 -04002975 return NULL;
2976 }
Victor Stinner8370e072021-03-24 02:23:01 +01002977 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Eric V. Smith235a6f02015-09-19 14:51:32 -04002978 if (!p)
2979 return NULL;
2980 p->kind = FormattedValue_kind;
2981 p->v.FormattedValue.value = value;
2982 p->v.FormattedValue.conversion = conversion;
2983 p->v.FormattedValue.format_spec = format_spec;
2984 p->lineno = lineno;
2985 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002986 p->end_lineno = end_lineno;
2987 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002988 return p;
2989}
2990
2991expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02002992_PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
2993 end_lineno, int end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002994{
2995 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01002996 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Eric V. Smith235a6f02015-09-19 14:51:32 -04002997 if (!p)
2998 return NULL;
2999 p->kind = JoinedStr_kind;
3000 p->v.JoinedStr.values = values;
3001 p->lineno = lineno;
3002 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003003 p->end_lineno = end_lineno;
3004 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003005 return p;
3006}
3007
3008expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003009_PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
3010 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003011{
3012 expr_ty p;
3013 if (!value) {
3014 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003015 "field 'value' is required for Constant");
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003016 return NULL;
3017 }
Victor Stinner8370e072021-03-24 02:23:01 +01003018 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003019 if (!p)
3020 return NULL;
3021 p->kind = Constant_kind;
3022 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003023 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003024 p->lineno = lineno;
3025 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003026 p->end_lineno = end_lineno;
3027 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003028 return p;
3029}
3030
3031expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003032_PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
3033 lineno, int col_offset, int end_lineno, int end_col_offset,
3034 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003035{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003036 expr_ty p;
3037 if (!value) {
3038 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003039 "field 'value' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003040 return NULL;
3041 }
3042 if (!attr) {
3043 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003044 "field 'attr' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003045 return NULL;
3046 }
3047 if (!ctx) {
3048 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003049 "field 'ctx' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003050 return NULL;
3051 }
Victor Stinner8370e072021-03-24 02:23:01 +01003052 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003053 if (!p)
3054 return NULL;
3055 p->kind = Attribute_kind;
3056 p->v.Attribute.value = value;
3057 p->v.Attribute.attr = attr;
3058 p->v.Attribute.ctx = ctx;
3059 p->lineno = lineno;
3060 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003061 p->end_lineno = end_lineno;
3062 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003063 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003064}
3065
3066expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003067_PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
3068 int col_offset, int end_lineno, int end_col_offset, PyArena
3069 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003070{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003071 expr_ty p;
3072 if (!value) {
3073 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003074 "field 'value' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003075 return NULL;
3076 }
3077 if (!slice) {
3078 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003079 "field 'slice' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003080 return NULL;
3081 }
3082 if (!ctx) {
3083 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003084 "field 'ctx' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003085 return NULL;
3086 }
Victor Stinner8370e072021-03-24 02:23:01 +01003087 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003088 if (!p)
3089 return NULL;
3090 p->kind = Subscript_kind;
3091 p->v.Subscript.value = value;
3092 p->v.Subscript.slice = slice;
3093 p->v.Subscript.ctx = ctx;
3094 p->lineno = lineno;
3095 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003096 p->end_lineno = end_lineno;
3097 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003098 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003099}
3100
3101expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003102_PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
3103 int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003104{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003105 expr_ty p;
3106 if (!value) {
3107 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003108 "field 'value' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003109 return NULL;
3110 }
3111 if (!ctx) {
3112 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003113 "field 'ctx' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003114 return NULL;
3115 }
Victor Stinner8370e072021-03-24 02:23:01 +01003116 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003117 if (!p)
3118 return NULL;
3119 p->kind = Starred_kind;
3120 p->v.Starred.value = value;
3121 p->v.Starred.ctx = ctx;
3122 p->lineno = lineno;
3123 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003124 p->end_lineno = end_lineno;
3125 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003126 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003127}
3128
3129expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003130_PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3131 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003132{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003133 expr_ty p;
3134 if (!id) {
3135 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003136 "field 'id' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003137 return NULL;
3138 }
3139 if (!ctx) {
3140 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003141 "field 'ctx' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003142 return NULL;
3143 }
Victor Stinner8370e072021-03-24 02:23:01 +01003144 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003145 if (!p)
3146 return NULL;
3147 p->kind = Name_kind;
3148 p->v.Name.id = id;
3149 p->v.Name.ctx = ctx;
3150 p->lineno = lineno;
3151 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003152 p->end_lineno = end_lineno;
3153 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003154 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003155}
3156
3157expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003158_PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3159 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003160{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003161 expr_ty p;
3162 if (!ctx) {
3163 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003164 "field 'ctx' is required for List");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003165 return NULL;
3166 }
Victor Stinner8370e072021-03-24 02:23:01 +01003167 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003168 if (!p)
3169 return NULL;
3170 p->kind = List_kind;
3171 p->v.List.elts = elts;
3172 p->v.List.ctx = ctx;
3173 p->lineno = lineno;
3174 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003175 p->end_lineno = end_lineno;
3176 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003177 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003178}
3179
3180expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003181_PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
3182 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003183{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003184 expr_ty p;
3185 if (!ctx) {
3186 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003187 "field 'ctx' is required for Tuple");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003188 return NULL;
3189 }
Victor Stinner8370e072021-03-24 02:23:01 +01003190 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003191 if (!p)
3192 return NULL;
3193 p->kind = Tuple_kind;
3194 p->v.Tuple.elts = elts;
3195 p->v.Tuple.ctx = ctx;
3196 p->lineno = lineno;
3197 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003198 p->end_lineno = end_lineno;
3199 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003200 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003201}
3202
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003203expr_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003204_PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
3205 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003206{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003207 expr_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01003208 p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003209 if (!p)
3210 return NULL;
3211 p->kind = Slice_kind;
3212 p->v.Slice.lower = lower;
3213 p->v.Slice.upper = upper;
3214 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003215 p->lineno = lineno;
3216 p->col_offset = col_offset;
3217 p->end_lineno = end_lineno;
3218 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003219 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003220}
3221
3222comprehension_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003223_PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
3224 is_async, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003225{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003226 comprehension_ty p;
3227 if (!target) {
3228 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003229 "field 'target' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003230 return NULL;
3231 }
3232 if (!iter) {
3233 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003234 "field 'iter' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003235 return NULL;
3236 }
Victor Stinner8370e072021-03-24 02:23:01 +01003237 p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003238 if (!p)
3239 return NULL;
3240 p->target = target;
3241 p->iter = iter;
3242 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003243 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003244 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003245}
3246
3247excepthandler_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003248_PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
3249 lineno, int col_offset, int end_lineno, int
3250 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003251{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003252 excepthandler_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01003253 p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003254 if (!p)
3255 return NULL;
3256 p->kind = ExceptHandler_kind;
3257 p->v.ExceptHandler.type = type;
3258 p->v.ExceptHandler.name = name;
3259 p->v.ExceptHandler.body = body;
3260 p->lineno = lineno;
3261 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003262 p->end_lineno = end_lineno;
3263 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003264 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003265}
3266
3267arguments_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003268_PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
3269 vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
3270 kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
3271 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003272{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003273 arguments_ty p;
Victor Stinner8370e072021-03-24 02:23:01 +01003274 p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003275 if (!p)
3276 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003277 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003278 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003279 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003280 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003281 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003282 p->kwarg = kwarg;
3283 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003284 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003285}
3286
Neal Norwitzc1505362006-12-28 06:47:50 +00003287arg_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003288_PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
3289 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003290{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003291 arg_ty p;
3292 if (!arg) {
3293 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003294 "field 'arg' is required for arg");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003295 return NULL;
3296 }
Victor Stinner8370e072021-03-24 02:23:01 +01003297 p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003298 if (!p)
3299 return NULL;
3300 p->arg = arg;
3301 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003302 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003303 p->lineno = lineno;
3304 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003305 p->end_lineno = end_lineno;
3306 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003307 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003308}
3309
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003310keyword_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003311_PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3312 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003313{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003314 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003315 if (!value) {
3316 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003317 "field 'value' is required for keyword");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003318 return NULL;
3319 }
Victor Stinner8370e072021-03-24 02:23:01 +01003320 p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003321 if (!p)
3322 return NULL;
3323 p->arg = arg;
3324 p->value = value;
Pablo Galindo168660b2020-04-02 00:47:39 +01003325 p->lineno = lineno;
3326 p->col_offset = col_offset;
3327 p->end_lineno = end_lineno;
3328 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003329 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003330}
3331
3332alias_ty
Matthew Suozzo75a06f02021-04-10 16:56:28 -04003333_PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
3334 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003335{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003336 alias_ty p;
3337 if (!name) {
3338 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003339 "field 'name' is required for alias");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003340 return NULL;
3341 }
Victor Stinner8370e072021-03-24 02:23:01 +01003342 p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003343 if (!p)
3344 return NULL;
3345 p->name = name;
3346 p->asname = asname;
Matthew Suozzo75a06f02021-04-10 16:56:28 -04003347 p->lineno = lineno;
3348 p->col_offset = col_offset;
3349 p->end_lineno = end_lineno;
3350 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003351 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003352}
3353
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003354withitem_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003355_PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003356{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003357 withitem_ty p;
3358 if (!context_expr) {
3359 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003360 "field 'context_expr' is required for withitem");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003361 return NULL;
3362 }
Victor Stinner8370e072021-03-24 02:23:01 +01003363 p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003364 if (!p)
3365 return NULL;
3366 p->context_expr = context_expr;
3367 p->optional_vars = optional_vars;
3368 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003369}
3370
Brandt Bucher145bf262021-02-26 14:51:55 -08003371match_case_ty
Nick Coghlan1e7b8582021-04-29 15:58:44 +10003372_PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
3373 PyArena *arena)
Brandt Bucher145bf262021-02-26 14:51:55 -08003374{
3375 match_case_ty p;
3376 if (!pattern) {
3377 PyErr_SetString(PyExc_ValueError,
3378 "field 'pattern' is required for match_case");
3379 return NULL;
3380 }
Victor Stinner8370e072021-03-24 02:23:01 +01003381 p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
Brandt Bucher145bf262021-02-26 14:51:55 -08003382 if (!p)
3383 return NULL;
3384 p->pattern = pattern;
3385 p->guard = guard;
3386 p->body = body;
3387 return p;
3388}
3389
Nick Coghlan1e7b8582021-04-29 15:58:44 +10003390pattern_ty
3391_PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
3392 int end_col_offset, PyArena *arena)
3393{
3394 pattern_ty p;
3395 if (!value) {
3396 PyErr_SetString(PyExc_ValueError,
3397 "field 'value' is required for MatchValue");
3398 return NULL;
3399 }
3400 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3401 if (!p)
3402 return NULL;
3403 p->kind = MatchValue_kind;
3404 p->v.MatchValue.value = value;
3405 p->lineno = lineno;
3406 p->col_offset = col_offset;
3407 p->end_lineno = end_lineno;
3408 p->end_col_offset = end_col_offset;
3409 return p;
3410}
3411
3412pattern_ty
3413_PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
3414 end_lineno, int end_col_offset, PyArena *arena)
3415{
3416 pattern_ty p;
3417 if (!value) {
3418 PyErr_SetString(PyExc_ValueError,
3419 "field 'value' is required for MatchSingleton");
3420 return NULL;
3421 }
3422 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3423 if (!p)
3424 return NULL;
3425 p->kind = MatchSingleton_kind;
3426 p->v.MatchSingleton.value = value;
3427 p->lineno = lineno;
3428 p->col_offset = col_offset;
3429 p->end_lineno = end_lineno;
3430 p->end_col_offset = end_col_offset;
3431 return p;
3432}
3433
3434pattern_ty
3435_PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
3436 int end_lineno, int end_col_offset, PyArena *arena)
3437{
3438 pattern_ty p;
3439 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3440 if (!p)
3441 return NULL;
3442 p->kind = MatchSequence_kind;
3443 p->v.MatchSequence.patterns = patterns;
3444 p->lineno = lineno;
3445 p->col_offset = col_offset;
3446 p->end_lineno = end_lineno;
3447 p->end_col_offset = end_col_offset;
3448 return p;
3449}
3450
3451pattern_ty
3452_PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
3453 identifier rest, int lineno, int col_offset, int
3454 end_lineno, int end_col_offset, PyArena *arena)
3455{
3456 pattern_ty p;
3457 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3458 if (!p)
3459 return NULL;
3460 p->kind = MatchMapping_kind;
3461 p->v.MatchMapping.keys = keys;
3462 p->v.MatchMapping.patterns = patterns;
3463 p->v.MatchMapping.rest = rest;
3464 p->lineno = lineno;
3465 p->col_offset = col_offset;
3466 p->end_lineno = end_lineno;
3467 p->end_col_offset = end_col_offset;
3468 return p;
3469}
3470
3471pattern_ty
3472_PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
3473 * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
3474 col_offset, int end_lineno, int end_col_offset, PyArena
3475 *arena)
3476{
3477 pattern_ty p;
3478 if (!cls) {
3479 PyErr_SetString(PyExc_ValueError,
3480 "field 'cls' is required for MatchClass");
3481 return NULL;
3482 }
3483 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3484 if (!p)
3485 return NULL;
3486 p->kind = MatchClass_kind;
3487 p->v.MatchClass.cls = cls;
3488 p->v.MatchClass.patterns = patterns;
3489 p->v.MatchClass.kwd_attrs = kwd_attrs;
3490 p->v.MatchClass.kwd_patterns = kwd_patterns;
3491 p->lineno = lineno;
3492 p->col_offset = col_offset;
3493 p->end_lineno = end_lineno;
3494 p->end_col_offset = end_col_offset;
3495 return p;
3496}
3497
3498pattern_ty
3499_PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
3500 int end_col_offset, PyArena *arena)
3501{
3502 pattern_ty p;
3503 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3504 if (!p)
3505 return NULL;
3506 p->kind = MatchStar_kind;
3507 p->v.MatchStar.name = name;
3508 p->lineno = lineno;
3509 p->col_offset = col_offset;
3510 p->end_lineno = end_lineno;
3511 p->end_col_offset = end_col_offset;
3512 return p;
3513}
3514
3515pattern_ty
3516_PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
3517 int end_lineno, int end_col_offset, PyArena *arena)
3518{
3519 pattern_ty p;
3520 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3521 if (!p)
3522 return NULL;
3523 p->kind = MatchAs_kind;
3524 p->v.MatchAs.pattern = pattern;
3525 p->v.MatchAs.name = name;
3526 p->lineno = lineno;
3527 p->col_offset = col_offset;
3528 p->end_lineno = end_lineno;
3529 p->end_col_offset = end_col_offset;
3530 return p;
3531}
3532
3533pattern_ty
3534_PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
3535 end_lineno, int end_col_offset, PyArena *arena)
3536{
3537 pattern_ty p;
3538 p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
3539 if (!p)
3540 return NULL;
3541 p->kind = MatchOr_kind;
3542 p->v.MatchOr.patterns = patterns;
3543 p->lineno = lineno;
3544 p->col_offset = col_offset;
3545 p->end_lineno = end_lineno;
3546 p->end_col_offset = end_col_offset;
3547 return p;
3548}
3549
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003550type_ignore_ty
Victor Stinnerd27f8d22021-04-07 21:34:22 +02003551_PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003552{
3553 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003554 if (!tag) {
3555 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003556 "field 'tag' is required for TypeIgnore");
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003557 return NULL;
3558 }
Victor Stinner8370e072021-03-24 02:23:01 +01003559 p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003560 if (!p)
3561 return NULL;
3562 p->kind = TypeIgnore_kind;
3563 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003564 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003565 return p;
3566}
3567
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003568
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003569PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01003570ast2obj_mod(struct ast_state *state, void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003571{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003572 mod_ty o = (mod_ty)_o;
3573 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003574 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003575 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003576 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003577 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003578 switch (o->kind) {
3579 case Module_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003580 tp = (PyTypeObject *)state->Module_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003581 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003582 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003583 value = ast2obj_list(state, (asdl_seq*)o->v.Module.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003584 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003585 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003586 goto failed;
3587 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003588 value = ast2obj_list(state, (asdl_seq*)o->v.Module.type_ignores,
Victor Stinner74419f02020-07-03 11:35:37 +02003589 ast2obj_type_ignore);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003590 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003591 if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003592 goto failed;
3593 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003594 break;
3595 case Interactive_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003596 tp = (PyTypeObject *)state->Interactive_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003597 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003598 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003599 value = ast2obj_list(state, (asdl_seq*)o->v.Interactive.body,
3600 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003601 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003602 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003603 goto failed;
3604 Py_DECREF(value);
3605 break;
3606 case Expression_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003607 tp = (PyTypeObject *)state->Expression_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003608 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003609 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003610 value = ast2obj_expr(state, o->v.Expression.body);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003611 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003612 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003613 goto failed;
3614 Py_DECREF(value);
3615 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003616 case FunctionType_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003617 tp = (PyTypeObject *)state->FunctionType_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003618 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003619 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003620 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionType.argtypes,
3621 ast2obj_expr);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003622 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003623 if (PyObject_SetAttr(result, state->argtypes, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003624 goto failed;
3625 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003626 value = ast2obj_expr(state, o->v.FunctionType.returns);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003627 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003628 if (PyObject_SetAttr(result, state->returns, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003629 goto failed;
3630 Py_DECREF(value);
3631 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003632 }
3633 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003634failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003635 Py_XDECREF(value);
3636 Py_XDECREF(result);
3637 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003638}
3639
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003640PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01003641ast2obj_stmt(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003642{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003643 stmt_ty o = (stmt_ty)_o;
3644 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003645 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003646 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003647 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003648 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003649 switch (o->kind) {
3650 case FunctionDef_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003651 tp = (PyTypeObject *)state->FunctionDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003652 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003653 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003654 value = ast2obj_identifier(state, o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003655 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003656 if (PyObject_SetAttr(result, state->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003657 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003658 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003659 value = ast2obj_arguments(state, o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003660 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003661 if (PyObject_SetAttr(result, state->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003662 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003663 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003664 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.body,
3665 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003666 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003667 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003668 goto failed;
3669 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003670 value = ast2obj_list(state, (asdl_seq*)o->v.FunctionDef.decorator_list,
Victor Stinner74419f02020-07-03 11:35:37 +02003671 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003672 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003673 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003674 goto failed;
3675 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003676 value = ast2obj_expr(state, o->v.FunctionDef.returns);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003677 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003678 if (PyObject_SetAttr(result, state->returns, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003679 goto failed;
3680 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003681 value = ast2obj_string(state, o->v.FunctionDef.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003682 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003683 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003684 goto failed;
3685 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003686 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003687 case AsyncFunctionDef_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003688 tp = (PyTypeObject *)state->AsyncFunctionDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003689 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003690 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003691 value = ast2obj_identifier(state, o->v.AsyncFunctionDef.name);
Yury Selivanov75445082015-05-11 22:57:16 -04003692 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003693 if (PyObject_SetAttr(result, state->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003694 goto failed;
3695 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003696 value = ast2obj_arguments(state, o->v.AsyncFunctionDef.args);
Yury Selivanov75445082015-05-11 22:57:16 -04003697 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003698 if (PyObject_SetAttr(result, state->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003699 goto failed;
3700 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003701 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFunctionDef.body,
3702 ast2obj_stmt);
Yury Selivanov75445082015-05-11 22:57:16 -04003703 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003704 if (PyObject_SetAttr(result, state->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003705 goto failed;
3706 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003707 value = ast2obj_list(state,
3708 (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
Yury Selivanov75445082015-05-11 22:57:16 -04003709 ast2obj_expr);
3710 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003711 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003712 goto failed;
3713 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003714 value = ast2obj_expr(state, o->v.AsyncFunctionDef.returns);
Yury Selivanov75445082015-05-11 22:57:16 -04003715 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003716 if (PyObject_SetAttr(result, state->returns, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003717 goto failed;
3718 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003719 value = ast2obj_string(state, o->v.AsyncFunctionDef.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003720 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003721 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003722 goto failed;
3723 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003724 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003725 case ClassDef_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003726 tp = (PyTypeObject *)state->ClassDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003727 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003728 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003729 value = ast2obj_identifier(state, o->v.ClassDef.name);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003730 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003731 if (PyObject_SetAttr(result, state->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003732 goto failed;
3733 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003734 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.bases,
3735 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003736 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003737 if (PyObject_SetAttr(result, state->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003738 goto failed;
3739 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003740 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.keywords,
3741 ast2obj_keyword);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003742 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003743 if (PyObject_SetAttr(result, state->keywords, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003744 goto failed;
3745 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003746 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.body,
3747 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003748 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003749 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003750 goto failed;
3751 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003752 value = ast2obj_list(state, (asdl_seq*)o->v.ClassDef.decorator_list,
3753 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003754 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003755 if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003756 goto failed;
3757 Py_DECREF(value);
3758 break;
3759 case Return_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003760 tp = (PyTypeObject *)state->Return_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003761 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003762 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003763 value = ast2obj_expr(state, o->v.Return.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003764 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003765 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003766 goto failed;
3767 Py_DECREF(value);
3768 break;
3769 case Delete_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003770 tp = (PyTypeObject *)state->Delete_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003771 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003772 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003773 value = ast2obj_list(state, (asdl_seq*)o->v.Delete.targets,
3774 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003775 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003776 if (PyObject_SetAttr(result, state->targets, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003777 goto failed;
3778 Py_DECREF(value);
3779 break;
3780 case Assign_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003781 tp = (PyTypeObject *)state->Assign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003782 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003783 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003784 value = ast2obj_list(state, (asdl_seq*)o->v.Assign.targets,
3785 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003786 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003787 if (PyObject_SetAttr(result, state->targets, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003788 goto failed;
3789 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003790 value = ast2obj_expr(state, o->v.Assign.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003791 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003792 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003793 goto failed;
3794 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003795 value = ast2obj_string(state, o->v.Assign.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003796 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003797 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003798 goto failed;
3799 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003800 break;
3801 case AugAssign_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003802 tp = (PyTypeObject *)state->AugAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003803 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003804 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003805 value = ast2obj_expr(state, o->v.AugAssign.target);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003806 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003807 if (PyObject_SetAttr(result, state->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003808 goto failed;
3809 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003810 value = ast2obj_operator(state, o->v.AugAssign.op);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003811 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003812 if (PyObject_SetAttr(result, state->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003813 goto failed;
3814 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003815 value = ast2obj_expr(state, o->v.AugAssign.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003816 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003817 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003818 goto failed;
3819 Py_DECREF(value);
3820 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003821 case AnnAssign_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003822 tp = (PyTypeObject *)state->AnnAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003823 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003824 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003825 value = ast2obj_expr(state, o->v.AnnAssign.target);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003826 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003827 if (PyObject_SetAttr(result, state->target, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003828 goto failed;
3829 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003830 value = ast2obj_expr(state, o->v.AnnAssign.annotation);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003831 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003832 if (PyObject_SetAttr(result, state->annotation, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003833 goto failed;
3834 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003835 value = ast2obj_expr(state, o->v.AnnAssign.value);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003836 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003837 if (PyObject_SetAttr(result, state->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003838 goto failed;
3839 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003840 value = ast2obj_int(state, o->v.AnnAssign.simple);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003841 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003842 if (PyObject_SetAttr(result, state->simple, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003843 goto failed;
3844 Py_DECREF(value);
3845 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003846 case For_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003847 tp = (PyTypeObject *)state->For_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003848 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003849 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003850 value = ast2obj_expr(state, o->v.For.target);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003851 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003852 if (PyObject_SetAttr(result, state->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003853 goto failed;
3854 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003855 value = ast2obj_expr(state, o->v.For.iter);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003856 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003857 if (PyObject_SetAttr(result, state->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003858 goto failed;
3859 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003860 value = ast2obj_list(state, (asdl_seq*)o->v.For.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003861 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003862 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003863 goto failed;
3864 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003865 value = ast2obj_list(state, (asdl_seq*)o->v.For.orelse, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003866 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003867 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003868 goto failed;
3869 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003870 value = ast2obj_string(state, o->v.For.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003871 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003872 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003873 goto failed;
3874 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003875 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003876 case AsyncFor_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003877 tp = (PyTypeObject *)state->AsyncFor_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003878 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003879 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003880 value = ast2obj_expr(state, o->v.AsyncFor.target);
Yury Selivanov75445082015-05-11 22:57:16 -04003881 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003882 if (PyObject_SetAttr(result, state->target, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003883 goto failed;
3884 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003885 value = ast2obj_expr(state, o->v.AsyncFor.iter);
Yury Selivanov75445082015-05-11 22:57:16 -04003886 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003887 if (PyObject_SetAttr(result, state->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003888 goto failed;
3889 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003890 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.body,
3891 ast2obj_stmt);
Yury Selivanov75445082015-05-11 22:57:16 -04003892 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003893 if (PyObject_SetAttr(result, state->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003894 goto failed;
3895 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003896 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncFor.orelse,
3897 ast2obj_stmt);
Yury Selivanov75445082015-05-11 22:57:16 -04003898 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003899 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003900 goto failed;
3901 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003902 value = ast2obj_string(state, o->v.AsyncFor.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003903 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003904 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003905 goto failed;
3906 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003907 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003908 case While_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003909 tp = (PyTypeObject *)state->While_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003910 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003911 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003912 value = ast2obj_expr(state, o->v.While.test);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003913 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003914 if (PyObject_SetAttr(result, state->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003915 goto failed;
3916 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003917 value = ast2obj_list(state, (asdl_seq*)o->v.While.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003918 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003919 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003920 goto failed;
3921 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003922 value = ast2obj_list(state, (asdl_seq*)o->v.While.orelse, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003923 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003924 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003925 goto failed;
3926 Py_DECREF(value);
3927 break;
3928 case If_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003929 tp = (PyTypeObject *)state->If_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003930 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003931 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003932 value = ast2obj_expr(state, o->v.If.test);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003933 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003934 if (PyObject_SetAttr(result, state->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003935 goto failed;
3936 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003937 value = ast2obj_list(state, (asdl_seq*)o->v.If.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003938 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003939 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003940 goto failed;
3941 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003942 value = ast2obj_list(state, (asdl_seq*)o->v.If.orelse, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003943 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003944 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003945 goto failed;
3946 Py_DECREF(value);
3947 break;
3948 case With_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003949 tp = (PyTypeObject *)state->With_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003950 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003951 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003952 value = ast2obj_list(state, (asdl_seq*)o->v.With.items,
3953 ast2obj_withitem);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003954 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003955 if (PyObject_SetAttr(result, state->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003956 goto failed;
3957 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003958 value = ast2obj_list(state, (asdl_seq*)o->v.With.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003959 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003960 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003961 goto failed;
3962 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003963 value = ast2obj_string(state, o->v.With.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003964 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003965 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003966 goto failed;
3967 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003968 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003969 case AsyncWith_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02003970 tp = (PyTypeObject *)state->AsyncWith_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003971 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003972 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01003973 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.items,
3974 ast2obj_withitem);
Yury Selivanov75445082015-05-11 22:57:16 -04003975 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003976 if (PyObject_SetAttr(result, state->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003977 goto failed;
3978 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01003979 value = ast2obj_list(state, (asdl_seq*)o->v.AsyncWith.body,
3980 ast2obj_stmt);
Yury Selivanov75445082015-05-11 22:57:16 -04003981 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003982 if (PyObject_SetAttr(result, state->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003983 goto failed;
3984 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02003985 value = ast2obj_string(state, o->v.AsyncWith.type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003986 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02003987 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003988 goto failed;
3989 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003990 break;
Brandt Bucher145bf262021-02-26 14:51:55 -08003991 case Match_kind:
3992 tp = (PyTypeObject *)state->Match_type;
3993 result = PyType_GenericNew(tp, NULL, NULL);
3994 if (!result) goto failed;
3995 value = ast2obj_expr(state, o->v.Match.subject);
3996 if (!value) goto failed;
3997 if (PyObject_SetAttr(result, state->subject, value) == -1)
3998 goto failed;
3999 Py_DECREF(value);
4000 value = ast2obj_list(state, (asdl_seq*)o->v.Match.cases,
4001 ast2obj_match_case);
4002 if (!value) goto failed;
4003 if (PyObject_SetAttr(result, state->cases, value) == -1)
4004 goto failed;
4005 Py_DECREF(value);
4006 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004007 case Raise_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004008 tp = (PyTypeObject *)state->Raise_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004009 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004010 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004011 value = ast2obj_expr(state, o->v.Raise.exc);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004012 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004013 if (PyObject_SetAttr(result, state->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004014 goto failed;
4015 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004016 value = ast2obj_expr(state, o->v.Raise.cause);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004017 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004018 if (PyObject_SetAttr(result, state->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004019 goto failed;
4020 Py_DECREF(value);
4021 break;
4022 case Try_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004023 tp = (PyTypeObject *)state->Try_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004024 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004025 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004026 value = ast2obj_list(state, (asdl_seq*)o->v.Try.body, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004027 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004028 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004029 goto failed;
4030 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004031 value = ast2obj_list(state, (asdl_seq*)o->v.Try.handlers,
4032 ast2obj_excepthandler);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004033 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004034 if (PyObject_SetAttr(result, state->handlers, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004035 goto failed;
4036 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004037 value = ast2obj_list(state, (asdl_seq*)o->v.Try.orelse, ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004038 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004039 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004040 goto failed;
4041 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004042 value = ast2obj_list(state, (asdl_seq*)o->v.Try.finalbody,
4043 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004044 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004045 if (PyObject_SetAttr(result, state->finalbody, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004046 goto failed;
4047 Py_DECREF(value);
4048 break;
4049 case Assert_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004050 tp = (PyTypeObject *)state->Assert_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004051 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004052 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004053 value = ast2obj_expr(state, o->v.Assert.test);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004054 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004055 if (PyObject_SetAttr(result, state->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004056 goto failed;
4057 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004058 value = ast2obj_expr(state, o->v.Assert.msg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004059 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004060 if (PyObject_SetAttr(result, state->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004061 goto failed;
4062 Py_DECREF(value);
4063 break;
4064 case Import_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004065 tp = (PyTypeObject *)state->Import_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004066 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004067 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004068 value = ast2obj_list(state, (asdl_seq*)o->v.Import.names,
4069 ast2obj_alias);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004070 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004071 if (PyObject_SetAttr(result, state->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004072 goto failed;
4073 Py_DECREF(value);
4074 break;
4075 case ImportFrom_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004076 tp = (PyTypeObject *)state->ImportFrom_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004077 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004078 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004079 value = ast2obj_identifier(state, o->v.ImportFrom.module);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004080 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004081 if (PyObject_SetAttr(result, state->module, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004082 goto failed;
4083 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004084 value = ast2obj_list(state, (asdl_seq*)o->v.ImportFrom.names,
4085 ast2obj_alias);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004086 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004087 if (PyObject_SetAttr(result, state->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004088 goto failed;
4089 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004090 value = ast2obj_int(state, o->v.ImportFrom.level);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004091 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004092 if (PyObject_SetAttr(result, state->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004093 goto failed;
4094 Py_DECREF(value);
4095 break;
4096 case Global_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004097 tp = (PyTypeObject *)state->Global_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004098 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004099 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004100 value = ast2obj_list(state, (asdl_seq*)o->v.Global.names,
4101 ast2obj_identifier);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004102 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004103 if (PyObject_SetAttr(result, state->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004104 goto failed;
4105 Py_DECREF(value);
4106 break;
4107 case Nonlocal_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004108 tp = (PyTypeObject *)state->Nonlocal_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004109 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004110 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004111 value = ast2obj_list(state, (asdl_seq*)o->v.Nonlocal.names,
4112 ast2obj_identifier);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004113 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004114 if (PyObject_SetAttr(result, state->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004115 goto failed;
4116 Py_DECREF(value);
4117 break;
4118 case Expr_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004119 tp = (PyTypeObject *)state->Expr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004120 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004121 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004122 value = ast2obj_expr(state, o->v.Expr.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004123 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004124 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004125 goto failed;
4126 Py_DECREF(value);
4127 break;
4128 case Pass_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004129 tp = (PyTypeObject *)state->Pass_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004130 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004131 if (!result) goto failed;
4132 break;
4133 case Break_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004134 tp = (PyTypeObject *)state->Break_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004135 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004136 if (!result) goto failed;
4137 break;
4138 case Continue_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004139 tp = (PyTypeObject *)state->Continue_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004140 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004141 if (!result) goto failed;
4142 break;
4143 }
Victor Stinner74419f02020-07-03 11:35:37 +02004144 value = ast2obj_int(state, o->lineno);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004145 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004146 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004147 goto failed;
4148 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004149 value = ast2obj_int(state, o->col_offset);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004150 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004151 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004152 goto failed;
4153 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004154 value = ast2obj_int(state, o->end_lineno);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004155 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004156 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004157 goto failed;
4158 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004159 value = ast2obj_int(state, o->end_col_offset);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004160 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004161 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004162 goto failed;
4163 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004164 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004165failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004166 Py_XDECREF(value);
4167 Py_XDECREF(result);
4168 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004169}
4170
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004171PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004172ast2obj_expr(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004173{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004174 expr_ty o = (expr_ty)_o;
4175 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004176 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004177 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004178 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004179 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004180 switch (o->kind) {
4181 case BoolOp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004182 tp = (PyTypeObject *)state->BoolOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004183 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004184 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004185 value = ast2obj_boolop(state, o->v.BoolOp.op);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004186 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004187 if (PyObject_SetAttr(result, state->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004188 goto failed;
4189 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004190 value = ast2obj_list(state, (asdl_seq*)o->v.BoolOp.values,
4191 ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004192 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004193 if (PyObject_SetAttr(result, state->values, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004194 goto failed;
4195 Py_DECREF(value);
4196 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004197 case NamedExpr_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004198 tp = (PyTypeObject *)state->NamedExpr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004199 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004200 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004201 value = ast2obj_expr(state, o->v.NamedExpr.target);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004202 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004203 if (PyObject_SetAttr(result, state->target, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004204 goto failed;
4205 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004206 value = ast2obj_expr(state, o->v.NamedExpr.value);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004207 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004208 if (PyObject_SetAttr(result, state->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004209 goto failed;
4210 Py_DECREF(value);
4211 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004212 case BinOp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004213 tp = (PyTypeObject *)state->BinOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004214 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004215 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004216 value = ast2obj_expr(state, o->v.BinOp.left);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004217 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004218 if (PyObject_SetAttr(result, state->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004219 goto failed;
4220 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004221 value = ast2obj_operator(state, o->v.BinOp.op);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004222 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004223 if (PyObject_SetAttr(result, state->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004224 goto failed;
4225 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004226 value = ast2obj_expr(state, o->v.BinOp.right);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004227 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004228 if (PyObject_SetAttr(result, state->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004229 goto failed;
4230 Py_DECREF(value);
4231 break;
4232 case UnaryOp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004233 tp = (PyTypeObject *)state->UnaryOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004234 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004235 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004236 value = ast2obj_unaryop(state, o->v.UnaryOp.op);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004237 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004238 if (PyObject_SetAttr(result, state->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004239 goto failed;
4240 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004241 value = ast2obj_expr(state, o->v.UnaryOp.operand);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004242 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004243 if (PyObject_SetAttr(result, state->operand, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004244 goto failed;
4245 Py_DECREF(value);
4246 break;
4247 case Lambda_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004248 tp = (PyTypeObject *)state->Lambda_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004249 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004250 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004251 value = ast2obj_arguments(state, o->v.Lambda.args);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004252 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004253 if (PyObject_SetAttr(result, state->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004254 goto failed;
4255 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004256 value = ast2obj_expr(state, o->v.Lambda.body);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004257 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004258 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004259 goto failed;
4260 Py_DECREF(value);
4261 break;
4262 case IfExp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004263 tp = (PyTypeObject *)state->IfExp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004264 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004265 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004266 value = ast2obj_expr(state, o->v.IfExp.test);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004267 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004268 if (PyObject_SetAttr(result, state->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004269 goto failed;
4270 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004271 value = ast2obj_expr(state, o->v.IfExp.body);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004272 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004273 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004274 goto failed;
4275 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004276 value = ast2obj_expr(state, o->v.IfExp.orelse);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004277 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004278 if (PyObject_SetAttr(result, state->orelse, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004279 goto failed;
4280 Py_DECREF(value);
4281 break;
4282 case Dict_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004283 tp = (PyTypeObject *)state->Dict_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004284 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004285 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004286 value = ast2obj_list(state, (asdl_seq*)o->v.Dict.keys, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004287 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004288 if (PyObject_SetAttr(result, state->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004289 goto failed;
4290 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004291 value = ast2obj_list(state, (asdl_seq*)o->v.Dict.values, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004292 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004293 if (PyObject_SetAttr(result, state->values, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004294 goto failed;
4295 Py_DECREF(value);
4296 break;
4297 case Set_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004298 tp = (PyTypeObject *)state->Set_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004299 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004300 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004301 value = ast2obj_list(state, (asdl_seq*)o->v.Set.elts, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004302 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004303 if (PyObject_SetAttr(result, state->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004304 goto failed;
4305 Py_DECREF(value);
4306 break;
4307 case ListComp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004308 tp = (PyTypeObject *)state->ListComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004309 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004310 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004311 value = ast2obj_expr(state, o->v.ListComp.elt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004312 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004313 if (PyObject_SetAttr(result, state->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004314 goto failed;
4315 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004316 value = ast2obj_list(state, (asdl_seq*)o->v.ListComp.generators,
Victor Stinner74419f02020-07-03 11:35:37 +02004317 ast2obj_comprehension);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004318 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004319 if (PyObject_SetAttr(result, state->generators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004320 goto failed;
4321 Py_DECREF(value);
4322 break;
4323 case SetComp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004324 tp = (PyTypeObject *)state->SetComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004325 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004326 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004327 value = ast2obj_expr(state, o->v.SetComp.elt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004328 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004329 if (PyObject_SetAttr(result, state->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004330 goto failed;
4331 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004332 value = ast2obj_list(state, (asdl_seq*)o->v.SetComp.generators,
Victor Stinner74419f02020-07-03 11:35:37 +02004333 ast2obj_comprehension);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004334 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004335 if (PyObject_SetAttr(result, state->generators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004336 goto failed;
4337 Py_DECREF(value);
4338 break;
4339 case DictComp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004340 tp = (PyTypeObject *)state->DictComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004341 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004342 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004343 value = ast2obj_expr(state, o->v.DictComp.key);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004344 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004345 if (PyObject_SetAttr(result, state->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004346 goto failed;
4347 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004348 value = ast2obj_expr(state, o->v.DictComp.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004349 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004350 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004351 goto failed;
4352 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004353 value = ast2obj_list(state, (asdl_seq*)o->v.DictComp.generators,
Victor Stinner74419f02020-07-03 11:35:37 +02004354 ast2obj_comprehension);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004355 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004356 if (PyObject_SetAttr(result, state->generators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004357 goto failed;
4358 Py_DECREF(value);
4359 break;
4360 case GeneratorExp_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004361 tp = (PyTypeObject *)state->GeneratorExp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004362 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004363 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004364 value = ast2obj_expr(state, o->v.GeneratorExp.elt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004365 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004366 if (PyObject_SetAttr(result, state->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004367 goto failed;
4368 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004369 value = ast2obj_list(state, (asdl_seq*)o->v.GeneratorExp.generators,
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004370 ast2obj_comprehension);
4371 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004372 if (PyObject_SetAttr(result, state->generators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004373 goto failed;
4374 Py_DECREF(value);
4375 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004376 case Await_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004377 tp = (PyTypeObject *)state->Await_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004378 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004379 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004380 value = ast2obj_expr(state, o->v.Await.value);
Yury Selivanov75445082015-05-11 22:57:16 -04004381 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004382 if (PyObject_SetAttr(result, state->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004383 goto failed;
4384 Py_DECREF(value);
4385 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004386 case Yield_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004387 tp = (PyTypeObject *)state->Yield_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004388 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004389 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004390 value = ast2obj_expr(state, o->v.Yield.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004391 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004392 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004393 goto failed;
4394 Py_DECREF(value);
4395 break;
4396 case YieldFrom_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004397 tp = (PyTypeObject *)state->YieldFrom_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004398 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004399 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004400 value = ast2obj_expr(state, o->v.YieldFrom.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004401 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004402 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004403 goto failed;
4404 Py_DECREF(value);
4405 break;
4406 case Compare_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004407 tp = (PyTypeObject *)state->Compare_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004408 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004409 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004410 value = ast2obj_expr(state, o->v.Compare.left);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004411 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004412 if (PyObject_SetAttr(result, state->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004413 goto failed;
4414 Py_DECREF(value);
4415 {
4416 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4417 value = PyList_New(n);
4418 if (!value) goto failed;
4419 for(i = 0; i < n; i++)
Victor Stinner74419f02020-07-03 11:35:37 +02004420 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 +00004421 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004422 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004423 if (PyObject_SetAttr(result, state->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004424 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004425 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004426 value = ast2obj_list(state, (asdl_seq*)o->v.Compare.comparators,
4427 ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004428 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004429 if (PyObject_SetAttr(result, state->comparators, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004430 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004431 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004432 break;
4433 case Call_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004434 tp = (PyTypeObject *)state->Call_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004435 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004436 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004437 value = ast2obj_expr(state, o->v.Call.func);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004438 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004439 if (PyObject_SetAttr(result, state->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004440 goto failed;
4441 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004442 value = ast2obj_list(state, (asdl_seq*)o->v.Call.args, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004443 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004444 if (PyObject_SetAttr(result, state->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004445 goto failed;
4446 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004447 value = ast2obj_list(state, (asdl_seq*)o->v.Call.keywords,
4448 ast2obj_keyword);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004449 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004450 if (PyObject_SetAttr(result, state->keywords, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004451 goto failed;
4452 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004453 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004454 case FormattedValue_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004455 tp = (PyTypeObject *)state->FormattedValue_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004456 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004457 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004458 value = ast2obj_expr(state, o->v.FormattedValue.value);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004459 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004460 if (PyObject_SetAttr(result, state->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004461 goto failed;
4462 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004463 value = ast2obj_int(state, o->v.FormattedValue.conversion);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004464 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004465 if (PyObject_SetAttr(result, state->conversion, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004466 goto failed;
4467 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004468 value = ast2obj_expr(state, o->v.FormattedValue.format_spec);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004469 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004470 if (PyObject_SetAttr(result, state->format_spec, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004471 goto failed;
4472 Py_DECREF(value);
4473 break;
4474 case JoinedStr_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004475 tp = (PyTypeObject *)state->JoinedStr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004476 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004477 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004478 value = ast2obj_list(state, (asdl_seq*)o->v.JoinedStr.values,
4479 ast2obj_expr);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004480 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004481 if (PyObject_SetAttr(result, state->values, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004482 goto failed;
4483 Py_DECREF(value);
4484 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004485 case Constant_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004486 tp = (PyTypeObject *)state->Constant_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004487 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004488 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004489 value = ast2obj_constant(state, o->v.Constant.value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004490 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004491 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004492 goto failed;
4493 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004494 value = ast2obj_string(state, o->v.Constant.kind);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004495 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004496 if (PyObject_SetAttr(result, state->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004497 goto failed;
4498 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004499 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004500 case Attribute_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004501 tp = (PyTypeObject *)state->Attribute_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004502 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004503 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004504 value = ast2obj_expr(state, o->v.Attribute.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004505 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004506 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004507 goto failed;
4508 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004509 value = ast2obj_identifier(state, o->v.Attribute.attr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004510 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004511 if (PyObject_SetAttr(result, state->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004512 goto failed;
4513 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004514 value = ast2obj_expr_context(state, o->v.Attribute.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004515 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004516 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004517 goto failed;
4518 Py_DECREF(value);
4519 break;
4520 case Subscript_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004521 tp = (PyTypeObject *)state->Subscript_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004522 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004523 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004524 value = ast2obj_expr(state, o->v.Subscript.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004525 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004526 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004527 goto failed;
4528 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004529 value = ast2obj_expr(state, o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004530 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004531 if (PyObject_SetAttr(result, state->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004532 goto failed;
4533 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004534 value = ast2obj_expr_context(state, o->v.Subscript.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004535 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004536 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004537 goto failed;
4538 Py_DECREF(value);
4539 break;
4540 case Starred_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004541 tp = (PyTypeObject *)state->Starred_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004542 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004543 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004544 value = ast2obj_expr(state, o->v.Starred.value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004545 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004546 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004547 goto failed;
4548 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004549 value = ast2obj_expr_context(state, o->v.Starred.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004550 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004551 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004552 goto failed;
4553 Py_DECREF(value);
4554 break;
4555 case Name_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004556 tp = (PyTypeObject *)state->Name_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004557 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004558 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004559 value = ast2obj_identifier(state, o->v.Name.id);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004560 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004561 if (PyObject_SetAttr(result, state->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004562 goto failed;
4563 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004564 value = ast2obj_expr_context(state, o->v.Name.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004565 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004566 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004567 goto failed;
4568 Py_DECREF(value);
4569 break;
4570 case List_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004571 tp = (PyTypeObject *)state->List_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004572 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004573 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004574 value = ast2obj_list(state, (asdl_seq*)o->v.List.elts, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004575 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004576 if (PyObject_SetAttr(result, state->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004577 goto failed;
4578 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004579 value = ast2obj_expr_context(state, o->v.List.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004580 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004581 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004582 goto failed;
4583 Py_DECREF(value);
4584 break;
4585 case Tuple_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004586 tp = (PyTypeObject *)state->Tuple_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004587 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004588 if (!result) goto failed;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004589 value = ast2obj_list(state, (asdl_seq*)o->v.Tuple.elts, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004590 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004591 if (PyObject_SetAttr(result, state->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004592 goto failed;
4593 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004594 value = ast2obj_expr_context(state, o->v.Tuple.ctx);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004595 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004596 if (PyObject_SetAttr(result, state->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004597 goto failed;
4598 Py_DECREF(value);
4599 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004600 case Slice_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004601 tp = (PyTypeObject *)state->Slice_type;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004602 result = PyType_GenericNew(tp, NULL, NULL);
4603 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004604 value = ast2obj_expr(state, o->v.Slice.lower);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004605 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004606 if (PyObject_SetAttr(result, state->lower, value) == -1)
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004607 goto failed;
4608 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004609 value = ast2obj_expr(state, o->v.Slice.upper);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004610 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004611 if (PyObject_SetAttr(result, state->upper, value) == -1)
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004612 goto failed;
4613 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004614 value = ast2obj_expr(state, o->v.Slice.step);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004615 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004616 if (PyObject_SetAttr(result, state->step, value) == -1)
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004617 goto failed;
4618 Py_DECREF(value);
4619 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004620 }
Victor Stinner74419f02020-07-03 11:35:37 +02004621 value = ast2obj_int(state, o->lineno);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004622 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004623 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004624 goto failed;
4625 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004626 value = ast2obj_int(state, o->col_offset);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004627 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004628 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004629 goto failed;
4630 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004631 value = ast2obj_int(state, o->end_lineno);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004632 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004633 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004634 goto failed;
4635 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004636 value = ast2obj_int(state, o->end_col_offset);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004637 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004638 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004639 goto failed;
4640 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004641 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004642failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004643 Py_XDECREF(value);
4644 Py_XDECREF(result);
4645 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004646}
4647
Victor Stinner5cf47822020-11-02 22:03:28 +01004648PyObject* ast2obj_expr_context(struct ast_state *state, expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004649{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004650 switch(o) {
4651 case Load:
Victor Stinner74419f02020-07-03 11:35:37 +02004652 Py_INCREF(state->Load_singleton);
4653 return state->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004654 case Store:
Victor Stinner74419f02020-07-03 11:35:37 +02004655 Py_INCREF(state->Store_singleton);
4656 return state->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004657 case Del:
Victor Stinner74419f02020-07-03 11:35:37 +02004658 Py_INCREF(state->Del_singleton);
4659 return state->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004660 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004661 Py_UNREACHABLE();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004662}
Victor Stinner5cf47822020-11-02 22:03:28 +01004663PyObject* ast2obj_boolop(struct ast_state *state, boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004664{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004665 switch(o) {
4666 case And:
Victor Stinner74419f02020-07-03 11:35:37 +02004667 Py_INCREF(state->And_singleton);
4668 return state->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004669 case Or:
Victor Stinner74419f02020-07-03 11:35:37 +02004670 Py_INCREF(state->Or_singleton);
4671 return state->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004672 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004673 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004674}
Victor Stinner5cf47822020-11-02 22:03:28 +01004675PyObject* ast2obj_operator(struct ast_state *state, operator_ty o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004676{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004677 switch(o) {
4678 case Add:
Victor Stinner74419f02020-07-03 11:35:37 +02004679 Py_INCREF(state->Add_singleton);
4680 return state->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004681 case Sub:
Victor Stinner74419f02020-07-03 11:35:37 +02004682 Py_INCREF(state->Sub_singleton);
4683 return state->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004684 case Mult:
Victor Stinner74419f02020-07-03 11:35:37 +02004685 Py_INCREF(state->Mult_singleton);
4686 return state->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004687 case MatMult:
Victor Stinner74419f02020-07-03 11:35:37 +02004688 Py_INCREF(state->MatMult_singleton);
4689 return state->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004690 case Div:
Victor Stinner74419f02020-07-03 11:35:37 +02004691 Py_INCREF(state->Div_singleton);
4692 return state->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004693 case Mod:
Victor Stinner74419f02020-07-03 11:35:37 +02004694 Py_INCREF(state->Mod_singleton);
4695 return state->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004696 case Pow:
Victor Stinner74419f02020-07-03 11:35:37 +02004697 Py_INCREF(state->Pow_singleton);
4698 return state->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004699 case LShift:
Victor Stinner74419f02020-07-03 11:35:37 +02004700 Py_INCREF(state->LShift_singleton);
4701 return state->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004702 case RShift:
Victor Stinner74419f02020-07-03 11:35:37 +02004703 Py_INCREF(state->RShift_singleton);
4704 return state->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004705 case BitOr:
Victor Stinner74419f02020-07-03 11:35:37 +02004706 Py_INCREF(state->BitOr_singleton);
4707 return state->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004708 case BitXor:
Victor Stinner74419f02020-07-03 11:35:37 +02004709 Py_INCREF(state->BitXor_singleton);
4710 return state->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004711 case BitAnd:
Victor Stinner74419f02020-07-03 11:35:37 +02004712 Py_INCREF(state->BitAnd_singleton);
4713 return state->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004714 case FloorDiv:
Victor Stinner74419f02020-07-03 11:35:37 +02004715 Py_INCREF(state->FloorDiv_singleton);
4716 return state->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004717 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004718 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004719}
Victor Stinner5cf47822020-11-02 22:03:28 +01004720PyObject* ast2obj_unaryop(struct ast_state *state, unaryop_ty o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004721{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004722 switch(o) {
4723 case Invert:
Victor Stinner74419f02020-07-03 11:35:37 +02004724 Py_INCREF(state->Invert_singleton);
4725 return state->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004726 case Not:
Victor Stinner74419f02020-07-03 11:35:37 +02004727 Py_INCREF(state->Not_singleton);
4728 return state->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004729 case UAdd:
Victor Stinner74419f02020-07-03 11:35:37 +02004730 Py_INCREF(state->UAdd_singleton);
4731 return state->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004732 case USub:
Victor Stinner74419f02020-07-03 11:35:37 +02004733 Py_INCREF(state->USub_singleton);
4734 return state->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004735 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004736 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004737}
Victor Stinner5cf47822020-11-02 22:03:28 +01004738PyObject* ast2obj_cmpop(struct ast_state *state, cmpop_ty o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004739{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004740 switch(o) {
4741 case Eq:
Victor Stinner74419f02020-07-03 11:35:37 +02004742 Py_INCREF(state->Eq_singleton);
4743 return state->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004744 case NotEq:
Victor Stinner74419f02020-07-03 11:35:37 +02004745 Py_INCREF(state->NotEq_singleton);
4746 return state->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004747 case Lt:
Victor Stinner74419f02020-07-03 11:35:37 +02004748 Py_INCREF(state->Lt_singleton);
4749 return state->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004750 case LtE:
Victor Stinner74419f02020-07-03 11:35:37 +02004751 Py_INCREF(state->LtE_singleton);
4752 return state->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004753 case Gt:
Victor Stinner74419f02020-07-03 11:35:37 +02004754 Py_INCREF(state->Gt_singleton);
4755 return state->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004756 case GtE:
Victor Stinner74419f02020-07-03 11:35:37 +02004757 Py_INCREF(state->GtE_singleton);
4758 return state->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004759 case Is:
Victor Stinner74419f02020-07-03 11:35:37 +02004760 Py_INCREF(state->Is_singleton);
4761 return state->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004762 case IsNot:
Victor Stinner74419f02020-07-03 11:35:37 +02004763 Py_INCREF(state->IsNot_singleton);
4764 return state->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004765 case In:
Victor Stinner74419f02020-07-03 11:35:37 +02004766 Py_INCREF(state->In_singleton);
4767 return state->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004768 case NotIn:
Victor Stinner74419f02020-07-03 11:35:37 +02004769 Py_INCREF(state->NotIn_singleton);
4770 return state->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004771 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004772 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004773}
4774PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004775ast2obj_comprehension(struct ast_state *state, void* _o)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004776{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004777 comprehension_ty o = (comprehension_ty)_o;
4778 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004779 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004780 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004781 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004782 }
Victor Stinner74419f02020-07-03 11:35:37 +02004783 tp = (PyTypeObject *)state->comprehension_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004784 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004785 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02004786 value = ast2obj_expr(state, o->target);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004787 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004788 if (PyObject_SetAttr(result, state->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004789 goto failed;
4790 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004791 value = ast2obj_expr(state, o->iter);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004792 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004793 if (PyObject_SetAttr(result, state->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004794 goto failed;
4795 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004796 value = ast2obj_list(state, (asdl_seq*)o->ifs, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004797 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004798 if (PyObject_SetAttr(result, state->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004799 goto failed;
4800 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004801 value = ast2obj_int(state, o->is_async);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004802 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004803 if (PyObject_SetAttr(result, state->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004804 goto failed;
4805 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004806 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004807failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004808 Py_XDECREF(value);
4809 Py_XDECREF(result);
4810 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004811}
4812
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004813PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004814ast2obj_excepthandler(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004815{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004816 excepthandler_ty o = (excepthandler_ty)_o;
4817 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004818 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004819 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004820 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004821 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004822 switch (o->kind) {
4823 case ExceptHandler_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02004824 tp = (PyTypeObject *)state->ExceptHandler_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004825 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004826 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004827 value = ast2obj_expr(state, o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004828 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004829 if (PyObject_SetAttr(result, state->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004830 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004831 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004832 value = ast2obj_identifier(state, o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004833 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004834 if (PyObject_SetAttr(result, state->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004835 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004836 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004837 value = ast2obj_list(state, (asdl_seq*)o->v.ExceptHandler.body,
4838 ast2obj_stmt);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004839 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004840 if (PyObject_SetAttr(result, state->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004841 goto failed;
4842 Py_DECREF(value);
4843 break;
4844 }
Victor Stinner74419f02020-07-03 11:35:37 +02004845 value = ast2obj_int(state, o->lineno);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004846 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004847 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004848 goto failed;
4849 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004850 value = ast2obj_int(state, o->col_offset);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004851 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004852 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004853 goto failed;
4854 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004855 value = ast2obj_int(state, o->end_lineno);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004856 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004857 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004858 goto failed;
4859 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004860 value = ast2obj_int(state, o->end_col_offset);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004861 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004862 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004863 goto failed;
4864 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004865 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004866failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004867 Py_XDECREF(value);
4868 Py_XDECREF(result);
4869 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004870}
4871
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004872PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004873ast2obj_arguments(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004874{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004875 arguments_ty o = (arguments_ty)_o;
4876 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004877 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004878 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004879 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004880 }
Victor Stinner74419f02020-07-03 11:35:37 +02004881 tp = (PyTypeObject *)state->arguments_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004882 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004883 if (!result) return NULL;
Pablo Galindoa5634c42020-09-16 19:42:00 +01004884 value = ast2obj_list(state, (asdl_seq*)o->posonlyargs, ast2obj_arg);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004885 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004886 if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004887 goto failed;
4888 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004889 value = ast2obj_list(state, (asdl_seq*)o->args, ast2obj_arg);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004890 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004891 if (PyObject_SetAttr(result, state->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004892 goto failed;
4893 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004894 value = ast2obj_arg(state, o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004895 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004896 if (PyObject_SetAttr(result, state->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004897 goto failed;
4898 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004899 value = ast2obj_list(state, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004900 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004901 if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004902 goto failed;
4903 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004904 value = ast2obj_list(state, (asdl_seq*)o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004905 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004906 if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004907 goto failed;
4908 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004909 value = ast2obj_arg(state, o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004910 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004911 if (PyObject_SetAttr(result, state->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004912 goto failed;
4913 Py_DECREF(value);
Pablo Galindoa5634c42020-09-16 19:42:00 +01004914 value = ast2obj_list(state, (asdl_seq*)o->defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004915 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004916 if (PyObject_SetAttr(result, state->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004917 goto failed;
4918 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004919 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004920failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004921 Py_XDECREF(value);
4922 Py_XDECREF(result);
4923 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004924}
4925
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004926PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004927ast2obj_arg(struct ast_state *state, void* _o)
Neal Norwitzc1505362006-12-28 06:47:50 +00004928{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004929 arg_ty o = (arg_ty)_o;
4930 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004931 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004932 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004933 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004934 }
Victor Stinner74419f02020-07-03 11:35:37 +02004935 tp = (PyTypeObject *)state->arg_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004936 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004937 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02004938 value = ast2obj_identifier(state, o->arg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004939 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004940 if (PyObject_SetAttr(result, state->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004941 goto failed;
4942 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004943 value = ast2obj_expr(state, o->annotation);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004944 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004945 if (PyObject_SetAttr(result, state->annotation, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004946 goto failed;
4947 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004948 value = ast2obj_string(state, o->type_comment);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004949 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004950 if (PyObject_SetAttr(result, state->type_comment, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004951 goto failed;
4952 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004953 value = ast2obj_int(state, o->lineno);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004954 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004955 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004956 goto failed;
4957 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004958 value = ast2obj_int(state, o->col_offset);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004959 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004960 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004961 goto failed;
4962 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004963 value = ast2obj_int(state, o->end_lineno);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004964 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004965 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004966 goto failed;
4967 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004968 value = ast2obj_int(state, o->end_col_offset);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004969 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004970 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004971 goto failed;
4972 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004973 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004974failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004975 Py_XDECREF(value);
4976 Py_XDECREF(result);
4977 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004978}
4979
4980PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01004981ast2obj_keyword(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004982{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004983 keyword_ty o = (keyword_ty)_o;
4984 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004985 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004986 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004987 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004988 }
Victor Stinner74419f02020-07-03 11:35:37 +02004989 tp = (PyTypeObject *)state->keyword_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004990 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004991 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02004992 value = ast2obj_identifier(state, o->arg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004993 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004994 if (PyObject_SetAttr(result, state->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004995 goto failed;
4996 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02004997 value = ast2obj_expr(state, o->value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004998 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02004999 if (PyObject_SetAttr(result, state->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005000 goto failed;
5001 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005002 value = ast2obj_int(state, o->lineno);
Pablo Galindo168660b2020-04-02 00:47:39 +01005003 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005004 if (PyObject_SetAttr(result, state->lineno, value) < 0)
Pablo Galindo168660b2020-04-02 00:47:39 +01005005 goto failed;
5006 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005007 value = ast2obj_int(state, o->col_offset);
Pablo Galindo168660b2020-04-02 00:47:39 +01005008 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005009 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
Pablo Galindo168660b2020-04-02 00:47:39 +01005010 goto failed;
5011 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005012 value = ast2obj_int(state, o->end_lineno);
Pablo Galindo168660b2020-04-02 00:47:39 +01005013 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005014 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
Pablo Galindo168660b2020-04-02 00:47:39 +01005015 goto failed;
5016 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005017 value = ast2obj_int(state, o->end_col_offset);
Pablo Galindo168660b2020-04-02 00:47:39 +01005018 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005019 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
Pablo Galindo168660b2020-04-02 00:47:39 +01005020 goto failed;
5021 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005022 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005023failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005024 Py_XDECREF(value);
5025 Py_XDECREF(result);
5026 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005027}
5028
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005029PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01005030ast2obj_alias(struct ast_state *state, void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005031{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005032 alias_ty o = (alias_ty)_o;
5033 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005034 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005035 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005036 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005037 }
Victor Stinner74419f02020-07-03 11:35:37 +02005038 tp = (PyTypeObject *)state->alias_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005039 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005040 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02005041 value = ast2obj_identifier(state, o->name);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005042 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005043 if (PyObject_SetAttr(result, state->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005044 goto failed;
5045 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005046 value = ast2obj_identifier(state, o->asname);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005047 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005048 if (PyObject_SetAttr(result, state->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005049 goto failed;
5050 Py_DECREF(value);
Matthew Suozzo75a06f02021-04-10 16:56:28 -04005051 value = ast2obj_int(state, o->lineno);
5052 if (!value) goto failed;
5053 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5054 goto failed;
5055 Py_DECREF(value);
5056 value = ast2obj_int(state, o->col_offset);
5057 if (!value) goto failed;
5058 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5059 goto failed;
5060 Py_DECREF(value);
5061 value = ast2obj_int(state, o->end_lineno);
5062 if (!value) goto failed;
5063 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5064 goto failed;
5065 Py_DECREF(value);
5066 value = ast2obj_int(state, o->end_col_offset);
5067 if (!value) goto failed;
5068 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5069 goto failed;
5070 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005071 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005072failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005073 Py_XDECREF(value);
5074 Py_XDECREF(result);
5075 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005076}
5077
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005078PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01005079ast2obj_withitem(struct ast_state *state, void* _o)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005080{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005081 withitem_ty o = (withitem_ty)_o;
5082 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005083 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005084 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005085 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005086 }
Victor Stinner74419f02020-07-03 11:35:37 +02005087 tp = (PyTypeObject *)state->withitem_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005088 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005089 if (!result) return NULL;
Victor Stinner74419f02020-07-03 11:35:37 +02005090 value = ast2obj_expr(state, o->context_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005091 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005092 if (PyObject_SetAttr(result, state->context_expr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005093 goto failed;
5094 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005095 value = ast2obj_expr(state, o->optional_vars);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005096 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005097 if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005098 goto failed;
5099 Py_DECREF(value);
5100 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005101failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005102 Py_XDECREF(value);
5103 Py_XDECREF(result);
5104 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005105}
5106
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005107PyObject*
Brandt Bucher145bf262021-02-26 14:51:55 -08005108ast2obj_match_case(struct ast_state *state, void* _o)
5109{
5110 match_case_ty o = (match_case_ty)_o;
5111 PyObject *result = NULL, *value = NULL;
5112 PyTypeObject *tp;
5113 if (!o) {
5114 Py_RETURN_NONE;
5115 }
5116 tp = (PyTypeObject *)state->match_case_type;
5117 result = PyType_GenericNew(tp, NULL, NULL);
5118 if (!result) return NULL;
Nick Coghlan1e7b8582021-04-29 15:58:44 +10005119 value = ast2obj_pattern(state, o->pattern);
Brandt Bucher145bf262021-02-26 14:51:55 -08005120 if (!value) goto failed;
5121 if (PyObject_SetAttr(result, state->pattern, value) == -1)
5122 goto failed;
5123 Py_DECREF(value);
5124 value = ast2obj_expr(state, o->guard);
5125 if (!value) goto failed;
5126 if (PyObject_SetAttr(result, state->guard, value) == -1)
5127 goto failed;
5128 Py_DECREF(value);
5129 value = ast2obj_list(state, (asdl_seq*)o->body, ast2obj_stmt);
5130 if (!value) goto failed;
5131 if (PyObject_SetAttr(result, state->body, value) == -1)
5132 goto failed;
5133 Py_DECREF(value);
5134 return result;
5135failed:
5136 Py_XDECREF(value);
5137 Py_XDECREF(result);
5138 return NULL;
5139}
5140
5141PyObject*
Nick Coghlan1e7b8582021-04-29 15:58:44 +10005142ast2obj_pattern(struct ast_state *state, void* _o)
5143{
5144 pattern_ty o = (pattern_ty)_o;
5145 PyObject *result = NULL, *value = NULL;
5146 PyTypeObject *tp;
5147 if (!o) {
5148 Py_RETURN_NONE;
5149 }
5150 switch (o->kind) {
5151 case MatchValue_kind:
5152 tp = (PyTypeObject *)state->MatchValue_type;
5153 result = PyType_GenericNew(tp, NULL, NULL);
5154 if (!result) goto failed;
5155 value = ast2obj_expr(state, o->v.MatchValue.value);
5156 if (!value) goto failed;
5157 if (PyObject_SetAttr(result, state->value, value) == -1)
5158 goto failed;
5159 Py_DECREF(value);
5160 break;
5161 case MatchSingleton_kind:
5162 tp = (PyTypeObject *)state->MatchSingleton_type;
5163 result = PyType_GenericNew(tp, NULL, NULL);
5164 if (!result) goto failed;
5165 value = ast2obj_constant(state, o->v.MatchSingleton.value);
5166 if (!value) goto failed;
5167 if (PyObject_SetAttr(result, state->value, value) == -1)
5168 goto failed;
5169 Py_DECREF(value);
5170 break;
5171 case MatchSequence_kind:
5172 tp = (PyTypeObject *)state->MatchSequence_type;
5173 result = PyType_GenericNew(tp, NULL, NULL);
5174 if (!result) goto failed;
5175 value = ast2obj_list(state, (asdl_seq*)o->v.MatchSequence.patterns,
5176 ast2obj_pattern);
5177 if (!value) goto failed;
5178 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5179 goto failed;
5180 Py_DECREF(value);
5181 break;
5182 case MatchMapping_kind:
5183 tp = (PyTypeObject *)state->MatchMapping_type;
5184 result = PyType_GenericNew(tp, NULL, NULL);
5185 if (!result) goto failed;
5186 value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.keys,
5187 ast2obj_expr);
5188 if (!value) goto failed;
5189 if (PyObject_SetAttr(result, state->keys, value) == -1)
5190 goto failed;
5191 Py_DECREF(value);
5192 value = ast2obj_list(state, (asdl_seq*)o->v.MatchMapping.patterns,
5193 ast2obj_pattern);
5194 if (!value) goto failed;
5195 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5196 goto failed;
5197 Py_DECREF(value);
5198 value = ast2obj_identifier(state, o->v.MatchMapping.rest);
5199 if (!value) goto failed;
5200 if (PyObject_SetAttr(result, state->rest, value) == -1)
5201 goto failed;
5202 Py_DECREF(value);
5203 break;
5204 case MatchClass_kind:
5205 tp = (PyTypeObject *)state->MatchClass_type;
5206 result = PyType_GenericNew(tp, NULL, NULL);
5207 if (!result) goto failed;
5208 value = ast2obj_expr(state, o->v.MatchClass.cls);
5209 if (!value) goto failed;
5210 if (PyObject_SetAttr(result, state->cls, value) == -1)
5211 goto failed;
5212 Py_DECREF(value);
5213 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.patterns,
5214 ast2obj_pattern);
5215 if (!value) goto failed;
5216 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5217 goto failed;
5218 Py_DECREF(value);
5219 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_attrs,
5220 ast2obj_identifier);
5221 if (!value) goto failed;
5222 if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
5223 goto failed;
5224 Py_DECREF(value);
5225 value = ast2obj_list(state, (asdl_seq*)o->v.MatchClass.kwd_patterns,
5226 ast2obj_pattern);
5227 if (!value) goto failed;
5228 if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
5229 goto failed;
5230 Py_DECREF(value);
5231 break;
5232 case MatchStar_kind:
5233 tp = (PyTypeObject *)state->MatchStar_type;
5234 result = PyType_GenericNew(tp, NULL, NULL);
5235 if (!result) goto failed;
5236 value = ast2obj_identifier(state, o->v.MatchStar.name);
5237 if (!value) goto failed;
5238 if (PyObject_SetAttr(result, state->name, value) == -1)
5239 goto failed;
5240 Py_DECREF(value);
5241 break;
5242 case MatchAs_kind:
5243 tp = (PyTypeObject *)state->MatchAs_type;
5244 result = PyType_GenericNew(tp, NULL, NULL);
5245 if (!result) goto failed;
5246 value = ast2obj_pattern(state, o->v.MatchAs.pattern);
5247 if (!value) goto failed;
5248 if (PyObject_SetAttr(result, state->pattern, value) == -1)
5249 goto failed;
5250 Py_DECREF(value);
5251 value = ast2obj_identifier(state, o->v.MatchAs.name);
5252 if (!value) goto failed;
5253 if (PyObject_SetAttr(result, state->name, value) == -1)
5254 goto failed;
5255 Py_DECREF(value);
5256 break;
5257 case MatchOr_kind:
5258 tp = (PyTypeObject *)state->MatchOr_type;
5259 result = PyType_GenericNew(tp, NULL, NULL);
5260 if (!result) goto failed;
5261 value = ast2obj_list(state, (asdl_seq*)o->v.MatchOr.patterns,
5262 ast2obj_pattern);
5263 if (!value) goto failed;
5264 if (PyObject_SetAttr(result, state->patterns, value) == -1)
5265 goto failed;
5266 Py_DECREF(value);
5267 break;
5268 }
5269 value = ast2obj_int(state, o->lineno);
5270 if (!value) goto failed;
5271 if (PyObject_SetAttr(result, state->lineno, value) < 0)
5272 goto failed;
5273 Py_DECREF(value);
5274 value = ast2obj_int(state, o->col_offset);
5275 if (!value) goto failed;
5276 if (PyObject_SetAttr(result, state->col_offset, value) < 0)
5277 goto failed;
5278 Py_DECREF(value);
5279 value = ast2obj_int(state, o->end_lineno);
5280 if (!value) goto failed;
5281 if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
5282 goto failed;
5283 Py_DECREF(value);
5284 value = ast2obj_int(state, o->end_col_offset);
5285 if (!value) goto failed;
5286 if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
5287 goto failed;
5288 Py_DECREF(value);
5289 return result;
5290failed:
5291 Py_XDECREF(value);
5292 Py_XDECREF(result);
5293 return NULL;
5294}
5295
5296PyObject*
Victor Stinner5cf47822020-11-02 22:03:28 +01005297ast2obj_type_ignore(struct ast_state *state, void* _o)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005298{
5299 type_ignore_ty o = (type_ignore_ty)_o;
5300 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005301 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005302 if (!o) {
5303 Py_RETURN_NONE;
5304 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005305 switch (o->kind) {
5306 case TypeIgnore_kind:
Victor Stinner74419f02020-07-03 11:35:37 +02005307 tp = (PyTypeObject *)state->TypeIgnore_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005308 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005309 if (!result) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005310 value = ast2obj_int(state, o->v.TypeIgnore.lineno);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005311 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005312 if (PyObject_SetAttr(result, state->lineno, value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005313 goto failed;
5314 Py_DECREF(value);
Victor Stinner74419f02020-07-03 11:35:37 +02005315 value = ast2obj_string(state, o->v.TypeIgnore.tag);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005316 if (!value) goto failed;
Victor Stinner74419f02020-07-03 11:35:37 +02005317 if (PyObject_SetAttr(result, state->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005318 goto failed;
5319 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005320 break;
5321 }
5322 return result;
5323failed:
5324 Py_XDECREF(value);
5325 Py_XDECREF(result);
5326 return NULL;
5327}
5328
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005329
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005330int
Victor Stinner5cf47822020-11-02 22:03:28 +01005331obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005332{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005333 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005334
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005335 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005336 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005337
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005338 if (obj == Py_None) {
5339 *out = NULL;
5340 return 0;
5341 }
Victor Stinner74419f02020-07-03 11:35:37 +02005342 tp = state->Module_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005343 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005344 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005345 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005346 }
5347 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01005348 asdl_stmt_seq* body;
5349 asdl_type_ignore_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005350
Victor Stinner74419f02020-07-03 11:35:37 +02005351 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005352 return 1;
5353 }
5354 if (tmp == NULL) {
5355 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5356 return 1;
5357 }
5358 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005359 int res;
5360 Py_ssize_t len;
5361 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005362 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005363 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 +02005364 goto failed;
5365 }
5366 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005367 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005368 if (body == NULL) goto failed;
5369 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005370 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005371 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5372 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005373 if (Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5374 goto failed;
5375 }
Victor Stinner74419f02020-07-03 11:35:37 +02005376 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005377 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005378 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005379 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005380 if (len != PyList_GET_SIZE(tmp)) {
5381 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5382 goto failed;
5383 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005384 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005385 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005386 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005387 }
Victor Stinner74419f02020-07-03 11:35:37 +02005388 if (_PyObject_LookupAttr(obj, state->type_ignores, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005389 return 1;
5390 }
5391 if (tmp == NULL) {
5392 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5393 return 1;
5394 }
5395 else {
5396 int res;
5397 Py_ssize_t len;
5398 Py_ssize_t i;
5399 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005400 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 -08005401 goto failed;
5402 }
5403 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005404 type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005405 if (type_ignores == NULL) goto failed;
5406 for (i = 0; i < len; i++) {
5407 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005408 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5409 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005410 if (Py_EnterRecursiveCall(" while traversing 'Module' node")) {
5411 goto failed;
5412 }
Victor Stinner74419f02020-07-03 11:35:37 +02005413 res = obj2ast_type_ignore(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005414 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005415 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005416 if (res != 0) goto failed;
5417 if (len != PyList_GET_SIZE(tmp)) {
5418 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5419 goto failed;
5420 }
5421 asdl_seq_SET(type_ignores, i, val);
5422 }
5423 Py_CLEAR(tmp);
5424 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005425 *out = _PyAST_Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005426 if (*out == NULL) goto failed;
5427 return 0;
5428 }
Victor Stinner74419f02020-07-03 11:35:37 +02005429 tp = state->Interactive_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005430 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005431 if (isinstance == -1) {
5432 return 1;
5433 }
5434 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01005435 asdl_stmt_seq* body;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005436
Victor Stinner74419f02020-07-03 11:35:37 +02005437 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005438 return 1;
5439 }
5440 if (tmp == NULL) {
5441 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5442 return 1;
5443 }
5444 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005445 int res;
5446 Py_ssize_t len;
5447 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005448 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005449 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 +02005450 goto failed;
5451 }
5452 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005453 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005454 if (body == NULL) goto failed;
5455 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005456 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005457 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5458 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005459 if (Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
5460 goto failed;
5461 }
Victor Stinner74419f02020-07-03 11:35:37 +02005462 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005463 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005464 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005465 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005466 if (len != PyList_GET_SIZE(tmp)) {
5467 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5468 goto failed;
5469 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005470 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005471 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005472 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005473 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005474 *out = _PyAST_Interactive(body, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005475 if (*out == NULL) goto failed;
5476 return 0;
5477 }
Victor Stinner74419f02020-07-03 11:35:37 +02005478 tp = state->Expression_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005479 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005480 if (isinstance == -1) {
5481 return 1;
5482 }
5483 if (isinstance) {
5484 expr_ty body;
5485
Victor Stinner74419f02020-07-03 11:35:37 +02005486 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005487 return 1;
5488 }
5489 if (tmp == NULL) {
5490 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5491 return 1;
5492 }
5493 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005494 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005495 if (Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
5496 goto failed;
5497 }
Victor Stinner74419f02020-07-03 11:35:37 +02005498 res = obj2ast_expr(state, tmp, &body, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005499 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005500 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005501 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005502 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005503 *out = _PyAST_Expression(body, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005504 if (*out == NULL) goto failed;
5505 return 0;
5506 }
Victor Stinner74419f02020-07-03 11:35:37 +02005507 tp = state->FunctionType_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005508 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005509 if (isinstance == -1) {
5510 return 1;
5511 }
5512 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01005513 asdl_expr_seq* argtypes;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005514 expr_ty returns;
5515
Victor Stinner74419f02020-07-03 11:35:37 +02005516 if (_PyObject_LookupAttr(obj, state->argtypes, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005517 return 1;
5518 }
5519 if (tmp == NULL) {
5520 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5521 return 1;
5522 }
5523 else {
5524 int res;
5525 Py_ssize_t len;
5526 Py_ssize_t i;
5527 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005528 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 -08005529 goto failed;
5530 }
5531 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005532 argtypes = _Py_asdl_expr_seq_new(len, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005533 if (argtypes == NULL) goto failed;
5534 for (i = 0; i < len; i++) {
5535 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005536 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5537 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005538 if (Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5539 goto failed;
5540 }
Victor Stinner74419f02020-07-03 11:35:37 +02005541 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005542 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005543 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005544 if (res != 0) goto failed;
5545 if (len != PyList_GET_SIZE(tmp)) {
5546 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5547 goto failed;
5548 }
5549 asdl_seq_SET(argtypes, i, val);
5550 }
5551 Py_CLEAR(tmp);
5552 }
Victor Stinner74419f02020-07-03 11:35:37 +02005553 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005554 return 1;
5555 }
5556 if (tmp == NULL) {
5557 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5558 return 1;
5559 }
5560 else {
5561 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005562 if (Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
5563 goto failed;
5564 }
Victor Stinner74419f02020-07-03 11:35:37 +02005565 res = obj2ast_expr(state, tmp, &returns, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005566 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005567 if (res != 0) goto failed;
5568 Py_CLEAR(tmp);
5569 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005570 *out = _PyAST_FunctionType(argtypes, returns, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005571 if (*out == NULL) goto failed;
5572 return 0;
5573 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005574
5575 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5576 failed:
5577 Py_XDECREF(tmp);
5578 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005579}
5580
5581int
Victor Stinner5cf47822020-11-02 22:03:28 +01005582obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
5583 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005584{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005585 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005586
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005587 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005588 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005589 int lineno;
5590 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005591 int end_lineno;
5592 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005593
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005594 if (obj == Py_None) {
5595 *out = NULL;
5596 return 0;
5597 }
Victor Stinner74419f02020-07-03 11:35:37 +02005598 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005599 return 1;
5600 }
5601 if (tmp == NULL) {
5602 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5603 return 1;
5604 }
5605 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005606 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005607 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5608 goto failed;
5609 }
Victor Stinner74419f02020-07-03 11:35:37 +02005610 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005611 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005612 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005613 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005614 }
Victor Stinner74419f02020-07-03 11:35:37 +02005615 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005616 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005617 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005618 if (tmp == NULL) {
5619 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5620 return 1;
5621 }
5622 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005623 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005624 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5625 goto failed;
5626 }
Victor Stinner74419f02020-07-03 11:35:37 +02005627 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005628 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005629 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005630 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005631 }
Victor Stinner74419f02020-07-03 11:35:37 +02005632 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005633 return 1;
5634 }
5635 if (tmp == NULL || tmp == Py_None) {
5636 Py_CLEAR(tmp);
5637 end_lineno = 0;
5638 }
5639 else {
5640 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005641 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5642 goto failed;
5643 }
Victor Stinner74419f02020-07-03 11:35:37 +02005644 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005645 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005646 if (res != 0) goto failed;
5647 Py_CLEAR(tmp);
5648 }
Victor Stinner74419f02020-07-03 11:35:37 +02005649 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005650 return 1;
5651 }
5652 if (tmp == NULL || tmp == Py_None) {
5653 Py_CLEAR(tmp);
5654 end_col_offset = 0;
5655 }
5656 else {
5657 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005658 if (Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
5659 goto failed;
5660 }
Victor Stinner74419f02020-07-03 11:35:37 +02005661 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005662 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005663 if (res != 0) goto failed;
5664 Py_CLEAR(tmp);
5665 }
Victor Stinner74419f02020-07-03 11:35:37 +02005666 tp = state->FunctionDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005667 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005668 if (isinstance == -1) {
5669 return 1;
5670 }
5671 if (isinstance) {
5672 identifier name;
5673 arguments_ty args;
Pablo Galindoa5634c42020-09-16 19:42:00 +01005674 asdl_stmt_seq* body;
5675 asdl_expr_seq* decorator_list;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005676 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005677 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005678
Victor Stinner74419f02020-07-03 11:35:37 +02005679 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005680 return 1;
5681 }
5682 if (tmp == NULL) {
5683 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5684 return 1;
5685 }
5686 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005687 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005688 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5689 goto failed;
5690 }
Victor Stinner74419f02020-07-03 11:35:37 +02005691 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005692 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005693 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005694 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005695 }
Victor Stinner74419f02020-07-03 11:35:37 +02005696 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005697 return 1;
5698 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005699 if (tmp == NULL) {
5700 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5701 return 1;
5702 }
5703 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005704 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005705 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5706 goto failed;
5707 }
Victor Stinner74419f02020-07-03 11:35:37 +02005708 res = obj2ast_arguments(state, tmp, &args, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005709 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005710 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005711 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005712 }
Victor Stinner74419f02020-07-03 11:35:37 +02005713 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005714 return 1;
5715 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005716 if (tmp == NULL) {
5717 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5718 return 1;
5719 }
5720 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005721 int res;
5722 Py_ssize_t len;
5723 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005724 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005725 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 +02005726 goto failed;
5727 }
5728 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005729 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005730 if (body == NULL) goto failed;
5731 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005732 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005733 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5734 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005735 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5736 goto failed;
5737 }
Victor Stinner74419f02020-07-03 11:35:37 +02005738 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005739 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005740 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005741 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005742 if (len != PyList_GET_SIZE(tmp)) {
5743 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5744 goto failed;
5745 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005746 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005747 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005748 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005749 }
Victor Stinner74419f02020-07-03 11:35:37 +02005750 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005751 return 1;
5752 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005753 if (tmp == NULL) {
5754 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5755 return 1;
5756 }
5757 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005758 int res;
5759 Py_ssize_t len;
5760 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005761 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005762 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 +02005763 goto failed;
5764 }
5765 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005766 decorator_list = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005767 if (decorator_list == NULL) goto failed;
5768 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005769 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005770 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5771 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005772 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5773 goto failed;
5774 }
Victor Stinner74419f02020-07-03 11:35:37 +02005775 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005776 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005777 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005778 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005779 if (len != PyList_GET_SIZE(tmp)) {
5780 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5781 goto failed;
5782 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005783 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005784 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005785 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005786 }
Victor Stinner74419f02020-07-03 11:35:37 +02005787 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005788 return 1;
5789 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005790 if (tmp == NULL || tmp == Py_None) {
5791 Py_CLEAR(tmp);
5792 returns = NULL;
5793 }
5794 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005795 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005796 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5797 goto failed;
5798 }
Victor Stinner74419f02020-07-03 11:35:37 +02005799 res = obj2ast_expr(state, tmp, &returns, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005800 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005801 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005802 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005803 }
Victor Stinner74419f02020-07-03 11:35:37 +02005804 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005805 return 1;
5806 }
5807 if (tmp == NULL || tmp == Py_None) {
5808 Py_CLEAR(tmp);
5809 type_comment = NULL;
5810 }
5811 else {
5812 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005813 if (Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
5814 goto failed;
5815 }
Victor Stinner74419f02020-07-03 11:35:37 +02005816 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005817 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005818 if (res != 0) goto failed;
5819 Py_CLEAR(tmp);
5820 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005821 *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
5822 type_comment, lineno, col_offset, end_lineno,
5823 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005824 if (*out == NULL) goto failed;
5825 return 0;
5826 }
Victor Stinner74419f02020-07-03 11:35:37 +02005827 tp = state->AsyncFunctionDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005828 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005829 if (isinstance == -1) {
5830 return 1;
5831 }
5832 if (isinstance) {
5833 identifier name;
5834 arguments_ty args;
Pablo Galindoa5634c42020-09-16 19:42:00 +01005835 asdl_stmt_seq* body;
5836 asdl_expr_seq* decorator_list;
Yury Selivanov75445082015-05-11 22:57:16 -04005837 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005838 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005839
Victor Stinner74419f02020-07-03 11:35:37 +02005840 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005841 return 1;
5842 }
5843 if (tmp == NULL) {
5844 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5845 return 1;
5846 }
5847 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005848 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005849 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5850 goto failed;
5851 }
Victor Stinner74419f02020-07-03 11:35:37 +02005852 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005853 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04005854 if (res != 0) goto failed;
5855 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005856 }
Victor Stinner74419f02020-07-03 11:35:37 +02005857 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005858 return 1;
5859 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005860 if (tmp == NULL) {
5861 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5862 return 1;
5863 }
5864 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005865 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005866 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5867 goto failed;
5868 }
Victor Stinner74419f02020-07-03 11:35:37 +02005869 res = obj2ast_arguments(state, tmp, &args, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005870 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04005871 if (res != 0) goto failed;
5872 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005873 }
Victor Stinner74419f02020-07-03 11:35:37 +02005874 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005875 return 1;
5876 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005877 if (tmp == NULL) {
5878 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5879 return 1;
5880 }
5881 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005882 int res;
5883 Py_ssize_t len;
5884 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005885 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005886 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 -04005887 goto failed;
5888 }
5889 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005890 body = _Py_asdl_stmt_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005891 if (body == NULL) goto failed;
5892 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005893 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005894 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5895 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005896 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5897 goto failed;
5898 }
Victor Stinner74419f02020-07-03 11:35:37 +02005899 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005900 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005901 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005902 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005903 if (len != PyList_GET_SIZE(tmp)) {
5904 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5905 goto failed;
5906 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005907 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005908 }
5909 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005910 }
Victor Stinner74419f02020-07-03 11:35:37 +02005911 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005912 return 1;
5913 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005914 if (tmp == NULL) {
5915 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5916 return 1;
5917 }
5918 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005919 int res;
5920 Py_ssize_t len;
5921 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005922 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005923 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 -04005924 goto failed;
5925 }
5926 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01005927 decorator_list = _Py_asdl_expr_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005928 if (decorator_list == NULL) goto failed;
5929 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005930 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005931 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5932 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005933 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5934 goto failed;
5935 }
Victor Stinner74419f02020-07-03 11:35:37 +02005936 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005937 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005938 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005939 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005940 if (len != PyList_GET_SIZE(tmp)) {
5941 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5942 goto failed;
5943 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005944 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005945 }
5946 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005947 }
Victor Stinner74419f02020-07-03 11:35:37 +02005948 if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005949 return 1;
5950 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005951 if (tmp == NULL || tmp == Py_None) {
5952 Py_CLEAR(tmp);
5953 returns = NULL;
5954 }
5955 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005956 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005957 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5958 goto failed;
5959 }
Victor Stinner74419f02020-07-03 11:35:37 +02005960 res = obj2ast_expr(state, tmp, &returns, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005961 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04005962 if (res != 0) goto failed;
5963 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005964 }
Victor Stinner74419f02020-07-03 11:35:37 +02005965 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005966 return 1;
5967 }
5968 if (tmp == NULL || tmp == Py_None) {
5969 Py_CLEAR(tmp);
5970 type_comment = NULL;
5971 }
5972 else {
5973 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005974 if (Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
5975 goto failed;
5976 }
Victor Stinner74419f02020-07-03 11:35:37 +02005977 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07005978 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005979 if (res != 0) goto failed;
5980 Py_CLEAR(tmp);
5981 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02005982 *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
5983 returns, type_comment, lineno,
5984 col_offset, end_lineno, end_col_offset,
5985 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005986 if (*out == NULL) goto failed;
5987 return 0;
5988 }
Victor Stinner74419f02020-07-03 11:35:37 +02005989 tp = state->ClassDef_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005990 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005991 if (isinstance == -1) {
5992 return 1;
5993 }
5994 if (isinstance) {
5995 identifier name;
Pablo Galindoa5634c42020-09-16 19:42:00 +01005996 asdl_expr_seq* bases;
5997 asdl_keyword_seq* keywords;
5998 asdl_stmt_seq* body;
5999 asdl_expr_seq* decorator_list;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006000
Victor Stinner74419f02020-07-03 11:35:37 +02006001 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006002 return 1;
6003 }
6004 if (tmp == NULL) {
6005 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
6006 return 1;
6007 }
6008 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006009 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006010 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6011 goto failed;
6012 }
Victor Stinner74419f02020-07-03 11:35:37 +02006013 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006014 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006015 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006016 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006017 }
Victor Stinner74419f02020-07-03 11:35:37 +02006018 if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006019 return 1;
6020 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006021 if (tmp == NULL) {
6022 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
6023 return 1;
6024 }
6025 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006026 int res;
6027 Py_ssize_t len;
6028 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006029 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006030 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 +02006031 goto failed;
6032 }
6033 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006034 bases = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006035 if (bases == NULL) goto failed;
6036 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006037 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006038 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6039 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006040 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6041 goto failed;
6042 }
Victor Stinner74419f02020-07-03 11:35:37 +02006043 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006044 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006045 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006046 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006047 if (len != PyList_GET_SIZE(tmp)) {
6048 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
6049 goto failed;
6050 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006051 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006052 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006053 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006054 }
Victor Stinner74419f02020-07-03 11:35:37 +02006055 if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006056 return 1;
6057 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006058 if (tmp == NULL) {
6059 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
6060 return 1;
6061 }
6062 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006063 int res;
6064 Py_ssize_t len;
6065 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006066 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006067 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 +02006068 goto failed;
6069 }
6070 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006071 keywords = _Py_asdl_keyword_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006072 if (keywords == NULL) goto failed;
6073 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006074 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006075 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6076 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006077 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6078 goto failed;
6079 }
Victor Stinner74419f02020-07-03 11:35:37 +02006080 res = obj2ast_keyword(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006081 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006082 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006083 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006084 if (len != PyList_GET_SIZE(tmp)) {
6085 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
6086 goto failed;
6087 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006088 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006089 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006090 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006091 }
Victor Stinner74419f02020-07-03 11:35:37 +02006092 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006093 return 1;
6094 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006095 if (tmp == NULL) {
6096 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
6097 return 1;
6098 }
6099 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006100 int res;
6101 Py_ssize_t len;
6102 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006103 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006104 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 +02006105 goto failed;
6106 }
6107 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006108 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006109 if (body == NULL) goto failed;
6110 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006111 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006112 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6113 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006114 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6115 goto failed;
6116 }
Victor Stinner74419f02020-07-03 11:35:37 +02006117 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006118 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006119 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006120 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006121 if (len != PyList_GET_SIZE(tmp)) {
6122 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
6123 goto failed;
6124 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006125 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006126 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006127 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006128 }
Victor Stinner74419f02020-07-03 11:35:37 +02006129 if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006130 return 1;
6131 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006132 if (tmp == NULL) {
6133 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
6134 return 1;
6135 }
6136 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006137 int res;
6138 Py_ssize_t len;
6139 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006140 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006141 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 +02006142 goto failed;
6143 }
6144 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006145 decorator_list = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006146 if (decorator_list == NULL) goto failed;
6147 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006148 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006149 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6150 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006151 if (Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
6152 goto failed;
6153 }
Victor Stinner74419f02020-07-03 11:35:37 +02006154 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006155 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006156 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006157 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006158 if (len != PyList_GET_SIZE(tmp)) {
6159 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
6160 goto failed;
6161 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006162 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006163 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006164 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006165 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006166 *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
6167 lineno, col_offset, end_lineno, end_col_offset,
6168 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006169 if (*out == NULL) goto failed;
6170 return 0;
6171 }
Victor Stinner74419f02020-07-03 11:35:37 +02006172 tp = state->Return_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006173 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006174 if (isinstance == -1) {
6175 return 1;
6176 }
6177 if (isinstance) {
6178 expr_ty value;
6179
Victor Stinner74419f02020-07-03 11:35:37 +02006180 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006181 return 1;
6182 }
6183 if (tmp == NULL || tmp == Py_None) {
6184 Py_CLEAR(tmp);
6185 value = NULL;
6186 }
6187 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006188 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006189 if (Py_EnterRecursiveCall(" while traversing 'Return' node")) {
6190 goto failed;
6191 }
Victor Stinner74419f02020-07-03 11:35:37 +02006192 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006193 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006194 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006195 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006196 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006197 *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
6198 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006199 if (*out == NULL) goto failed;
6200 return 0;
6201 }
Victor Stinner74419f02020-07-03 11:35:37 +02006202 tp = state->Delete_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006203 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006204 if (isinstance == -1) {
6205 return 1;
6206 }
6207 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01006208 asdl_expr_seq* targets;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006209
Victor Stinner74419f02020-07-03 11:35:37 +02006210 if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006211 return 1;
6212 }
6213 if (tmp == NULL) {
6214 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
6215 return 1;
6216 }
6217 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006218 int res;
6219 Py_ssize_t len;
6220 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006221 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006222 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 +02006223 goto failed;
6224 }
6225 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006226 targets = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006227 if (targets == NULL) goto failed;
6228 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006229 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006230 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6231 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006232 if (Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
6233 goto failed;
6234 }
Victor Stinner74419f02020-07-03 11:35:37 +02006235 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006236 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006237 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006238 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006239 if (len != PyList_GET_SIZE(tmp)) {
6240 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
6241 goto failed;
6242 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006243 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006244 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006245 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006246 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006247 *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
6248 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006249 if (*out == NULL) goto failed;
6250 return 0;
6251 }
Victor Stinner74419f02020-07-03 11:35:37 +02006252 tp = state->Assign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006253 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006254 if (isinstance == -1) {
6255 return 1;
6256 }
6257 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01006258 asdl_expr_seq* targets;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006259 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006260 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006261
Victor Stinner74419f02020-07-03 11:35:37 +02006262 if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006263 return 1;
6264 }
6265 if (tmp == NULL) {
6266 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
6267 return 1;
6268 }
6269 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006270 int res;
6271 Py_ssize_t len;
6272 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006273 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006274 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 +02006275 goto failed;
6276 }
6277 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006278 targets = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006279 if (targets == NULL) goto failed;
6280 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006281 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006282 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6283 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006284 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6285 goto failed;
6286 }
Victor Stinner74419f02020-07-03 11:35:37 +02006287 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006288 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006289 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006290 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006291 if (len != PyList_GET_SIZE(tmp)) {
6292 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
6293 goto failed;
6294 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006295 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006296 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006297 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006298 }
Victor Stinner74419f02020-07-03 11:35:37 +02006299 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006300 return 1;
6301 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006302 if (tmp == NULL) {
6303 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
6304 return 1;
6305 }
6306 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006307 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006308 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6309 goto failed;
6310 }
Victor Stinner74419f02020-07-03 11:35:37 +02006311 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006312 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006313 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006314 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006315 }
Victor Stinner74419f02020-07-03 11:35:37 +02006316 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006317 return 1;
6318 }
6319 if (tmp == NULL || tmp == Py_None) {
6320 Py_CLEAR(tmp);
6321 type_comment = NULL;
6322 }
6323 else {
6324 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006325 if (Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
6326 goto failed;
6327 }
Victor Stinner74419f02020-07-03 11:35:37 +02006328 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006329 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006330 if (res != 0) goto failed;
6331 Py_CLEAR(tmp);
6332 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006333 *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
6334 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006335 if (*out == NULL) goto failed;
6336 return 0;
6337 }
Victor Stinner74419f02020-07-03 11:35:37 +02006338 tp = state->AugAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006339 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006340 if (isinstance == -1) {
6341 return 1;
6342 }
6343 if (isinstance) {
6344 expr_ty target;
6345 operator_ty op;
6346 expr_ty value;
6347
Victor Stinner74419f02020-07-03 11:35:37 +02006348 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006349 return 1;
6350 }
6351 if (tmp == NULL) {
6352 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6353 return 1;
6354 }
6355 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006356 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006357 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6358 goto failed;
6359 }
Victor Stinner74419f02020-07-03 11:35:37 +02006360 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006361 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006362 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006363 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006364 }
Victor Stinner74419f02020-07-03 11:35:37 +02006365 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006366 return 1;
6367 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006368 if (tmp == NULL) {
6369 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6370 return 1;
6371 }
6372 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006373 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006374 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6375 goto failed;
6376 }
Victor Stinner74419f02020-07-03 11:35:37 +02006377 res = obj2ast_operator(state, tmp, &op, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006378 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006379 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006380 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006381 }
Victor Stinner74419f02020-07-03 11:35:37 +02006382 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006383 return 1;
6384 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006385 if (tmp == NULL) {
6386 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6387 return 1;
6388 }
6389 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006390 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006391 if (Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
6392 goto failed;
6393 }
Victor Stinner74419f02020-07-03 11:35:37 +02006394 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006395 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006396 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006397 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006398 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006399 *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
6400 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006401 if (*out == NULL) goto failed;
6402 return 0;
6403 }
Victor Stinner74419f02020-07-03 11:35:37 +02006404 tp = state->AnnAssign_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006405 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006406 if (isinstance == -1) {
6407 return 1;
6408 }
6409 if (isinstance) {
6410 expr_ty target;
6411 expr_ty annotation;
6412 expr_ty value;
6413 int simple;
6414
Victor Stinner74419f02020-07-03 11:35:37 +02006415 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006416 return 1;
6417 }
6418 if (tmp == NULL) {
6419 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6420 return 1;
6421 }
6422 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006423 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006424 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6425 goto failed;
6426 }
Victor Stinner74419f02020-07-03 11:35:37 +02006427 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006428 Py_LeaveRecursiveCall();
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006429 if (res != 0) goto failed;
6430 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006431 }
Victor Stinner74419f02020-07-03 11:35:37 +02006432 if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006433 return 1;
6434 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006435 if (tmp == NULL) {
6436 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6437 return 1;
6438 }
6439 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006440 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006441 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6442 goto failed;
6443 }
Victor Stinner74419f02020-07-03 11:35:37 +02006444 res = obj2ast_expr(state, tmp, &annotation, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006445 Py_LeaveRecursiveCall();
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006446 if (res != 0) goto failed;
6447 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006448 }
Victor Stinner74419f02020-07-03 11:35:37 +02006449 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006450 return 1;
6451 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006452 if (tmp == NULL || tmp == Py_None) {
6453 Py_CLEAR(tmp);
6454 value = NULL;
6455 }
6456 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006457 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006458 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6459 goto failed;
6460 }
Victor Stinner74419f02020-07-03 11:35:37 +02006461 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006462 Py_LeaveRecursiveCall();
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006463 if (res != 0) goto failed;
6464 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006465 }
Victor Stinner74419f02020-07-03 11:35:37 +02006466 if (_PyObject_LookupAttr(obj, state->simple, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006467 return 1;
6468 }
6469 if (tmp == NULL) {
6470 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6471 return 1;
6472 }
6473 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006474 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006475 if (Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
6476 goto failed;
6477 }
Victor Stinner74419f02020-07-03 11:35:37 +02006478 res = obj2ast_int(state, tmp, &simple, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006479 Py_LeaveRecursiveCall();
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006480 if (res != 0) goto failed;
6481 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006482 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006483 *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
6484 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006485 if (*out == NULL) goto failed;
6486 return 0;
6487 }
Victor Stinner74419f02020-07-03 11:35:37 +02006488 tp = state->For_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006489 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006490 if (isinstance == -1) {
6491 return 1;
6492 }
6493 if (isinstance) {
6494 expr_ty target;
6495 expr_ty iter;
Pablo Galindoa5634c42020-09-16 19:42:00 +01006496 asdl_stmt_seq* body;
6497 asdl_stmt_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006498 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006499
Victor Stinner74419f02020-07-03 11:35:37 +02006500 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006501 return 1;
6502 }
6503 if (tmp == NULL) {
6504 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6505 return 1;
6506 }
6507 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006508 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006509 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6510 goto failed;
6511 }
Victor Stinner74419f02020-07-03 11:35:37 +02006512 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006513 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006514 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006515 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006516 }
Victor Stinner74419f02020-07-03 11:35:37 +02006517 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006518 return 1;
6519 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006520 if (tmp == NULL) {
6521 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6522 return 1;
6523 }
6524 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006525 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006526 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6527 goto failed;
6528 }
Victor Stinner74419f02020-07-03 11:35:37 +02006529 res = obj2ast_expr(state, tmp, &iter, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006530 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006531 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006532 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006533 }
Victor Stinner74419f02020-07-03 11:35:37 +02006534 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006535 return 1;
6536 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006537 if (tmp == NULL) {
6538 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6539 return 1;
6540 }
6541 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006542 int res;
6543 Py_ssize_t len;
6544 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006545 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006546 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 +02006547 goto failed;
6548 }
6549 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006550 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006551 if (body == NULL) goto failed;
6552 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006553 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006554 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6555 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006556 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6557 goto failed;
6558 }
Victor Stinner74419f02020-07-03 11:35:37 +02006559 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006560 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006561 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006562 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006563 if (len != PyList_GET_SIZE(tmp)) {
6564 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6565 goto failed;
6566 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006567 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006568 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006569 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006570 }
Victor Stinner74419f02020-07-03 11:35:37 +02006571 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006572 return 1;
6573 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006574 if (tmp == NULL) {
6575 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6576 return 1;
6577 }
6578 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006579 int res;
6580 Py_ssize_t len;
6581 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006582 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006583 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 +02006584 goto failed;
6585 }
6586 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006587 orelse = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006588 if (orelse == NULL) goto failed;
6589 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006590 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006591 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6592 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006593 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6594 goto failed;
6595 }
Victor Stinner74419f02020-07-03 11:35:37 +02006596 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006597 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006598 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006599 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006600 if (len != PyList_GET_SIZE(tmp)) {
6601 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6602 goto failed;
6603 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006604 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006605 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006606 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006607 }
Victor Stinner74419f02020-07-03 11:35:37 +02006608 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006609 return 1;
6610 }
6611 if (tmp == NULL || tmp == Py_None) {
6612 Py_CLEAR(tmp);
6613 type_comment = NULL;
6614 }
6615 else {
6616 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006617 if (Py_EnterRecursiveCall(" while traversing 'For' node")) {
6618 goto failed;
6619 }
Victor Stinner74419f02020-07-03 11:35:37 +02006620 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006621 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006622 if (res != 0) goto failed;
6623 Py_CLEAR(tmp);
6624 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006625 *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
6626 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006627 if (*out == NULL) goto failed;
6628 return 0;
6629 }
Victor Stinner74419f02020-07-03 11:35:37 +02006630 tp = state->AsyncFor_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006631 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006632 if (isinstance == -1) {
6633 return 1;
6634 }
6635 if (isinstance) {
6636 expr_ty target;
6637 expr_ty iter;
Pablo Galindoa5634c42020-09-16 19:42:00 +01006638 asdl_stmt_seq* body;
6639 asdl_stmt_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006640 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006641
Victor Stinner74419f02020-07-03 11:35:37 +02006642 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006643 return 1;
6644 }
6645 if (tmp == NULL) {
6646 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6647 return 1;
6648 }
6649 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006650 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006651 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6652 goto failed;
6653 }
Victor Stinner74419f02020-07-03 11:35:37 +02006654 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006655 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04006656 if (res != 0) goto failed;
6657 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006658 }
Victor Stinner74419f02020-07-03 11:35:37 +02006659 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006660 return 1;
6661 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006662 if (tmp == NULL) {
6663 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6664 return 1;
6665 }
6666 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006667 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006668 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6669 goto failed;
6670 }
Victor Stinner74419f02020-07-03 11:35:37 +02006671 res = obj2ast_expr(state, tmp, &iter, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006672 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04006673 if (res != 0) goto failed;
6674 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006675 }
Victor Stinner74419f02020-07-03 11:35:37 +02006676 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006677 return 1;
6678 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006679 if (tmp == NULL) {
6680 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6681 return 1;
6682 }
6683 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006684 int res;
6685 Py_ssize_t len;
6686 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006687 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006688 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 -04006689 goto failed;
6690 }
6691 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006692 body = _Py_asdl_stmt_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006693 if (body == NULL) goto failed;
6694 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006695 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006696 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6697 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006698 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6699 goto failed;
6700 }
Victor Stinner74419f02020-07-03 11:35:37 +02006701 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006702 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006703 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006704 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006705 if (len != PyList_GET_SIZE(tmp)) {
6706 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6707 goto failed;
6708 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006709 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006710 }
6711 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006712 }
Victor Stinner74419f02020-07-03 11:35:37 +02006713 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006714 return 1;
6715 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006716 if (tmp == NULL) {
6717 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6718 return 1;
6719 }
6720 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006721 int res;
6722 Py_ssize_t len;
6723 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006724 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006725 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 -04006726 goto failed;
6727 }
6728 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006729 orelse = _Py_asdl_stmt_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006730 if (orelse == NULL) goto failed;
6731 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006732 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006733 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6734 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006735 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6736 goto failed;
6737 }
Victor Stinner74419f02020-07-03 11:35:37 +02006738 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006739 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006740 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006741 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006742 if (len != PyList_GET_SIZE(tmp)) {
6743 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6744 goto failed;
6745 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006746 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006747 }
6748 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006749 }
Victor Stinner74419f02020-07-03 11:35:37 +02006750 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006751 return 1;
6752 }
6753 if (tmp == NULL || tmp == Py_None) {
6754 Py_CLEAR(tmp);
6755 type_comment = NULL;
6756 }
6757 else {
6758 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006759 if (Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
6760 goto failed;
6761 }
Victor Stinner74419f02020-07-03 11:35:37 +02006762 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006763 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006764 if (res != 0) goto failed;
6765 Py_CLEAR(tmp);
6766 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006767 *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
6768 lineno, col_offset, end_lineno, end_col_offset,
6769 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006770 if (*out == NULL) goto failed;
6771 return 0;
6772 }
Victor Stinner74419f02020-07-03 11:35:37 +02006773 tp = state->While_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006774 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006775 if (isinstance == -1) {
6776 return 1;
6777 }
6778 if (isinstance) {
6779 expr_ty test;
Pablo Galindoa5634c42020-09-16 19:42:00 +01006780 asdl_stmt_seq* body;
6781 asdl_stmt_seq* orelse;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006782
Victor Stinner74419f02020-07-03 11:35:37 +02006783 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006784 return 1;
6785 }
6786 if (tmp == NULL) {
6787 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6788 return 1;
6789 }
6790 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006791 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006792 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6793 goto failed;
6794 }
Victor Stinner74419f02020-07-03 11:35:37 +02006795 res = obj2ast_expr(state, tmp, &test, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006796 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006797 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006798 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006799 }
Victor Stinner74419f02020-07-03 11:35:37 +02006800 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006801 return 1;
6802 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006803 if (tmp == NULL) {
6804 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6805 return 1;
6806 }
6807 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006808 int res;
6809 Py_ssize_t len;
6810 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006811 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006812 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 +02006813 goto failed;
6814 }
6815 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006816 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006817 if (body == NULL) goto failed;
6818 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006819 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006820 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6821 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006822 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6823 goto failed;
6824 }
Victor Stinner74419f02020-07-03 11:35:37 +02006825 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006826 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006827 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006828 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006829 if (len != PyList_GET_SIZE(tmp)) {
6830 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6831 goto failed;
6832 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006833 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006834 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006835 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006836 }
Victor Stinner74419f02020-07-03 11:35:37 +02006837 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006838 return 1;
6839 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006840 if (tmp == NULL) {
6841 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6842 return 1;
6843 }
6844 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006845 int res;
6846 Py_ssize_t len;
6847 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006848 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006849 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 +02006850 goto failed;
6851 }
6852 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006853 orelse = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006854 if (orelse == NULL) goto failed;
6855 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006856 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006857 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6858 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006859 if (Py_EnterRecursiveCall(" while traversing 'While' node")) {
6860 goto failed;
6861 }
Victor Stinner74419f02020-07-03 11:35:37 +02006862 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006863 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006864 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006865 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006866 if (len != PyList_GET_SIZE(tmp)) {
6867 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6868 goto failed;
6869 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006870 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006871 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006872 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006873 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006874 *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
6875 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006876 if (*out == NULL) goto failed;
6877 return 0;
6878 }
Victor Stinner74419f02020-07-03 11:35:37 +02006879 tp = state->If_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006880 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006881 if (isinstance == -1) {
6882 return 1;
6883 }
6884 if (isinstance) {
6885 expr_ty test;
Pablo Galindoa5634c42020-09-16 19:42:00 +01006886 asdl_stmt_seq* body;
6887 asdl_stmt_seq* orelse;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006888
Victor Stinner74419f02020-07-03 11:35:37 +02006889 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006890 return 1;
6891 }
6892 if (tmp == NULL) {
6893 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6894 return 1;
6895 }
6896 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006897 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006898 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6899 goto failed;
6900 }
Victor Stinner74419f02020-07-03 11:35:37 +02006901 res = obj2ast_expr(state, tmp, &test, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006902 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006903 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006904 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006905 }
Victor Stinner74419f02020-07-03 11:35:37 +02006906 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006907 return 1;
6908 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006909 if (tmp == NULL) {
6910 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6911 return 1;
6912 }
6913 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006914 int res;
6915 Py_ssize_t len;
6916 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006917 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006918 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 +02006919 goto failed;
6920 }
6921 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006922 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006923 if (body == NULL) goto failed;
6924 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006925 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006926 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6927 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006928 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6929 goto failed;
6930 }
Victor Stinner74419f02020-07-03 11:35:37 +02006931 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006932 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006933 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006934 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006935 if (len != PyList_GET_SIZE(tmp)) {
6936 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6937 goto failed;
6938 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006939 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006940 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006941 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006942 }
Victor Stinner74419f02020-07-03 11:35:37 +02006943 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006944 return 1;
6945 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006946 if (tmp == NULL) {
6947 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6948 return 1;
6949 }
6950 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006951 int res;
6952 Py_ssize_t len;
6953 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006954 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006955 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 +02006956 goto failed;
6957 }
6958 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01006959 orelse = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006960 if (orelse == NULL) goto failed;
6961 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006962 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006963 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6964 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006965 if (Py_EnterRecursiveCall(" while traversing 'If' node")) {
6966 goto failed;
6967 }
Victor Stinner74419f02020-07-03 11:35:37 +02006968 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07006969 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006970 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006971 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006972 if (len != PyList_GET_SIZE(tmp)) {
6973 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6974 goto failed;
6975 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006976 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006977 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006978 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006979 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02006980 *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
6981 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006982 if (*out == NULL) goto failed;
6983 return 0;
6984 }
Victor Stinner74419f02020-07-03 11:35:37 +02006985 tp = state->With_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07006986 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006987 if (isinstance == -1) {
6988 return 1;
6989 }
6990 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01006991 asdl_withitem_seq* items;
6992 asdl_stmt_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006993 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006994
Victor Stinner74419f02020-07-03 11:35:37 +02006995 if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006996 return 1;
6997 }
6998 if (tmp == NULL) {
6999 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
7000 return 1;
7001 }
7002 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007003 int res;
7004 Py_ssize_t len;
7005 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007006 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007007 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 +02007008 goto failed;
7009 }
7010 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007011 items = _Py_asdl_withitem_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007012 if (items == NULL) goto failed;
7013 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007014 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007015 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7016 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007017 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7018 goto failed;
7019 }
Victor Stinner74419f02020-07-03 11:35:37 +02007020 res = obj2ast_withitem(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007021 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007022 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007023 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007024 if (len != PyList_GET_SIZE(tmp)) {
7025 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
7026 goto failed;
7027 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007028 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007029 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007030 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007031 }
Victor Stinner74419f02020-07-03 11:35:37 +02007032 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007033 return 1;
7034 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007035 if (tmp == NULL) {
7036 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
7037 return 1;
7038 }
7039 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007040 int res;
7041 Py_ssize_t len;
7042 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007043 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007044 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 +02007045 goto failed;
7046 }
7047 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007048 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007049 if (body == NULL) goto failed;
7050 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007051 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007052 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7053 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007054 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7055 goto failed;
7056 }
Victor Stinner74419f02020-07-03 11:35:37 +02007057 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007058 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007059 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007060 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007061 if (len != PyList_GET_SIZE(tmp)) {
7062 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
7063 goto failed;
7064 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007065 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007066 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007067 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007068 }
Victor Stinner74419f02020-07-03 11:35:37 +02007069 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007070 return 1;
7071 }
7072 if (tmp == NULL || tmp == Py_None) {
7073 Py_CLEAR(tmp);
7074 type_comment = NULL;
7075 }
7076 else {
7077 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007078 if (Py_EnterRecursiveCall(" while traversing 'With' node")) {
7079 goto failed;
7080 }
Victor Stinner74419f02020-07-03 11:35:37 +02007081 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007082 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007083 if (res != 0) goto failed;
7084 Py_CLEAR(tmp);
7085 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007086 *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
7087 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007088 if (*out == NULL) goto failed;
7089 return 0;
7090 }
Victor Stinner74419f02020-07-03 11:35:37 +02007091 tp = state->AsyncWith_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007092 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007093 if (isinstance == -1) {
7094 return 1;
7095 }
7096 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007097 asdl_withitem_seq* items;
7098 asdl_stmt_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007099 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04007100
Victor Stinner74419f02020-07-03 11:35:37 +02007101 if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007102 return 1;
7103 }
7104 if (tmp == NULL) {
7105 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
7106 return 1;
7107 }
7108 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007109 int res;
7110 Py_ssize_t len;
7111 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04007112 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007113 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 -04007114 goto failed;
7115 }
7116 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007117 items = _Py_asdl_withitem_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007118 if (items == NULL) goto failed;
7119 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007120 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007121 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7122 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007123 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7124 goto failed;
7125 }
Victor Stinner74419f02020-07-03 11:35:37 +02007126 res = obj2ast_withitem(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007127 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007128 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04007129 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007130 if (len != PyList_GET_SIZE(tmp)) {
7131 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
7132 goto failed;
7133 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007134 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04007135 }
7136 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007137 }
Victor Stinner74419f02020-07-03 11:35:37 +02007138 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04007139 return 1;
7140 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007141 if (tmp == NULL) {
7142 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
7143 return 1;
7144 }
7145 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007146 int res;
7147 Py_ssize_t len;
7148 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04007149 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007150 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 -04007151 goto failed;
7152 }
7153 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007154 body = _Py_asdl_stmt_seq_new(len, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007155 if (body == NULL) goto failed;
7156 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007157 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007158 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7159 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007160 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7161 goto failed;
7162 }
Victor Stinner74419f02020-07-03 11:35:37 +02007163 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007164 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007165 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04007166 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007167 if (len != PyList_GET_SIZE(tmp)) {
7168 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
7169 goto failed;
7170 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007171 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04007172 }
7173 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007174 }
Victor Stinner74419f02020-07-03 11:35:37 +02007175 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007176 return 1;
7177 }
7178 if (tmp == NULL || tmp == Py_None) {
7179 Py_CLEAR(tmp);
7180 type_comment = NULL;
7181 }
7182 else {
7183 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007184 if (Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
7185 goto failed;
7186 }
Victor Stinner74419f02020-07-03 11:35:37 +02007187 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007188 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -08007189 if (res != 0) goto failed;
7190 Py_CLEAR(tmp);
7191 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007192 *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
7193 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007194 if (*out == NULL) goto failed;
7195 return 0;
7196 }
Brandt Bucher145bf262021-02-26 14:51:55 -08007197 tp = state->Match_type;
7198 isinstance = PyObject_IsInstance(obj, tp);
7199 if (isinstance == -1) {
7200 return 1;
7201 }
7202 if (isinstance) {
7203 expr_ty subject;
7204 asdl_match_case_seq* cases;
7205
7206 if (_PyObject_LookupAttr(obj, state->subject, &tmp) < 0) {
7207 return 1;
7208 }
7209 if (tmp == NULL) {
7210 PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
7211 return 1;
7212 }
7213 else {
7214 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007215 if (Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7216 goto failed;
7217 }
Brandt Bucher145bf262021-02-26 14:51:55 -08007218 res = obj2ast_expr(state, tmp, &subject, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007219 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -08007220 if (res != 0) goto failed;
7221 Py_CLEAR(tmp);
7222 }
7223 if (_PyObject_LookupAttr(obj, state->cases, &tmp) < 0) {
7224 return 1;
7225 }
7226 if (tmp == NULL) {
7227 PyErr_SetString(PyExc_TypeError, "required field \"cases\" missing from Match");
7228 return 1;
7229 }
7230 else {
7231 int res;
7232 Py_ssize_t len;
7233 Py_ssize_t i;
7234 if (!PyList_Check(tmp)) {
7235 PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
7236 goto failed;
7237 }
7238 len = PyList_GET_SIZE(tmp);
7239 cases = _Py_asdl_match_case_seq_new(len, arena);
7240 if (cases == NULL) goto failed;
7241 for (i = 0; i < len; i++) {
7242 match_case_ty val;
7243 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7244 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007245 if (Py_EnterRecursiveCall(" while traversing 'Match' node")) {
7246 goto failed;
7247 }
Brandt Bucher145bf262021-02-26 14:51:55 -08007248 res = obj2ast_match_case(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007249 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -08007250 Py_DECREF(tmp2);
7251 if (res != 0) goto failed;
7252 if (len != PyList_GET_SIZE(tmp)) {
7253 PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
7254 goto failed;
7255 }
7256 asdl_seq_SET(cases, i, val);
7257 }
7258 Py_CLEAR(tmp);
7259 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007260 *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
7261 end_col_offset, arena);
Brandt Bucher145bf262021-02-26 14:51:55 -08007262 if (*out == NULL) goto failed;
7263 return 0;
7264 }
Victor Stinner74419f02020-07-03 11:35:37 +02007265 tp = state->Raise_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007266 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007267 if (isinstance == -1) {
7268 return 1;
7269 }
7270 if (isinstance) {
7271 expr_ty exc;
7272 expr_ty cause;
7273
Victor Stinner74419f02020-07-03 11:35:37 +02007274 if (_PyObject_LookupAttr(obj, state->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007275 return 1;
7276 }
7277 if (tmp == NULL || tmp == Py_None) {
7278 Py_CLEAR(tmp);
7279 exc = NULL;
7280 }
7281 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007282 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007283 if (Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7284 goto failed;
7285 }
Victor Stinner74419f02020-07-03 11:35:37 +02007286 res = obj2ast_expr(state, tmp, &exc, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007287 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007288 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007289 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007290 }
Victor Stinner74419f02020-07-03 11:35:37 +02007291 if (_PyObject_LookupAttr(obj, state->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007292 return 1;
7293 }
7294 if (tmp == NULL || tmp == Py_None) {
7295 Py_CLEAR(tmp);
7296 cause = NULL;
7297 }
7298 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007299 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007300 if (Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
7301 goto failed;
7302 }
Victor Stinner74419f02020-07-03 11:35:37 +02007303 res = obj2ast_expr(state, tmp, &cause, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007304 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007305 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007306 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007307 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007308 *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
7309 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007310 if (*out == NULL) goto failed;
7311 return 0;
7312 }
Victor Stinner74419f02020-07-03 11:35:37 +02007313 tp = state->Try_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007314 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007315 if (isinstance == -1) {
7316 return 1;
7317 }
7318 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007319 asdl_stmt_seq* body;
7320 asdl_excepthandler_seq* handlers;
7321 asdl_stmt_seq* orelse;
7322 asdl_stmt_seq* finalbody;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007323
Victor Stinner74419f02020-07-03 11:35:37 +02007324 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007325 return 1;
7326 }
7327 if (tmp == NULL) {
7328 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
7329 return 1;
7330 }
7331 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007332 int res;
7333 Py_ssize_t len;
7334 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007335 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007336 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 +02007337 goto failed;
7338 }
7339 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007340 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007341 if (body == NULL) goto failed;
7342 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007343 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007344 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7345 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007346 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7347 goto failed;
7348 }
Victor Stinner74419f02020-07-03 11:35:37 +02007349 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007350 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007351 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007352 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007353 if (len != PyList_GET_SIZE(tmp)) {
7354 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
7355 goto failed;
7356 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007357 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007358 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007359 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007360 }
Victor Stinner74419f02020-07-03 11:35:37 +02007361 if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007362 return 1;
7363 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007364 if (tmp == NULL) {
7365 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
7366 return 1;
7367 }
7368 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007369 int res;
7370 Py_ssize_t len;
7371 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007372 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007373 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 +02007374 goto failed;
7375 }
7376 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007377 handlers = _Py_asdl_excepthandler_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007378 if (handlers == NULL) goto failed;
7379 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007380 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007381 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7382 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007383 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7384 goto failed;
7385 }
Victor Stinner74419f02020-07-03 11:35:37 +02007386 res = obj2ast_excepthandler(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007387 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007388 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007389 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007390 if (len != PyList_GET_SIZE(tmp)) {
7391 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
7392 goto failed;
7393 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007394 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007395 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007396 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007397 }
Victor Stinner74419f02020-07-03 11:35:37 +02007398 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007399 return 1;
7400 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007401 if (tmp == NULL) {
7402 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
7403 return 1;
7404 }
7405 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007406 int res;
7407 Py_ssize_t len;
7408 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007409 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007410 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 +02007411 goto failed;
7412 }
7413 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007414 orelse = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007415 if (orelse == NULL) goto failed;
7416 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007417 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007418 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7419 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007420 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7421 goto failed;
7422 }
Victor Stinner74419f02020-07-03 11:35:37 +02007423 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007424 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007425 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007426 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007427 if (len != PyList_GET_SIZE(tmp)) {
7428 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
7429 goto failed;
7430 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007431 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007432 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007433 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007434 }
Victor Stinner74419f02020-07-03 11:35:37 +02007435 if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007436 return 1;
7437 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007438 if (tmp == NULL) {
7439 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
7440 return 1;
7441 }
7442 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007443 int res;
7444 Py_ssize_t len;
7445 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007446 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007447 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 +02007448 goto failed;
7449 }
7450 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007451 finalbody = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007452 if (finalbody == NULL) goto failed;
7453 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007454 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007455 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7456 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007457 if (Py_EnterRecursiveCall(" while traversing 'Try' node")) {
7458 goto failed;
7459 }
Victor Stinner74419f02020-07-03 11:35:37 +02007460 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007461 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007462 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007463 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007464 if (len != PyList_GET_SIZE(tmp)) {
7465 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
7466 goto failed;
7467 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007468 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007469 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007470 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007471 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007472 *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
7473 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007474 if (*out == NULL) goto failed;
7475 return 0;
7476 }
Victor Stinner74419f02020-07-03 11:35:37 +02007477 tp = state->Assert_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007478 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007479 if (isinstance == -1) {
7480 return 1;
7481 }
7482 if (isinstance) {
7483 expr_ty test;
7484 expr_ty msg;
7485
Victor Stinner74419f02020-07-03 11:35:37 +02007486 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007487 return 1;
7488 }
7489 if (tmp == NULL) {
7490 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
7491 return 1;
7492 }
7493 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007494 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007495 if (Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
7496 goto failed;
7497 }
Victor Stinner74419f02020-07-03 11:35:37 +02007498 res = obj2ast_expr(state, tmp, &test, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007499 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007500 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007501 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007502 }
Victor Stinner74419f02020-07-03 11:35:37 +02007503 if (_PyObject_LookupAttr(obj, state->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007504 return 1;
7505 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007506 if (tmp == NULL || tmp == Py_None) {
7507 Py_CLEAR(tmp);
7508 msg = NULL;
7509 }
7510 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007511 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007512 if (Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
7513 goto failed;
7514 }
Victor Stinner74419f02020-07-03 11:35:37 +02007515 res = obj2ast_expr(state, tmp, &msg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007516 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007517 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007518 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007519 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007520 *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
7521 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007522 if (*out == NULL) goto failed;
7523 return 0;
7524 }
Victor Stinner74419f02020-07-03 11:35:37 +02007525 tp = state->Import_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007526 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007527 if (isinstance == -1) {
7528 return 1;
7529 }
7530 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007531 asdl_alias_seq* names;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007532
Victor Stinner74419f02020-07-03 11:35:37 +02007533 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007534 return 1;
7535 }
7536 if (tmp == NULL) {
7537 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
7538 return 1;
7539 }
7540 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007541 int res;
7542 Py_ssize_t len;
7543 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007544 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007545 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 +02007546 goto failed;
7547 }
7548 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007549 names = _Py_asdl_alias_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007550 if (names == NULL) goto failed;
7551 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007552 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007553 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7554 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007555 if (Py_EnterRecursiveCall(" while traversing 'Import' node")) {
7556 goto failed;
7557 }
Victor Stinner74419f02020-07-03 11:35:37 +02007558 res = obj2ast_alias(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007559 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007560 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007561 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007562 if (len != PyList_GET_SIZE(tmp)) {
7563 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
7564 goto failed;
7565 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007566 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007567 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007568 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007569 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007570 *out = _PyAST_Import(names, lineno, col_offset, end_lineno,
7571 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007572 if (*out == NULL) goto failed;
7573 return 0;
7574 }
Victor Stinner74419f02020-07-03 11:35:37 +02007575 tp = state->ImportFrom_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007576 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007577 if (isinstance == -1) {
7578 return 1;
7579 }
7580 if (isinstance) {
7581 identifier module;
Pablo Galindoa5634c42020-09-16 19:42:00 +01007582 asdl_alias_seq* names;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007583 int level;
7584
Victor Stinner74419f02020-07-03 11:35:37 +02007585 if (_PyObject_LookupAttr(obj, state->module, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007586 return 1;
7587 }
7588 if (tmp == NULL || tmp == Py_None) {
7589 Py_CLEAR(tmp);
7590 module = NULL;
7591 }
7592 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007593 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007594 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7595 goto failed;
7596 }
Victor Stinner74419f02020-07-03 11:35:37 +02007597 res = obj2ast_identifier(state, tmp, &module, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007598 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007599 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007600 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007601 }
Victor Stinner74419f02020-07-03 11:35:37 +02007602 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007603 return 1;
7604 }
7605 if (tmp == NULL) {
7606 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7607 return 1;
7608 }
7609 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007610 int res;
7611 Py_ssize_t len;
7612 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007613 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007614 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 +02007615 goto failed;
7616 }
7617 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007618 names = _Py_asdl_alias_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007619 if (names == NULL) goto failed;
7620 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007621 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007622 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7623 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007624 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7625 goto failed;
7626 }
Victor Stinner74419f02020-07-03 11:35:37 +02007627 res = obj2ast_alias(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007628 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007629 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007630 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007631 if (len != PyList_GET_SIZE(tmp)) {
7632 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7633 goto failed;
7634 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007635 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007636 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007637 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007638 }
Victor Stinner74419f02020-07-03 11:35:37 +02007639 if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007640 return 1;
7641 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007642 if (tmp == NULL || tmp == Py_None) {
7643 Py_CLEAR(tmp);
7644 level = 0;
7645 }
7646 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007647 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007648 if (Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
7649 goto failed;
7650 }
Victor Stinner74419f02020-07-03 11:35:37 +02007651 res = obj2ast_int(state, tmp, &level, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007652 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007653 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007654 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007655 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007656 *out = _PyAST_ImportFrom(module, names, level, lineno, col_offset,
7657 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007658 if (*out == NULL) goto failed;
7659 return 0;
7660 }
Victor Stinner74419f02020-07-03 11:35:37 +02007661 tp = state->Global_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007662 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007663 if (isinstance == -1) {
7664 return 1;
7665 }
7666 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007667 asdl_identifier_seq* names;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007668
Victor Stinner74419f02020-07-03 11:35:37 +02007669 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007670 return 1;
7671 }
7672 if (tmp == NULL) {
7673 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7674 return 1;
7675 }
7676 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007677 int res;
7678 Py_ssize_t len;
7679 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007680 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007681 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 +02007682 goto failed;
7683 }
7684 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007685 names = _Py_asdl_identifier_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007686 if (names == NULL) goto failed;
7687 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007688 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007689 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7690 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007691 if (Py_EnterRecursiveCall(" while traversing 'Global' node")) {
7692 goto failed;
7693 }
Victor Stinner74419f02020-07-03 11:35:37 +02007694 res = obj2ast_identifier(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007695 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007696 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007697 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007698 if (len != PyList_GET_SIZE(tmp)) {
7699 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7700 goto failed;
7701 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007702 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007703 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007704 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007705 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007706 *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
7707 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007708 if (*out == NULL) goto failed;
7709 return 0;
7710 }
Victor Stinner74419f02020-07-03 11:35:37 +02007711 tp = state->Nonlocal_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007712 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007713 if (isinstance == -1) {
7714 return 1;
7715 }
7716 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01007717 asdl_identifier_seq* names;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007718
Victor Stinner74419f02020-07-03 11:35:37 +02007719 if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007720 return 1;
7721 }
7722 if (tmp == NULL) {
7723 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7724 return 1;
7725 }
7726 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007727 int res;
7728 Py_ssize_t len;
7729 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007730 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007731 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 +02007732 goto failed;
7733 }
7734 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007735 names = _Py_asdl_identifier_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007736 if (names == NULL) goto failed;
7737 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007738 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007739 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7740 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007741 if (Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
7742 goto failed;
7743 }
Victor Stinner74419f02020-07-03 11:35:37 +02007744 res = obj2ast_identifier(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007745 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007746 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007747 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007748 if (len != PyList_GET_SIZE(tmp)) {
7749 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7750 goto failed;
7751 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007752 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007753 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007754 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007755 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007756 *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
7757 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007758 if (*out == NULL) goto failed;
7759 return 0;
7760 }
Victor Stinner74419f02020-07-03 11:35:37 +02007761 tp = state->Expr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007762 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007763 if (isinstance == -1) {
7764 return 1;
7765 }
7766 if (isinstance) {
7767 expr_ty value;
7768
Victor Stinner74419f02020-07-03 11:35:37 +02007769 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007770 return 1;
7771 }
7772 if (tmp == NULL) {
7773 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7774 return 1;
7775 }
7776 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007777 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007778 if (Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
7779 goto failed;
7780 }
Victor Stinner74419f02020-07-03 11:35:37 +02007781 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007782 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007783 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007784 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007785 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007786 *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
7787 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007788 if (*out == NULL) goto failed;
7789 return 0;
7790 }
Victor Stinner74419f02020-07-03 11:35:37 +02007791 tp = state->Pass_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007792 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007793 if (isinstance == -1) {
7794 return 1;
7795 }
7796 if (isinstance) {
7797
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007798 *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
7799 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007800 if (*out == NULL) goto failed;
7801 return 0;
7802 }
Victor Stinner74419f02020-07-03 11:35:37 +02007803 tp = state->Break_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007804 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007805 if (isinstance == -1) {
7806 return 1;
7807 }
7808 if (isinstance) {
7809
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007810 *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
7811 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007812 if (*out == NULL) goto failed;
7813 return 0;
7814 }
Victor Stinner74419f02020-07-03 11:35:37 +02007815 tp = state->Continue_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007816 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007817 if (isinstance == -1) {
7818 return 1;
7819 }
7820 if (isinstance) {
7821
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007822 *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
7823 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007824 if (*out == NULL) goto failed;
7825 return 0;
7826 }
7827
7828 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7829 failed:
7830 Py_XDECREF(tmp);
7831 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007832}
7833
7834int
Victor Stinner5cf47822020-11-02 22:03:28 +01007835obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
7836 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007837{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007838 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007839
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007840 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007841 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007842 int lineno;
7843 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007844 int end_lineno;
7845 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007846
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007847 if (obj == Py_None) {
7848 *out = NULL;
7849 return 0;
7850 }
Victor Stinner74419f02020-07-03 11:35:37 +02007851 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007852 return 1;
7853 }
7854 if (tmp == NULL) {
7855 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7856 return 1;
7857 }
7858 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007859 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007860 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7861 goto failed;
7862 }
Victor Stinner74419f02020-07-03 11:35:37 +02007863 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007864 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007865 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007866 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007867 }
Victor Stinner74419f02020-07-03 11:35:37 +02007868 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007869 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007870 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007871 if (tmp == NULL) {
7872 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7873 return 1;
7874 }
7875 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007876 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007877 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7878 goto failed;
7879 }
Victor Stinner74419f02020-07-03 11:35:37 +02007880 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007881 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007882 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007883 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007884 }
Victor Stinner74419f02020-07-03 11:35:37 +02007885 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007886 return 1;
7887 }
7888 if (tmp == NULL || tmp == Py_None) {
7889 Py_CLEAR(tmp);
7890 end_lineno = 0;
7891 }
7892 else {
7893 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007894 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7895 goto failed;
7896 }
Victor Stinner74419f02020-07-03 11:35:37 +02007897 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007898 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007899 if (res != 0) goto failed;
7900 Py_CLEAR(tmp);
7901 }
Victor Stinner74419f02020-07-03 11:35:37 +02007902 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007903 return 1;
7904 }
7905 if (tmp == NULL || tmp == Py_None) {
7906 Py_CLEAR(tmp);
7907 end_col_offset = 0;
7908 }
7909 else {
7910 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007911 if (Py_EnterRecursiveCall(" while traversing 'expr' node")) {
7912 goto failed;
7913 }
Victor Stinner74419f02020-07-03 11:35:37 +02007914 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007915 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007916 if (res != 0) goto failed;
7917 Py_CLEAR(tmp);
7918 }
Victor Stinner74419f02020-07-03 11:35:37 +02007919 tp = state->BoolOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007920 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007921 if (isinstance == -1) {
7922 return 1;
7923 }
7924 if (isinstance) {
7925 boolop_ty op;
Pablo Galindoa5634c42020-09-16 19:42:00 +01007926 asdl_expr_seq* values;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007927
Victor Stinner74419f02020-07-03 11:35:37 +02007928 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007929 return 1;
7930 }
7931 if (tmp == NULL) {
7932 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7933 return 1;
7934 }
7935 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007936 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007937 if (Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
7938 goto failed;
7939 }
Victor Stinner74419f02020-07-03 11:35:37 +02007940 res = obj2ast_boolop(state, tmp, &op, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007941 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007942 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007943 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007944 }
Victor Stinner74419f02020-07-03 11:35:37 +02007945 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007946 return 1;
7947 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007948 if (tmp == NULL) {
7949 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7950 return 1;
7951 }
7952 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007953 int res;
7954 Py_ssize_t len;
7955 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007956 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007957 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 +02007958 goto failed;
7959 }
7960 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01007961 values = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007962 if (values == NULL) goto failed;
7963 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007964 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007965 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7966 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007967 if (Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
7968 goto failed;
7969 }
Victor Stinner74419f02020-07-03 11:35:37 +02007970 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07007971 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007972 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007973 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007974 if (len != PyList_GET_SIZE(tmp)) {
7975 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7976 goto failed;
7977 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007978 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007979 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007980 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007981 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02007982 *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
7983 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007984 if (*out == NULL) goto failed;
7985 return 0;
7986 }
Victor Stinner74419f02020-07-03 11:35:37 +02007987 tp = state->NamedExpr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007988 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007989 if (isinstance == -1) {
7990 return 1;
7991 }
7992 if (isinstance) {
7993 expr_ty target;
7994 expr_ty value;
7995
Victor Stinner74419f02020-07-03 11:35:37 +02007996 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007997 return 1;
7998 }
7999 if (tmp == NULL) {
8000 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
8001 return 1;
8002 }
8003 else {
8004 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008005 if (Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8006 goto failed;
8007 }
Victor Stinner74419f02020-07-03 11:35:37 +02008008 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008009 Py_LeaveRecursiveCall();
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008010 if (res != 0) goto failed;
8011 Py_CLEAR(tmp);
8012 }
Victor Stinner74419f02020-07-03 11:35:37 +02008013 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008014 return 1;
8015 }
8016 if (tmp == NULL) {
8017 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
8018 return 1;
8019 }
8020 else {
8021 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008022 if (Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
8023 goto failed;
8024 }
Victor Stinner74419f02020-07-03 11:35:37 +02008025 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008026 Py_LeaveRecursiveCall();
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008027 if (res != 0) goto failed;
8028 Py_CLEAR(tmp);
8029 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008030 *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
8031 end_col_offset, arena);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07008032 if (*out == NULL) goto failed;
8033 return 0;
8034 }
Victor Stinner74419f02020-07-03 11:35:37 +02008035 tp = state->BinOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008036 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008037 if (isinstance == -1) {
8038 return 1;
8039 }
8040 if (isinstance) {
8041 expr_ty left;
8042 operator_ty op;
8043 expr_ty right;
8044
Victor Stinner74419f02020-07-03 11:35:37 +02008045 if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008046 return 1;
8047 }
8048 if (tmp == NULL) {
8049 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
8050 return 1;
8051 }
8052 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008053 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008054 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8055 goto failed;
8056 }
Victor Stinner74419f02020-07-03 11:35:37 +02008057 res = obj2ast_expr(state, tmp, &left, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008058 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008059 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008060 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008061 }
Victor Stinner74419f02020-07-03 11:35:37 +02008062 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008063 return 1;
8064 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008065 if (tmp == NULL) {
8066 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
8067 return 1;
8068 }
8069 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008070 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008071 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8072 goto failed;
8073 }
Victor Stinner74419f02020-07-03 11:35:37 +02008074 res = obj2ast_operator(state, tmp, &op, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008075 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008076 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008077 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008078 }
Victor Stinner74419f02020-07-03 11:35:37 +02008079 if (_PyObject_LookupAttr(obj, state->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008080 return 1;
8081 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008082 if (tmp == NULL) {
8083 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
8084 return 1;
8085 }
8086 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008087 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008088 if (Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
8089 goto failed;
8090 }
Victor Stinner74419f02020-07-03 11:35:37 +02008091 res = obj2ast_expr(state, tmp, &right, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008092 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008093 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008094 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008095 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008096 *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
8097 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008098 if (*out == NULL) goto failed;
8099 return 0;
8100 }
Victor Stinner74419f02020-07-03 11:35:37 +02008101 tp = state->UnaryOp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008102 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008103 if (isinstance == -1) {
8104 return 1;
8105 }
8106 if (isinstance) {
8107 unaryop_ty op;
8108 expr_ty operand;
8109
Victor Stinner74419f02020-07-03 11:35:37 +02008110 if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008111 return 1;
8112 }
8113 if (tmp == NULL) {
8114 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
8115 return 1;
8116 }
8117 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008118 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008119 if (Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8120 goto failed;
8121 }
Victor Stinner74419f02020-07-03 11:35:37 +02008122 res = obj2ast_unaryop(state, tmp, &op, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008123 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008124 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008125 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008126 }
Victor Stinner74419f02020-07-03 11:35:37 +02008127 if (_PyObject_LookupAttr(obj, state->operand, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008128 return 1;
8129 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008130 if (tmp == NULL) {
8131 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
8132 return 1;
8133 }
8134 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008135 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008136 if (Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
8137 goto failed;
8138 }
Victor Stinner74419f02020-07-03 11:35:37 +02008139 res = obj2ast_expr(state, tmp, &operand, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008140 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008141 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008142 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008143 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008144 *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
8145 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008146 if (*out == NULL) goto failed;
8147 return 0;
8148 }
Victor Stinner74419f02020-07-03 11:35:37 +02008149 tp = state->Lambda_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008150 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008151 if (isinstance == -1) {
8152 return 1;
8153 }
8154 if (isinstance) {
8155 arguments_ty args;
8156 expr_ty body;
8157
Victor Stinner74419f02020-07-03 11:35:37 +02008158 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008159 return 1;
8160 }
8161 if (tmp == NULL) {
8162 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
8163 return 1;
8164 }
8165 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008166 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008167 if (Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8168 goto failed;
8169 }
Victor Stinner74419f02020-07-03 11:35:37 +02008170 res = obj2ast_arguments(state, tmp, &args, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008171 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008172 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008173 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008174 }
Victor Stinner74419f02020-07-03 11:35:37 +02008175 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008176 return 1;
8177 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008178 if (tmp == NULL) {
8179 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
8180 return 1;
8181 }
8182 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008183 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008184 if (Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
8185 goto failed;
8186 }
Victor Stinner74419f02020-07-03 11:35:37 +02008187 res = obj2ast_expr(state, tmp, &body, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008188 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008189 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008190 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008191 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008192 *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
8193 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008194 if (*out == NULL) goto failed;
8195 return 0;
8196 }
Victor Stinner74419f02020-07-03 11:35:37 +02008197 tp = state->IfExp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008198 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008199 if (isinstance == -1) {
8200 return 1;
8201 }
8202 if (isinstance) {
8203 expr_ty test;
8204 expr_ty body;
8205 expr_ty orelse;
8206
Victor Stinner74419f02020-07-03 11:35:37 +02008207 if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008208 return 1;
8209 }
8210 if (tmp == NULL) {
8211 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
8212 return 1;
8213 }
8214 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008215 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008216 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8217 goto failed;
8218 }
Victor Stinner74419f02020-07-03 11:35:37 +02008219 res = obj2ast_expr(state, tmp, &test, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008220 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008221 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008222 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008223 }
Victor Stinner74419f02020-07-03 11:35:37 +02008224 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008225 return 1;
8226 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008227 if (tmp == NULL) {
8228 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
8229 return 1;
8230 }
8231 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008232 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008233 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8234 goto failed;
8235 }
Victor Stinner74419f02020-07-03 11:35:37 +02008236 res = obj2ast_expr(state, tmp, &body, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008237 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008238 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008239 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008240 }
Victor Stinner74419f02020-07-03 11:35:37 +02008241 if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008242 return 1;
8243 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008244 if (tmp == NULL) {
8245 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
8246 return 1;
8247 }
8248 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008249 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008250 if (Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
8251 goto failed;
8252 }
Victor Stinner74419f02020-07-03 11:35:37 +02008253 res = obj2ast_expr(state, tmp, &orelse, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008254 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008255 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008256 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008257 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008258 *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
8259 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008260 if (*out == NULL) goto failed;
8261 return 0;
8262 }
Victor Stinner74419f02020-07-03 11:35:37 +02008263 tp = state->Dict_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008264 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008265 if (isinstance == -1) {
8266 return 1;
8267 }
8268 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01008269 asdl_expr_seq* keys;
8270 asdl_expr_seq* values;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008271
Victor Stinner74419f02020-07-03 11:35:37 +02008272 if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008273 return 1;
8274 }
8275 if (tmp == NULL) {
8276 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
8277 return 1;
8278 }
8279 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008280 int res;
8281 Py_ssize_t len;
8282 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008283 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008284 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 +02008285 goto failed;
8286 }
8287 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008288 keys = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008289 if (keys == NULL) goto failed;
8290 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008291 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008292 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8293 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008294 if (Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
8295 goto failed;
8296 }
Victor Stinner74419f02020-07-03 11:35:37 +02008297 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008298 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008299 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008300 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008301 if (len != PyList_GET_SIZE(tmp)) {
8302 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
8303 goto failed;
8304 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008305 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008306 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008307 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008308 }
Victor Stinner74419f02020-07-03 11:35:37 +02008309 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008310 return 1;
8311 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008312 if (tmp == NULL) {
8313 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
8314 return 1;
8315 }
8316 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008317 int res;
8318 Py_ssize_t len;
8319 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008320 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008321 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 +02008322 goto failed;
8323 }
8324 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008325 values = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008326 if (values == NULL) goto failed;
8327 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008328 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008329 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8330 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008331 if (Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
8332 goto failed;
8333 }
Victor Stinner74419f02020-07-03 11:35:37 +02008334 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008335 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008336 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008337 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008338 if (len != PyList_GET_SIZE(tmp)) {
8339 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
8340 goto failed;
8341 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008342 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008343 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008344 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008345 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008346 *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
8347 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008348 if (*out == NULL) goto failed;
8349 return 0;
8350 }
Victor Stinner74419f02020-07-03 11:35:37 +02008351 tp = state->Set_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008352 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008353 if (isinstance == -1) {
8354 return 1;
8355 }
8356 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01008357 asdl_expr_seq* elts;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008358
Victor Stinner74419f02020-07-03 11:35:37 +02008359 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008360 return 1;
8361 }
8362 if (tmp == NULL) {
8363 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
8364 return 1;
8365 }
8366 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008367 int res;
8368 Py_ssize_t len;
8369 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008370 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008371 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 +02008372 goto failed;
8373 }
8374 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008375 elts = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008376 if (elts == NULL) goto failed;
8377 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008378 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008379 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8380 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008381 if (Py_EnterRecursiveCall(" while traversing 'Set' node")) {
8382 goto failed;
8383 }
Victor Stinner74419f02020-07-03 11:35:37 +02008384 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008385 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008386 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008387 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008388 if (len != PyList_GET_SIZE(tmp)) {
8389 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
8390 goto failed;
8391 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008392 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008393 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008394 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008395 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008396 *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
8397 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008398 if (*out == NULL) goto failed;
8399 return 0;
8400 }
Victor Stinner74419f02020-07-03 11:35:37 +02008401 tp = state->ListComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008402 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008403 if (isinstance == -1) {
8404 return 1;
8405 }
8406 if (isinstance) {
8407 expr_ty elt;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008408 asdl_comprehension_seq* generators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008409
Victor Stinner74419f02020-07-03 11:35:37 +02008410 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008411 return 1;
8412 }
8413 if (tmp == NULL) {
8414 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
8415 return 1;
8416 }
8417 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008418 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008419 if (Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
8420 goto failed;
8421 }
Victor Stinner74419f02020-07-03 11:35:37 +02008422 res = obj2ast_expr(state, tmp, &elt, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008423 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008424 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008425 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008426 }
Victor Stinner74419f02020-07-03 11:35:37 +02008427 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008428 return 1;
8429 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008430 if (tmp == NULL) {
8431 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
8432 return 1;
8433 }
8434 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008435 int res;
8436 Py_ssize_t len;
8437 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008438 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008439 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 +02008440 goto failed;
8441 }
8442 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008443 generators = _Py_asdl_comprehension_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008444 if (generators == NULL) goto failed;
8445 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008446 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008447 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8448 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008449 if (Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
8450 goto failed;
8451 }
Victor Stinner74419f02020-07-03 11:35:37 +02008452 res = obj2ast_comprehension(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008453 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008454 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008455 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008456 if (len != PyList_GET_SIZE(tmp)) {
8457 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
8458 goto failed;
8459 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008460 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008461 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008462 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008463 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008464 *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
8465 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008466 if (*out == NULL) goto failed;
8467 return 0;
8468 }
Victor Stinner74419f02020-07-03 11:35:37 +02008469 tp = state->SetComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008470 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008471 if (isinstance == -1) {
8472 return 1;
8473 }
8474 if (isinstance) {
8475 expr_ty elt;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008476 asdl_comprehension_seq* generators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008477
Victor Stinner74419f02020-07-03 11:35:37 +02008478 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008479 return 1;
8480 }
8481 if (tmp == NULL) {
8482 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
8483 return 1;
8484 }
8485 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008486 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008487 if (Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
8488 goto failed;
8489 }
Victor Stinner74419f02020-07-03 11:35:37 +02008490 res = obj2ast_expr(state, tmp, &elt, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008491 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008492 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008493 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008494 }
Victor Stinner74419f02020-07-03 11:35:37 +02008495 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008496 return 1;
8497 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008498 if (tmp == NULL) {
8499 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
8500 return 1;
8501 }
8502 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008503 int res;
8504 Py_ssize_t len;
8505 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008506 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008507 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 +02008508 goto failed;
8509 }
8510 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008511 generators = _Py_asdl_comprehension_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008512 if (generators == NULL) goto failed;
8513 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008514 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008515 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8516 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008517 if (Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
8518 goto failed;
8519 }
Victor Stinner74419f02020-07-03 11:35:37 +02008520 res = obj2ast_comprehension(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008521 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008522 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008523 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008524 if (len != PyList_GET_SIZE(tmp)) {
8525 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
8526 goto failed;
8527 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008528 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008529 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008530 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008531 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008532 *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
8533 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008534 if (*out == NULL) goto failed;
8535 return 0;
8536 }
Victor Stinner74419f02020-07-03 11:35:37 +02008537 tp = state->DictComp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008538 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008539 if (isinstance == -1) {
8540 return 1;
8541 }
8542 if (isinstance) {
8543 expr_ty key;
8544 expr_ty value;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008545 asdl_comprehension_seq* generators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008546
Victor Stinner74419f02020-07-03 11:35:37 +02008547 if (_PyObject_LookupAttr(obj, state->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008548 return 1;
8549 }
8550 if (tmp == NULL) {
8551 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
8552 return 1;
8553 }
8554 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008555 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008556 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8557 goto failed;
8558 }
Victor Stinner74419f02020-07-03 11:35:37 +02008559 res = obj2ast_expr(state, tmp, &key, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008560 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008561 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008562 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008563 }
Victor Stinner74419f02020-07-03 11:35:37 +02008564 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008565 return 1;
8566 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008567 if (tmp == NULL) {
8568 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
8569 return 1;
8570 }
8571 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008572 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008573 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8574 goto failed;
8575 }
Victor Stinner74419f02020-07-03 11:35:37 +02008576 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008577 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008578 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008579 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008580 }
Victor Stinner74419f02020-07-03 11:35:37 +02008581 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008582 return 1;
8583 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008584 if (tmp == NULL) {
8585 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
8586 return 1;
8587 }
8588 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008589 int res;
8590 Py_ssize_t len;
8591 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008592 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008593 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 +02008594 goto failed;
8595 }
8596 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008597 generators = _Py_asdl_comprehension_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008598 if (generators == NULL) goto failed;
8599 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008600 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008601 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8602 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008603 if (Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
8604 goto failed;
8605 }
Victor Stinner74419f02020-07-03 11:35:37 +02008606 res = obj2ast_comprehension(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008607 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008608 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008609 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008610 if (len != PyList_GET_SIZE(tmp)) {
8611 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
8612 goto failed;
8613 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008614 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008615 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008616 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008617 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008618 *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
8619 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008620 if (*out == NULL) goto failed;
8621 return 0;
8622 }
Victor Stinner74419f02020-07-03 11:35:37 +02008623 tp = state->GeneratorExp_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008624 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008625 if (isinstance == -1) {
8626 return 1;
8627 }
8628 if (isinstance) {
8629 expr_ty elt;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008630 asdl_comprehension_seq* generators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008631
Victor Stinner74419f02020-07-03 11:35:37 +02008632 if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008633 return 1;
8634 }
8635 if (tmp == NULL) {
8636 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
8637 return 1;
8638 }
8639 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008640 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008641 if (Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
8642 goto failed;
8643 }
Victor Stinner74419f02020-07-03 11:35:37 +02008644 res = obj2ast_expr(state, tmp, &elt, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008645 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008646 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008647 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008648 }
Victor Stinner74419f02020-07-03 11:35:37 +02008649 if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008650 return 1;
8651 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008652 if (tmp == NULL) {
8653 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
8654 return 1;
8655 }
8656 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008657 int res;
8658 Py_ssize_t len;
8659 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008660 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008661 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 +02008662 goto failed;
8663 }
8664 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008665 generators = _Py_asdl_comprehension_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008666 if (generators == NULL) goto failed;
8667 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008668 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008669 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8670 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008671 if (Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
8672 goto failed;
8673 }
Victor Stinner74419f02020-07-03 11:35:37 +02008674 res = obj2ast_comprehension(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008675 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008676 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008677 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008678 if (len != PyList_GET_SIZE(tmp)) {
8679 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
8680 goto failed;
8681 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008682 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008683 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008684 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008685 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008686 *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
8687 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008688 if (*out == NULL) goto failed;
8689 return 0;
8690 }
Victor Stinner74419f02020-07-03 11:35:37 +02008691 tp = state->Await_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008692 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04008693 if (isinstance == -1) {
8694 return 1;
8695 }
8696 if (isinstance) {
8697 expr_ty value;
8698
Victor Stinner74419f02020-07-03 11:35:37 +02008699 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008700 return 1;
8701 }
8702 if (tmp == NULL) {
8703 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
8704 return 1;
8705 }
8706 else {
Yury Selivanov75445082015-05-11 22:57:16 -04008707 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008708 if (Py_EnterRecursiveCall(" while traversing 'Await' node")) {
8709 goto failed;
8710 }
Victor Stinner74419f02020-07-03 11:35:37 +02008711 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008712 Py_LeaveRecursiveCall();
Yury Selivanov75445082015-05-11 22:57:16 -04008713 if (res != 0) goto failed;
8714 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04008715 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008716 *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
8717 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04008718 if (*out == NULL) goto failed;
8719 return 0;
8720 }
Victor Stinner74419f02020-07-03 11:35:37 +02008721 tp = state->Yield_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008722 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008723 if (isinstance == -1) {
8724 return 1;
8725 }
8726 if (isinstance) {
8727 expr_ty value;
8728
Victor Stinner74419f02020-07-03 11:35:37 +02008729 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008730 return 1;
8731 }
8732 if (tmp == NULL || tmp == Py_None) {
8733 Py_CLEAR(tmp);
8734 value = NULL;
8735 }
8736 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008737 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008738 if (Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
8739 goto failed;
8740 }
Victor Stinner74419f02020-07-03 11:35:37 +02008741 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008742 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008743 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008744 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008745 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008746 *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
8747 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008748 if (*out == NULL) goto failed;
8749 return 0;
8750 }
Victor Stinner74419f02020-07-03 11:35:37 +02008751 tp = state->YieldFrom_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008752 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008753 if (isinstance == -1) {
8754 return 1;
8755 }
8756 if (isinstance) {
8757 expr_ty value;
8758
Victor Stinner74419f02020-07-03 11:35:37 +02008759 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008760 return 1;
8761 }
8762 if (tmp == NULL) {
8763 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8764 return 1;
8765 }
8766 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008767 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008768 if (Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
8769 goto failed;
8770 }
Victor Stinner74419f02020-07-03 11:35:37 +02008771 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008772 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008773 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008774 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008775 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008776 *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
8777 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008778 if (*out == NULL) goto failed;
8779 return 0;
8780 }
Victor Stinner74419f02020-07-03 11:35:37 +02008781 tp = state->Compare_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008782 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008783 if (isinstance == -1) {
8784 return 1;
8785 }
8786 if (isinstance) {
8787 expr_ty left;
8788 asdl_int_seq* ops;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008789 asdl_expr_seq* comparators;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008790
Victor Stinner74419f02020-07-03 11:35:37 +02008791 if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008792 return 1;
8793 }
8794 if (tmp == NULL) {
8795 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8796 return 1;
8797 }
8798 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008799 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008800 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8801 goto failed;
8802 }
Victor Stinner74419f02020-07-03 11:35:37 +02008803 res = obj2ast_expr(state, tmp, &left, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008804 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008805 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008806 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008807 }
Victor Stinner74419f02020-07-03 11:35:37 +02008808 if (_PyObject_LookupAttr(obj, state->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008809 return 1;
8810 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008811 if (tmp == NULL) {
8812 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8813 return 1;
8814 }
8815 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008816 int res;
8817 Py_ssize_t len;
8818 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008819 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008820 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 +02008821 goto failed;
8822 }
8823 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008824 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008825 if (ops == NULL) goto failed;
8826 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008827 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008828 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8829 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008830 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8831 goto failed;
8832 }
Victor Stinner74419f02020-07-03 11:35:37 +02008833 res = obj2ast_cmpop(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008834 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008835 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008836 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008837 if (len != PyList_GET_SIZE(tmp)) {
8838 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8839 goto failed;
8840 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008841 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008842 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008843 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008844 }
Victor Stinner74419f02020-07-03 11:35:37 +02008845 if (_PyObject_LookupAttr(obj, state->comparators, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008846 return 1;
8847 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008848 if (tmp == NULL) {
8849 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8850 return 1;
8851 }
8852 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008853 int res;
8854 Py_ssize_t len;
8855 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008856 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008857 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 +02008858 goto failed;
8859 }
8860 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008861 comparators = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008862 if (comparators == NULL) goto failed;
8863 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008864 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008865 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8866 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008867 if (Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
8868 goto failed;
8869 }
Victor Stinner74419f02020-07-03 11:35:37 +02008870 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008871 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008872 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008873 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008874 if (len != PyList_GET_SIZE(tmp)) {
8875 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8876 goto failed;
8877 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008878 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008879 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008880 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008881 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008882 *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
8883 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008884 if (*out == NULL) goto failed;
8885 return 0;
8886 }
Victor Stinner74419f02020-07-03 11:35:37 +02008887 tp = state->Call_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008888 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008889 if (isinstance == -1) {
8890 return 1;
8891 }
8892 if (isinstance) {
8893 expr_ty func;
Pablo Galindoa5634c42020-09-16 19:42:00 +01008894 asdl_expr_seq* args;
8895 asdl_keyword_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008896
Victor Stinner74419f02020-07-03 11:35:37 +02008897 if (_PyObject_LookupAttr(obj, state->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008898 return 1;
8899 }
8900 if (tmp == NULL) {
8901 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8902 return 1;
8903 }
8904 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008905 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008906 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8907 goto failed;
8908 }
Victor Stinner74419f02020-07-03 11:35:37 +02008909 res = obj2ast_expr(state, tmp, &func, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008910 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008911 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008912 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008913 }
Victor Stinner74419f02020-07-03 11:35:37 +02008914 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008915 return 1;
8916 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008917 if (tmp == NULL) {
8918 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8919 return 1;
8920 }
8921 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008922 int res;
8923 Py_ssize_t len;
8924 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008925 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008926 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 +02008927 goto failed;
8928 }
8929 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008930 args = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008931 if (args == NULL) goto failed;
8932 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008933 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008934 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8935 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008936 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8937 goto failed;
8938 }
Victor Stinner74419f02020-07-03 11:35:37 +02008939 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008940 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008941 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008942 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008943 if (len != PyList_GET_SIZE(tmp)) {
8944 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8945 goto failed;
8946 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008947 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008948 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008949 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008950 }
Victor Stinner74419f02020-07-03 11:35:37 +02008951 if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008952 return 1;
8953 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008954 if (tmp == NULL) {
8955 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8956 return 1;
8957 }
8958 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008959 int res;
8960 Py_ssize_t len;
8961 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008962 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008963 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 +02008964 goto failed;
8965 }
8966 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01008967 keywords = _Py_asdl_keyword_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008968 if (keywords == NULL) goto failed;
8969 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008970 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008971 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8972 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008973 if (Py_EnterRecursiveCall(" while traversing 'Call' node")) {
8974 goto failed;
8975 }
Victor Stinner74419f02020-07-03 11:35:37 +02008976 res = obj2ast_keyword(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07008977 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008978 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008979 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008980 if (len != PyList_GET_SIZE(tmp)) {
8981 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8982 goto failed;
8983 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008984 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008985 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008986 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008987 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02008988 *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
8989 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008990 if (*out == NULL) goto failed;
8991 return 0;
8992 }
Victor Stinner74419f02020-07-03 11:35:37 +02008993 tp = state->FormattedValue_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008994 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008995 if (isinstance == -1) {
8996 return 1;
8997 }
8998 if (isinstance) {
8999 expr_ty value;
9000 int conversion;
9001 expr_ty format_spec;
9002
Victor Stinner74419f02020-07-03 11:35:37 +02009003 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009004 return 1;
9005 }
9006 if (tmp == NULL) {
9007 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
9008 return 1;
9009 }
9010 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009011 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009012 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9013 goto failed;
9014 }
Victor Stinner74419f02020-07-03 11:35:37 +02009015 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009016 Py_LeaveRecursiveCall();
Eric V. Smith235a6f02015-09-19 14:51:32 -04009017 if (res != 0) goto failed;
9018 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009019 }
Victor Stinner74419f02020-07-03 11:35:37 +02009020 if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009021 return 1;
9022 }
Miss Islington (bot)bea3f422022-01-07 14:30:18 -08009023 if (tmp == NULL) {
9024 PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
9025 return 1;
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009026 }
9027 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009028 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009029 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9030 goto failed;
9031 }
Victor Stinner74419f02020-07-03 11:35:37 +02009032 res = obj2ast_int(state, tmp, &conversion, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009033 Py_LeaveRecursiveCall();
Eric V. Smith235a6f02015-09-19 14:51:32 -04009034 if (res != 0) goto failed;
9035 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009036 }
Victor Stinner74419f02020-07-03 11:35:37 +02009037 if (_PyObject_LookupAttr(obj, state->format_spec, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009038 return 1;
9039 }
9040 if (tmp == NULL || tmp == Py_None) {
9041 Py_CLEAR(tmp);
9042 format_spec = NULL;
9043 }
9044 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009045 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009046 if (Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
9047 goto failed;
9048 }
Victor Stinner74419f02020-07-03 11:35:37 +02009049 res = obj2ast_expr(state, tmp, &format_spec, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009050 Py_LeaveRecursiveCall();
Eric V. Smith235a6f02015-09-19 14:51:32 -04009051 if (res != 0) goto failed;
9052 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009053 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009054 *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
9055 col_offset, end_lineno, end_col_offset,
9056 arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009057 if (*out == NULL) goto failed;
9058 return 0;
9059 }
Victor Stinner74419f02020-07-03 11:35:37 +02009060 tp = state->JoinedStr_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009061 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009062 if (isinstance == -1) {
9063 return 1;
9064 }
9065 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01009066 asdl_expr_seq* values;
Eric V. Smith235a6f02015-09-19 14:51:32 -04009067
Victor Stinner74419f02020-07-03 11:35:37 +02009068 if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009069 return 1;
9070 }
9071 if (tmp == NULL) {
9072 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
9073 return 1;
9074 }
9075 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04009076 int res;
9077 Py_ssize_t len;
9078 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04009079 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009080 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 -04009081 goto failed;
9082 }
9083 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01009084 values = _Py_asdl_expr_seq_new(len, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009085 if (values == NULL) goto failed;
9086 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009087 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009088 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9089 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009090 if (Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
9091 goto failed;
9092 }
Victor Stinner74419f02020-07-03 11:35:37 +02009093 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009094 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009095 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009096 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03009097 if (len != PyList_GET_SIZE(tmp)) {
9098 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
9099 goto failed;
9100 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009101 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009102 }
9103 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009104 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009105 *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
9106 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04009107 if (*out == NULL) goto failed;
9108 return 0;
9109 }
Victor Stinner74419f02020-07-03 11:35:37 +02009110 tp = state->Constant_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009111 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009112 if (isinstance == -1) {
9113 return 1;
9114 }
9115 if (isinstance) {
9116 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07009117 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009118
Victor Stinner74419f02020-07-03 11:35:37 +02009119 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009120 return 1;
9121 }
9122 if (tmp == NULL) {
9123 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
9124 return 1;
9125 }
9126 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009127 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009128 if (Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9129 goto failed;
9130 }
Victor Stinner74419f02020-07-03 11:35:37 +02009131 res = obj2ast_constant(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009132 Py_LeaveRecursiveCall();
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009133 if (res != 0) goto failed;
9134 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009135 }
Victor Stinner74419f02020-07-03 11:35:37 +02009136 if (_PyObject_LookupAttr(obj, state->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07009137 return 1;
9138 }
9139 if (tmp == NULL || tmp == Py_None) {
9140 Py_CLEAR(tmp);
9141 kind = NULL;
9142 }
9143 else {
9144 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009145 if (Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
9146 goto failed;
9147 }
Victor Stinner74419f02020-07-03 11:35:37 +02009148 res = obj2ast_string(state, tmp, &kind, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009149 Py_LeaveRecursiveCall();
Guido van Rossum10f8ce62019-03-13 13:00:46 -07009150 if (res != 0) goto failed;
9151 Py_CLEAR(tmp);
9152 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009153 *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
9154 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01009155 if (*out == NULL) goto failed;
9156 return 0;
9157 }
Victor Stinner74419f02020-07-03 11:35:37 +02009158 tp = state->Attribute_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009159 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009160 if (isinstance == -1) {
9161 return 1;
9162 }
9163 if (isinstance) {
9164 expr_ty value;
9165 identifier attr;
9166 expr_context_ty ctx;
9167
Victor Stinner74419f02020-07-03 11:35:37 +02009168 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009169 return 1;
9170 }
9171 if (tmp == NULL) {
9172 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
9173 return 1;
9174 }
9175 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009176 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009177 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9178 goto failed;
9179 }
Victor Stinner74419f02020-07-03 11:35:37 +02009180 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009181 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009182 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009183 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009184 }
Victor Stinner74419f02020-07-03 11:35:37 +02009185 if (_PyObject_LookupAttr(obj, state->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009186 return 1;
9187 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009188 if (tmp == NULL) {
9189 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
9190 return 1;
9191 }
9192 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009193 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009194 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9195 goto failed;
9196 }
Victor Stinner74419f02020-07-03 11:35:37 +02009197 res = obj2ast_identifier(state, tmp, &attr, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009198 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009199 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009200 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009201 }
Victor Stinner74419f02020-07-03 11:35:37 +02009202 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009203 return 1;
9204 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009205 if (tmp == NULL) {
9206 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
9207 return 1;
9208 }
9209 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009210 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009211 if (Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
9212 goto failed;
9213 }
Victor Stinner74419f02020-07-03 11:35:37 +02009214 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009215 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009216 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009217 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009218 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009219 *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
9220 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009221 if (*out == NULL) goto failed;
9222 return 0;
9223 }
Victor Stinner74419f02020-07-03 11:35:37 +02009224 tp = state->Subscript_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009225 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009226 if (isinstance == -1) {
9227 return 1;
9228 }
9229 if (isinstance) {
9230 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009231 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009232 expr_context_ty ctx;
9233
Victor Stinner74419f02020-07-03 11:35:37 +02009234 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009235 return 1;
9236 }
9237 if (tmp == NULL) {
9238 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
9239 return 1;
9240 }
9241 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009242 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009243 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9244 goto failed;
9245 }
Victor Stinner74419f02020-07-03 11:35:37 +02009246 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009247 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009248 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009249 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009250 }
Victor Stinner74419f02020-07-03 11:35:37 +02009251 if (_PyObject_LookupAttr(obj, state->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009252 return 1;
9253 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009254 if (tmp == NULL) {
9255 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
9256 return 1;
9257 }
9258 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009259 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009260 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9261 goto failed;
9262 }
Victor Stinner74419f02020-07-03 11:35:37 +02009263 res = obj2ast_expr(state, tmp, &slice, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009264 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009265 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009266 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009267 }
Victor Stinner74419f02020-07-03 11:35:37 +02009268 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009269 return 1;
9270 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009271 if (tmp == NULL) {
9272 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
9273 return 1;
9274 }
9275 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009276 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009277 if (Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
9278 goto failed;
9279 }
Victor Stinner74419f02020-07-03 11:35:37 +02009280 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009281 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009282 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009283 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009284 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009285 *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
9286 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009287 if (*out == NULL) goto failed;
9288 return 0;
9289 }
Victor Stinner74419f02020-07-03 11:35:37 +02009290 tp = state->Starred_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009291 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009292 if (isinstance == -1) {
9293 return 1;
9294 }
9295 if (isinstance) {
9296 expr_ty value;
9297 expr_context_ty ctx;
9298
Victor Stinner74419f02020-07-03 11:35:37 +02009299 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009300 return 1;
9301 }
9302 if (tmp == NULL) {
9303 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
9304 return 1;
9305 }
9306 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009307 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009308 if (Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
9309 goto failed;
9310 }
Victor Stinner74419f02020-07-03 11:35:37 +02009311 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009312 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009313 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009314 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009315 }
Victor Stinner74419f02020-07-03 11:35:37 +02009316 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009317 return 1;
9318 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009319 if (tmp == NULL) {
9320 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
9321 return 1;
9322 }
9323 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009324 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009325 if (Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
9326 goto failed;
9327 }
Victor Stinner74419f02020-07-03 11:35:37 +02009328 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009329 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009330 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009331 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009332 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009333 *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
9334 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009335 if (*out == NULL) goto failed;
9336 return 0;
9337 }
Victor Stinner74419f02020-07-03 11:35:37 +02009338 tp = state->Name_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009339 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009340 if (isinstance == -1) {
9341 return 1;
9342 }
9343 if (isinstance) {
9344 identifier id;
9345 expr_context_ty ctx;
9346
Victor Stinner74419f02020-07-03 11:35:37 +02009347 if (_PyObject_LookupAttr(obj, state->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009348 return 1;
9349 }
9350 if (tmp == NULL) {
9351 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
9352 return 1;
9353 }
9354 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009355 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009356 if (Py_EnterRecursiveCall(" while traversing 'Name' node")) {
9357 goto failed;
9358 }
Victor Stinner74419f02020-07-03 11:35:37 +02009359 res = obj2ast_identifier(state, tmp, &id, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009360 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009361 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009362 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009363 }
Victor Stinner74419f02020-07-03 11:35:37 +02009364 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009365 return 1;
9366 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009367 if (tmp == NULL) {
9368 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
9369 return 1;
9370 }
9371 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009372 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009373 if (Py_EnterRecursiveCall(" while traversing 'Name' node")) {
9374 goto failed;
9375 }
Victor Stinner74419f02020-07-03 11:35:37 +02009376 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009377 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009378 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009379 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009380 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009381 *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
9382 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009383 if (*out == NULL) goto failed;
9384 return 0;
9385 }
Victor Stinner74419f02020-07-03 11:35:37 +02009386 tp = state->List_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009387 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009388 if (isinstance == -1) {
9389 return 1;
9390 }
9391 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01009392 asdl_expr_seq* elts;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009393 expr_context_ty ctx;
9394
Victor Stinner74419f02020-07-03 11:35:37 +02009395 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009396 return 1;
9397 }
9398 if (tmp == NULL) {
9399 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
9400 return 1;
9401 }
9402 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009403 int res;
9404 Py_ssize_t len;
9405 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009406 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009407 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 +02009408 goto failed;
9409 }
9410 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01009411 elts = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009412 if (elts == NULL) goto failed;
9413 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009414 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009415 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9416 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009417 if (Py_EnterRecursiveCall(" while traversing 'List' node")) {
9418 goto failed;
9419 }
Victor Stinner74419f02020-07-03 11:35:37 +02009420 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009421 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009422 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009423 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009424 if (len != PyList_GET_SIZE(tmp)) {
9425 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
9426 goto failed;
9427 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009428 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009429 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009430 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009431 }
Victor Stinner74419f02020-07-03 11:35:37 +02009432 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009433 return 1;
9434 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009435 if (tmp == NULL) {
9436 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
9437 return 1;
9438 }
9439 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009440 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009441 if (Py_EnterRecursiveCall(" while traversing 'List' node")) {
9442 goto failed;
9443 }
Victor Stinner74419f02020-07-03 11:35:37 +02009444 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009445 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009446 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009447 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009448 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009449 *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
9450 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009451 if (*out == NULL) goto failed;
9452 return 0;
9453 }
Victor Stinner74419f02020-07-03 11:35:37 +02009454 tp = state->Tuple_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009455 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009456 if (isinstance == -1) {
9457 return 1;
9458 }
9459 if (isinstance) {
Pablo Galindoa5634c42020-09-16 19:42:00 +01009460 asdl_expr_seq* elts;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009461 expr_context_ty ctx;
9462
Victor Stinner74419f02020-07-03 11:35:37 +02009463 if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009464 return 1;
9465 }
9466 if (tmp == NULL) {
9467 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
9468 return 1;
9469 }
9470 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009471 int res;
9472 Py_ssize_t len;
9473 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009474 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009475 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 +02009476 goto failed;
9477 }
9478 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01009479 elts = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009480 if (elts == NULL) goto failed;
9481 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009482 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009483 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9484 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009485 if (Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
9486 goto failed;
9487 }
Victor Stinner74419f02020-07-03 11:35:37 +02009488 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009489 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009490 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009491 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009492 if (len != PyList_GET_SIZE(tmp)) {
9493 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
9494 goto failed;
9495 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009496 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009497 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009498 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009499 }
Victor Stinner74419f02020-07-03 11:35:37 +02009500 if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009501 return 1;
9502 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009503 if (tmp == NULL) {
9504 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
9505 return 1;
9506 }
9507 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009508 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009509 if (Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
9510 goto failed;
9511 }
Victor Stinner74419f02020-07-03 11:35:37 +02009512 res = obj2ast_expr_context(state, tmp, &ctx, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009513 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009514 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009515 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009516 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009517 *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
9518 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009519 if (*out == NULL) goto failed;
9520 return 0;
9521 }
Victor Stinner74419f02020-07-03 11:35:37 +02009522 tp = state->Slice_type;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009523 isinstance = PyObject_IsInstance(obj, tp);
9524 if (isinstance == -1) {
9525 return 1;
9526 }
9527 if (isinstance) {
9528 expr_ty lower;
9529 expr_ty upper;
9530 expr_ty step;
9531
Victor Stinner74419f02020-07-03 11:35:37 +02009532 if (_PyObject_LookupAttr(obj, state->lower, &tmp) < 0) {
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009533 return 1;
9534 }
9535 if (tmp == NULL || tmp == Py_None) {
9536 Py_CLEAR(tmp);
9537 lower = NULL;
9538 }
9539 else {
9540 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009541 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9542 goto failed;
9543 }
Victor Stinner74419f02020-07-03 11:35:37 +02009544 res = obj2ast_expr(state, tmp, &lower, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009545 Py_LeaveRecursiveCall();
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009546 if (res != 0) goto failed;
9547 Py_CLEAR(tmp);
9548 }
Victor Stinner74419f02020-07-03 11:35:37 +02009549 if (_PyObject_LookupAttr(obj, state->upper, &tmp) < 0) {
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009550 return 1;
9551 }
9552 if (tmp == NULL || tmp == Py_None) {
9553 Py_CLEAR(tmp);
9554 upper = NULL;
9555 }
9556 else {
9557 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009558 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9559 goto failed;
9560 }
Victor Stinner74419f02020-07-03 11:35:37 +02009561 res = obj2ast_expr(state, tmp, &upper, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009562 Py_LeaveRecursiveCall();
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009563 if (res != 0) goto failed;
9564 Py_CLEAR(tmp);
9565 }
Victor Stinner74419f02020-07-03 11:35:37 +02009566 if (_PyObject_LookupAttr(obj, state->step, &tmp) < 0) {
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009567 return 1;
9568 }
9569 if (tmp == NULL || tmp == Py_None) {
9570 Py_CLEAR(tmp);
9571 step = NULL;
9572 }
9573 else {
9574 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009575 if (Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
9576 goto failed;
9577 }
Victor Stinner74419f02020-07-03 11:35:37 +02009578 res = obj2ast_expr(state, tmp, &step, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009579 Py_LeaveRecursiveCall();
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009580 if (res != 0) goto failed;
9581 Py_CLEAR(tmp);
9582 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +02009583 *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
9584 end_col_offset, arena);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02009585 if (*out == NULL) goto failed;
9586 return 0;
9587 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009588
9589 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
9590 failed:
9591 Py_XDECREF(tmp);
9592 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009593}
9594
9595int
Victor Stinner5cf47822020-11-02 22:03:28 +01009596obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
Victor Stinner74419f02020-07-03 11:35:37 +02009597 out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009598{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009599 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009600
Victor Stinner74419f02020-07-03 11:35:37 +02009601 isinstance = PyObject_IsInstance(obj, state->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009602 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009603 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009604 }
9605 if (isinstance) {
9606 *out = Load;
9607 return 0;
9608 }
Victor Stinner74419f02020-07-03 11:35:37 +02009609 isinstance = PyObject_IsInstance(obj, state->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009610 if (isinstance == -1) {
9611 return 1;
9612 }
9613 if (isinstance) {
9614 *out = Store;
9615 return 0;
9616 }
Victor Stinner74419f02020-07-03 11:35:37 +02009617 isinstance = PyObject_IsInstance(obj, state->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009618 if (isinstance == -1) {
9619 return 1;
9620 }
9621 if (isinstance) {
9622 *out = Del;
9623 return 0;
9624 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009625
9626 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
9627 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009628}
9629
9630int
Victor Stinner5cf47822020-11-02 22:03:28 +01009631obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
Victor Stinner74419f02020-07-03 11:35:37 +02009632 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009633{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009634 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009635
Victor Stinner74419f02020-07-03 11:35:37 +02009636 isinstance = PyObject_IsInstance(obj, state->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009637 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009638 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009639 }
9640 if (isinstance) {
9641 *out = And;
9642 return 0;
9643 }
Victor Stinner74419f02020-07-03 11:35:37 +02009644 isinstance = PyObject_IsInstance(obj, state->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009645 if (isinstance == -1) {
9646 return 1;
9647 }
9648 if (isinstance) {
9649 *out = Or;
9650 return 0;
9651 }
9652
9653 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
9654 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009655}
9656
9657int
Victor Stinner5cf47822020-11-02 22:03:28 +01009658obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +02009659 PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009660{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009661 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009662
Victor Stinner74419f02020-07-03 11:35:37 +02009663 isinstance = PyObject_IsInstance(obj, state->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009664 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009665 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009666 }
9667 if (isinstance) {
9668 *out = Add;
9669 return 0;
9670 }
Victor Stinner74419f02020-07-03 11:35:37 +02009671 isinstance = PyObject_IsInstance(obj, state->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009672 if (isinstance == -1) {
9673 return 1;
9674 }
9675 if (isinstance) {
9676 *out = Sub;
9677 return 0;
9678 }
Victor Stinner74419f02020-07-03 11:35:37 +02009679 isinstance = PyObject_IsInstance(obj, state->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009680 if (isinstance == -1) {
9681 return 1;
9682 }
9683 if (isinstance) {
9684 *out = Mult;
9685 return 0;
9686 }
Victor Stinner74419f02020-07-03 11:35:37 +02009687 isinstance = PyObject_IsInstance(obj, state->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04009688 if (isinstance == -1) {
9689 return 1;
9690 }
9691 if (isinstance) {
9692 *out = MatMult;
9693 return 0;
9694 }
Victor Stinner74419f02020-07-03 11:35:37 +02009695 isinstance = PyObject_IsInstance(obj, state->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009696 if (isinstance == -1) {
9697 return 1;
9698 }
9699 if (isinstance) {
9700 *out = Div;
9701 return 0;
9702 }
Victor Stinner74419f02020-07-03 11:35:37 +02009703 isinstance = PyObject_IsInstance(obj, state->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009704 if (isinstance == -1) {
9705 return 1;
9706 }
9707 if (isinstance) {
9708 *out = Mod;
9709 return 0;
9710 }
Victor Stinner74419f02020-07-03 11:35:37 +02009711 isinstance = PyObject_IsInstance(obj, state->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009712 if (isinstance == -1) {
9713 return 1;
9714 }
9715 if (isinstance) {
9716 *out = Pow;
9717 return 0;
9718 }
Victor Stinner74419f02020-07-03 11:35:37 +02009719 isinstance = PyObject_IsInstance(obj, state->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009720 if (isinstance == -1) {
9721 return 1;
9722 }
9723 if (isinstance) {
9724 *out = LShift;
9725 return 0;
9726 }
Victor Stinner74419f02020-07-03 11:35:37 +02009727 isinstance = PyObject_IsInstance(obj, state->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009728 if (isinstance == -1) {
9729 return 1;
9730 }
9731 if (isinstance) {
9732 *out = RShift;
9733 return 0;
9734 }
Victor Stinner74419f02020-07-03 11:35:37 +02009735 isinstance = PyObject_IsInstance(obj, state->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009736 if (isinstance == -1) {
9737 return 1;
9738 }
9739 if (isinstance) {
9740 *out = BitOr;
9741 return 0;
9742 }
Victor Stinner74419f02020-07-03 11:35:37 +02009743 isinstance = PyObject_IsInstance(obj, state->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009744 if (isinstance == -1) {
9745 return 1;
9746 }
9747 if (isinstance) {
9748 *out = BitXor;
9749 return 0;
9750 }
Victor Stinner74419f02020-07-03 11:35:37 +02009751 isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009752 if (isinstance == -1) {
9753 return 1;
9754 }
9755 if (isinstance) {
9756 *out = BitAnd;
9757 return 0;
9758 }
Victor Stinner74419f02020-07-03 11:35:37 +02009759 isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009760 if (isinstance == -1) {
9761 return 1;
9762 }
9763 if (isinstance) {
9764 *out = FloorDiv;
9765 return 0;
9766 }
9767
9768 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
9769 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009770}
9771
9772int
Victor Stinner5cf47822020-11-02 22:03:28 +01009773obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
9774 PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009775{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009776 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009777
Victor Stinner74419f02020-07-03 11:35:37 +02009778 isinstance = PyObject_IsInstance(obj, state->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009779 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009780 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009781 }
9782 if (isinstance) {
9783 *out = Invert;
9784 return 0;
9785 }
Victor Stinner74419f02020-07-03 11:35:37 +02009786 isinstance = PyObject_IsInstance(obj, state->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009787 if (isinstance == -1) {
9788 return 1;
9789 }
9790 if (isinstance) {
9791 *out = Not;
9792 return 0;
9793 }
Victor Stinner74419f02020-07-03 11:35:37 +02009794 isinstance = PyObject_IsInstance(obj, state->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009795 if (isinstance == -1) {
9796 return 1;
9797 }
9798 if (isinstance) {
9799 *out = UAdd;
9800 return 0;
9801 }
Victor Stinner74419f02020-07-03 11:35:37 +02009802 isinstance = PyObject_IsInstance(obj, state->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009803 if (isinstance == -1) {
9804 return 1;
9805 }
9806 if (isinstance) {
9807 *out = USub;
9808 return 0;
9809 }
9810
9811 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9812 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009813}
9814
9815int
Victor Stinner5cf47822020-11-02 22:03:28 +01009816obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
Victor Stinner74419f02020-07-03 11:35:37 +02009817 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009818{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009819 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009820
Victor Stinner74419f02020-07-03 11:35:37 +02009821 isinstance = PyObject_IsInstance(obj, state->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009822 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009823 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009824 }
9825 if (isinstance) {
9826 *out = Eq;
9827 return 0;
9828 }
Victor Stinner74419f02020-07-03 11:35:37 +02009829 isinstance = PyObject_IsInstance(obj, state->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009830 if (isinstance == -1) {
9831 return 1;
9832 }
9833 if (isinstance) {
9834 *out = NotEq;
9835 return 0;
9836 }
Victor Stinner74419f02020-07-03 11:35:37 +02009837 isinstance = PyObject_IsInstance(obj, state->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009838 if (isinstance == -1) {
9839 return 1;
9840 }
9841 if (isinstance) {
9842 *out = Lt;
9843 return 0;
9844 }
Victor Stinner74419f02020-07-03 11:35:37 +02009845 isinstance = PyObject_IsInstance(obj, state->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009846 if (isinstance == -1) {
9847 return 1;
9848 }
9849 if (isinstance) {
9850 *out = LtE;
9851 return 0;
9852 }
Victor Stinner74419f02020-07-03 11:35:37 +02009853 isinstance = PyObject_IsInstance(obj, state->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009854 if (isinstance == -1) {
9855 return 1;
9856 }
9857 if (isinstance) {
9858 *out = Gt;
9859 return 0;
9860 }
Victor Stinner74419f02020-07-03 11:35:37 +02009861 isinstance = PyObject_IsInstance(obj, state->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009862 if (isinstance == -1) {
9863 return 1;
9864 }
9865 if (isinstance) {
9866 *out = GtE;
9867 return 0;
9868 }
Victor Stinner74419f02020-07-03 11:35:37 +02009869 isinstance = PyObject_IsInstance(obj, state->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009870 if (isinstance == -1) {
9871 return 1;
9872 }
9873 if (isinstance) {
9874 *out = Is;
9875 return 0;
9876 }
Victor Stinner74419f02020-07-03 11:35:37 +02009877 isinstance = PyObject_IsInstance(obj, state->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009878 if (isinstance == -1) {
9879 return 1;
9880 }
9881 if (isinstance) {
9882 *out = IsNot;
9883 return 0;
9884 }
Victor Stinner74419f02020-07-03 11:35:37 +02009885 isinstance = PyObject_IsInstance(obj, state->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009886 if (isinstance == -1) {
9887 return 1;
9888 }
9889 if (isinstance) {
9890 *out = In;
9891 return 0;
9892 }
Victor Stinner74419f02020-07-03 11:35:37 +02009893 isinstance = PyObject_IsInstance(obj, state->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009894 if (isinstance == -1) {
9895 return 1;
9896 }
9897 if (isinstance) {
9898 *out = NotIn;
9899 return 0;
9900 }
9901
9902 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9903 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009904}
9905
9906int
Victor Stinner5cf47822020-11-02 22:03:28 +01009907obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
Victor Stinner74419f02020-07-03 11:35:37 +02009908 out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009909{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009910 PyObject* tmp = NULL;
9911 expr_ty target;
9912 expr_ty iter;
Pablo Galindoa5634c42020-09-16 19:42:00 +01009913 asdl_expr_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009914 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009915
Victor Stinner74419f02020-07-03 11:35:37 +02009916 if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009917 return 1;
9918 }
9919 if (tmp == NULL) {
9920 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9921 return 1;
9922 }
9923 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009924 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009925 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9926 goto failed;
9927 }
Victor Stinner74419f02020-07-03 11:35:37 +02009928 res = obj2ast_expr(state, tmp, &target, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009929 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009930 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009931 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009932 }
Victor Stinner74419f02020-07-03 11:35:37 +02009933 if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009934 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009935 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009936 if (tmp == NULL) {
9937 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9938 return 1;
9939 }
9940 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009941 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009942 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9943 goto failed;
9944 }
Victor Stinner74419f02020-07-03 11:35:37 +02009945 res = obj2ast_expr(state, tmp, &iter, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009946 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009947 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009948 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009949 }
Victor Stinner74419f02020-07-03 11:35:37 +02009950 if (_PyObject_LookupAttr(obj, state->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009951 return 1;
9952 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009953 if (tmp == NULL) {
9954 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9955 return 1;
9956 }
9957 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009958 int res;
9959 Py_ssize_t len;
9960 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009961 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009962 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 +02009963 goto failed;
9964 }
9965 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +01009966 ifs = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009967 if (ifs == NULL) goto failed;
9968 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009969 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009970 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9971 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009972 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9973 goto failed;
9974 }
Victor Stinner74419f02020-07-03 11:35:37 +02009975 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009976 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009977 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009978 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009979 if (len != PyList_GET_SIZE(tmp)) {
9980 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9981 goto failed;
9982 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009983 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009984 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009985 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009986 }
Victor Stinner74419f02020-07-03 11:35:37 +02009987 if (_PyObject_LookupAttr(obj, state->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009988 return 1;
9989 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009990 if (tmp == NULL) {
9991 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9992 return 1;
9993 }
9994 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009995 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -07009996 if (Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
9997 goto failed;
9998 }
Victor Stinner74419f02020-07-03 11:35:37 +02009999 res = obj2ast_int(state, tmp, &is_async, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010000 Py_LeaveRecursiveCall();
Yury Selivanov52c4e7c2016-09-09 10:36:01 -070010001 if (res != 0) goto failed;
10002 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -070010003 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010004 *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010005 return 0;
10006failed:
10007 Py_XDECREF(tmp);
10008 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010009}
10010
10011int
Victor Stinner5cf47822020-11-02 22:03:28 +010010012obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
Victor Stinner74419f02020-07-03 11:35:37 +020010013 out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010014{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010015 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +000010016
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010017 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010018 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010019 int lineno;
10020 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010021 int end_lineno;
10022 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010023
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010024 if (obj == Py_None) {
10025 *out = NULL;
10026 return 0;
10027 }
Victor Stinner74419f02020-07-03 11:35:37 +020010028 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010029 return 1;
10030 }
10031 if (tmp == NULL) {
10032 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
10033 return 1;
10034 }
10035 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010036 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010037 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10038 goto failed;
10039 }
Victor Stinner74419f02020-07-03 11:35:37 +020010040 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010041 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010042 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010043 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010044 }
Victor Stinner74419f02020-07-03 11:35:37 +020010045 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010046 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010047 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010048 if (tmp == NULL) {
10049 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
10050 return 1;
10051 }
10052 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010053 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010054 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10055 goto failed;
10056 }
Victor Stinner74419f02020-07-03 11:35:37 +020010057 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010058 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010059 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010060 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010061 }
Victor Stinner74419f02020-07-03 11:35:37 +020010062 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010063 return 1;
10064 }
10065 if (tmp == NULL || tmp == Py_None) {
10066 Py_CLEAR(tmp);
10067 end_lineno = 0;
10068 }
10069 else {
10070 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010071 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10072 goto failed;
10073 }
Victor Stinner74419f02020-07-03 11:35:37 +020010074 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010075 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010076 if (res != 0) goto failed;
10077 Py_CLEAR(tmp);
10078 }
Victor Stinner74419f02020-07-03 11:35:37 +020010079 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010080 return 1;
10081 }
10082 if (tmp == NULL || tmp == Py_None) {
10083 Py_CLEAR(tmp);
10084 end_col_offset = 0;
10085 }
10086 else {
10087 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010088 if (Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
10089 goto failed;
10090 }
Victor Stinner74419f02020-07-03 11:35:37 +020010091 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010092 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010093 if (res != 0) goto failed;
10094 Py_CLEAR(tmp);
10095 }
Victor Stinner74419f02020-07-03 11:35:37 +020010096 tp = state->ExceptHandler_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010097 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010098 if (isinstance == -1) {
10099 return 1;
10100 }
10101 if (isinstance) {
10102 expr_ty type;
10103 identifier name;
Pablo Galindoa5634c42020-09-16 19:42:00 +010010104 asdl_stmt_seq* body;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010105
Victor Stinner74419f02020-07-03 11:35:37 +020010106 if (_PyObject_LookupAttr(obj, state->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010107 return 1;
10108 }
10109 if (tmp == NULL || tmp == Py_None) {
10110 Py_CLEAR(tmp);
10111 type = NULL;
10112 }
10113 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010114 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010115 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10116 goto failed;
10117 }
Victor Stinner74419f02020-07-03 11:35:37 +020010118 res = obj2ast_expr(state, tmp, &type, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010119 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010120 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010121 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010122 }
Victor Stinner74419f02020-07-03 11:35:37 +020010123 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010124 return 1;
10125 }
10126 if (tmp == NULL || tmp == Py_None) {
10127 Py_CLEAR(tmp);
10128 name = NULL;
10129 }
10130 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010131 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010132 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10133 goto failed;
10134 }
Victor Stinner74419f02020-07-03 11:35:37 +020010135 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010136 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010137 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010138 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010139 }
Victor Stinner74419f02020-07-03 11:35:37 +020010140 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010141 return 1;
10142 }
10143 if (tmp == NULL) {
10144 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
10145 return 1;
10146 }
10147 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010148 int res;
10149 Py_ssize_t len;
10150 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010151 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010152 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 +020010153 goto failed;
10154 }
10155 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010156 body = _Py_asdl_stmt_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010157 if (body == NULL) goto failed;
10158 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010159 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010160 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10161 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010162 if (Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
10163 goto failed;
10164 }
Victor Stinner74419f02020-07-03 11:35:37 +020010165 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010166 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010167 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010168 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +030010169 if (len != PyList_GET_SIZE(tmp)) {
10170 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
10171 goto failed;
10172 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010173 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010174 }
Victor Stinner1acc1292013-07-27 00:03:47 +020010175 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010176 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010177 *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
10178 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010179 if (*out == NULL) goto failed;
10180 return 0;
10181 }
10182
10183 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
10184 failed:
10185 Py_XDECREF(tmp);
10186 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010187}
10188
10189int
Victor Stinner5cf47822020-11-02 22:03:28 +010010190obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +020010191 PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010192{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010193 PyObject* tmp = NULL;
Pablo Galindoa5634c42020-09-16 19:42:00 +010010194 asdl_arg_seq* posonlyargs;
10195 asdl_arg_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +020010196 arg_ty vararg;
Pablo Galindoa5634c42020-09-16 19:42:00 +010010197 asdl_arg_seq* kwonlyargs;
10198 asdl_expr_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +020010199 arg_ty kwarg;
Pablo Galindoa5634c42020-09-16 19:42:00 +010010200 asdl_expr_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010201
Victor Stinner74419f02020-07-03 11:35:37 +020010202 if (_PyObject_LookupAttr(obj, state->posonlyargs, &tmp) < 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +010010203 return 1;
10204 }
10205 if (tmp == NULL) {
10206 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
10207 return 1;
10208 }
10209 else {
10210 int res;
10211 Py_ssize_t len;
10212 Py_ssize_t i;
10213 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010214 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 +010010215 goto failed;
10216 }
10217 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010218 posonlyargs = _Py_asdl_arg_seq_new(len, arena);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +010010219 if (posonlyargs == NULL) goto failed;
10220 for (i = 0; i < len; i++) {
10221 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010222 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10223 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010224 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10225 goto failed;
10226 }
Victor Stinner74419f02020-07-03 11:35:37 +020010227 res = obj2ast_arg(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010228 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010229 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +010010230 if (res != 0) goto failed;
10231 if (len != PyList_GET_SIZE(tmp)) {
10232 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
10233 goto failed;
10234 }
10235 asdl_seq_SET(posonlyargs, i, val);
10236 }
10237 Py_CLEAR(tmp);
10238 }
Victor Stinner74419f02020-07-03 11:35:37 +020010239 if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +020010240 return 1;
10241 }
10242 if (tmp == NULL) {
10243 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
10244 return 1;
10245 }
10246 else {
10247 int res;
10248 Py_ssize_t len;
10249 Py_ssize_t i;
10250 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010251 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 +020010252 goto failed;
10253 }
10254 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010255 args = _Py_asdl_arg_seq_new(len, arena);
Pablo Galindocd6e83b2019-07-15 01:32:18 +020010256 if (args == NULL) goto failed;
10257 for (i = 0; i < len; i++) {
10258 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010259 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10260 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010261 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10262 goto failed;
10263 }
Victor Stinner74419f02020-07-03 11:35:37 +020010264 res = obj2ast_arg(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010265 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010266 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +020010267 if (res != 0) goto failed;
10268 if (len != PyList_GET_SIZE(tmp)) {
10269 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
10270 goto failed;
10271 }
10272 asdl_seq_SET(args, i, val);
10273 }
10274 Py_CLEAR(tmp);
10275 }
Victor Stinner74419f02020-07-03 11:35:37 +020010276 if (_PyObject_LookupAttr(obj, state->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010277 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010278 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010279 if (tmp == NULL || tmp == Py_None) {
10280 Py_CLEAR(tmp);
10281 vararg = NULL;
10282 }
10283 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010284 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010285 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10286 goto failed;
10287 }
Victor Stinner74419f02020-07-03 11:35:37 +020010288 res = obj2ast_arg(state, tmp, &vararg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010289 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010290 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010291 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010292 }
Victor Stinner74419f02020-07-03 11:35:37 +020010293 if (_PyObject_LookupAttr(obj, state->kwonlyargs, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010294 return 1;
10295 }
10296 if (tmp == NULL) {
10297 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
10298 return 1;
10299 }
10300 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010301 int res;
10302 Py_ssize_t len;
10303 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010304 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010305 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 +020010306 goto failed;
10307 }
10308 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010309 kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010310 if (kwonlyargs == NULL) goto failed;
10311 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010312 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010313 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10314 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010315 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10316 goto failed;
10317 }
Victor Stinner74419f02020-07-03 11:35:37 +020010318 res = obj2ast_arg(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010319 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010320 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010321 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +030010322 if (len != PyList_GET_SIZE(tmp)) {
10323 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
10324 goto failed;
10325 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010326 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010327 }
Victor Stinner1acc1292013-07-27 00:03:47 +020010328 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010329 }
Victor Stinner74419f02020-07-03 11:35:37 +020010330 if (_PyObject_LookupAttr(obj, state->kw_defaults, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010331 return 1;
10332 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010333 if (tmp == NULL) {
10334 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
10335 return 1;
10336 }
10337 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010338 int res;
10339 Py_ssize_t len;
10340 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010341 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010342 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 +020010343 goto failed;
10344 }
10345 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010346 kw_defaults = _Py_asdl_expr_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010347 if (kw_defaults == NULL) goto failed;
10348 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010349 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010350 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10351 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010352 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10353 goto failed;
10354 }
Victor Stinner74419f02020-07-03 11:35:37 +020010355 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010356 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010357 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010358 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +030010359 if (len != PyList_GET_SIZE(tmp)) {
10360 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
10361 goto failed;
10362 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010363 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010364 }
Victor Stinner1acc1292013-07-27 00:03:47 +020010365 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010366 }
Victor Stinner74419f02020-07-03 11:35:37 +020010367 if (_PyObject_LookupAttr(obj, state->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010368 return 1;
10369 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010370 if (tmp == NULL || tmp == Py_None) {
10371 Py_CLEAR(tmp);
10372 kwarg = NULL;
10373 }
10374 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +020010375 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010376 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10377 goto failed;
10378 }
Victor Stinner74419f02020-07-03 11:35:37 +020010379 res = obj2ast_arg(state, tmp, &kwarg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010380 Py_LeaveRecursiveCall();
Victor Stinneree4b59c2013-07-27 00:01:35 +020010381 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +020010382 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010383 }
Victor Stinner74419f02020-07-03 11:35:37 +020010384 if (_PyObject_LookupAttr(obj, state->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010385 return 1;
10386 }
10387 if (tmp == NULL) {
10388 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
10389 return 1;
10390 }
10391 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +020010392 int res;
10393 Py_ssize_t len;
10394 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +020010395 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -070010396 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 +020010397 goto failed;
10398 }
10399 len = PyList_GET_SIZE(tmp);
Pablo Galindoa5634c42020-09-16 19:42:00 +010010400 defaults = _Py_asdl_expr_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010401 if (defaults == NULL) goto failed;
10402 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010403 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010404 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10405 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010406 if (Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
10407 goto failed;
10408 }
Victor Stinner74419f02020-07-03 11:35:37 +020010409 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010410 Py_LeaveRecursiveCall();
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010411 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010412 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +030010413 if (len != PyList_GET_SIZE(tmp)) {
10414 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
10415 goto failed;
10416 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -070010417 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010418 }
Victor Stinnerb3189902013-07-27 00:04:42 +020010419 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +020010420 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010421 *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
10422 kwarg, defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010423 return 0;
10424failed:
10425 Py_XDECREF(tmp);
10426 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010427}
10428
10429int
Victor Stinner5cf47822020-11-02 22:03:28 +010010430obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010431{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010432 PyObject* tmp = NULL;
10433 identifier arg;
10434 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -080010435 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +010010436 int lineno;
10437 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010438 int end_lineno;
10439 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010440
Victor Stinner74419f02020-07-03 11:35:37 +020010441 if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010442 return 1;
10443 }
10444 if (tmp == NULL) {
10445 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
10446 return 1;
10447 }
10448 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010449 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010450 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10451 goto failed;
10452 }
Victor Stinner74419f02020-07-03 11:35:37 +020010453 res = obj2ast_identifier(state, tmp, &arg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010454 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010455 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010456 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010457 }
Victor Stinner74419f02020-07-03 11:35:37 +020010458 if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010459 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010460 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010461 if (tmp == NULL || tmp == Py_None) {
10462 Py_CLEAR(tmp);
10463 annotation = NULL;
10464 }
10465 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010466 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010467 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10468 goto failed;
10469 }
Victor Stinner74419f02020-07-03 11:35:37 +020010470 res = obj2ast_expr(state, tmp, &annotation, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010471 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010472 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010473 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010474 }
Victor Stinner74419f02020-07-03 11:35:37 +020010475 if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -080010476 return 1;
10477 }
10478 if (tmp == NULL || tmp == Py_None) {
10479 Py_CLEAR(tmp);
10480 type_comment = NULL;
10481 }
10482 else {
10483 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010484 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10485 goto failed;
10486 }
Victor Stinner74419f02020-07-03 11:35:37 +020010487 res = obj2ast_string(state, tmp, &type_comment, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010488 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -080010489 if (res != 0) goto failed;
10490 Py_CLEAR(tmp);
10491 }
Victor Stinner74419f02020-07-03 11:35:37 +020010492 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010493 return 1;
10494 }
10495 if (tmp == NULL) {
10496 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
10497 return 1;
10498 }
10499 else {
Victor Stinnerc106c682015-11-06 17:01:48 +010010500 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010501 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10502 goto failed;
10503 }
Victor Stinner74419f02020-07-03 11:35:37 +020010504 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010505 Py_LeaveRecursiveCall();
Victor Stinnerc106c682015-11-06 17:01:48 +010010506 if (res != 0) goto failed;
10507 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010508 }
Victor Stinner74419f02020-07-03 11:35:37 +020010509 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Victor Stinnerc106c682015-11-06 17:01:48 +010010510 return 1;
10511 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010512 if (tmp == NULL) {
10513 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
10514 return 1;
10515 }
10516 else {
Victor Stinnerc106c682015-11-06 17:01:48 +010010517 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010518 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10519 goto failed;
10520 }
Victor Stinner74419f02020-07-03 11:35:37 +020010521 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010522 Py_LeaveRecursiveCall();
Victor Stinnerc106c682015-11-06 17:01:48 +010010523 if (res != 0) goto failed;
10524 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +010010525 }
Victor Stinner74419f02020-07-03 11:35:37 +020010526 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010527 return 1;
10528 }
10529 if (tmp == NULL || tmp == Py_None) {
10530 Py_CLEAR(tmp);
10531 end_lineno = 0;
10532 }
10533 else {
10534 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010535 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10536 goto failed;
10537 }
Victor Stinner74419f02020-07-03 11:35:37 +020010538 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010539 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010540 if (res != 0) goto failed;
10541 Py_CLEAR(tmp);
10542 }
Victor Stinner74419f02020-07-03 11:35:37 +020010543 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010544 return 1;
10545 }
10546 if (tmp == NULL || tmp == Py_None) {
10547 Py_CLEAR(tmp);
10548 end_col_offset = 0;
10549 }
10550 else {
10551 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010552 if (Py_EnterRecursiveCall(" while traversing 'arg' node")) {
10553 goto failed;
10554 }
Victor Stinner74419f02020-07-03 11:35:37 +020010555 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010556 Py_LeaveRecursiveCall();
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000010557 if (res != 0) goto failed;
10558 Py_CLEAR(tmp);
10559 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010560 *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
10561 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010562 return 0;
10563failed:
10564 Py_XDECREF(tmp);
10565 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010566}
10567
10568int
Victor Stinner5cf47822020-11-02 22:03:28 +010010569obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
10570 PyArena* arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010571{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010572 PyObject* tmp = NULL;
10573 identifier arg;
10574 expr_ty value;
Pablo Galindo168660b2020-04-02 00:47:39 +010010575 int lineno;
10576 int col_offset;
10577 int end_lineno;
10578 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010579
Victor Stinner74419f02020-07-03 11:35:37 +020010580 if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010581 return 1;
10582 }
10583 if (tmp == NULL || tmp == Py_None) {
10584 Py_CLEAR(tmp);
10585 arg = NULL;
10586 }
10587 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010588 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010589 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10590 goto failed;
10591 }
Victor Stinner74419f02020-07-03 11:35:37 +020010592 res = obj2ast_identifier(state, tmp, &arg, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010593 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010594 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010595 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010596 }
Victor Stinner74419f02020-07-03 11:35:37 +020010597 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010598 return 1;
10599 }
10600 if (tmp == NULL) {
10601 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
10602 return 1;
10603 }
10604 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010605 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010606 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10607 goto failed;
10608 }
Victor Stinner74419f02020-07-03 11:35:37 +020010609 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010610 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010611 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010612 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010613 }
Victor Stinner74419f02020-07-03 11:35:37 +020010614 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Pablo Galindo168660b2020-04-02 00:47:39 +010010615 return 1;
10616 }
10617 if (tmp == NULL) {
10618 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
10619 return 1;
10620 }
10621 else {
10622 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010623 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10624 goto failed;
10625 }
Victor Stinner74419f02020-07-03 11:35:37 +020010626 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010627 Py_LeaveRecursiveCall();
Pablo Galindo168660b2020-04-02 00:47:39 +010010628 if (res != 0) goto failed;
10629 Py_CLEAR(tmp);
10630 }
Victor Stinner74419f02020-07-03 11:35:37 +020010631 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
Pablo Galindo168660b2020-04-02 00:47:39 +010010632 return 1;
10633 }
10634 if (tmp == NULL) {
10635 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
10636 return 1;
10637 }
10638 else {
10639 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010640 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10641 goto failed;
10642 }
Victor Stinner74419f02020-07-03 11:35:37 +020010643 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010644 Py_LeaveRecursiveCall();
Pablo Galindo168660b2020-04-02 00:47:39 +010010645 if (res != 0) goto failed;
10646 Py_CLEAR(tmp);
10647 }
Victor Stinner74419f02020-07-03 11:35:37 +020010648 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
Pablo Galindo168660b2020-04-02 00:47:39 +010010649 return 1;
10650 }
10651 if (tmp == NULL || tmp == Py_None) {
10652 Py_CLEAR(tmp);
10653 end_lineno = 0;
10654 }
10655 else {
10656 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010657 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10658 goto failed;
10659 }
Victor Stinner74419f02020-07-03 11:35:37 +020010660 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010661 Py_LeaveRecursiveCall();
Pablo Galindo168660b2020-04-02 00:47:39 +010010662 if (res != 0) goto failed;
10663 Py_CLEAR(tmp);
10664 }
Victor Stinner74419f02020-07-03 11:35:37 +020010665 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
Pablo Galindo168660b2020-04-02 00:47:39 +010010666 return 1;
10667 }
10668 if (tmp == NULL || tmp == Py_None) {
10669 Py_CLEAR(tmp);
10670 end_col_offset = 0;
10671 }
10672 else {
10673 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010674 if (Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
10675 goto failed;
10676 }
Victor Stinner74419f02020-07-03 11:35:37 +020010677 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010678 Py_LeaveRecursiveCall();
Pablo Galindo168660b2020-04-02 00:47:39 +010010679 if (res != 0) goto failed;
10680 Py_CLEAR(tmp);
10681 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010682 *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
10683 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010684 return 0;
10685failed:
10686 Py_XDECREF(tmp);
10687 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010688}
10689
10690int
Victor Stinner5cf47822020-11-02 22:03:28 +010010691obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
Victor Stinner74419f02020-07-03 11:35:37 +020010692 arena)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010693{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010694 PyObject* tmp = NULL;
10695 identifier name;
10696 identifier asname;
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010697 int lineno;
10698 int col_offset;
10699 int end_lineno;
10700 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010701
Victor Stinner74419f02020-07-03 11:35:37 +020010702 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010703 return 1;
10704 }
10705 if (tmp == NULL) {
10706 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
10707 return 1;
10708 }
10709 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010710 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010711 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10712 goto failed;
10713 }
Victor Stinner74419f02020-07-03 11:35:37 +020010714 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010715 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010716 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010717 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010718 }
Victor Stinner74419f02020-07-03 11:35:37 +020010719 if (_PyObject_LookupAttr(obj, state->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010720 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010721 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010722 if (tmp == NULL || tmp == Py_None) {
10723 Py_CLEAR(tmp);
10724 asname = NULL;
10725 }
10726 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010727 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010728 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10729 goto failed;
10730 }
Victor Stinner74419f02020-07-03 11:35:37 +020010731 res = obj2ast_identifier(state, tmp, &asname, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010732 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010733 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010734 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010735 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010736 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10737 return 1;
10738 }
10739 if (tmp == NULL) {
10740 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
10741 return 1;
10742 }
10743 else {
10744 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010745 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10746 goto failed;
10747 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010748 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010749 Py_LeaveRecursiveCall();
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010750 if (res != 0) goto failed;
10751 Py_CLEAR(tmp);
10752 }
10753 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10754 return 1;
10755 }
10756 if (tmp == NULL) {
10757 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
10758 return 1;
10759 }
10760 else {
10761 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010762 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10763 goto failed;
10764 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010765 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010766 Py_LeaveRecursiveCall();
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010767 if (res != 0) goto failed;
10768 Py_CLEAR(tmp);
10769 }
10770 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
10771 return 1;
10772 }
10773 if (tmp == NULL || tmp == Py_None) {
10774 Py_CLEAR(tmp);
10775 end_lineno = 0;
10776 }
10777 else {
10778 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010779 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10780 goto failed;
10781 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010782 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010783 Py_LeaveRecursiveCall();
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010784 if (res != 0) goto failed;
10785 Py_CLEAR(tmp);
10786 }
10787 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
10788 return 1;
10789 }
10790 if (tmp == NULL || tmp == Py_None) {
10791 Py_CLEAR(tmp);
10792 end_col_offset = 0;
10793 }
10794 else {
10795 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010796 if (Py_EnterRecursiveCall(" while traversing 'alias' node")) {
10797 goto failed;
10798 }
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010799 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010800 Py_LeaveRecursiveCall();
Matthew Suozzo75a06f02021-04-10 16:56:28 -040010801 if (res != 0) goto failed;
10802 Py_CLEAR(tmp);
10803 }
10804 *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
10805 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010806 return 0;
10807failed:
10808 Py_XDECREF(tmp);
10809 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010810}
10811
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010812int
Victor Stinner5cf47822020-11-02 22:03:28 +010010813obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
Victor Stinner74419f02020-07-03 11:35:37 +020010814 PyArena* arena)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010815{
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010816 PyObject* tmp = NULL;
10817 expr_ty context_expr;
10818 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010819
Victor Stinner74419f02020-07-03 11:35:37 +020010820 if (_PyObject_LookupAttr(obj, state->context_expr, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010821 return 1;
10822 }
10823 if (tmp == NULL) {
10824 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
10825 return 1;
10826 }
10827 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010828 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010829 if (Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
10830 goto failed;
10831 }
Victor Stinner74419f02020-07-03 11:35:37 +020010832 res = obj2ast_expr(state, tmp, &context_expr, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010833 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010834 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010835 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010836 }
Victor Stinner74419f02020-07-03 11:35:37 +020010837 if (_PyObject_LookupAttr(obj, state->optional_vars, &tmp) < 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010838 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010839 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +020010840 if (tmp == NULL || tmp == Py_None) {
10841 Py_CLEAR(tmp);
10842 optional_vars = NULL;
10843 }
10844 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010845 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010846 if (Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
10847 goto failed;
10848 }
Victor Stinner74419f02020-07-03 11:35:37 +020010849 res = obj2ast_expr(state, tmp, &optional_vars, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010850 Py_LeaveRecursiveCall();
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010851 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +020010852 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010853 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010854 *out = _PyAST_withitem(context_expr, optional_vars, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010855 return 0;
10856failed:
10857 Py_XDECREF(tmp);
10858 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050010859}
10860
Guido van Rossumdcfcd142019-01-31 03:40:27 -080010861int
Brandt Bucher145bf262021-02-26 14:51:55 -080010862obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
10863 PyArena* arena)
10864{
10865 PyObject* tmp = NULL;
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010866 pattern_ty pattern;
Brandt Bucher145bf262021-02-26 14:51:55 -080010867 expr_ty guard;
10868 asdl_stmt_seq* body;
10869
10870 if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
10871 return 1;
10872 }
10873 if (tmp == NULL) {
10874 PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
10875 return 1;
10876 }
10877 else {
10878 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010879 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10880 goto failed;
10881 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010882 res = obj2ast_pattern(state, tmp, &pattern, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010883 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -080010884 if (res != 0) goto failed;
10885 Py_CLEAR(tmp);
10886 }
10887 if (_PyObject_LookupAttr(obj, state->guard, &tmp) < 0) {
10888 return 1;
10889 }
10890 if (tmp == NULL || tmp == Py_None) {
10891 Py_CLEAR(tmp);
10892 guard = NULL;
10893 }
10894 else {
10895 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010896 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10897 goto failed;
10898 }
Brandt Bucher145bf262021-02-26 14:51:55 -080010899 res = obj2ast_expr(state, tmp, &guard, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010900 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -080010901 if (res != 0) goto failed;
10902 Py_CLEAR(tmp);
10903 }
10904 if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
10905 return 1;
10906 }
10907 if (tmp == NULL) {
10908 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from match_case");
10909 return 1;
10910 }
10911 else {
10912 int res;
10913 Py_ssize_t len;
10914 Py_ssize_t i;
10915 if (!PyList_Check(tmp)) {
10916 PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
10917 goto failed;
10918 }
10919 len = PyList_GET_SIZE(tmp);
10920 body = _Py_asdl_stmt_seq_new(len, arena);
10921 if (body == NULL) goto failed;
10922 for (i = 0; i < len; i++) {
10923 stmt_ty val;
10924 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
10925 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010926 if (Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
10927 goto failed;
10928 }
Brandt Bucher145bf262021-02-26 14:51:55 -080010929 res = obj2ast_stmt(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010930 Py_LeaveRecursiveCall();
Brandt Bucher145bf262021-02-26 14:51:55 -080010931 Py_DECREF(tmp2);
10932 if (res != 0) goto failed;
10933 if (len != PyList_GET_SIZE(tmp)) {
10934 PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
10935 goto failed;
10936 }
10937 asdl_seq_SET(body, i, val);
10938 }
10939 Py_CLEAR(tmp);
10940 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020010941 *out = _PyAST_match_case(pattern, guard, body, arena);
Brandt Bucher145bf262021-02-26 14:51:55 -080010942 return 0;
10943failed:
10944 Py_XDECREF(tmp);
10945 return 1;
10946}
10947
10948int
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010949obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
10950 PyArena* arena)
10951{
10952 int isinstance;
10953
10954 PyObject *tmp = NULL;
10955 PyObject *tp;
10956 int lineno;
10957 int col_offset;
10958 int end_lineno;
10959 int end_col_offset;
10960
10961 if (obj == Py_None) {
10962 *out = NULL;
10963 return 0;
10964 }
10965 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
10966 return 1;
10967 }
10968 if (tmp == NULL) {
10969 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
10970 return 1;
10971 }
10972 else {
10973 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010974 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
10975 goto failed;
10976 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010977 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010978 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010979 if (res != 0) goto failed;
10980 Py_CLEAR(tmp);
10981 }
10982 if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
10983 return 1;
10984 }
10985 if (tmp == NULL) {
10986 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
10987 return 1;
10988 }
10989 else {
10990 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010991 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
10992 goto failed;
10993 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010994 res = obj2ast_int(state, tmp, &col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070010995 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100010996 if (res != 0) goto failed;
10997 Py_CLEAR(tmp);
10998 }
10999 if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
11000 return 1;
11001 }
11002 if (tmp == NULL) {
11003 PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
11004 return 1;
11005 }
11006 else {
11007 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011008 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11009 goto failed;
11010 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011011 res = obj2ast_int(state, tmp, &end_lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011012 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011013 if (res != 0) goto failed;
11014 Py_CLEAR(tmp);
11015 }
11016 if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
11017 return 1;
11018 }
11019 if (tmp == NULL) {
11020 PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
11021 return 1;
11022 }
11023 else {
11024 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011025 if (Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
11026 goto failed;
11027 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011028 res = obj2ast_int(state, tmp, &end_col_offset, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011029 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011030 if (res != 0) goto failed;
11031 Py_CLEAR(tmp);
11032 }
11033 tp = state->MatchValue_type;
11034 isinstance = PyObject_IsInstance(obj, tp);
11035 if (isinstance == -1) {
11036 return 1;
11037 }
11038 if (isinstance) {
11039 expr_ty value;
11040
11041 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11042 return 1;
11043 }
11044 if (tmp == NULL) {
11045 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
11046 return 1;
11047 }
11048 else {
11049 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011050 if (Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
11051 goto failed;
11052 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011053 res = obj2ast_expr(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011054 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011055 if (res != 0) goto failed;
11056 Py_CLEAR(tmp);
11057 }
11058 *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
11059 end_col_offset, arena);
11060 if (*out == NULL) goto failed;
11061 return 0;
11062 }
11063 tp = state->MatchSingleton_type;
11064 isinstance = PyObject_IsInstance(obj, tp);
11065 if (isinstance == -1) {
11066 return 1;
11067 }
11068 if (isinstance) {
11069 constant value;
11070
11071 if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
11072 return 1;
11073 }
11074 if (tmp == NULL) {
11075 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
11076 return 1;
11077 }
11078 else {
11079 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011080 if (Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
11081 goto failed;
11082 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011083 res = obj2ast_constant(state, tmp, &value, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011084 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011085 if (res != 0) goto failed;
11086 Py_CLEAR(tmp);
11087 }
11088 *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
11089 end_col_offset, arena);
11090 if (*out == NULL) goto failed;
11091 return 0;
11092 }
11093 tp = state->MatchSequence_type;
11094 isinstance = PyObject_IsInstance(obj, tp);
11095 if (isinstance == -1) {
11096 return 1;
11097 }
11098 if (isinstance) {
11099 asdl_pattern_seq* patterns;
11100
11101 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11102 return 1;
11103 }
11104 if (tmp == NULL) {
11105 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchSequence");
11106 return 1;
11107 }
11108 else {
11109 int res;
11110 Py_ssize_t len;
11111 Py_ssize_t i;
11112 if (!PyList_Check(tmp)) {
11113 PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11114 goto failed;
11115 }
11116 len = PyList_GET_SIZE(tmp);
11117 patterns = _Py_asdl_pattern_seq_new(len, arena);
11118 if (patterns == NULL) goto failed;
11119 for (i = 0; i < len; i++) {
11120 pattern_ty val;
11121 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11122 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011123 if (Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
11124 goto failed;
11125 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011126 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011127 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011128 Py_DECREF(tmp2);
11129 if (res != 0) goto failed;
11130 if (len != PyList_GET_SIZE(tmp)) {
11131 PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
11132 goto failed;
11133 }
11134 asdl_seq_SET(patterns, i, val);
11135 }
11136 Py_CLEAR(tmp);
11137 }
11138 *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
11139 end_col_offset, arena);
11140 if (*out == NULL) goto failed;
11141 return 0;
11142 }
11143 tp = state->MatchMapping_type;
11144 isinstance = PyObject_IsInstance(obj, tp);
11145 if (isinstance == -1) {
11146 return 1;
11147 }
11148 if (isinstance) {
11149 asdl_expr_seq* keys;
11150 asdl_pattern_seq* patterns;
11151 identifier rest;
11152
11153 if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
11154 return 1;
11155 }
11156 if (tmp == NULL) {
11157 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from MatchMapping");
11158 return 1;
11159 }
11160 else {
11161 int res;
11162 Py_ssize_t len;
11163 Py_ssize_t i;
11164 if (!PyList_Check(tmp)) {
11165 PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11166 goto failed;
11167 }
11168 len = PyList_GET_SIZE(tmp);
11169 keys = _Py_asdl_expr_seq_new(len, arena);
11170 if (keys == NULL) goto failed;
11171 for (i = 0; i < len; i++) {
11172 expr_ty val;
11173 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11174 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011175 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11176 goto failed;
11177 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011178 res = obj2ast_expr(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011179 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011180 Py_DECREF(tmp2);
11181 if (res != 0) goto failed;
11182 if (len != PyList_GET_SIZE(tmp)) {
11183 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
11184 goto failed;
11185 }
11186 asdl_seq_SET(keys, i, val);
11187 }
11188 Py_CLEAR(tmp);
11189 }
11190 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11191 return 1;
11192 }
11193 if (tmp == NULL) {
11194 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchMapping");
11195 return 1;
11196 }
11197 else {
11198 int res;
11199 Py_ssize_t len;
11200 Py_ssize_t i;
11201 if (!PyList_Check(tmp)) {
11202 PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11203 goto failed;
11204 }
11205 len = PyList_GET_SIZE(tmp);
11206 patterns = _Py_asdl_pattern_seq_new(len, arena);
11207 if (patterns == NULL) goto failed;
11208 for (i = 0; i < len; i++) {
11209 pattern_ty val;
11210 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11211 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011212 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11213 goto failed;
11214 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011215 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011216 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011217 Py_DECREF(tmp2);
11218 if (res != 0) goto failed;
11219 if (len != PyList_GET_SIZE(tmp)) {
11220 PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
11221 goto failed;
11222 }
11223 asdl_seq_SET(patterns, i, val);
11224 }
11225 Py_CLEAR(tmp);
11226 }
11227 if (_PyObject_LookupAttr(obj, state->rest, &tmp) < 0) {
11228 return 1;
11229 }
11230 if (tmp == NULL || tmp == Py_None) {
11231 Py_CLEAR(tmp);
11232 rest = NULL;
11233 }
11234 else {
11235 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011236 if (Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
11237 goto failed;
11238 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011239 res = obj2ast_identifier(state, tmp, &rest, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011240 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011241 if (res != 0) goto failed;
11242 Py_CLEAR(tmp);
11243 }
11244 *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
11245 end_lineno, end_col_offset, arena);
11246 if (*out == NULL) goto failed;
11247 return 0;
11248 }
11249 tp = state->MatchClass_type;
11250 isinstance = PyObject_IsInstance(obj, tp);
11251 if (isinstance == -1) {
11252 return 1;
11253 }
11254 if (isinstance) {
11255 expr_ty cls;
11256 asdl_pattern_seq* patterns;
11257 asdl_identifier_seq* kwd_attrs;
11258 asdl_pattern_seq* kwd_patterns;
11259
11260 if (_PyObject_LookupAttr(obj, state->cls, &tmp) < 0) {
11261 return 1;
11262 }
11263 if (tmp == NULL) {
11264 PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
11265 return 1;
11266 }
11267 else {
11268 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011269 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11270 goto failed;
11271 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011272 res = obj2ast_expr(state, tmp, &cls, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011273 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011274 if (res != 0) goto failed;
11275 Py_CLEAR(tmp);
11276 }
11277 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11278 return 1;
11279 }
11280 if (tmp == NULL) {
11281 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchClass");
11282 return 1;
11283 }
11284 else {
11285 int res;
11286 Py_ssize_t len;
11287 Py_ssize_t i;
11288 if (!PyList_Check(tmp)) {
11289 PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11290 goto failed;
11291 }
11292 len = PyList_GET_SIZE(tmp);
11293 patterns = _Py_asdl_pattern_seq_new(len, arena);
11294 if (patterns == NULL) goto failed;
11295 for (i = 0; i < len; i++) {
11296 pattern_ty val;
11297 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11298 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011299 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11300 goto failed;
11301 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011302 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011303 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011304 Py_DECREF(tmp2);
11305 if (res != 0) goto failed;
11306 if (len != PyList_GET_SIZE(tmp)) {
11307 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
11308 goto failed;
11309 }
11310 asdl_seq_SET(patterns, i, val);
11311 }
11312 Py_CLEAR(tmp);
11313 }
11314 if (_PyObject_LookupAttr(obj, state->kwd_attrs, &tmp) < 0) {
11315 return 1;
11316 }
11317 if (tmp == NULL) {
11318 PyErr_SetString(PyExc_TypeError, "required field \"kwd_attrs\" missing from MatchClass");
11319 return 1;
11320 }
11321 else {
11322 int res;
11323 Py_ssize_t len;
11324 Py_ssize_t i;
11325 if (!PyList_Check(tmp)) {
11326 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11327 goto failed;
11328 }
11329 len = PyList_GET_SIZE(tmp);
11330 kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
11331 if (kwd_attrs == NULL) goto failed;
11332 for (i = 0; i < len; i++) {
11333 identifier val;
11334 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11335 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011336 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11337 goto failed;
11338 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011339 res = obj2ast_identifier(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011340 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011341 Py_DECREF(tmp2);
11342 if (res != 0) goto failed;
11343 if (len != PyList_GET_SIZE(tmp)) {
11344 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
11345 goto failed;
11346 }
11347 asdl_seq_SET(kwd_attrs, i, val);
11348 }
11349 Py_CLEAR(tmp);
11350 }
11351 if (_PyObject_LookupAttr(obj, state->kwd_patterns, &tmp) < 0) {
11352 return 1;
11353 }
11354 if (tmp == NULL) {
11355 PyErr_SetString(PyExc_TypeError, "required field \"kwd_patterns\" missing from MatchClass");
11356 return 1;
11357 }
11358 else {
11359 int res;
11360 Py_ssize_t len;
11361 Py_ssize_t i;
11362 if (!PyList_Check(tmp)) {
11363 PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11364 goto failed;
11365 }
11366 len = PyList_GET_SIZE(tmp);
11367 kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
11368 if (kwd_patterns == NULL) goto failed;
11369 for (i = 0; i < len; i++) {
11370 pattern_ty val;
11371 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11372 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011373 if (Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
11374 goto failed;
11375 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011376 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011377 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011378 Py_DECREF(tmp2);
11379 if (res != 0) goto failed;
11380 if (len != PyList_GET_SIZE(tmp)) {
11381 PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
11382 goto failed;
11383 }
11384 asdl_seq_SET(kwd_patterns, i, val);
11385 }
11386 Py_CLEAR(tmp);
11387 }
11388 *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
11389 lineno, col_offset, end_lineno,
11390 end_col_offset, arena);
11391 if (*out == NULL) goto failed;
11392 return 0;
11393 }
11394 tp = state->MatchStar_type;
11395 isinstance = PyObject_IsInstance(obj, tp);
11396 if (isinstance == -1) {
11397 return 1;
11398 }
11399 if (isinstance) {
11400 identifier name;
11401
11402 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11403 return 1;
11404 }
11405 if (tmp == NULL || tmp == Py_None) {
11406 Py_CLEAR(tmp);
11407 name = NULL;
11408 }
11409 else {
11410 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011411 if (Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
11412 goto failed;
11413 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011414 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011415 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011416 if (res != 0) goto failed;
11417 Py_CLEAR(tmp);
11418 }
11419 *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
11420 end_col_offset, arena);
11421 if (*out == NULL) goto failed;
11422 return 0;
11423 }
11424 tp = state->MatchAs_type;
11425 isinstance = PyObject_IsInstance(obj, tp);
11426 if (isinstance == -1) {
11427 return 1;
11428 }
11429 if (isinstance) {
11430 pattern_ty pattern;
11431 identifier name;
11432
11433 if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
11434 return 1;
11435 }
11436 if (tmp == NULL || tmp == Py_None) {
11437 Py_CLEAR(tmp);
11438 pattern = NULL;
11439 }
11440 else {
11441 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011442 if (Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
11443 goto failed;
11444 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011445 res = obj2ast_pattern(state, tmp, &pattern, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011446 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011447 if (res != 0) goto failed;
11448 Py_CLEAR(tmp);
11449 }
11450 if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
11451 return 1;
11452 }
11453 if (tmp == NULL || tmp == Py_None) {
11454 Py_CLEAR(tmp);
11455 name = NULL;
11456 }
11457 else {
11458 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011459 if (Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
11460 goto failed;
11461 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011462 res = obj2ast_identifier(state, tmp, &name, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011463 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011464 if (res != 0) goto failed;
11465 Py_CLEAR(tmp);
11466 }
11467 *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
11468 end_col_offset, arena);
11469 if (*out == NULL) goto failed;
11470 return 0;
11471 }
11472 tp = state->MatchOr_type;
11473 isinstance = PyObject_IsInstance(obj, tp);
11474 if (isinstance == -1) {
11475 return 1;
11476 }
11477 if (isinstance) {
11478 asdl_pattern_seq* patterns;
11479
11480 if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
11481 return 1;
11482 }
11483 if (tmp == NULL) {
11484 PyErr_SetString(PyExc_TypeError, "required field \"patterns\" missing from MatchOr");
11485 return 1;
11486 }
11487 else {
11488 int res;
11489 Py_ssize_t len;
11490 Py_ssize_t i;
11491 if (!PyList_Check(tmp)) {
11492 PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
11493 goto failed;
11494 }
11495 len = PyList_GET_SIZE(tmp);
11496 patterns = _Py_asdl_pattern_seq_new(len, arena);
11497 if (patterns == NULL) goto failed;
11498 for (i = 0; i < len; i++) {
11499 pattern_ty val;
11500 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
11501 Py_INCREF(tmp2);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011502 if (Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
11503 goto failed;
11504 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011505 res = obj2ast_pattern(state, tmp2, &val, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011506 Py_LeaveRecursiveCall();
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011507 Py_DECREF(tmp2);
11508 if (res != 0) goto failed;
11509 if (len != PyList_GET_SIZE(tmp)) {
11510 PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
11511 goto failed;
11512 }
11513 asdl_seq_SET(patterns, i, val);
11514 }
11515 Py_CLEAR(tmp);
11516 }
11517 *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
11518 end_col_offset, arena);
11519 if (*out == NULL) goto failed;
11520 return 0;
11521 }
11522
11523 PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
11524 failed:
11525 Py_XDECREF(tmp);
11526 return 1;
11527}
11528
11529int
Victor Stinner5cf47822020-11-02 22:03:28 +010011530obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
11531 out, PyArena* arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011532{
11533 int isinstance;
11534
11535 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -070011536 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011537
11538 if (obj == Py_None) {
11539 *out = NULL;
11540 return 0;
11541 }
Victor Stinner74419f02020-07-03 11:35:37 +020011542 tp = state->TypeIgnore_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070011543 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011544 if (isinstance == -1) {
11545 return 1;
11546 }
11547 if (isinstance) {
11548 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -070011549 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011550
Victor Stinner74419f02020-07-03 11:35:37 +020011551 if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011552 return 1;
11553 }
11554 if (tmp == NULL) {
11555 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
11556 return 1;
11557 }
11558 else {
11559 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011560 if (Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
11561 goto failed;
11562 }
Victor Stinner74419f02020-07-03 11:35:37 +020011563 res = obj2ast_int(state, tmp, &lineno, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011564 Py_LeaveRecursiveCall();
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011565 if (res != 0) goto failed;
11566 Py_CLEAR(tmp);
11567 }
Victor Stinner74419f02020-07-03 11:35:37 +020011568 if (_PyObject_LookupAttr(obj, state->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -070011569 return 1;
11570 }
11571 if (tmp == NULL) {
11572 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
11573 return 1;
11574 }
11575 else {
11576 int res;
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011577 if (Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
11578 goto failed;
11579 }
Victor Stinner74419f02020-07-03 11:35:37 +020011580 res = obj2ast_string(state, tmp, &tag, arena);
Miss Islington (bot)976598d2021-06-03 13:27:00 -070011581 Py_LeaveRecursiveCall();
Michael J. Sullivan933e1502019-05-22 07:54:20 -070011582 if (res != 0) goto failed;
11583 Py_CLEAR(tmp);
11584 }
Victor Stinnerd27f8d22021-04-07 21:34:22 +020011585 *out = _PyAST_TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -080011586 if (*out == NULL) goto failed;
11587 return 0;
11588 }
11589
11590 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
11591 failed:
11592 Py_XDECREF(tmp);
11593 return 1;
11594}
11595
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000011596
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011597static int
11598astmodule_exec(PyObject *m)
Martin v. Löwis577b5b92006-02-27 15:23:19 +000011599{
Victor Stinner5cf47822020-11-02 22:03:28 +010011600 struct ast_state *state = get_ast_state();
11601 if (state == NULL) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011602 return -1;
Victor Stinner91e1bc12020-07-03 14:15:53 +020011603 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011604 if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011605 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011606 }
Brandt Bucherd2f96672020-02-06 06:45:46 -080011607 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011608 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011609 }
11610 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 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_TYPE_COMMENTS) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011614 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011615 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011616 if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 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, "Module", state->Module_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, "Interactive", state->Interactive_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, "Expression", state->Expression_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, "FunctionType", state->FunctionType_type) < 0)
11629 {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011630 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011631 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011632 if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
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, "FunctionDef", state->FunctionDef_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, "AsyncFunctionDef",
11639 state->AsyncFunctionDef_type) < 0) {
11640 return -1;
11641 }
11642 if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
11643 return -1;
11644 }
11645 if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
11646 return -1;
11647 }
11648 if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
11649 return -1;
11650 }
11651 if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
11652 return -1;
11653 }
11654 if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
11655 return -1;
11656 }
11657 if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
11658 return -1;
11659 }
11660 if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
11661 return -1;
11662 }
11663 if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
11664 return -1;
11665 }
11666 if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
11667 return -1;
11668 }
11669 if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
11670 return -1;
11671 }
11672 if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
11673 return -1;
11674 }
11675 if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
11676 return -1;
11677 }
Brandt Bucher145bf262021-02-26 14:51:55 -080011678 if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
11679 return -1;
11680 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011681 if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
11682 return -1;
11683 }
11684 if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
11685 return -1;
11686 }
11687 if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
11688 return -1;
11689 }
11690 if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
11691 return -1;
11692 }
11693 if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
11694 return -1;
11695 }
11696 if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
11697 return -1;
11698 }
11699 if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
11700 return -1;
11701 }
11702 if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
11703 return -1;
11704 }
11705 if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
11706 return -1;
11707 }
11708 if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
11709 return -1;
11710 }
11711 if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
11712 return -1;
11713 }
11714 if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
11715 return -1;
11716 }
11717 if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
11718 return -1;
11719 }
11720 if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
11721 return -1;
11722 }
11723 if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
11724 return -1;
11725 }
11726 if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
11727 return -1;
11728 }
11729 if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
11730 return -1;
11731 }
11732 if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
11733 return -1;
11734 }
11735 if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
11736 return -1;
11737 }
11738 if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
11739 return -1;
11740 }
11741 if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
11742 return -1;
11743 }
11744 if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
11745 return -1;
11746 }
11747 if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
11748 return -1;
11749 }
11750 if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
11751 {
11752 return -1;
11753 }
11754 if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
11755 return -1;
11756 }
11757 if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
11758 return -1;
11759 }
11760 if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
11761 return -1;
11762 }
11763 if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
11764 return -1;
11765 }
11766 if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
11767 return -1;
11768 }
11769 if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080011770 < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011771 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011772 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011773 if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011774 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011775 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011776 if (PyModule_AddObjectRef(m, "Constant", state->Constant_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, "Attribute", state->Attribute_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, "Subscript", state->Subscript_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, "Starred", state->Starred_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, "Name", state->Name_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, "List", state->List_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, "Tuple", state->Tuple_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, "Slice", state->Slice_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, "expr_context", state->expr_context_type) < 0)
11801 {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011802 return -1;
Victor Stinner74419f02020-07-03 11:35:37 +020011803 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011804 if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
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, "Store", state->Store_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, "Del", state->Del_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, "boolop", state->boolop_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, "And", state->And_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, "Or", state->Or_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, "operator", state->operator_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, "Add", state->Add_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, "Sub", state->Sub_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, "Mult", state->Mult_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, "MatMult", state->MatMult_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, "Div", state->Div_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, "Mod", state->Mod_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, "Pow", state->Pow_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, "LShift", state->LShift_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, "RShift", state->RShift_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, "BitOr", state->BitOr_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, "BitXor", state->BitXor_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, "BitAnd", state->BitAnd_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, "FloorDiv", state->FloorDiv_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, "unaryop", state->unaryop_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, "Invert", state->Invert_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, "Not", state->Not_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, "UAdd", state->UAdd_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, "USub", state->USub_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, "cmpop", state->cmpop_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, "Eq", state->Eq_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, "NotEq", state->NotEq_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, "Lt", state->Lt_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, "LtE", state->LtE_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, "Gt", state->Gt_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, "GtE", state->GtE_type) < 0) {
11898 return -1;
11899 }
11900 if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
11901 return -1;
11902 }
11903 if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
11904 return -1;
11905 }
11906 if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
11907 return -1;
11908 }
11909 if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
11910 return -1;
11911 }
11912 if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080011913 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011914 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011915 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011916 if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
11917 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011918 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011919 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011920 if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
11921 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011922 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011923 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011924 if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 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, "arg", state->arg_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, "keyword", state->keyword_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, "alias", state->alias_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, "withitem", state->withitem_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011937 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011938 }
Brandt Bucher145bf262021-02-26 14:51:55 -080011939 if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
11940 return -1;
11941 }
Nick Coghlan1e7b8582021-04-29 15:58:44 +100011942 if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
11943 return -1;
11944 }
11945 if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
11946 return -1;
11947 }
11948 if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
11949 < 0) {
11950 return -1;
11951 }
11952 if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
11953 0) {
11954 return -1;
11955 }
11956 if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
11957 {
11958 return -1;
11959 }
11960 if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
11961 return -1;
11962 }
11963 if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
11964 return -1;
11965 }
11966 if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
11967 return -1;
11968 }
11969 if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
11970 return -1;
11971 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011972 if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011973 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011974 }
Victor Stinner18ce7f12020-11-04 16:37:07 +010011975 if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011976 return -1;
Brandt Bucherd2f96672020-02-06 06:45:46 -080011977 }
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011978 return 0;
11979}
Victor Stinner91e1bc12020-07-03 14:15:53 +020011980
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011981static PyModuleDef_Slot astmodule_slots[] = {
11982 {Py_mod_exec, astmodule_exec},
11983 {0, NULL}
11984};
11985
11986static struct PyModuleDef _astmodule = {
11987 PyModuleDef_HEAD_INIT,
11988 .m_name = "_ast",
Victor Stinner5cf47822020-11-02 22:03:28 +010011989 // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
Victor Stinnere5fbe0c2020-09-15 18:03:34 +020011990 .m_size = 0,
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011991 .m_slots = astmodule_slots,
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020011992};
11993
11994PyMODINIT_FUNC
11995PyInit__ast(void)
11996{
11997 return PyModuleDef_Init(&_astmodule);
Martin v. Löwis577b5b92006-02-27 15:23:19 +000011998}
11999
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000012000
Martin v. Löwisbd260da2006-02-26 19:42:26 +000012001PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000012002{
Victor Stinner5cf47822020-11-02 22:03:28 +010012003 struct ast_state *state = get_ast_state();
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020012004 if (state == NULL) {
Victor Stinnerbdf630c2013-07-17 00:17:15 +020012005 return NULL;
Victor Stinner91e1bc12020-07-03 14:15:53 +020012006 }
Victor Stinner74419f02020-07-03 11:35:37 +020012007 return ast2obj_mod(state, t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000012008}
Martin v. Löwis5b222132007-06-10 09:51:05 +000012009
Neal Norwitzdb4115f2008-03-31 04:20:05 +000012010/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
12011mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000012012{
Serhiy Storchaka43c97312019-09-10 13:02:30 +030012013 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000012014 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050012015
Steve Dowerb82e17e2019-05-23 08:45:22 -070012016 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
12017 return NULL;
12018 }
12019
Victor Stinner5cf47822020-11-02 22:03:28 +010012020 struct ast_state *state = get_ast_state();
12021 if (state == NULL) {
12022 return NULL;
12023 }
12024
Victor Stinner74419f02020-07-03 11:35:37 +020012025 PyObject *req_type[3];
12026 req_type[0] = state->Module_type;
12027 req_type[1] = state->Expression_type;
12028 req_type[2] = state->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050012029
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080012030 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000012031
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000012032 isinstance = PyObject_IsInstance(ast, req_type[mode]);
12033 if (isinstance == -1)
12034 return NULL;
12035 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000012036 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070012037 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000012038 return NULL;
12039 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090012040
12041 mod_ty res = NULL;
Victor Stinner74419f02020-07-03 11:35:37 +020012042 if (obj2ast_mod(state, ast, &res, arena) != 0)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000012043 return NULL;
12044 else
12045 return res;
12046}
12047
12048int PyAST_Check(PyObject* obj)
12049{
Victor Stinner5cf47822020-11-02 22:03:28 +010012050 struct ast_state *state = get_ast_state();
Victor Stinnerb1cc6ba2020-07-03 20:01:46 +020012051 if (state == NULL) {
Victor Stinnerbdf630c2013-07-17 00:17:15 +020012052 return -1;
Victor Stinner91e1bc12020-07-03 14:15:53 +020012053 }
Victor Stinner74419f02020-07-03 11:35:37 +020012054 return PyObject_IsInstance(obj, state->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000012055}
12056
Martin v. Löwis5b222132007-06-10 09:51:05 +000012057