Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 3 | #include <stddef.h> |
| 4 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5 | #include "Python.h" |
| 6 | #include "Python-ast.h" |
Victor Stinner | 4a21e57 | 2020-04-15 02:35:41 +0200 | [diff] [blame] | 7 | #include "structmember.h" // PyMemberDef |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9 | typedef struct { |
| 10 | int initialized; |
| 11 | PyObject *AST_type; |
| 12 | PyObject *Add_singleton; |
| 13 | PyObject *Add_type; |
| 14 | PyObject *And_singleton; |
| 15 | PyObject *And_type; |
| 16 | PyObject *AnnAssign_type; |
| 17 | PyObject *Assert_type; |
| 18 | PyObject *Assign_type; |
| 19 | PyObject *AsyncFor_type; |
| 20 | PyObject *AsyncFunctionDef_type; |
| 21 | PyObject *AsyncWith_type; |
| 22 | PyObject *Attribute_type; |
| 23 | PyObject *AugAssign_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 24 | PyObject *Await_type; |
| 25 | PyObject *BinOp_type; |
| 26 | PyObject *BitAnd_singleton; |
| 27 | PyObject *BitAnd_type; |
| 28 | PyObject *BitOr_singleton; |
| 29 | PyObject *BitOr_type; |
| 30 | PyObject *BitXor_singleton; |
| 31 | PyObject *BitXor_type; |
| 32 | PyObject *BoolOp_type; |
| 33 | PyObject *Break_type; |
| 34 | PyObject *Call_type; |
| 35 | PyObject *ClassDef_type; |
| 36 | PyObject *Compare_type; |
| 37 | PyObject *Constant_type; |
| 38 | PyObject *Continue_type; |
| 39 | PyObject *Del_singleton; |
| 40 | PyObject *Del_type; |
| 41 | PyObject *Delete_type; |
| 42 | PyObject *DictComp_type; |
| 43 | PyObject *Dict_type; |
| 44 | PyObject *Div_singleton; |
| 45 | PyObject *Div_type; |
| 46 | PyObject *Eq_singleton; |
| 47 | PyObject *Eq_type; |
| 48 | PyObject *ExceptHandler_type; |
| 49 | PyObject *Expr_type; |
| 50 | PyObject *Expression_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 51 | PyObject *FloorDiv_singleton; |
| 52 | PyObject *FloorDiv_type; |
| 53 | PyObject *For_type; |
| 54 | PyObject *FormattedValue_type; |
| 55 | PyObject *FunctionDef_type; |
| 56 | PyObject *FunctionType_type; |
| 57 | PyObject *GeneratorExp_type; |
| 58 | PyObject *Global_type; |
| 59 | PyObject *GtE_singleton; |
| 60 | PyObject *GtE_type; |
| 61 | PyObject *Gt_singleton; |
| 62 | PyObject *Gt_type; |
| 63 | PyObject *IfExp_type; |
| 64 | PyObject *If_type; |
| 65 | PyObject *ImportFrom_type; |
| 66 | PyObject *Import_type; |
| 67 | PyObject *In_singleton; |
| 68 | PyObject *In_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 69 | PyObject *Interactive_type; |
| 70 | PyObject *Invert_singleton; |
| 71 | PyObject *Invert_type; |
| 72 | PyObject *IsNot_singleton; |
| 73 | PyObject *IsNot_type; |
| 74 | PyObject *Is_singleton; |
| 75 | PyObject *Is_type; |
| 76 | PyObject *JoinedStr_type; |
| 77 | PyObject *LShift_singleton; |
| 78 | PyObject *LShift_type; |
| 79 | PyObject *Lambda_type; |
| 80 | PyObject *ListComp_type; |
| 81 | PyObject *List_type; |
| 82 | PyObject *Load_singleton; |
| 83 | PyObject *Load_type; |
| 84 | PyObject *LtE_singleton; |
| 85 | PyObject *LtE_type; |
| 86 | PyObject *Lt_singleton; |
| 87 | PyObject *Lt_type; |
| 88 | PyObject *MatMult_singleton; |
| 89 | PyObject *MatMult_type; |
| 90 | PyObject *Mod_singleton; |
| 91 | PyObject *Mod_type; |
| 92 | PyObject *Module_type; |
| 93 | PyObject *Mult_singleton; |
| 94 | PyObject *Mult_type; |
| 95 | PyObject *Name_type; |
| 96 | PyObject *NamedExpr_type; |
| 97 | PyObject *Nonlocal_type; |
| 98 | PyObject *NotEq_singleton; |
| 99 | PyObject *NotEq_type; |
| 100 | PyObject *NotIn_singleton; |
| 101 | PyObject *NotIn_type; |
| 102 | PyObject *Not_singleton; |
| 103 | PyObject *Not_type; |
| 104 | PyObject *Or_singleton; |
| 105 | PyObject *Or_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 106 | PyObject *Pass_type; |
| 107 | PyObject *Pow_singleton; |
| 108 | PyObject *Pow_type; |
| 109 | PyObject *RShift_singleton; |
| 110 | PyObject *RShift_type; |
| 111 | PyObject *Raise_type; |
| 112 | PyObject *Return_type; |
| 113 | PyObject *SetComp_type; |
| 114 | PyObject *Set_type; |
| 115 | PyObject *Slice_type; |
| 116 | PyObject *Starred_type; |
| 117 | PyObject *Store_singleton; |
| 118 | PyObject *Store_type; |
| 119 | PyObject *Sub_singleton; |
| 120 | PyObject *Sub_type; |
| 121 | PyObject *Subscript_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 122 | PyObject *Try_type; |
| 123 | PyObject *Tuple_type; |
| 124 | PyObject *TypeIgnore_type; |
| 125 | PyObject *UAdd_singleton; |
| 126 | PyObject *UAdd_type; |
| 127 | PyObject *USub_singleton; |
| 128 | PyObject *USub_type; |
| 129 | PyObject *UnaryOp_type; |
| 130 | PyObject *While_type; |
| 131 | PyObject *With_type; |
| 132 | PyObject *YieldFrom_type; |
| 133 | PyObject *Yield_type; |
| 134 | PyObject *__dict__; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 135 | PyObject *__doc__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 136 | PyObject *__module__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 137 | PyObject *_attributes; |
| 138 | PyObject *_fields; |
| 139 | PyObject *alias_type; |
| 140 | PyObject *annotation; |
| 141 | PyObject *arg; |
| 142 | PyObject *arg_type; |
| 143 | PyObject *args; |
| 144 | PyObject *argtypes; |
| 145 | PyObject *arguments_type; |
| 146 | PyObject *asname; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 147 | PyObject *ast; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 148 | PyObject *attr; |
| 149 | PyObject *bases; |
| 150 | PyObject *body; |
| 151 | PyObject *boolop_type; |
| 152 | PyObject *cause; |
| 153 | PyObject *cmpop_type; |
| 154 | PyObject *col_offset; |
| 155 | PyObject *comparators; |
| 156 | PyObject *comprehension_type; |
| 157 | PyObject *context_expr; |
| 158 | PyObject *conversion; |
| 159 | PyObject *ctx; |
| 160 | PyObject *decorator_list; |
| 161 | PyObject *defaults; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 162 | PyObject *elt; |
| 163 | PyObject *elts; |
| 164 | PyObject *end_col_offset; |
| 165 | PyObject *end_lineno; |
| 166 | PyObject *exc; |
| 167 | PyObject *excepthandler_type; |
| 168 | PyObject *expr_context_type; |
| 169 | PyObject *expr_type; |
| 170 | PyObject *finalbody; |
| 171 | PyObject *format_spec; |
| 172 | PyObject *func; |
| 173 | PyObject *generators; |
| 174 | PyObject *handlers; |
| 175 | PyObject *id; |
| 176 | PyObject *ifs; |
| 177 | PyObject *is_async; |
| 178 | PyObject *items; |
| 179 | PyObject *iter; |
| 180 | PyObject *key; |
| 181 | PyObject *keys; |
| 182 | PyObject *keyword_type; |
| 183 | PyObject *keywords; |
| 184 | PyObject *kind; |
| 185 | PyObject *kw_defaults; |
| 186 | PyObject *kwarg; |
| 187 | PyObject *kwonlyargs; |
| 188 | PyObject *left; |
| 189 | PyObject *level; |
| 190 | PyObject *lineno; |
| 191 | PyObject *lower; |
| 192 | PyObject *mod_type; |
| 193 | PyObject *module; |
| 194 | PyObject *msg; |
| 195 | PyObject *name; |
| 196 | PyObject *names; |
| 197 | PyObject *op; |
| 198 | PyObject *operand; |
| 199 | PyObject *operator_type; |
| 200 | PyObject *ops; |
| 201 | PyObject *optional_vars; |
| 202 | PyObject *orelse; |
| 203 | PyObject *posonlyargs; |
| 204 | PyObject *returns; |
| 205 | PyObject *right; |
| 206 | PyObject *simple; |
| 207 | PyObject *slice; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 208 | PyObject *step; |
| 209 | PyObject *stmt_type; |
| 210 | PyObject *tag; |
| 211 | PyObject *target; |
| 212 | PyObject *targets; |
| 213 | PyObject *test; |
| 214 | PyObject *type; |
| 215 | PyObject *type_comment; |
| 216 | PyObject *type_ignore_type; |
| 217 | PyObject *type_ignores; |
| 218 | PyObject *unaryop_type; |
| 219 | PyObject *upper; |
| 220 | PyObject *value; |
| 221 | PyObject *values; |
| 222 | PyObject *vararg; |
| 223 | PyObject *withitem_type; |
| 224 | } astmodulestate; |
| 225 | |
| 226 | |
| 227 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 228 | |
| 229 | static int astmodule_clear(PyObject *module) |
| 230 | { |
| 231 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 232 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 233 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 234 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 235 | Py_CLEAR(astmodulestate(module)->And_type); |
| 236 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 237 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 238 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 239 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 240 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 241 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 242 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 243 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 244 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 245 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 246 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 247 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 248 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 249 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 250 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 251 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 252 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 253 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 254 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 255 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 256 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 257 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 258 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 259 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 260 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 261 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 262 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 263 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 264 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 265 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 266 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 267 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 268 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 269 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 271 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 272 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 273 | Py_CLEAR(astmodulestate(module)->For_type); |
| 274 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 275 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 276 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 277 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 278 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 279 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 280 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 281 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 282 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 283 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 284 | Py_CLEAR(astmodulestate(module)->If_type); |
| 285 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 286 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 287 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 288 | Py_CLEAR(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 289 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 290 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 291 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 292 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 293 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 294 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 295 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 296 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 297 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 298 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 299 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 300 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 301 | Py_CLEAR(astmodulestate(module)->List_type); |
| 302 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 303 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 304 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 305 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 306 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 307 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 308 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 309 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 310 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 311 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 312 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 313 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 314 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 315 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 316 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 317 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 318 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 319 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 320 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 321 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 322 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 323 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 324 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 325 | Py_CLEAR(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 326 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 327 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 328 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 329 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 330 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 331 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 332 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 333 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 334 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 335 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 336 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 337 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 338 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 339 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 340 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 341 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 342 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 343 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 344 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 345 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 346 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 347 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 348 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 349 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 350 | Py_CLEAR(astmodulestate(module)->While_type); |
| 351 | Py_CLEAR(astmodulestate(module)->With_type); |
| 352 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 353 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 354 | Py_CLEAR(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 355 | Py_CLEAR(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 356 | Py_CLEAR(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 357 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 358 | Py_CLEAR(astmodulestate(module)->_fields); |
| 359 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 360 | Py_CLEAR(astmodulestate(module)->annotation); |
| 361 | Py_CLEAR(astmodulestate(module)->arg); |
| 362 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 363 | Py_CLEAR(astmodulestate(module)->args); |
| 364 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 365 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 366 | Py_CLEAR(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 367 | Py_CLEAR(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 368 | Py_CLEAR(astmodulestate(module)->attr); |
| 369 | Py_CLEAR(astmodulestate(module)->bases); |
| 370 | Py_CLEAR(astmodulestate(module)->body); |
| 371 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 372 | Py_CLEAR(astmodulestate(module)->cause); |
| 373 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 374 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 375 | Py_CLEAR(astmodulestate(module)->comparators); |
| 376 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 377 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 378 | Py_CLEAR(astmodulestate(module)->conversion); |
| 379 | Py_CLEAR(astmodulestate(module)->ctx); |
| 380 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 381 | Py_CLEAR(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 382 | Py_CLEAR(astmodulestate(module)->elt); |
| 383 | Py_CLEAR(astmodulestate(module)->elts); |
| 384 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 385 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 386 | Py_CLEAR(astmodulestate(module)->exc); |
| 387 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 388 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 389 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 390 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 391 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 392 | Py_CLEAR(astmodulestate(module)->func); |
| 393 | Py_CLEAR(astmodulestate(module)->generators); |
| 394 | Py_CLEAR(astmodulestate(module)->handlers); |
| 395 | Py_CLEAR(astmodulestate(module)->id); |
| 396 | Py_CLEAR(astmodulestate(module)->ifs); |
| 397 | Py_CLEAR(astmodulestate(module)->is_async); |
| 398 | Py_CLEAR(astmodulestate(module)->items); |
| 399 | Py_CLEAR(astmodulestate(module)->iter); |
| 400 | Py_CLEAR(astmodulestate(module)->key); |
| 401 | Py_CLEAR(astmodulestate(module)->keys); |
| 402 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 403 | Py_CLEAR(astmodulestate(module)->keywords); |
| 404 | Py_CLEAR(astmodulestate(module)->kind); |
| 405 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 406 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 407 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 408 | Py_CLEAR(astmodulestate(module)->left); |
| 409 | Py_CLEAR(astmodulestate(module)->level); |
| 410 | Py_CLEAR(astmodulestate(module)->lineno); |
| 411 | Py_CLEAR(astmodulestate(module)->lower); |
| 412 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 413 | Py_CLEAR(astmodulestate(module)->module); |
| 414 | Py_CLEAR(astmodulestate(module)->msg); |
| 415 | Py_CLEAR(astmodulestate(module)->name); |
| 416 | Py_CLEAR(astmodulestate(module)->names); |
| 417 | Py_CLEAR(astmodulestate(module)->op); |
| 418 | Py_CLEAR(astmodulestate(module)->operand); |
| 419 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 420 | Py_CLEAR(astmodulestate(module)->ops); |
| 421 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 422 | Py_CLEAR(astmodulestate(module)->orelse); |
| 423 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 424 | Py_CLEAR(astmodulestate(module)->returns); |
| 425 | Py_CLEAR(astmodulestate(module)->right); |
| 426 | Py_CLEAR(astmodulestate(module)->simple); |
| 427 | Py_CLEAR(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 428 | Py_CLEAR(astmodulestate(module)->step); |
| 429 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 430 | Py_CLEAR(astmodulestate(module)->tag); |
| 431 | Py_CLEAR(astmodulestate(module)->target); |
| 432 | Py_CLEAR(astmodulestate(module)->targets); |
| 433 | Py_CLEAR(astmodulestate(module)->test); |
| 434 | Py_CLEAR(astmodulestate(module)->type); |
| 435 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 436 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 437 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 438 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 439 | Py_CLEAR(astmodulestate(module)->upper); |
| 440 | Py_CLEAR(astmodulestate(module)->value); |
| 441 | Py_CLEAR(astmodulestate(module)->values); |
| 442 | Py_CLEAR(astmodulestate(module)->vararg); |
| 443 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 449 | { |
| 450 | Py_VISIT(astmodulestate(module)->AST_type); |
| 451 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 452 | Py_VISIT(astmodulestate(module)->Add_type); |
| 453 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 454 | Py_VISIT(astmodulestate(module)->And_type); |
| 455 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 456 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 457 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 458 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 459 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 460 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 461 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 462 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 463 | Py_VISIT(astmodulestate(module)->Await_type); |
| 464 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 465 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 466 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 467 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 468 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 469 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 470 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 471 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 472 | Py_VISIT(astmodulestate(module)->Break_type); |
| 473 | Py_VISIT(astmodulestate(module)->Call_type); |
| 474 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 475 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 476 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 477 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 478 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 479 | Py_VISIT(astmodulestate(module)->Del_type); |
| 480 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 481 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 482 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 483 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->Div_type); |
| 485 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 486 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 487 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 488 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 489 | Py_VISIT(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 490 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 491 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 492 | Py_VISIT(astmodulestate(module)->For_type); |
| 493 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 494 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 495 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 496 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 497 | Py_VISIT(astmodulestate(module)->Global_type); |
| 498 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 499 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 500 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 501 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 502 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 503 | Py_VISIT(astmodulestate(module)->If_type); |
| 504 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 505 | Py_VISIT(astmodulestate(module)->Import_type); |
| 506 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 507 | Py_VISIT(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 508 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 509 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 510 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 511 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 512 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 513 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 514 | Py_VISIT(astmodulestate(module)->Is_type); |
| 515 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 516 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 517 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 518 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 519 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 520 | Py_VISIT(astmodulestate(module)->List_type); |
| 521 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 522 | Py_VISIT(astmodulestate(module)->Load_type); |
| 523 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 525 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 526 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 527 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 528 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 529 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 530 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 531 | Py_VISIT(astmodulestate(module)->Module_type); |
| 532 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 533 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 534 | Py_VISIT(astmodulestate(module)->Name_type); |
| 535 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 536 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 537 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 539 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 540 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 541 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 542 | Py_VISIT(astmodulestate(module)->Not_type); |
| 543 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 544 | Py_VISIT(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 545 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 546 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 547 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 548 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 549 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 550 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 551 | Py_VISIT(astmodulestate(module)->Return_type); |
| 552 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 553 | Py_VISIT(astmodulestate(module)->Set_type); |
| 554 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 555 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 556 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 557 | Py_VISIT(astmodulestate(module)->Store_type); |
| 558 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 559 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 560 | Py_VISIT(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 561 | Py_VISIT(astmodulestate(module)->Try_type); |
| 562 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 563 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 564 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 565 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 566 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 567 | Py_VISIT(astmodulestate(module)->USub_type); |
| 568 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 569 | Py_VISIT(astmodulestate(module)->While_type); |
| 570 | Py_VISIT(astmodulestate(module)->With_type); |
| 571 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 572 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 573 | Py_VISIT(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 574 | Py_VISIT(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 575 | Py_VISIT(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 576 | Py_VISIT(astmodulestate(module)->_attributes); |
| 577 | Py_VISIT(astmodulestate(module)->_fields); |
| 578 | Py_VISIT(astmodulestate(module)->alias_type); |
| 579 | Py_VISIT(astmodulestate(module)->annotation); |
| 580 | Py_VISIT(astmodulestate(module)->arg); |
| 581 | Py_VISIT(astmodulestate(module)->arg_type); |
| 582 | Py_VISIT(astmodulestate(module)->args); |
| 583 | Py_VISIT(astmodulestate(module)->argtypes); |
| 584 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 585 | Py_VISIT(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 586 | Py_VISIT(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 587 | Py_VISIT(astmodulestate(module)->attr); |
| 588 | Py_VISIT(astmodulestate(module)->bases); |
| 589 | Py_VISIT(astmodulestate(module)->body); |
| 590 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 591 | Py_VISIT(astmodulestate(module)->cause); |
| 592 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 593 | Py_VISIT(astmodulestate(module)->col_offset); |
| 594 | Py_VISIT(astmodulestate(module)->comparators); |
| 595 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 596 | Py_VISIT(astmodulestate(module)->context_expr); |
| 597 | Py_VISIT(astmodulestate(module)->conversion); |
| 598 | Py_VISIT(astmodulestate(module)->ctx); |
| 599 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 600 | Py_VISIT(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 601 | Py_VISIT(astmodulestate(module)->elt); |
| 602 | Py_VISIT(astmodulestate(module)->elts); |
| 603 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 604 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 605 | Py_VISIT(astmodulestate(module)->exc); |
| 606 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 607 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 608 | Py_VISIT(astmodulestate(module)->expr_type); |
| 609 | Py_VISIT(astmodulestate(module)->finalbody); |
| 610 | Py_VISIT(astmodulestate(module)->format_spec); |
| 611 | Py_VISIT(astmodulestate(module)->func); |
| 612 | Py_VISIT(astmodulestate(module)->generators); |
| 613 | Py_VISIT(astmodulestate(module)->handlers); |
| 614 | Py_VISIT(astmodulestate(module)->id); |
| 615 | Py_VISIT(astmodulestate(module)->ifs); |
| 616 | Py_VISIT(astmodulestate(module)->is_async); |
| 617 | Py_VISIT(astmodulestate(module)->items); |
| 618 | Py_VISIT(astmodulestate(module)->iter); |
| 619 | Py_VISIT(astmodulestate(module)->key); |
| 620 | Py_VISIT(astmodulestate(module)->keys); |
| 621 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 622 | Py_VISIT(astmodulestate(module)->keywords); |
| 623 | Py_VISIT(astmodulestate(module)->kind); |
| 624 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 625 | Py_VISIT(astmodulestate(module)->kwarg); |
| 626 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 627 | Py_VISIT(astmodulestate(module)->left); |
| 628 | Py_VISIT(astmodulestate(module)->level); |
| 629 | Py_VISIT(astmodulestate(module)->lineno); |
| 630 | Py_VISIT(astmodulestate(module)->lower); |
| 631 | Py_VISIT(astmodulestate(module)->mod_type); |
| 632 | Py_VISIT(astmodulestate(module)->module); |
| 633 | Py_VISIT(astmodulestate(module)->msg); |
| 634 | Py_VISIT(astmodulestate(module)->name); |
| 635 | Py_VISIT(astmodulestate(module)->names); |
| 636 | Py_VISIT(astmodulestate(module)->op); |
| 637 | Py_VISIT(astmodulestate(module)->operand); |
| 638 | Py_VISIT(astmodulestate(module)->operator_type); |
| 639 | Py_VISIT(astmodulestate(module)->ops); |
| 640 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 641 | Py_VISIT(astmodulestate(module)->orelse); |
| 642 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 643 | Py_VISIT(astmodulestate(module)->returns); |
| 644 | Py_VISIT(astmodulestate(module)->right); |
| 645 | Py_VISIT(astmodulestate(module)->simple); |
| 646 | Py_VISIT(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 647 | Py_VISIT(astmodulestate(module)->step); |
| 648 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 649 | Py_VISIT(astmodulestate(module)->tag); |
| 650 | Py_VISIT(astmodulestate(module)->target); |
| 651 | Py_VISIT(astmodulestate(module)->targets); |
| 652 | Py_VISIT(astmodulestate(module)->test); |
| 653 | Py_VISIT(astmodulestate(module)->type); |
| 654 | Py_VISIT(astmodulestate(module)->type_comment); |
| 655 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 656 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 657 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 658 | Py_VISIT(astmodulestate(module)->upper); |
| 659 | Py_VISIT(astmodulestate(module)->value); |
| 660 | Py_VISIT(astmodulestate(module)->values); |
| 661 | Py_VISIT(astmodulestate(module)->vararg); |
| 662 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static void astmodule_free(void* module) { |
| 668 | astmodule_clear((PyObject*)module); |
| 669 | } |
| 670 | |
| 671 | static struct PyModuleDef _astmodule = { |
| 672 | PyModuleDef_HEAD_INIT, |
| 673 | "_ast", |
| 674 | NULL, |
| 675 | sizeof(astmodulestate), |
| 676 | NULL, |
| 677 | NULL, |
| 678 | astmodule_traverse, |
| 679 | astmodule_clear, |
| 680 | astmodule_free, |
| 681 | }; |
| 682 | |
| 683 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 684 | |
| 685 | static int init_identifiers(void) |
| 686 | { |
| 687 | astmodulestate *state = astmodulestate_global; |
| 688 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 689 | if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 690 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 691 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 692 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 693 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 694 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 695 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 696 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 697 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 698 | if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 699 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 700 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 701 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 702 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 703 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 704 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 705 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 706 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 707 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 708 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 709 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 710 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 711 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 712 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 713 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 714 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 715 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 716 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 717 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 718 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 719 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 720 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 721 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 722 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 723 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 724 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 725 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 726 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 727 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 728 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 729 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 730 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 731 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 732 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 733 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 734 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 735 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 736 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 737 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 738 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 739 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 740 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 741 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 742 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 743 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 744 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 745 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 746 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 747 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 748 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 749 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 750 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 751 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 752 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 753 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 754 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 755 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 756 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 757 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 758 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 759 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 760 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 761 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 762 | return 1; |
| 763 | }; |
| 764 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 766 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 767 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 768 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 769 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 770 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 771 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 773 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 774 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 776 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 777 | "argtypes", |
| 778 | "returns", |
| 779 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 780 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 781 | "lineno", |
| 782 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 783 | "end_lineno", |
| 784 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 787 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 788 | "name", |
| 789 | "args", |
| 790 | "body", |
| 791 | "decorator_list", |
| 792 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 793 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 795 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 796 | "name", |
| 797 | "args", |
| 798 | "body", |
| 799 | "decorator_list", |
| 800 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 801 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 802 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 803 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 804 | "name", |
| 805 | "bases", |
| 806 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 807 | "body", |
| 808 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 809 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 810 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 811 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 813 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 814 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 815 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 816 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 817 | "targets", |
| 818 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 819 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 821 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 822 | "target", |
| 823 | "op", |
| 824 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 825 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 826 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 827 | "target", |
| 828 | "annotation", |
| 829 | "value", |
| 830 | "simple", |
| 831 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 832 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 833 | "target", |
| 834 | "iter", |
| 835 | "body", |
| 836 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 837 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 838 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 839 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 840 | "target", |
| 841 | "iter", |
| 842 | "body", |
| 843 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 844 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 845 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 846 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 847 | "test", |
| 848 | "body", |
| 849 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 850 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 851 | static const char * const If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 852 | "test", |
| 853 | "body", |
| 854 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 855 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 856 | static const char * const With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 857 | "items", |
| 858 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 859 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 860 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 861 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 862 | "items", |
| 863 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 864 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 865 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 866 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 867 | "exc", |
| 868 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 870 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 871 | "body", |
| 872 | "handlers", |
| 873 | "orelse", |
| 874 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 875 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 876 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 877 | "test", |
| 878 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 879 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 880 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 881 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 883 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | "module", |
| 885 | "names", |
| 886 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 887 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 888 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 889 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 890 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 891 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 892 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 893 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 894 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 895 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 896 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 897 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | "lineno", |
| 899 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 900 | "end_lineno", |
| 901 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 903 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 904 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 905 | "op", |
| 906 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 907 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 908 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 909 | "target", |
| 910 | "value", |
| 911 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 912 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 913 | "left", |
| 914 | "op", |
| 915 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 916 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 917 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 918 | "op", |
| 919 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 920 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 921 | static const char * const Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | "args", |
| 923 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 924 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 925 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 926 | "test", |
| 927 | "body", |
| 928 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 929 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 930 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 931 | "keys", |
| 932 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 933 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 934 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 935 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 936 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 937 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 938 | "elt", |
| 939 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 940 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 941 | static const char * const SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 942 | "elt", |
| 943 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 944 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 945 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 946 | "key", |
| 947 | "value", |
| 948 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 949 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 950 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 951 | "elt", |
| 952 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 953 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 954 | static const char * const Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 955 | "value", |
| 956 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 957 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 958 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 959 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 960 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 961 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 962 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 963 | static const char * const Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 964 | "left", |
| 965 | "ops", |
| 966 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 967 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 968 | static const char * const Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 969 | "func", |
| 970 | "args", |
| 971 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 972 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 973 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 974 | "value", |
| 975 | "conversion", |
| 976 | "format_spec", |
| 977 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 978 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 979 | "values", |
| 980 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 981 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 982 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 983 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 984 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 985 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 986 | "value", |
| 987 | "attr", |
| 988 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 989 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 990 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | "value", |
| 992 | "slice", |
| 993 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 994 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 995 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 996 | "value", |
| 997 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 998 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 999 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1000 | "id", |
| 1001 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1002 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1003 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1004 | "elts", |
| 1005 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1006 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1007 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1008 | "elts", |
| 1009 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1010 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1011 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1012 | "lower", |
| 1013 | "upper", |
| 1014 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1015 | }; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1016 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1017 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1018 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1019 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1020 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1021 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1022 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1023 | "target", |
| 1024 | "iter", |
| 1025 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1026 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1027 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1028 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1029 | "lineno", |
| 1030 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1031 | "end_lineno", |
| 1032 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1033 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1034 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1035 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1036 | "type", |
| 1037 | "name", |
| 1038 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1040 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1041 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1042 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1043 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1044 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1045 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1046 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1047 | "kwarg", |
| 1048 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1049 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1050 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1051 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1052 | "lineno", |
| 1053 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1054 | "end_lineno", |
| 1055 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1056 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1057 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1058 | "arg", |
| 1059 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1060 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1061 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1062 | static PyObject* ast2obj_keyword(void*); |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 1063 | static const char * const keyword_attributes[] = { |
| 1064 | "lineno", |
| 1065 | "col_offset", |
| 1066 | "end_lineno", |
| 1067 | "end_col_offset", |
| 1068 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1069 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1070 | "arg", |
| 1071 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1072 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1073 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1074 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1075 | "name", |
| 1076 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1077 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1078 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1079 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1080 | "context_expr", |
| 1081 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1082 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1083 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1084 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1085 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1086 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1087 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1088 | |
| 1089 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1090 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1091 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1092 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1093 | PyObject *dict; |
| 1094 | } AST_object; |
| 1095 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1096 | static void |
| 1097 | ast_dealloc(AST_object *self) |
| 1098 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1099 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1100 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1101 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1102 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1103 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1104 | assert(free_func != NULL); |
| 1105 | free_func(self); |
| 1106 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1107 | } |
| 1108 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1109 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1110 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1111 | { |
Miss Islington (bot) | bcbe5c5 | 2020-05-28 08:12:23 -0700 | [diff] [blame^] | 1112 | Py_VISIT(Py_TYPE(self)); |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1113 | Py_VISIT(self->dict); |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1117 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1118 | ast_clear(AST_object *self) |
| 1119 | { |
| 1120 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1121 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1125 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1126 | { |
| 1127 | Py_ssize_t i, numfields = 0; |
| 1128 | int res = -1; |
| 1129 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1130 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1131 | goto cleanup; |
| 1132 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1133 | if (fields) { |
| 1134 | numfields = PySequence_Size(fields); |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1135 | if (numfields == -1) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1136 | goto cleanup; |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1137 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1138 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1139 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1140 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1141 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1142 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1143 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1144 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1145 | numfields, numfields == 1 ? "" : "s"); |
| 1146 | res = -1; |
| 1147 | goto cleanup; |
| 1148 | } |
| 1149 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1150 | /* cannot be reached when fields is NULL */ |
| 1151 | PyObject *name = PySequence_GetItem(fields, i); |
| 1152 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1153 | res = -1; |
| 1154 | goto cleanup; |
| 1155 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1156 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1157 | Py_DECREF(name); |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1158 | if (res < 0) { |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1159 | goto cleanup; |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1160 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1161 | } |
| 1162 | if (kw) { |
| 1163 | i = 0; /* needed by PyDict_Next */ |
| 1164 | while (PyDict_Next(kw, &i, &key, &value)) { |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1165 | int contains = PySequence_Contains(fields, key); |
| 1166 | if (contains == -1) { |
| 1167 | res = -1; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1168 | goto cleanup; |
Miss Islington (bot) | 1a4e9e6 | 2020-05-24 14:32:32 -0700 | [diff] [blame] | 1169 | } else if (contains == 1) { |
| 1170 | Py_ssize_t p = PySequence_Index(fields, key); |
| 1171 | if (p == -1) { |
| 1172 | res = -1; |
| 1173 | goto cleanup; |
| 1174 | } |
| 1175 | if (p < PyTuple_GET_SIZE(args)) { |
| 1176 | PyErr_Format(PyExc_TypeError, |
| 1177 | "%.400s got multiple values for argument '%U'", |
| 1178 | Py_TYPE(self)->tp_name, key); |
| 1179 | res = -1; |
| 1180 | goto cleanup; |
| 1181 | } |
| 1182 | } |
| 1183 | res = PyObject_SetAttr(self, key, value); |
| 1184 | if (res < 0) { |
| 1185 | goto cleanup; |
| 1186 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | cleanup: |
| 1190 | Py_XDECREF(fields); |
| 1191 | return res; |
| 1192 | } |
| 1193 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1194 | /* Pickling support */ |
| 1195 | static PyObject * |
| 1196 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1197 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1198 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1199 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1200 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1201 | } |
| 1202 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1203 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1204 | } |
| 1205 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1206 | } |
| 1207 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1208 | static PyMemberDef ast_type_members[] = { |
| 1209 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1210 | {NULL} /* Sentinel */ |
| 1211 | }; |
| 1212 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1213 | static PyMethodDef ast_type_methods[] = { |
| 1214 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1215 | {NULL} |
| 1216 | }; |
| 1217 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1218 | static PyGetSetDef ast_type_getsets[] = { |
| 1219 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1220 | {NULL} |
| 1221 | }; |
| 1222 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1223 | static PyType_Slot AST_type_slots[] = { |
| 1224 | {Py_tp_dealloc, ast_dealloc}, |
| 1225 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1226 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1227 | {Py_tp_traverse, ast_traverse}, |
| 1228 | {Py_tp_clear, ast_clear}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1229 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1230 | {Py_tp_methods, ast_type_methods}, |
| 1231 | {Py_tp_getset, ast_type_getsets}, |
| 1232 | {Py_tp_init, ast_type_init}, |
| 1233 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1234 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1235 | {Py_tp_free, PyObject_GC_Del}, |
| 1236 | {0, 0}, |
| 1237 | }; |
| 1238 | |
| 1239 | static PyType_Spec AST_type_spec = { |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1240 | "ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1241 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1242 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1243 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1244 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1245 | }; |
| 1246 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1247 | static PyObject * |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1248 | make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1249 | { |
| 1250 | PyObject *fnames, *result; |
| 1251 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1252 | fnames = PyTuple_New(num_fields); |
| 1253 | if (!fnames) return NULL; |
| 1254 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1255 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1256 | if (!field) { |
| 1257 | Py_DECREF(fnames); |
| 1258 | return NULL; |
| 1259 | } |
| 1260 | PyTuple_SET_ITEM(fnames, i, field); |
| 1261 | } |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1262 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1263 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1264 | astmodulestate_global->_fields, fnames, |
| 1265 | astmodulestate_global->__module__, |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1266 | astmodulestate_global->ast, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1267 | astmodulestate_global->__doc__, doc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1268 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1269 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1272 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1273 | add_attributes(PyObject *type, const char * const *attrs, int num_fields) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1274 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1275 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1276 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1277 | if (!l) |
| 1278 | return 0; |
| 1279 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1280 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1281 | if (!s) { |
| 1282 | Py_DECREF(l); |
| 1283 | return 0; |
| 1284 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1285 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1286 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1287 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1288 | Py_DECREF(l); |
| 1289 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1292 | /* Conversion AST -> Python */ |
| 1293 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1294 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1295 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1296 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1297 | PyObject *result = PyList_New(n); |
| 1298 | PyObject *value; |
| 1299 | if (!result) |
| 1300 | return NULL; |
| 1301 | for (i = 0; i < n; i++) { |
| 1302 | value = func(asdl_seq_GET(seq, i)); |
| 1303 | if (!value) { |
| 1304 | Py_DECREF(result); |
| 1305 | return NULL; |
| 1306 | } |
| 1307 | PyList_SET_ITEM(result, i, value); |
| 1308 | } |
| 1309 | return result; |
| 1310 | } |
| 1311 | |
| 1312 | static PyObject* ast2obj_object(void *o) |
| 1313 | { |
| 1314 | if (!o) |
| 1315 | o = Py_None; |
| 1316 | Py_INCREF((PyObject*)o); |
| 1317 | return (PyObject*)o; |
| 1318 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1319 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1320 | #define ast2obj_identifier ast2obj_object |
| 1321 | #define ast2obj_string ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1322 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1323 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1324 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1325 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1328 | /* Conversion Python -> AST */ |
| 1329 | |
| 1330 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1331 | { |
| 1332 | if (obj == Py_None) |
| 1333 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1334 | if (obj) { |
| 1335 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1336 | *out = NULL; |
| 1337 | return -1; |
| 1338 | } |
| 1339 | Py_INCREF(obj); |
| 1340 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1341 | *out = obj; |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1345 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1346 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1347 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1348 | *out = NULL; |
| 1349 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1350 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1351 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1352 | *out = obj; |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1356 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1357 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1358 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1359 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1360 | return 1; |
| 1361 | } |
| 1362 | return obj2ast_object(obj, out, arena); |
| 1363 | } |
| 1364 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1365 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1366 | { |
| 1367 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1368 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1369 | return 1; |
| 1370 | } |
| 1371 | return obj2ast_object(obj, out, arena); |
| 1372 | } |
| 1373 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1374 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1375 | { |
| 1376 | int i; |
| 1377 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1378 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1379 | return 1; |
| 1380 | } |
| 1381 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1382 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1383 | if (i == -1 && PyErr_Occurred()) |
| 1384 | return 1; |
| 1385 | *out = i; |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1389 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1390 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1391 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1392 | empty_tuple = PyTuple_New(0); |
| 1393 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1394 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1395 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1396 | Py_XDECREF(empty_tuple); |
| 1397 | return -1; |
| 1398 | } |
| 1399 | Py_DECREF(empty_tuple); |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1403 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1404 | static int init_types(void) |
| 1405 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1406 | PyObject *m; |
| 1407 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1408 | m = PyModule_Create(&_astmodule); |
| 1409 | if (!m) return 0; |
| 1410 | PyState_AddModule(m, &_astmodule); |
| 1411 | } |
| 1412 | astmodulestate *state = astmodulestate_global; |
| 1413 | if (state->initialized) return 1; |
| 1414 | if (init_identifiers() < 0) return 0; |
| 1415 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1416 | if (!state->AST_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1417 | if (add_ast_fields() < 0) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1418 | state->mod_type = make_type("mod", state->AST_type, NULL, 0, |
| 1419 | "mod = Module(stmt* body, type_ignore* type_ignores)\n" |
| 1420 | " | Interactive(stmt* body)\n" |
| 1421 | " | Expression(expr body)\n" |
| 1422 | " | FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1423 | if (!state->mod_type) return 0; |
| 1424 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1425 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2, |
| 1426 | "Module(stmt* body, type_ignore* type_ignores)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1427 | if (!state->Module_type) return 0; |
| 1428 | state->Interactive_type = make_type("Interactive", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1429 | Interactive_fields, 1, |
| 1430 | "Interactive(stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1431 | if (!state->Interactive_type) return 0; |
| 1432 | state->Expression_type = make_type("Expression", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1433 | Expression_fields, 1, |
| 1434 | "Expression(expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1435 | if (!state->Expression_type) return 0; |
| 1436 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1437 | FunctionType_fields, 2, |
| 1438 | "FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1439 | if (!state->FunctionType_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1440 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0, |
| 1441 | "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1442 | " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1443 | " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" |
| 1444 | " | Return(expr? value)\n" |
| 1445 | " | Delete(expr* targets)\n" |
| 1446 | " | Assign(expr* targets, expr value, string? type_comment)\n" |
| 1447 | " | AugAssign(expr target, operator op, expr value)\n" |
| 1448 | " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n" |
| 1449 | " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1450 | " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1451 | " | While(expr test, stmt* body, stmt* orelse)\n" |
| 1452 | " | If(expr test, stmt* body, stmt* orelse)\n" |
| 1453 | " | With(withitem* items, stmt* body, string? type_comment)\n" |
| 1454 | " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n" |
| 1455 | " | Raise(expr? exc, expr? cause)\n" |
| 1456 | " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n" |
| 1457 | " | Assert(expr test, expr? msg)\n" |
| 1458 | " | Import(alias* names)\n" |
| 1459 | " | ImportFrom(identifier? module, alias* names, int? level)\n" |
| 1460 | " | Global(identifier* names)\n" |
| 1461 | " | Nonlocal(identifier* names)\n" |
| 1462 | " | Expr(expr value)\n" |
| 1463 | " | Pass\n" |
| 1464 | " | Break\n" |
| 1465 | " | Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1466 | if (!state->stmt_type) return 0; |
| 1467 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1468 | if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) |
| 1469 | return 0; |
| 1470 | if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == |
| 1471 | -1) |
| 1472 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1473 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1474 | FunctionDef_fields, 6, |
| 1475 | "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1476 | if (!state->FunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1477 | if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == |
| 1478 | -1) |
| 1479 | return 0; |
| 1480 | if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) |
| 1481 | == -1) |
| 1482 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1483 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1484 | state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1485 | AsyncFunctionDef_fields, 6, |
| 1486 | "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1487 | if (!state->AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1488 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) |
| 1489 | == -1) |
| 1490 | return 0; |
| 1491 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, |
| 1492 | Py_None) == -1) |
| 1493 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1494 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1495 | ClassDef_fields, 5, |
| 1496 | "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1497 | if (!state->ClassDef_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1498 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1, |
| 1499 | "Return(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1500 | if (!state->Return_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1501 | if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) |
| 1502 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1503 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1, |
| 1504 | "Delete(expr* targets)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1505 | if (!state->Delete_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1506 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3, |
| 1507 | "Assign(expr* targets, expr value, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1508 | if (!state->Assign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1509 | if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == |
| 1510 | -1) |
| 1511 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1512 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1513 | AugAssign_fields, 3, |
| 1514 | "AugAssign(expr target, operator op, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1515 | if (!state->AugAssign_type) return 0; |
| 1516 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1517 | AnnAssign_fields, 4, |
| 1518 | "AnnAssign(expr target, expr annotation, expr? value, int simple)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1519 | if (!state->AnnAssign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1520 | if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) |
| 1521 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1522 | state->For_type = make_type("For", state->stmt_type, For_fields, 5, |
| 1523 | "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1524 | if (!state->For_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1525 | if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) |
| 1526 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1527 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1528 | AsyncFor_fields, 5, |
| 1529 | "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1530 | if (!state->AsyncFor_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1531 | if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == |
| 1532 | -1) |
| 1533 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1534 | state->While_type = make_type("While", state->stmt_type, While_fields, 3, |
| 1535 | "While(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1536 | if (!state->While_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1537 | state->If_type = make_type("If", state->stmt_type, If_fields, 3, |
| 1538 | "If(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1539 | if (!state->If_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1540 | state->With_type = make_type("With", state->stmt_type, With_fields, 3, |
| 1541 | "With(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1542 | if (!state->With_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1543 | if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) |
| 1544 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1545 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1546 | AsyncWith_fields, 3, |
| 1547 | "AsyncWith(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1548 | if (!state->AsyncWith_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1549 | if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) |
| 1550 | == -1) |
| 1551 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1552 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2, |
| 1553 | "Raise(expr? exc, expr? cause)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1554 | if (!state->Raise_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1555 | if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) |
| 1556 | return 0; |
| 1557 | if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) |
| 1558 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1559 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4, |
| 1560 | "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1561 | if (!state->Try_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1562 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2, |
| 1563 | "Assert(expr test, expr? msg)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1564 | if (!state->Assert_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1565 | if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) |
| 1566 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1567 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1, |
| 1568 | "Import(alias* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1569 | if (!state->Import_type) return 0; |
| 1570 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1571 | ImportFrom_fields, 3, |
| 1572 | "ImportFrom(identifier? module, alias* names, int? level)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1573 | if (!state->ImportFrom_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1574 | if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) |
| 1575 | return 0; |
| 1576 | if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) |
| 1577 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1578 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1, |
| 1579 | "Global(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1580 | if (!state->Global_type) return 0; |
| 1581 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1582 | Nonlocal_fields, 1, |
| 1583 | "Nonlocal(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1584 | if (!state->Nonlocal_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1585 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1, |
| 1586 | "Expr(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1587 | if (!state->Expr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1588 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0, |
| 1589 | "Pass"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1590 | if (!state->Pass_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1591 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0, |
| 1592 | "Break"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1593 | if (!state->Break_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1594 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0, |
| 1595 | "Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1596 | if (!state->Continue_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1597 | state->expr_type = make_type("expr", state->AST_type, NULL, 0, |
| 1598 | "expr = BoolOp(boolop op, expr* values)\n" |
| 1599 | " | NamedExpr(expr target, expr value)\n" |
| 1600 | " | BinOp(expr left, operator op, expr right)\n" |
| 1601 | " | UnaryOp(unaryop op, expr operand)\n" |
| 1602 | " | Lambda(arguments args, expr body)\n" |
| 1603 | " | IfExp(expr test, expr body, expr orelse)\n" |
| 1604 | " | Dict(expr* keys, expr* values)\n" |
| 1605 | " | Set(expr* elts)\n" |
| 1606 | " | ListComp(expr elt, comprehension* generators)\n" |
| 1607 | " | SetComp(expr elt, comprehension* generators)\n" |
| 1608 | " | DictComp(expr key, expr value, comprehension* generators)\n" |
| 1609 | " | GeneratorExp(expr elt, comprehension* generators)\n" |
| 1610 | " | Await(expr value)\n" |
| 1611 | " | Yield(expr? value)\n" |
| 1612 | " | YieldFrom(expr value)\n" |
| 1613 | " | Compare(expr left, cmpop* ops, expr* comparators)\n" |
| 1614 | " | Call(expr func, expr* args, keyword* keywords)\n" |
| 1615 | " | FormattedValue(expr value, int? conversion, expr? format_spec)\n" |
| 1616 | " | JoinedStr(expr* values)\n" |
| 1617 | " | Constant(constant value, string? kind)\n" |
| 1618 | " | Attribute(expr value, identifier attr, expr_context ctx)\n" |
| 1619 | " | Subscript(expr value, expr slice, expr_context ctx)\n" |
| 1620 | " | Starred(expr value, expr_context ctx)\n" |
| 1621 | " | Name(identifier id, expr_context ctx)\n" |
| 1622 | " | List(expr* elts, expr_context ctx)\n" |
| 1623 | " | Tuple(expr* elts, expr_context ctx)\n" |
| 1624 | " | Slice(expr? lower, expr? upper, expr? step)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1625 | if (!state->expr_type) return 0; |
| 1626 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1627 | if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) |
| 1628 | return 0; |
| 1629 | if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == |
| 1630 | -1) |
| 1631 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1632 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2, |
| 1633 | "BoolOp(boolop op, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1634 | if (!state->BoolOp_type) return 0; |
| 1635 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1636 | NamedExpr_fields, 2, |
| 1637 | "NamedExpr(expr target, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1638 | if (!state->NamedExpr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1639 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3, |
| 1640 | "BinOp(expr left, operator op, expr right)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1641 | if (!state->BinOp_type) return 0; |
| 1642 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1643 | UnaryOp_fields, 2, |
| 1644 | "UnaryOp(unaryop op, expr operand)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1645 | if (!state->UnaryOp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1646 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2, |
| 1647 | "Lambda(arguments args, expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1648 | if (!state->Lambda_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1649 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3, |
| 1650 | "IfExp(expr test, expr body, expr orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1651 | if (!state->IfExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1652 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2, |
| 1653 | "Dict(expr* keys, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1654 | if (!state->Dict_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1655 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1, |
| 1656 | "Set(expr* elts)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1657 | if (!state->Set_type) return 0; |
| 1658 | state->ListComp_type = make_type("ListComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1659 | ListComp_fields, 2, |
| 1660 | "ListComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1661 | if (!state->ListComp_type) return 0; |
| 1662 | state->SetComp_type = make_type("SetComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1663 | SetComp_fields, 2, |
| 1664 | "SetComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1665 | if (!state->SetComp_type) return 0; |
| 1666 | state->DictComp_type = make_type("DictComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1667 | DictComp_fields, 3, |
| 1668 | "DictComp(expr key, expr value, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1669 | if (!state->DictComp_type) return 0; |
| 1670 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1671 | GeneratorExp_fields, 2, |
| 1672 | "GeneratorExp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1673 | if (!state->GeneratorExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1674 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1, |
| 1675 | "Await(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1676 | if (!state->Await_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1677 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1, |
| 1678 | "Yield(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1679 | if (!state->Yield_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1680 | if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) |
| 1681 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1682 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1683 | YieldFrom_fields, 1, |
| 1684 | "YieldFrom(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1685 | if (!state->YieldFrom_type) return 0; |
| 1686 | state->Compare_type = make_type("Compare", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1687 | Compare_fields, 3, |
| 1688 | "Compare(expr left, cmpop* ops, expr* comparators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1689 | if (!state->Compare_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1690 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3, |
| 1691 | "Call(expr func, expr* args, keyword* keywords)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1692 | if (!state->Call_type) return 0; |
| 1693 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1694 | FormattedValue_fields, 3, |
| 1695 | "FormattedValue(expr value, int? conversion, expr? format_spec)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1696 | if (!state->FormattedValue_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1697 | if (PyObject_SetAttr(state->FormattedValue_type, state->conversion, |
| 1698 | Py_None) == -1) |
| 1699 | return 0; |
| 1700 | if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, |
| 1701 | Py_None) == -1) |
| 1702 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1703 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1704 | JoinedStr_fields, 1, |
| 1705 | "JoinedStr(expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1706 | if (!state->JoinedStr_type) return 0; |
| 1707 | state->Constant_type = make_type("Constant", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1708 | Constant_fields, 2, |
| 1709 | "Constant(constant value, string? kind)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1710 | if (!state->Constant_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1711 | if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) |
| 1712 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1713 | state->Attribute_type = make_type("Attribute", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1714 | Attribute_fields, 3, |
| 1715 | "Attribute(expr value, identifier attr, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1716 | if (!state->Attribute_type) return 0; |
| 1717 | state->Subscript_type = make_type("Subscript", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1718 | Subscript_fields, 3, |
| 1719 | "Subscript(expr value, expr slice, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1720 | if (!state->Subscript_type) return 0; |
| 1721 | state->Starred_type = make_type("Starred", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1722 | Starred_fields, 2, |
| 1723 | "Starred(expr value, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1724 | if (!state->Starred_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1725 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2, |
| 1726 | "Name(identifier id, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1727 | if (!state->Name_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1728 | state->List_type = make_type("List", state->expr_type, List_fields, 2, |
| 1729 | "List(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1730 | if (!state->List_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1731 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2, |
| 1732 | "Tuple(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1733 | if (!state->Tuple_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1734 | state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3, |
| 1735 | "Slice(expr? lower, expr? upper, expr? step)"); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1736 | if (!state->Slice_type) return 0; |
| 1737 | if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) |
| 1738 | return 0; |
| 1739 | if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1) |
| 1740 | return 0; |
| 1741 | if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) |
| 1742 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1743 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1744 | 0, |
Serhiy Storchaka | 6b97598 | 2020-03-17 23:41:08 +0200 | [diff] [blame] | 1745 | "expr_context = Load | Store | Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1746 | if (!state->expr_context_type) return 0; |
| 1747 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1748 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0, |
| 1749 | "Load"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1750 | if (!state->Load_type) return 0; |
| 1751 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1752 | NULL, NULL); |
| 1753 | if (!state->Load_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1754 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0, |
| 1755 | "Store"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1756 | if (!state->Store_type) return 0; |
| 1757 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1758 | *)state->Store_type, NULL, NULL); |
| 1759 | if (!state->Store_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1760 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0, |
| 1761 | "Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1762 | if (!state->Del_type) return 0; |
| 1763 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1764 | NULL, NULL); |
| 1765 | if (!state->Del_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1766 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0, |
| 1767 | "boolop = And | Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1768 | if (!state->boolop_type) return 0; |
| 1769 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1770 | state->And_type = make_type("And", state->boolop_type, NULL, 0, |
| 1771 | "And"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1772 | if (!state->And_type) return 0; |
| 1773 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1774 | NULL, NULL); |
| 1775 | if (!state->And_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1776 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0, |
| 1777 | "Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1778 | if (!state->Or_type) return 0; |
| 1779 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1780 | NULL, NULL); |
| 1781 | if (!state->Or_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1782 | state->operator_type = make_type("operator", state->AST_type, NULL, 0, |
| 1783 | "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1784 | if (!state->operator_type) return 0; |
| 1785 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1786 | state->Add_type = make_type("Add", state->operator_type, NULL, 0, |
| 1787 | "Add"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1788 | if (!state->Add_type) return 0; |
| 1789 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1790 | NULL, NULL); |
| 1791 | if (!state->Add_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1792 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0, |
| 1793 | "Sub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1794 | if (!state->Sub_type) return 0; |
| 1795 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1796 | NULL, NULL); |
| 1797 | if (!state->Sub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1798 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0, |
| 1799 | "Mult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1800 | if (!state->Mult_type) return 0; |
| 1801 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1802 | NULL, NULL); |
| 1803 | if (!state->Mult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1804 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0, |
| 1805 | "MatMult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1806 | if (!state->MatMult_type) return 0; |
| 1807 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1808 | *)state->MatMult_type, NULL, |
| 1809 | NULL); |
| 1810 | if (!state->MatMult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1811 | state->Div_type = make_type("Div", state->operator_type, NULL, 0, |
| 1812 | "Div"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1813 | if (!state->Div_type) return 0; |
| 1814 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1815 | NULL, NULL); |
| 1816 | if (!state->Div_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1817 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0, |
| 1818 | "Mod"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1819 | if (!state->Mod_type) return 0; |
| 1820 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1821 | NULL, NULL); |
| 1822 | if (!state->Mod_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1823 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0, |
| 1824 | "Pow"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1825 | if (!state->Pow_type) return 0; |
| 1826 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1827 | NULL, NULL); |
| 1828 | if (!state->Pow_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1829 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0, |
| 1830 | "LShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1831 | if (!state->LShift_type) return 0; |
| 1832 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1833 | *)state->LShift_type, NULL, |
| 1834 | NULL); |
| 1835 | if (!state->LShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1836 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0, |
| 1837 | "RShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1838 | if (!state->RShift_type) return 0; |
| 1839 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1840 | *)state->RShift_type, NULL, |
| 1841 | NULL); |
| 1842 | if (!state->RShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1843 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0, |
| 1844 | "BitOr"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1845 | if (!state->BitOr_type) return 0; |
| 1846 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1847 | *)state->BitOr_type, NULL, NULL); |
| 1848 | if (!state->BitOr_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1849 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0, |
| 1850 | "BitXor"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1851 | if (!state->BitXor_type) return 0; |
| 1852 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1853 | *)state->BitXor_type, NULL, |
| 1854 | NULL); |
| 1855 | if (!state->BitXor_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1856 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0, |
| 1857 | "BitAnd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1858 | if (!state->BitAnd_type) return 0; |
| 1859 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1860 | *)state->BitAnd_type, NULL, |
| 1861 | NULL); |
| 1862 | if (!state->BitAnd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1863 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0, |
| 1864 | "FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1865 | if (!state->FloorDiv_type) return 0; |
| 1866 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1867 | *)state->FloorDiv_type, NULL, |
| 1868 | NULL); |
| 1869 | if (!state->FloorDiv_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1870 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0, |
| 1871 | "unaryop = Invert | Not | UAdd | USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1872 | if (!state->unaryop_type) return 0; |
| 1873 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1874 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0, |
| 1875 | "Invert"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1876 | if (!state->Invert_type) return 0; |
| 1877 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1878 | *)state->Invert_type, NULL, |
| 1879 | NULL); |
| 1880 | if (!state->Invert_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1881 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0, |
| 1882 | "Not"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1883 | if (!state->Not_type) return 0; |
| 1884 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1885 | NULL, NULL); |
| 1886 | if (!state->Not_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1887 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0, |
| 1888 | "UAdd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1889 | if (!state->UAdd_type) return 0; |
| 1890 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1891 | NULL, NULL); |
| 1892 | if (!state->UAdd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1893 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0, |
| 1894 | "USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1895 | if (!state->USub_type) return 0; |
| 1896 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1897 | NULL, NULL); |
| 1898 | if (!state->USub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1899 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0, |
| 1900 | "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1901 | if (!state->cmpop_type) return 0; |
| 1902 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1903 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0, |
| 1904 | "Eq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1905 | if (!state->Eq_type) return 0; |
| 1906 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1907 | NULL, NULL); |
| 1908 | if (!state->Eq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1909 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0, |
| 1910 | "NotEq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1911 | if (!state->NotEq_type) return 0; |
| 1912 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1913 | *)state->NotEq_type, NULL, NULL); |
| 1914 | if (!state->NotEq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1915 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0, |
| 1916 | "Lt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1917 | if (!state->Lt_type) return 0; |
| 1918 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1919 | NULL, NULL); |
| 1920 | if (!state->Lt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1921 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0, |
| 1922 | "LtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1923 | if (!state->LtE_type) return 0; |
| 1924 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1925 | NULL, NULL); |
| 1926 | if (!state->LtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1927 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0, |
| 1928 | "Gt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1929 | if (!state->Gt_type) return 0; |
| 1930 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1931 | NULL, NULL); |
| 1932 | if (!state->Gt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1933 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0, |
| 1934 | "GtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1935 | if (!state->GtE_type) return 0; |
| 1936 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1937 | NULL, NULL); |
| 1938 | if (!state->GtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1939 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0, |
| 1940 | "Is"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1941 | if (!state->Is_type) return 0; |
| 1942 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1943 | NULL, NULL); |
| 1944 | if (!state->Is_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1945 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0, |
| 1946 | "IsNot"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1947 | if (!state->IsNot_type) return 0; |
| 1948 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1949 | *)state->IsNot_type, NULL, NULL); |
| 1950 | if (!state->IsNot_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1951 | state->In_type = make_type("In", state->cmpop_type, NULL, 0, |
| 1952 | "In"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1953 | if (!state->In_type) return 0; |
| 1954 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1955 | NULL, NULL); |
| 1956 | if (!state->In_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1957 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0, |
| 1958 | "NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1959 | if (!state->NotIn_type) return 0; |
| 1960 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1961 | *)state->NotIn_type, NULL, NULL); |
| 1962 | if (!state->NotIn_singleton) return 0; |
| 1963 | state->comprehension_type = make_type("comprehension", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1964 | comprehension_fields, 4, |
| 1965 | "comprehension(expr target, expr iter, expr* ifs, int is_async)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1966 | if (!state->comprehension_type) return 0; |
| 1967 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1968 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1969 | NULL, 0, |
| 1970 | "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1971 | if (!state->excepthandler_type) return 0; |
| 1972 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1973 | 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1974 | if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) |
| 1975 | == -1) |
| 1976 | return 0; |
| 1977 | if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, |
| 1978 | Py_None) == -1) |
| 1979 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1980 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1981 | state->excepthandler_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1982 | ExceptHandler_fields, 3, |
| 1983 | "ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1984 | if (!state->ExceptHandler_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1985 | if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1) |
| 1986 | return 0; |
| 1987 | if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) |
| 1988 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1989 | state->arguments_type = make_type("arguments", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1990 | arguments_fields, 7, |
| 1991 | "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1992 | if (!state->arguments_type) return 0; |
| 1993 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1994 | if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) |
| 1995 | return 0; |
| 1996 | if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) |
| 1997 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1998 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3, |
| 1999 | "arg(identifier arg, expr? annotation, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2000 | if (!state->arg_type) return 0; |
| 2001 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2002 | if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) |
| 2003 | return 0; |
| 2004 | if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) |
| 2005 | return 0; |
| 2006 | if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1) |
| 2007 | return 0; |
| 2008 | if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) |
| 2009 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2010 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2011 | 2, |
| 2012 | "keyword(identifier? arg, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2013 | if (!state->keyword_type) return 0; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 2014 | if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2015 | if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) |
| 2016 | return 0; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 2017 | if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1) |
| 2018 | return 0; |
| 2019 | if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None) |
| 2020 | == -1) |
| 2021 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2022 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2, |
| 2023 | "alias(identifier name, identifier? asname)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2024 | if (!state->alias_type) return 0; |
| 2025 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2026 | if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) |
| 2027 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2028 | state->withitem_type = make_type("withitem", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2029 | withitem_fields, 2, |
| 2030 | "withitem(expr context_expr, expr? optional_vars)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2031 | if (!state->withitem_type) return 0; |
| 2032 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2033 | if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) |
| 2034 | == -1) |
| 2035 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2036 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0, |
| 2037 | "type_ignore = TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2038 | if (!state->type_ignore_type) return 0; |
| 2039 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 2040 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2041 | TypeIgnore_fields, 2, |
| 2042 | "TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2043 | if (!state->TypeIgnore_type) return 0; |
| 2044 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2045 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2046 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2047 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2048 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 2049 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 2050 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 2051 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 2052 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2053 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 2054 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 2055 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 2056 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 2057 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 2058 | arena); |
| 2059 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 2060 | arena); |
| 2061 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 2062 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 2063 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 2064 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2065 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2066 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 2067 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2068 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2069 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2070 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2071 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2072 | mod_ty p; |
| 2073 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2074 | if (!p) |
| 2075 | return NULL; |
| 2076 | p->kind = Module_kind; |
| 2077 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2078 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2079 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2083 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2084 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2085 | mod_ty p; |
| 2086 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2087 | if (!p) |
| 2088 | return NULL; |
| 2089 | p->kind = Interactive_kind; |
| 2090 | p->v.Interactive.body = body; |
| 2091 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2095 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2096 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2097 | mod_ty p; |
| 2098 | if (!body) { |
| 2099 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2100 | "field 'body' is required for Expression"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2101 | return NULL; |
| 2102 | } |
| 2103 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2104 | if (!p) |
| 2105 | return NULL; |
| 2106 | p->kind = Expression_kind; |
| 2107 | p->v.Expression.body = body; |
| 2108 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2112 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 2113 | { |
| 2114 | mod_ty p; |
| 2115 | if (!returns) { |
| 2116 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2117 | "field 'returns' is required for FunctionType"); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2118 | return NULL; |
| 2119 | } |
| 2120 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2121 | if (!p) |
| 2122 | return NULL; |
| 2123 | p->kind = FunctionType_kind; |
| 2124 | p->v.FunctionType.argtypes = argtypes; |
| 2125 | p->v.FunctionType.returns = returns; |
| 2126 | return p; |
| 2127 | } |
| 2128 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2129 | stmt_ty |
| 2130 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2131 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 2132 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2133 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2134 | stmt_ty p; |
| 2135 | if (!name) { |
| 2136 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2137 | "field 'name' is required for FunctionDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2138 | return NULL; |
| 2139 | } |
| 2140 | if (!args) { |
| 2141 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2142 | "field 'args' is required for FunctionDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2143 | return NULL; |
| 2144 | } |
| 2145 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2146 | if (!p) |
| 2147 | return NULL; |
| 2148 | p->kind = FunctionDef_kind; |
| 2149 | p->v.FunctionDef.name = name; |
| 2150 | p->v.FunctionDef.args = args; |
| 2151 | p->v.FunctionDef.body = body; |
| 2152 | p->v.FunctionDef.decorator_list = decorator_list; |
| 2153 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2154 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2155 | p->lineno = lineno; |
| 2156 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2157 | p->end_lineno = end_lineno; |
| 2158 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2159 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2163 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2164 | * decorator_list, expr_ty returns, string type_comment, int |
| 2165 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2166 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2167 | { |
| 2168 | stmt_ty p; |
| 2169 | if (!name) { |
| 2170 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2171 | "field 'name' is required for AsyncFunctionDef"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2172 | return NULL; |
| 2173 | } |
| 2174 | if (!args) { |
| 2175 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2176 | "field 'args' is required for AsyncFunctionDef"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2177 | return NULL; |
| 2178 | } |
| 2179 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2180 | if (!p) |
| 2181 | return NULL; |
| 2182 | p->kind = AsyncFunctionDef_kind; |
| 2183 | p->v.AsyncFunctionDef.name = name; |
| 2184 | p->v.AsyncFunctionDef.args = args; |
| 2185 | p->v.AsyncFunctionDef.body = body; |
| 2186 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 2187 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2188 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2189 | p->lineno = lineno; |
| 2190 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2191 | p->end_lineno = end_lineno; |
| 2192 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2193 | return p; |
| 2194 | } |
| 2195 | |
| 2196 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2197 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2198 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2199 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2200 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2201 | stmt_ty p; |
| 2202 | if (!name) { |
| 2203 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2204 | "field 'name' is required for ClassDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2205 | return NULL; |
| 2206 | } |
| 2207 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2208 | if (!p) |
| 2209 | return NULL; |
| 2210 | p->kind = ClassDef_kind; |
| 2211 | p->v.ClassDef.name = name; |
| 2212 | p->v.ClassDef.bases = bases; |
| 2213 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2214 | p->v.ClassDef.body = body; |
| 2215 | p->v.ClassDef.decorator_list = decorator_list; |
| 2216 | p->lineno = lineno; |
| 2217 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2218 | p->end_lineno = end_lineno; |
| 2219 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2220 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2224 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2225 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2226 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2227 | stmt_ty p; |
| 2228 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2229 | if (!p) |
| 2230 | return NULL; |
| 2231 | p->kind = Return_kind; |
| 2232 | p->v.Return.value = value; |
| 2233 | p->lineno = lineno; |
| 2234 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2235 | p->end_lineno = end_lineno; |
| 2236 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2237 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2241 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2242 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2243 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2244 | stmt_ty p; |
| 2245 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2246 | if (!p) |
| 2247 | return NULL; |
| 2248 | p->kind = Delete_kind; |
| 2249 | p->v.Delete.targets = targets; |
| 2250 | p->lineno = lineno; |
| 2251 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2252 | p->end_lineno = end_lineno; |
| 2253 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2254 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2258 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2259 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2260 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2261 | stmt_ty p; |
| 2262 | if (!value) { |
| 2263 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2264 | "field 'value' is required for Assign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2265 | return NULL; |
| 2266 | } |
| 2267 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2268 | if (!p) |
| 2269 | return NULL; |
| 2270 | p->kind = Assign_kind; |
| 2271 | p->v.Assign.targets = targets; |
| 2272 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2273 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2274 | p->lineno = lineno; |
| 2275 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2276 | p->end_lineno = end_lineno; |
| 2277 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2278 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2282 | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2283 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2284 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2285 | stmt_ty p; |
| 2286 | if (!target) { |
| 2287 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2288 | "field 'target' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2289 | return NULL; |
| 2290 | } |
| 2291 | if (!op) { |
| 2292 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2293 | "field 'op' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2294 | return NULL; |
| 2295 | } |
| 2296 | if (!value) { |
| 2297 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2298 | "field 'value' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2299 | return NULL; |
| 2300 | } |
| 2301 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2302 | if (!p) |
| 2303 | return NULL; |
| 2304 | p->kind = AugAssign_kind; |
| 2305 | p->v.AugAssign.target = target; |
| 2306 | p->v.AugAssign.op = op; |
| 2307 | p->v.AugAssign.value = value; |
| 2308 | p->lineno = lineno; |
| 2309 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2310 | p->end_lineno = end_lineno; |
| 2311 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2312 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2316 | AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2317 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2318 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2319 | { |
| 2320 | stmt_ty p; |
| 2321 | if (!target) { |
| 2322 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2323 | "field 'target' is required for AnnAssign"); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2324 | return NULL; |
| 2325 | } |
| 2326 | if (!annotation) { |
| 2327 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2328 | "field 'annotation' is required for AnnAssign"); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2329 | return NULL; |
| 2330 | } |
| 2331 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2332 | if (!p) |
| 2333 | return NULL; |
| 2334 | p->kind = AnnAssign_kind; |
| 2335 | p->v.AnnAssign.target = target; |
| 2336 | p->v.AnnAssign.annotation = annotation; |
| 2337 | p->v.AnnAssign.value = value; |
| 2338 | p->v.AnnAssign.simple = simple; |
| 2339 | p->lineno = lineno; |
| 2340 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2341 | p->end_lineno = end_lineno; |
| 2342 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2343 | return p; |
| 2344 | } |
| 2345 | |
| 2346 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2347 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2348 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2349 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2350 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2351 | stmt_ty p; |
| 2352 | if (!target) { |
| 2353 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2354 | "field 'target' is required for For"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2355 | return NULL; |
| 2356 | } |
| 2357 | if (!iter) { |
| 2358 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2359 | "field 'iter' is required for For"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2360 | return NULL; |
| 2361 | } |
| 2362 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2363 | if (!p) |
| 2364 | return NULL; |
| 2365 | p->kind = For_kind; |
| 2366 | p->v.For.target = target; |
| 2367 | p->v.For.iter = iter; |
| 2368 | p->v.For.body = body; |
| 2369 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2370 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2371 | p->lineno = lineno; |
| 2372 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2373 | p->end_lineno = end_lineno; |
| 2374 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2375 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2379 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2380 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2381 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2382 | { |
| 2383 | stmt_ty p; |
| 2384 | if (!target) { |
| 2385 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2386 | "field 'target' is required for AsyncFor"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2387 | return NULL; |
| 2388 | } |
| 2389 | if (!iter) { |
| 2390 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2391 | "field 'iter' is required for AsyncFor"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2392 | return NULL; |
| 2393 | } |
| 2394 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2395 | if (!p) |
| 2396 | return NULL; |
| 2397 | p->kind = AsyncFor_kind; |
| 2398 | p->v.AsyncFor.target = target; |
| 2399 | p->v.AsyncFor.iter = iter; |
| 2400 | p->v.AsyncFor.body = body; |
| 2401 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2402 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2403 | p->lineno = lineno; |
| 2404 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2405 | p->end_lineno = end_lineno; |
| 2406 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2407 | return p; |
| 2408 | } |
| 2409 | |
| 2410 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2411 | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2412 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2413 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2414 | stmt_ty p; |
| 2415 | if (!test) { |
| 2416 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2417 | "field 'test' is required for While"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2418 | return NULL; |
| 2419 | } |
| 2420 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2421 | if (!p) |
| 2422 | return NULL; |
| 2423 | p->kind = While_kind; |
| 2424 | p->v.While.test = test; |
| 2425 | p->v.While.body = body; |
| 2426 | p->v.While.orelse = orelse; |
| 2427 | p->lineno = lineno; |
| 2428 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2429 | p->end_lineno = end_lineno; |
| 2430 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2431 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2435 | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2436 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2437 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2438 | stmt_ty p; |
| 2439 | if (!test) { |
| 2440 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2441 | "field 'test' is required for If"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2442 | return NULL; |
| 2443 | } |
| 2444 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2445 | if (!p) |
| 2446 | return NULL; |
| 2447 | p->kind = If_kind; |
| 2448 | p->v.If.test = test; |
| 2449 | p->v.If.body = body; |
| 2450 | p->v.If.orelse = orelse; |
| 2451 | p->lineno = lineno; |
| 2452 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2453 | p->end_lineno = end_lineno; |
| 2454 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2455 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2459 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2460 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2461 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2462 | stmt_ty p; |
| 2463 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2464 | if (!p) |
| 2465 | return NULL; |
| 2466 | p->kind = With_kind; |
| 2467 | p->v.With.items = items; |
| 2468 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2469 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2470 | p->lineno = lineno; |
| 2471 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2472 | p->end_lineno = end_lineno; |
| 2473 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2474 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2478 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2479 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2480 | { |
| 2481 | stmt_ty p; |
| 2482 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2483 | if (!p) |
| 2484 | return NULL; |
| 2485 | p->kind = AsyncWith_kind; |
| 2486 | p->v.AsyncWith.items = items; |
| 2487 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2488 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2489 | p->lineno = lineno; |
| 2490 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2491 | p->end_lineno = end_lineno; |
| 2492 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2493 | return p; |
| 2494 | } |
| 2495 | |
| 2496 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2497 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2498 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2499 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2500 | stmt_ty p; |
| 2501 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2502 | if (!p) |
| 2503 | return NULL; |
| 2504 | p->kind = Raise_kind; |
| 2505 | p->v.Raise.exc = exc; |
| 2506 | p->v.Raise.cause = cause; |
| 2507 | p->lineno = lineno; |
| 2508 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2509 | p->end_lineno = end_lineno; |
| 2510 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2511 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2515 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2516 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2517 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2518 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2519 | stmt_ty p; |
| 2520 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2521 | if (!p) |
| 2522 | return NULL; |
| 2523 | p->kind = Try_kind; |
| 2524 | p->v.Try.body = body; |
| 2525 | p->v.Try.handlers = handlers; |
| 2526 | p->v.Try.orelse = orelse; |
| 2527 | p->v.Try.finalbody = finalbody; |
| 2528 | p->lineno = lineno; |
| 2529 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2530 | p->end_lineno = end_lineno; |
| 2531 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2532 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2536 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2537 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2538 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2539 | stmt_ty p; |
| 2540 | if (!test) { |
| 2541 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2542 | "field 'test' is required for Assert"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2543 | return NULL; |
| 2544 | } |
| 2545 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2546 | if (!p) |
| 2547 | return NULL; |
| 2548 | p->kind = Assert_kind; |
| 2549 | p->v.Assert.test = test; |
| 2550 | p->v.Assert.msg = msg; |
| 2551 | p->lineno = lineno; |
| 2552 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2553 | p->end_lineno = end_lineno; |
| 2554 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2555 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2559 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2560 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2561 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2562 | stmt_ty p; |
| 2563 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2564 | if (!p) |
| 2565 | return NULL; |
| 2566 | p->kind = Import_kind; |
| 2567 | p->v.Import.names = names; |
| 2568 | p->lineno = lineno; |
| 2569 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2570 | p->end_lineno = end_lineno; |
| 2571 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2572 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2576 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2577 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2578 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2579 | stmt_ty p; |
| 2580 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2581 | if (!p) |
| 2582 | return NULL; |
| 2583 | p->kind = ImportFrom_kind; |
| 2584 | p->v.ImportFrom.module = module; |
| 2585 | p->v.ImportFrom.names = names; |
| 2586 | p->v.ImportFrom.level = level; |
| 2587 | p->lineno = lineno; |
| 2588 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2589 | p->end_lineno = end_lineno; |
| 2590 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2591 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2595 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2596 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2597 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2598 | stmt_ty p; |
| 2599 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2600 | if (!p) |
| 2601 | return NULL; |
| 2602 | p->kind = Global_kind; |
| 2603 | p->v.Global.names = names; |
| 2604 | p->lineno = lineno; |
| 2605 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2606 | p->end_lineno = end_lineno; |
| 2607 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2608 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2612 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2613 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2614 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2615 | stmt_ty p; |
| 2616 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2617 | if (!p) |
| 2618 | return NULL; |
| 2619 | p->kind = Nonlocal_kind; |
| 2620 | p->v.Nonlocal.names = names; |
| 2621 | p->lineno = lineno; |
| 2622 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2623 | p->end_lineno = end_lineno; |
| 2624 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2625 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2629 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2630 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2631 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2632 | stmt_ty p; |
| 2633 | if (!value) { |
| 2634 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2635 | "field 'value' is required for Expr"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2636 | return NULL; |
| 2637 | } |
| 2638 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2639 | if (!p) |
| 2640 | return NULL; |
| 2641 | p->kind = Expr_kind; |
| 2642 | p->v.Expr.value = value; |
| 2643 | p->lineno = lineno; |
| 2644 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2645 | p->end_lineno = end_lineno; |
| 2646 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2647 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2651 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2652 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2653 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2654 | stmt_ty p; |
| 2655 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2656 | if (!p) |
| 2657 | return NULL; |
| 2658 | p->kind = Pass_kind; |
| 2659 | p->lineno = lineno; |
| 2660 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2661 | p->end_lineno = end_lineno; |
| 2662 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2663 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2667 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2668 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2669 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2670 | stmt_ty p; |
| 2671 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2672 | if (!p) |
| 2673 | return NULL; |
| 2674 | p->kind = Break_kind; |
| 2675 | p->lineno = lineno; |
| 2676 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2677 | p->end_lineno = end_lineno; |
| 2678 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2679 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2683 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2684 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2685 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2686 | stmt_ty p; |
| 2687 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2688 | if (!p) |
| 2689 | return NULL; |
| 2690 | p->kind = Continue_kind; |
| 2691 | p->lineno = lineno; |
| 2692 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2693 | p->end_lineno = end_lineno; |
| 2694 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2695 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2699 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2700 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2701 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2702 | expr_ty p; |
| 2703 | if (!op) { |
| 2704 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2705 | "field 'op' is required for BoolOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2706 | return NULL; |
| 2707 | } |
| 2708 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2709 | if (!p) |
| 2710 | return NULL; |
| 2711 | p->kind = BoolOp_kind; |
| 2712 | p->v.BoolOp.op = op; |
| 2713 | p->v.BoolOp.values = values; |
| 2714 | p->lineno = lineno; |
| 2715 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2716 | p->end_lineno = end_lineno; |
| 2717 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2718 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2722 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2723 | end_lineno, int end_col_offset, PyArena *arena) |
| 2724 | { |
| 2725 | expr_ty p; |
| 2726 | if (!target) { |
| 2727 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2728 | "field 'target' is required for NamedExpr"); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2729 | return NULL; |
| 2730 | } |
| 2731 | if (!value) { |
| 2732 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2733 | "field 'value' is required for NamedExpr"); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2734 | return NULL; |
| 2735 | } |
| 2736 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2737 | if (!p) |
| 2738 | return NULL; |
| 2739 | p->kind = NamedExpr_kind; |
| 2740 | p->v.NamedExpr.target = target; |
| 2741 | p->v.NamedExpr.value = value; |
| 2742 | p->lineno = lineno; |
| 2743 | p->col_offset = col_offset; |
| 2744 | p->end_lineno = end_lineno; |
| 2745 | p->end_col_offset = end_col_offset; |
| 2746 | return p; |
| 2747 | } |
| 2748 | |
| 2749 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2750 | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2751 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2752 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2753 | expr_ty p; |
| 2754 | if (!left) { |
| 2755 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2756 | "field 'left' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2757 | return NULL; |
| 2758 | } |
| 2759 | if (!op) { |
| 2760 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2761 | "field 'op' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2762 | return NULL; |
| 2763 | } |
| 2764 | if (!right) { |
| 2765 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2766 | "field 'right' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2767 | return NULL; |
| 2768 | } |
| 2769 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2770 | if (!p) |
| 2771 | return NULL; |
| 2772 | p->kind = BinOp_kind; |
| 2773 | p->v.BinOp.left = left; |
| 2774 | p->v.BinOp.op = op; |
| 2775 | p->v.BinOp.right = right; |
| 2776 | p->lineno = lineno; |
| 2777 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2778 | p->end_lineno = end_lineno; |
| 2779 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2780 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2784 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2785 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2786 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2787 | expr_ty p; |
| 2788 | if (!op) { |
| 2789 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2790 | "field 'op' is required for UnaryOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2791 | return NULL; |
| 2792 | } |
| 2793 | if (!operand) { |
| 2794 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2795 | "field 'operand' is required for UnaryOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2796 | return NULL; |
| 2797 | } |
| 2798 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2799 | if (!p) |
| 2800 | return NULL; |
| 2801 | p->kind = UnaryOp_kind; |
| 2802 | p->v.UnaryOp.op = op; |
| 2803 | p->v.UnaryOp.operand = operand; |
| 2804 | p->lineno = lineno; |
| 2805 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2806 | p->end_lineno = end_lineno; |
| 2807 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2808 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2812 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2813 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2814 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2815 | expr_ty p; |
| 2816 | if (!args) { |
| 2817 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2818 | "field 'args' is required for Lambda"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2819 | return NULL; |
| 2820 | } |
| 2821 | if (!body) { |
| 2822 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2823 | "field 'body' is required for Lambda"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2824 | return NULL; |
| 2825 | } |
| 2826 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2827 | if (!p) |
| 2828 | return NULL; |
| 2829 | p->kind = Lambda_kind; |
| 2830 | p->v.Lambda.args = args; |
| 2831 | p->v.Lambda.body = body; |
| 2832 | p->lineno = lineno; |
| 2833 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2834 | p->end_lineno = end_lineno; |
| 2835 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2836 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2840 | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2841 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2842 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2843 | expr_ty p; |
| 2844 | if (!test) { |
| 2845 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2846 | "field 'test' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2847 | return NULL; |
| 2848 | } |
| 2849 | if (!body) { |
| 2850 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2851 | "field 'body' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2852 | return NULL; |
| 2853 | } |
| 2854 | if (!orelse) { |
| 2855 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2856 | "field 'orelse' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2857 | return NULL; |
| 2858 | } |
| 2859 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2860 | if (!p) |
| 2861 | return NULL; |
| 2862 | p->kind = IfExp_kind; |
| 2863 | p->v.IfExp.test = test; |
| 2864 | p->v.IfExp.body = body; |
| 2865 | p->v.IfExp.orelse = orelse; |
| 2866 | p->lineno = lineno; |
| 2867 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2868 | p->end_lineno = end_lineno; |
| 2869 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2870 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2874 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2875 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2876 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2877 | expr_ty p; |
| 2878 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2879 | if (!p) |
| 2880 | return NULL; |
| 2881 | p->kind = Dict_kind; |
| 2882 | p->v.Dict.keys = keys; |
| 2883 | p->v.Dict.values = values; |
| 2884 | p->lineno = lineno; |
| 2885 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2886 | p->end_lineno = end_lineno; |
| 2887 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2888 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2892 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2893 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2894 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2895 | expr_ty p; |
| 2896 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2897 | if (!p) |
| 2898 | return NULL; |
| 2899 | p->kind = Set_kind; |
| 2900 | p->v.Set.elts = elts; |
| 2901 | p->lineno = lineno; |
| 2902 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2903 | p->end_lineno = end_lineno; |
| 2904 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2905 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2909 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2910 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2911 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2912 | expr_ty p; |
| 2913 | if (!elt) { |
| 2914 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2915 | "field 'elt' is required for ListComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2916 | return NULL; |
| 2917 | } |
| 2918 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2919 | if (!p) |
| 2920 | return NULL; |
| 2921 | p->kind = ListComp_kind; |
| 2922 | p->v.ListComp.elt = elt; |
| 2923 | p->v.ListComp.generators = generators; |
| 2924 | p->lineno = lineno; |
| 2925 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2926 | p->end_lineno = end_lineno; |
| 2927 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2928 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2932 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2933 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2934 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2935 | expr_ty p; |
| 2936 | if (!elt) { |
| 2937 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2938 | "field 'elt' is required for SetComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2939 | return NULL; |
| 2940 | } |
| 2941 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2942 | if (!p) |
| 2943 | return NULL; |
| 2944 | p->kind = SetComp_kind; |
| 2945 | p->v.SetComp.elt = elt; |
| 2946 | p->v.SetComp.generators = generators; |
| 2947 | p->lineno = lineno; |
| 2948 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2949 | p->end_lineno = end_lineno; |
| 2950 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2951 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2955 | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2956 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2957 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2958 | expr_ty p; |
| 2959 | if (!key) { |
| 2960 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2961 | "field 'key' is required for DictComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2962 | return NULL; |
| 2963 | } |
| 2964 | if (!value) { |
| 2965 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2966 | "field 'value' is required for DictComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2967 | return NULL; |
| 2968 | } |
| 2969 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2970 | if (!p) |
| 2971 | return NULL; |
| 2972 | p->kind = DictComp_kind; |
| 2973 | p->v.DictComp.key = key; |
| 2974 | p->v.DictComp.value = value; |
| 2975 | p->v.DictComp.generators = generators; |
| 2976 | p->lineno = lineno; |
| 2977 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2978 | p->end_lineno = end_lineno; |
| 2979 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2980 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2984 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2985 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2986 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2987 | expr_ty p; |
| 2988 | if (!elt) { |
| 2989 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2990 | "field 'elt' is required for GeneratorExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2991 | return NULL; |
| 2992 | } |
| 2993 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2994 | if (!p) |
| 2995 | return NULL; |
| 2996 | p->kind = GeneratorExp_kind; |
| 2997 | p->v.GeneratorExp.elt = elt; |
| 2998 | p->v.GeneratorExp.generators = generators; |
| 2999 | p->lineno = lineno; |
| 3000 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3001 | p->end_lineno = end_lineno; |
| 3002 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3003 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3007 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3008 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3009 | { |
| 3010 | expr_ty p; |
| 3011 | if (!value) { |
| 3012 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3013 | "field 'value' is required for Await"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3014 | return NULL; |
| 3015 | } |
| 3016 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3017 | if (!p) |
| 3018 | return NULL; |
| 3019 | p->kind = Await_kind; |
| 3020 | p->v.Await.value = value; |
| 3021 | p->lineno = lineno; |
| 3022 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3023 | p->end_lineno = end_lineno; |
| 3024 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3025 | return p; |
| 3026 | } |
| 3027 | |
| 3028 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3029 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3030 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3031 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3032 | expr_ty p; |
| 3033 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3034 | if (!p) |
| 3035 | return NULL; |
| 3036 | p->kind = Yield_kind; |
| 3037 | p->v.Yield.value = value; |
| 3038 | p->lineno = lineno; |
| 3039 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3040 | p->end_lineno = end_lineno; |
| 3041 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3042 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3046 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3047 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3048 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3049 | expr_ty p; |
| 3050 | if (!value) { |
| 3051 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3052 | "field 'value' is required for YieldFrom"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3053 | return NULL; |
| 3054 | } |
| 3055 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3056 | if (!p) |
| 3057 | return NULL; |
| 3058 | p->kind = YieldFrom_kind; |
| 3059 | p->v.YieldFrom.value = value; |
| 3060 | p->lineno = lineno; |
| 3061 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3062 | p->end_lineno = end_lineno; |
| 3063 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3064 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3068 | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3069 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3070 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3071 | expr_ty p; |
| 3072 | if (!left) { |
| 3073 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3074 | "field 'left' is required for Compare"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3075 | return NULL; |
| 3076 | } |
| 3077 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3078 | if (!p) |
| 3079 | return NULL; |
| 3080 | p->kind = Compare_kind; |
| 3081 | p->v.Compare.left = left; |
| 3082 | p->v.Compare.ops = ops; |
| 3083 | p->v.Compare.comparators = comparators; |
| 3084 | p->lineno = lineno; |
| 3085 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3086 | p->end_lineno = end_lineno; |
| 3087 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3088 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 3092 | Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3093 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3094 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3095 | expr_ty p; |
| 3096 | if (!func) { |
| 3097 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3098 | "field 'func' is required for Call"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3099 | return NULL; |
| 3100 | } |
| 3101 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3102 | if (!p) |
| 3103 | return NULL; |
| 3104 | p->kind = Call_kind; |
| 3105 | p->v.Call.func = func; |
| 3106 | p->v.Call.args = args; |
| 3107 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3108 | p->lineno = lineno; |
| 3109 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3110 | p->end_lineno = end_lineno; |
| 3111 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3112 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 3116 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 3117 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 3118 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3119 | { |
| 3120 | expr_ty p; |
| 3121 | if (!value) { |
| 3122 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3123 | "field 'value' is required for FormattedValue"); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3124 | return NULL; |
| 3125 | } |
| 3126 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3127 | if (!p) |
| 3128 | return NULL; |
| 3129 | p->kind = FormattedValue_kind; |
| 3130 | p->v.FormattedValue.value = value; |
| 3131 | p->v.FormattedValue.conversion = conversion; |
| 3132 | p->v.FormattedValue.format_spec = format_spec; |
| 3133 | p->lineno = lineno; |
| 3134 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3135 | p->end_lineno = end_lineno; |
| 3136 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3137 | return p; |
| 3138 | } |
| 3139 | |
| 3140 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3141 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 3142 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3143 | { |
| 3144 | expr_ty p; |
| 3145 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3146 | if (!p) |
| 3147 | return NULL; |
| 3148 | p->kind = JoinedStr_kind; |
| 3149 | p->v.JoinedStr.values = values; |
| 3150 | p->lineno = lineno; |
| 3151 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3152 | p->end_lineno = end_lineno; |
| 3153 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3154 | return p; |
| 3155 | } |
| 3156 | |
| 3157 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3158 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 3159 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3160 | { |
| 3161 | expr_ty p; |
| 3162 | if (!value) { |
| 3163 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3164 | "field 'value' is required for Constant"); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3165 | return NULL; |
| 3166 | } |
| 3167 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3168 | if (!p) |
| 3169 | return NULL; |
| 3170 | p->kind = Constant_kind; |
| 3171 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3172 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3173 | p->lineno = lineno; |
| 3174 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3175 | p->end_lineno = end_lineno; |
| 3176 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3177 | return p; |
| 3178 | } |
| 3179 | |
| 3180 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3181 | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3182 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3183 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3184 | expr_ty p; |
| 3185 | if (!value) { |
| 3186 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3187 | "field 'value' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3188 | return NULL; |
| 3189 | } |
| 3190 | if (!attr) { |
| 3191 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3192 | "field 'attr' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3193 | return NULL; |
| 3194 | } |
| 3195 | if (!ctx) { |
| 3196 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3197 | "field 'ctx' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3198 | return NULL; |
| 3199 | } |
| 3200 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3201 | if (!p) |
| 3202 | return NULL; |
| 3203 | p->kind = Attribute_kind; |
| 3204 | p->v.Attribute.value = value; |
| 3205 | p->v.Attribute.attr = attr; |
| 3206 | p->v.Attribute.ctx = ctx; |
| 3207 | p->lineno = lineno; |
| 3208 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3209 | p->end_lineno = end_lineno; |
| 3210 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3211 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | expr_ty |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3215 | Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3216 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3217 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3218 | expr_ty p; |
| 3219 | if (!value) { |
| 3220 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3221 | "field 'value' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3222 | return NULL; |
| 3223 | } |
| 3224 | if (!slice) { |
| 3225 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3226 | "field 'slice' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3227 | return NULL; |
| 3228 | } |
| 3229 | if (!ctx) { |
| 3230 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3231 | "field 'ctx' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3232 | return NULL; |
| 3233 | } |
| 3234 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3235 | if (!p) |
| 3236 | return NULL; |
| 3237 | p->kind = Subscript_kind; |
| 3238 | p->v.Subscript.value = value; |
| 3239 | p->v.Subscript.slice = slice; |
| 3240 | p->v.Subscript.ctx = ctx; |
| 3241 | p->lineno = lineno; |
| 3242 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3243 | p->end_lineno = end_lineno; |
| 3244 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3245 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3249 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3250 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3251 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3252 | expr_ty p; |
| 3253 | if (!value) { |
| 3254 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3255 | "field 'value' is required for Starred"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3256 | return NULL; |
| 3257 | } |
| 3258 | if (!ctx) { |
| 3259 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3260 | "field 'ctx' is required for Starred"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3261 | return NULL; |
| 3262 | } |
| 3263 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3264 | if (!p) |
| 3265 | return NULL; |
| 3266 | p->kind = Starred_kind; |
| 3267 | p->v.Starred.value = value; |
| 3268 | p->v.Starred.ctx = ctx; |
| 3269 | p->lineno = lineno; |
| 3270 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3271 | p->end_lineno = end_lineno; |
| 3272 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3273 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3277 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3278 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3279 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3280 | expr_ty p; |
| 3281 | if (!id) { |
| 3282 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3283 | "field 'id' is required for Name"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3284 | return NULL; |
| 3285 | } |
| 3286 | if (!ctx) { |
| 3287 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3288 | "field 'ctx' is required for Name"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3289 | return NULL; |
| 3290 | } |
| 3291 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3292 | if (!p) |
| 3293 | return NULL; |
| 3294 | p->kind = Name_kind; |
| 3295 | p->v.Name.id = id; |
| 3296 | p->v.Name.ctx = ctx; |
| 3297 | p->lineno = lineno; |
| 3298 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3299 | p->end_lineno = end_lineno; |
| 3300 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3301 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3305 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3306 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3307 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3308 | expr_ty p; |
| 3309 | if (!ctx) { |
| 3310 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3311 | "field 'ctx' is required for List"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3312 | return NULL; |
| 3313 | } |
| 3314 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3315 | if (!p) |
| 3316 | return NULL; |
| 3317 | p->kind = List_kind; |
| 3318 | p->v.List.elts = elts; |
| 3319 | p->v.List.ctx = ctx; |
| 3320 | p->lineno = lineno; |
| 3321 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3322 | p->end_lineno = end_lineno; |
| 3323 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3324 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3328 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3329 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3330 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3331 | expr_ty p; |
| 3332 | if (!ctx) { |
| 3333 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3334 | "field 'ctx' is required for Tuple"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3335 | return NULL; |
| 3336 | } |
| 3337 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3338 | if (!p) |
| 3339 | return NULL; |
| 3340 | p->kind = Tuple_kind; |
| 3341 | p->v.Tuple.elts = elts; |
| 3342 | p->v.Tuple.ctx = ctx; |
| 3343 | p->lineno = lineno; |
| 3344 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3345 | p->end_lineno = end_lineno; |
| 3346 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3347 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3348 | } |
| 3349 | |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3350 | expr_ty |
| 3351 | Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset, |
| 3352 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3353 | { |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3354 | expr_ty p; |
| 3355 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3356 | if (!p) |
| 3357 | return NULL; |
| 3358 | p->kind = Slice_kind; |
| 3359 | p->v.Slice.lower = lower; |
| 3360 | p->v.Slice.upper = upper; |
| 3361 | p->v.Slice.step = step; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3362 | p->lineno = lineno; |
| 3363 | p->col_offset = col_offset; |
| 3364 | p->end_lineno = end_lineno; |
| 3365 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3366 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3370 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3371 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3372 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3373 | comprehension_ty p; |
| 3374 | if (!target) { |
| 3375 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3376 | "field 'target' is required for comprehension"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3377 | return NULL; |
| 3378 | } |
| 3379 | if (!iter) { |
| 3380 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3381 | "field 'iter' is required for comprehension"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3382 | return NULL; |
| 3383 | } |
| 3384 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3385 | if (!p) |
| 3386 | return NULL; |
| 3387 | p->target = target; |
| 3388 | p->iter = iter; |
| 3389 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3390 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3391 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3395 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3396 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3397 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3398 | excepthandler_ty p; |
| 3399 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3400 | if (!p) |
| 3401 | return NULL; |
| 3402 | p->kind = ExceptHandler_kind; |
| 3403 | p->v.ExceptHandler.type = type; |
| 3404 | p->v.ExceptHandler.name = name; |
| 3405 | p->v.ExceptHandler.body = body; |
| 3406 | p->lineno = lineno; |
| 3407 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3408 | p->end_lineno = end_lineno; |
| 3409 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3410 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3414 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3415 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3416 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3417 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3418 | arguments_ty p; |
| 3419 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3420 | if (!p) |
| 3421 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3422 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3423 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3424 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3425 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3426 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3427 | p->kwarg = kwarg; |
| 3428 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3429 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3430 | } |
| 3431 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3432 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3433 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3434 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3435 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3436 | arg_ty p; |
| 3437 | if (!arg) { |
| 3438 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3439 | "field 'arg' is required for arg"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3440 | return NULL; |
| 3441 | } |
| 3442 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3443 | if (!p) |
| 3444 | return NULL; |
| 3445 | p->arg = arg; |
| 3446 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3447 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3448 | p->lineno = lineno; |
| 3449 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3450 | p->end_lineno = end_lineno; |
| 3451 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3452 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3453 | } |
| 3454 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3455 | keyword_ty |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 3456 | keyword(identifier arg, expr_ty value, int lineno, int col_offset, int |
| 3457 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3458 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3459 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3460 | if (!value) { |
| 3461 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3462 | "field 'value' is required for keyword"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3463 | return NULL; |
| 3464 | } |
| 3465 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3466 | if (!p) |
| 3467 | return NULL; |
| 3468 | p->arg = arg; |
| 3469 | p->value = value; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 3470 | p->lineno = lineno; |
| 3471 | p->col_offset = col_offset; |
| 3472 | p->end_lineno = end_lineno; |
| 3473 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3474 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3478 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3479 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3480 | alias_ty p; |
| 3481 | if (!name) { |
| 3482 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3483 | "field 'name' is required for alias"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3484 | return NULL; |
| 3485 | } |
| 3486 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3487 | if (!p) |
| 3488 | return NULL; |
| 3489 | p->name = name; |
| 3490 | p->asname = asname; |
| 3491 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3492 | } |
| 3493 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3494 | withitem_ty |
| 3495 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3496 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3497 | withitem_ty p; |
| 3498 | if (!context_expr) { |
| 3499 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3500 | "field 'context_expr' is required for withitem"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3501 | return NULL; |
| 3502 | } |
| 3503 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3504 | if (!p) |
| 3505 | return NULL; |
| 3506 | p->context_expr = context_expr; |
| 3507 | p->optional_vars = optional_vars; |
| 3508 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3509 | } |
| 3510 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3511 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3512 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3513 | { |
| 3514 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3515 | if (!tag) { |
| 3516 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3517 | "field 'tag' is required for TypeIgnore"); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3518 | return NULL; |
| 3519 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3520 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3521 | if (!p) |
| 3522 | return NULL; |
| 3523 | p->kind = TypeIgnore_kind; |
| 3524 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3525 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3526 | return p; |
| 3527 | } |
| 3528 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3529 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3530 | PyObject* |
| 3531 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3532 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3533 | mod_ty o = (mod_ty)_o; |
| 3534 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3535 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3536 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3537 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3538 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3539 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3540 | switch (o->kind) { |
| 3541 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3542 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3543 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3544 | if (!result) goto failed; |
| 3545 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3546 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3547 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3548 | goto failed; |
| 3549 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3550 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3551 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3552 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3553 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3554 | goto failed; |
| 3555 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3556 | break; |
| 3557 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3558 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3559 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3560 | if (!result) goto failed; |
| 3561 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3562 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3563 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3564 | goto failed; |
| 3565 | Py_DECREF(value); |
| 3566 | break; |
| 3567 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3568 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3569 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3570 | if (!result) goto failed; |
| 3571 | value = ast2obj_expr(o->v.Expression.body); |
| 3572 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3573 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3574 | goto failed; |
| 3575 | Py_DECREF(value); |
| 3576 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3577 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3578 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3579 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3580 | if (!result) goto failed; |
| 3581 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3582 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3583 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3584 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3585 | goto failed; |
| 3586 | Py_DECREF(value); |
| 3587 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3588 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3589 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3590 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3591 | goto failed; |
| 3592 | Py_DECREF(value); |
| 3593 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3594 | } |
| 3595 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3596 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3597 | Py_XDECREF(value); |
| 3598 | Py_XDECREF(result); |
| 3599 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3602 | PyObject* |
| 3603 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3604 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3605 | stmt_ty o = (stmt_ty)_o; |
| 3606 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3607 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3608 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3609 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3610 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3611 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3612 | switch (o->kind) { |
| 3613 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3614 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3615 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3616 | if (!result) goto failed; |
| 3617 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3618 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3619 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3620 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3621 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3622 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3623 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3624 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3625 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3626 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3627 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3628 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3629 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3630 | goto failed; |
| 3631 | Py_DECREF(value); |
| 3632 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3633 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3634 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3635 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3636 | goto failed; |
| 3637 | Py_DECREF(value); |
| 3638 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3639 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3640 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3641 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3642 | goto failed; |
| 3643 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3644 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3645 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3646 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3647 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3648 | goto failed; |
| 3649 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3650 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3651 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3652 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3653 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3654 | if (!result) goto failed; |
| 3655 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3656 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3657 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3658 | goto failed; |
| 3659 | Py_DECREF(value); |
| 3660 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3661 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3662 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3663 | goto failed; |
| 3664 | Py_DECREF(value); |
| 3665 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3666 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3667 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3668 | goto failed; |
| 3669 | Py_DECREF(value); |
| 3670 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3671 | ast2obj_expr); |
| 3672 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3673 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3674 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3675 | goto failed; |
| 3676 | Py_DECREF(value); |
| 3677 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3678 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3679 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3680 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3681 | goto failed; |
| 3682 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3683 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3684 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3685 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3686 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3687 | goto failed; |
| 3688 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3689 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3690 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3691 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3692 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3693 | if (!result) goto failed; |
| 3694 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3695 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3696 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3697 | goto failed; |
| 3698 | Py_DECREF(value); |
| 3699 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3700 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3701 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3702 | goto failed; |
| 3703 | Py_DECREF(value); |
| 3704 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3705 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3706 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3707 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3708 | goto failed; |
| 3709 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3710 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3711 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3712 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3713 | goto failed; |
| 3714 | Py_DECREF(value); |
| 3715 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3716 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3717 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3718 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3719 | goto failed; |
| 3720 | Py_DECREF(value); |
| 3721 | break; |
| 3722 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3723 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3724 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3725 | if (!result) goto failed; |
| 3726 | value = ast2obj_expr(o->v.Return.value); |
| 3727 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3728 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3729 | goto failed; |
| 3730 | Py_DECREF(value); |
| 3731 | break; |
| 3732 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3733 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3734 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3735 | if (!result) goto failed; |
| 3736 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3737 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3738 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3739 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3740 | goto failed; |
| 3741 | Py_DECREF(value); |
| 3742 | break; |
| 3743 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3744 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3745 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3746 | if (!result) goto failed; |
| 3747 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3748 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3749 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3750 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3751 | goto failed; |
| 3752 | Py_DECREF(value); |
| 3753 | value = ast2obj_expr(o->v.Assign.value); |
| 3754 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3755 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3756 | goto failed; |
| 3757 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3758 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3759 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3760 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3761 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3762 | goto failed; |
| 3763 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3764 | break; |
| 3765 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3766 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3767 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3768 | if (!result) goto failed; |
| 3769 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3770 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3771 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3772 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3773 | goto failed; |
| 3774 | Py_DECREF(value); |
| 3775 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3776 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3777 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3778 | goto failed; |
| 3779 | Py_DECREF(value); |
| 3780 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3781 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3782 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3783 | goto failed; |
| 3784 | Py_DECREF(value); |
| 3785 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3786 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3787 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3788 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3789 | if (!result) goto failed; |
| 3790 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3791 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3792 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3793 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3794 | goto failed; |
| 3795 | Py_DECREF(value); |
| 3796 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3797 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3798 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3799 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3800 | goto failed; |
| 3801 | Py_DECREF(value); |
| 3802 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3803 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3804 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3805 | goto failed; |
| 3806 | Py_DECREF(value); |
| 3807 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3808 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3809 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3810 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3811 | goto failed; |
| 3812 | Py_DECREF(value); |
| 3813 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3814 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3815 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3816 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3817 | if (!result) goto failed; |
| 3818 | value = ast2obj_expr(o->v.For.target); |
| 3819 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3820 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3821 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3822 | goto failed; |
| 3823 | Py_DECREF(value); |
| 3824 | value = ast2obj_expr(o->v.For.iter); |
| 3825 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3826 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3827 | goto failed; |
| 3828 | Py_DECREF(value); |
| 3829 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3830 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3831 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3832 | goto failed; |
| 3833 | Py_DECREF(value); |
| 3834 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3835 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3836 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3837 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3838 | goto failed; |
| 3839 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3840 | value = ast2obj_string(o->v.For.type_comment); |
| 3841 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3842 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3843 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3844 | goto failed; |
| 3845 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3846 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3847 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3848 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3849 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3850 | if (!result) goto failed; |
| 3851 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3852 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3853 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3854 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3855 | goto failed; |
| 3856 | Py_DECREF(value); |
| 3857 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3858 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3859 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3860 | goto failed; |
| 3861 | Py_DECREF(value); |
| 3862 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3863 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3864 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3865 | goto failed; |
| 3866 | Py_DECREF(value); |
| 3867 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3868 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3869 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3870 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3871 | goto failed; |
| 3872 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3873 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3874 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3875 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3876 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3877 | goto failed; |
| 3878 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3879 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3880 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3881 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3882 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3883 | if (!result) goto failed; |
| 3884 | value = ast2obj_expr(o->v.While.test); |
| 3885 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3886 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3887 | goto failed; |
| 3888 | Py_DECREF(value); |
| 3889 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3890 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3891 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3892 | goto failed; |
| 3893 | Py_DECREF(value); |
| 3894 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3895 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3896 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3897 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3898 | goto failed; |
| 3899 | Py_DECREF(value); |
| 3900 | break; |
| 3901 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3902 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3903 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3904 | if (!result) goto failed; |
| 3905 | value = ast2obj_expr(o->v.If.test); |
| 3906 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3907 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3908 | goto failed; |
| 3909 | Py_DECREF(value); |
| 3910 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3911 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3912 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3913 | goto failed; |
| 3914 | Py_DECREF(value); |
| 3915 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3916 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3917 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3918 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3919 | goto failed; |
| 3920 | Py_DECREF(value); |
| 3921 | break; |
| 3922 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3923 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3924 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3925 | if (!result) goto failed; |
| 3926 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3927 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3928 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3929 | goto failed; |
| 3930 | Py_DECREF(value); |
| 3931 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3932 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3933 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3934 | goto failed; |
| 3935 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3936 | value = ast2obj_string(o->v.With.type_comment); |
| 3937 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3938 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3939 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3940 | goto failed; |
| 3941 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3942 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3943 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3944 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3945 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3946 | if (!result) goto failed; |
| 3947 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3948 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3949 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3950 | goto failed; |
| 3951 | Py_DECREF(value); |
| 3952 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3953 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3954 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3955 | goto failed; |
| 3956 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3957 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3958 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3959 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3960 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3961 | goto failed; |
| 3962 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3963 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3964 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3965 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3966 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3967 | if (!result) goto failed; |
| 3968 | value = ast2obj_expr(o->v.Raise.exc); |
| 3969 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3970 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3971 | goto failed; |
| 3972 | Py_DECREF(value); |
| 3973 | value = ast2obj_expr(o->v.Raise.cause); |
| 3974 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3975 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | goto failed; |
| 3977 | Py_DECREF(value); |
| 3978 | break; |
| 3979 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3980 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3981 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3982 | if (!result) goto failed; |
| 3983 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3984 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3985 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3986 | goto failed; |
| 3987 | Py_DECREF(value); |
| 3988 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3989 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3990 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3991 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3992 | goto failed; |
| 3993 | Py_DECREF(value); |
| 3994 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3995 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3996 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3997 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3998 | goto failed; |
| 3999 | Py_DECREF(value); |
| 4000 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 4001 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4002 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 4003 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4004 | goto failed; |
| 4005 | Py_DECREF(value); |
| 4006 | break; |
| 4007 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4008 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 4009 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4010 | if (!result) goto failed; |
| 4011 | value = ast2obj_expr(o->v.Assert.test); |
| 4012 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4013 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4014 | goto failed; |
| 4015 | Py_DECREF(value); |
| 4016 | value = ast2obj_expr(o->v.Assert.msg); |
| 4017 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4018 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4019 | goto failed; |
| 4020 | Py_DECREF(value); |
| 4021 | break; |
| 4022 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4023 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 4024 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4025 | if (!result) goto failed; |
| 4026 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 4027 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4028 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4029 | goto failed; |
| 4030 | Py_DECREF(value); |
| 4031 | break; |
| 4032 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4033 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 4034 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4035 | if (!result) goto failed; |
| 4036 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 4037 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4038 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 4039 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4040 | goto failed; |
| 4041 | Py_DECREF(value); |
| 4042 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 4043 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4044 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4045 | goto failed; |
| 4046 | Py_DECREF(value); |
| 4047 | value = ast2obj_int(o->v.ImportFrom.level); |
| 4048 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4049 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4050 | goto failed; |
| 4051 | Py_DECREF(value); |
| 4052 | break; |
| 4053 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4054 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 4055 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4056 | if (!result) goto failed; |
| 4057 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 4058 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4059 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4060 | goto failed; |
| 4061 | Py_DECREF(value); |
| 4062 | break; |
| 4063 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4064 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 4065 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4066 | if (!result) goto failed; |
| 4067 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 4068 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4069 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4070 | goto failed; |
| 4071 | Py_DECREF(value); |
| 4072 | break; |
| 4073 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4074 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 4075 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4076 | if (!result) goto failed; |
| 4077 | value = ast2obj_expr(o->v.Expr.value); |
| 4078 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4079 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4080 | goto failed; |
| 4081 | Py_DECREF(value); |
| 4082 | break; |
| 4083 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4084 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 4085 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4086 | if (!result) goto failed; |
| 4087 | break; |
| 4088 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4089 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 4090 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4091 | if (!result) goto failed; |
| 4092 | break; |
| 4093 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4094 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 4095 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4096 | if (!result) goto failed; |
| 4097 | break; |
| 4098 | } |
| 4099 | value = ast2obj_int(o->lineno); |
| 4100 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4101 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4102 | goto failed; |
| 4103 | Py_DECREF(value); |
| 4104 | value = ast2obj_int(o->col_offset); |
| 4105 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4106 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4107 | goto failed; |
| 4108 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4109 | value = ast2obj_int(o->end_lineno); |
| 4110 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4111 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4112 | goto failed; |
| 4113 | Py_DECREF(value); |
| 4114 | value = ast2obj_int(o->end_col_offset); |
| 4115 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4116 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4117 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4118 | goto failed; |
| 4119 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4120 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4121 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4122 | Py_XDECREF(value); |
| 4123 | Py_XDECREF(result); |
| 4124 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4127 | PyObject* |
| 4128 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4129 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4130 | expr_ty o = (expr_ty)_o; |
| 4131 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4132 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4133 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4134 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4135 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4136 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4137 | switch (o->kind) { |
| 4138 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4139 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 4140 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4141 | if (!result) goto failed; |
| 4142 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 4143 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4144 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4145 | goto failed; |
| 4146 | Py_DECREF(value); |
| 4147 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 4148 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4149 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4150 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4151 | goto failed; |
| 4152 | Py_DECREF(value); |
| 4153 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4154 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4155 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 4156 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4157 | if (!result) goto failed; |
| 4158 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 4159 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4160 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 4161 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4162 | goto failed; |
| 4163 | Py_DECREF(value); |
| 4164 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 4165 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4166 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4167 | goto failed; |
| 4168 | Py_DECREF(value); |
| 4169 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4170 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4171 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4172 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4173 | if (!result) goto failed; |
| 4174 | value = ast2obj_expr(o->v.BinOp.left); |
| 4175 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4176 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4177 | goto failed; |
| 4178 | Py_DECREF(value); |
| 4179 | value = ast2obj_operator(o->v.BinOp.op); |
| 4180 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4181 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4182 | goto failed; |
| 4183 | Py_DECREF(value); |
| 4184 | value = ast2obj_expr(o->v.BinOp.right); |
| 4185 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4186 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4187 | goto failed; |
| 4188 | Py_DECREF(value); |
| 4189 | break; |
| 4190 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4191 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4192 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4193 | if (!result) goto failed; |
| 4194 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4195 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4196 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4197 | goto failed; |
| 4198 | Py_DECREF(value); |
| 4199 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4200 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4201 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4202 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4203 | goto failed; |
| 4204 | Py_DECREF(value); |
| 4205 | break; |
| 4206 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4207 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4208 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4209 | if (!result) goto failed; |
| 4210 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4211 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4212 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4213 | goto failed; |
| 4214 | Py_DECREF(value); |
| 4215 | value = ast2obj_expr(o->v.Lambda.body); |
| 4216 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4217 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4218 | goto failed; |
| 4219 | Py_DECREF(value); |
| 4220 | break; |
| 4221 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4222 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4223 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4224 | if (!result) goto failed; |
| 4225 | value = ast2obj_expr(o->v.IfExp.test); |
| 4226 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4227 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4228 | goto failed; |
| 4229 | Py_DECREF(value); |
| 4230 | value = ast2obj_expr(o->v.IfExp.body); |
| 4231 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4232 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4233 | goto failed; |
| 4234 | Py_DECREF(value); |
| 4235 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4236 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4237 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4238 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4239 | goto failed; |
| 4240 | Py_DECREF(value); |
| 4241 | break; |
| 4242 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4243 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4244 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4245 | if (!result) goto failed; |
| 4246 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4247 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4248 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4249 | goto failed; |
| 4250 | Py_DECREF(value); |
| 4251 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4252 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4253 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4254 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4255 | goto failed; |
| 4256 | Py_DECREF(value); |
| 4257 | break; |
| 4258 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4259 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4260 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4261 | if (!result) goto failed; |
| 4262 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4263 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4264 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4265 | goto failed; |
| 4266 | Py_DECREF(value); |
| 4267 | break; |
| 4268 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4269 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4270 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4271 | if (!result) goto failed; |
| 4272 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4273 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4274 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4275 | goto failed; |
| 4276 | Py_DECREF(value); |
| 4277 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4278 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4279 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4280 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4281 | goto failed; |
| 4282 | Py_DECREF(value); |
| 4283 | break; |
| 4284 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4285 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4286 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4287 | if (!result) goto failed; |
| 4288 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4289 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4290 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4291 | goto failed; |
| 4292 | Py_DECREF(value); |
| 4293 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4294 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4295 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4296 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4297 | goto failed; |
| 4298 | Py_DECREF(value); |
| 4299 | break; |
| 4300 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4301 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4302 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4303 | if (!result) goto failed; |
| 4304 | value = ast2obj_expr(o->v.DictComp.key); |
| 4305 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4306 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4307 | goto failed; |
| 4308 | Py_DECREF(value); |
| 4309 | value = ast2obj_expr(o->v.DictComp.value); |
| 4310 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4311 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4312 | goto failed; |
| 4313 | Py_DECREF(value); |
| 4314 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4315 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4316 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4317 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4318 | goto failed; |
| 4319 | Py_DECREF(value); |
| 4320 | break; |
| 4321 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4322 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4323 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4324 | if (!result) goto failed; |
| 4325 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4326 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4327 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4328 | goto failed; |
| 4329 | Py_DECREF(value); |
| 4330 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4331 | ast2obj_comprehension); |
| 4332 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4333 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4334 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4335 | goto failed; |
| 4336 | Py_DECREF(value); |
| 4337 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4338 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4339 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4340 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4341 | if (!result) goto failed; |
| 4342 | value = ast2obj_expr(o->v.Await.value); |
| 4343 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4344 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4345 | goto failed; |
| 4346 | Py_DECREF(value); |
| 4347 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4348 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4349 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4350 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4351 | if (!result) goto failed; |
| 4352 | value = ast2obj_expr(o->v.Yield.value); |
| 4353 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4354 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4355 | goto failed; |
| 4356 | Py_DECREF(value); |
| 4357 | break; |
| 4358 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4359 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4360 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4361 | if (!result) goto failed; |
| 4362 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4363 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4364 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4365 | goto failed; |
| 4366 | Py_DECREF(value); |
| 4367 | break; |
| 4368 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4369 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4370 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4371 | if (!result) goto failed; |
| 4372 | value = ast2obj_expr(o->v.Compare.left); |
| 4373 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4374 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4375 | goto failed; |
| 4376 | Py_DECREF(value); |
| 4377 | { |
| 4378 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4379 | value = PyList_New(n); |
| 4380 | if (!value) goto failed; |
| 4381 | for(i = 0; i < n; i++) |
| 4382 | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4383 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4384 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4385 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4386 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4387 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4388 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4389 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4390 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4391 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4392 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4393 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4394 | break; |
| 4395 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4396 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4397 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4398 | if (!result) goto failed; |
| 4399 | value = ast2obj_expr(o->v.Call.func); |
| 4400 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4401 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4402 | goto failed; |
| 4403 | Py_DECREF(value); |
| 4404 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4405 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4406 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4407 | goto failed; |
| 4408 | Py_DECREF(value); |
| 4409 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4410 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4411 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4412 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4413 | goto failed; |
| 4414 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4415 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4416 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4417 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4418 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4419 | if (!result) goto failed; |
| 4420 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4421 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4422 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4423 | goto failed; |
| 4424 | Py_DECREF(value); |
| 4425 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4426 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4427 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4428 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4429 | goto failed; |
| 4430 | Py_DECREF(value); |
| 4431 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4432 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4433 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4434 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4435 | goto failed; |
| 4436 | Py_DECREF(value); |
| 4437 | break; |
| 4438 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4439 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4440 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4441 | if (!result) goto failed; |
| 4442 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4443 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4444 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4445 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4446 | goto failed; |
| 4447 | Py_DECREF(value); |
| 4448 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4449 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4450 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4451 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4452 | if (!result) goto failed; |
| 4453 | value = ast2obj_constant(o->v.Constant.value); |
| 4454 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4455 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4456 | goto failed; |
| 4457 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4458 | value = ast2obj_string(o->v.Constant.kind); |
| 4459 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4460 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4461 | goto failed; |
| 4462 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4463 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4464 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4465 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4466 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4467 | if (!result) goto failed; |
| 4468 | value = ast2obj_expr(o->v.Attribute.value); |
| 4469 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4470 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4471 | goto failed; |
| 4472 | Py_DECREF(value); |
| 4473 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4474 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4475 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4476 | goto failed; |
| 4477 | Py_DECREF(value); |
| 4478 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4479 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4480 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4481 | goto failed; |
| 4482 | Py_DECREF(value); |
| 4483 | break; |
| 4484 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4485 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4486 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4487 | if (!result) goto failed; |
| 4488 | value = ast2obj_expr(o->v.Subscript.value); |
| 4489 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4490 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4491 | goto failed; |
| 4492 | Py_DECREF(value); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4493 | value = ast2obj_expr(o->v.Subscript.slice); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4494 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4495 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4496 | goto failed; |
| 4497 | Py_DECREF(value); |
| 4498 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4499 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4500 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4501 | goto failed; |
| 4502 | Py_DECREF(value); |
| 4503 | break; |
| 4504 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4505 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4506 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4507 | if (!result) goto failed; |
| 4508 | value = ast2obj_expr(o->v.Starred.value); |
| 4509 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4510 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4511 | goto failed; |
| 4512 | Py_DECREF(value); |
| 4513 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4514 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4515 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4516 | goto failed; |
| 4517 | Py_DECREF(value); |
| 4518 | break; |
| 4519 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4520 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4521 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4522 | if (!result) goto failed; |
| 4523 | value = ast2obj_identifier(o->v.Name.id); |
| 4524 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4525 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4526 | goto failed; |
| 4527 | Py_DECREF(value); |
| 4528 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4529 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4530 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4531 | goto failed; |
| 4532 | Py_DECREF(value); |
| 4533 | break; |
| 4534 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4535 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4536 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4537 | if (!result) goto failed; |
| 4538 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4539 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4540 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4541 | goto failed; |
| 4542 | Py_DECREF(value); |
| 4543 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4544 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4545 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4546 | goto failed; |
| 4547 | Py_DECREF(value); |
| 4548 | break; |
| 4549 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4550 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4551 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4552 | if (!result) goto failed; |
| 4553 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4554 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4555 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4556 | goto failed; |
| 4557 | Py_DECREF(value); |
| 4558 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4559 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4560 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4561 | goto failed; |
| 4562 | Py_DECREF(value); |
| 4563 | break; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4564 | case Slice_kind: |
| 4565 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4566 | result = PyType_GenericNew(tp, NULL, NULL); |
| 4567 | if (!result) goto failed; |
| 4568 | value = ast2obj_expr(o->v.Slice.lower); |
| 4569 | if (!value) goto failed; |
| 4570 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
| 4571 | goto failed; |
| 4572 | Py_DECREF(value); |
| 4573 | value = ast2obj_expr(o->v.Slice.upper); |
| 4574 | if (!value) goto failed; |
| 4575 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
| 4576 | goto failed; |
| 4577 | Py_DECREF(value); |
| 4578 | value = ast2obj_expr(o->v.Slice.step); |
| 4579 | if (!value) goto failed; |
| 4580 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
| 4581 | goto failed; |
| 4582 | Py_DECREF(value); |
| 4583 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4584 | } |
| 4585 | value = ast2obj_int(o->lineno); |
| 4586 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4587 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4588 | goto failed; |
| 4589 | Py_DECREF(value); |
| 4590 | value = ast2obj_int(o->col_offset); |
| 4591 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4592 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4593 | goto failed; |
| 4594 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4595 | value = ast2obj_int(o->end_lineno); |
| 4596 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4597 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4598 | goto failed; |
| 4599 | Py_DECREF(value); |
| 4600 | value = ast2obj_int(o->end_col_offset); |
| 4601 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4602 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4603 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4604 | goto failed; |
| 4605 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4606 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4607 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4608 | Py_XDECREF(value); |
| 4609 | Py_XDECREF(result); |
| 4610 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4613 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4614 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4615 | switch(o) { |
| 4616 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4617 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4618 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4619 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4620 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4621 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4622 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4623 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4624 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4625 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4626 | Py_UNREACHABLE(); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4627 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4628 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4629 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4630 | switch(o) { |
| 4631 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4632 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4633 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4634 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4635 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4636 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4637 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4638 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4639 | } |
| 4640 | PyObject* ast2obj_operator(operator_ty o) |
| 4641 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4642 | switch(o) { |
| 4643 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4644 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4645 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4646 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4647 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4648 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4649 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4650 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4651 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4652 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4653 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4654 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4655 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4656 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4657 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4658 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4659 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4660 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4661 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4662 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4663 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4664 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4665 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4666 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4667 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4668 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4669 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4670 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4671 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4672 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4673 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4674 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4675 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4676 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4677 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4678 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4679 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4680 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4681 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4682 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4683 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4684 | } |
| 4685 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4686 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4687 | switch(o) { |
| 4688 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4689 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4690 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4691 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4692 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4693 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4694 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4695 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4696 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4697 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4698 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4699 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4700 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4701 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4702 | } |
| 4703 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4704 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4705 | switch(o) { |
| 4706 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4707 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4708 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4709 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4710 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4711 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4712 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4713 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4714 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4715 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4716 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4717 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4718 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4719 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4720 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4721 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4722 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4723 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4724 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4725 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4726 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4727 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4728 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4729 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4730 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4731 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4732 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4733 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4734 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4735 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4736 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4737 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4738 | } |
| 4739 | PyObject* |
| 4740 | ast2obj_comprehension(void* _o) |
| 4741 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4742 | comprehension_ty o = (comprehension_ty)_o; |
| 4743 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4744 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4745 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4746 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4747 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4748 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4749 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4750 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4751 | if (!result) return NULL; |
| 4752 | value = ast2obj_expr(o->target); |
| 4753 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4754 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4755 | goto failed; |
| 4756 | Py_DECREF(value); |
| 4757 | value = ast2obj_expr(o->iter); |
| 4758 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4759 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4760 | goto failed; |
| 4761 | Py_DECREF(value); |
| 4762 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4763 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4764 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4765 | goto failed; |
| 4766 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4767 | value = ast2obj_int(o->is_async); |
| 4768 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4769 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4770 | goto failed; |
| 4771 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4772 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4773 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4774 | Py_XDECREF(value); |
| 4775 | Py_XDECREF(result); |
| 4776 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4777 | } |
| 4778 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4779 | PyObject* |
| 4780 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4781 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4782 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4783 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4784 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4785 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4786 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4787 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4788 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4789 | switch (o->kind) { |
| 4790 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4791 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4792 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4793 | if (!result) goto failed; |
| 4794 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4795 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4796 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4797 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4798 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4799 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4800 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4801 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4802 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4803 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4804 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4805 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4806 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4807 | goto failed; |
| 4808 | Py_DECREF(value); |
| 4809 | break; |
| 4810 | } |
| 4811 | value = ast2obj_int(o->lineno); |
| 4812 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4813 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4814 | goto failed; |
| 4815 | Py_DECREF(value); |
| 4816 | value = ast2obj_int(o->col_offset); |
| 4817 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4818 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4819 | goto failed; |
| 4820 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4821 | value = ast2obj_int(o->end_lineno); |
| 4822 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4823 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4824 | goto failed; |
| 4825 | Py_DECREF(value); |
| 4826 | value = ast2obj_int(o->end_col_offset); |
| 4827 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4828 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4829 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4830 | goto failed; |
| 4831 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4832 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4833 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4834 | Py_XDECREF(value); |
| 4835 | Py_XDECREF(result); |
| 4836 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4839 | PyObject* |
| 4840 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4841 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4842 | arguments_ty o = (arguments_ty)_o; |
| 4843 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4844 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4845 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4846 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4847 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4848 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4849 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4850 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4851 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4852 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4853 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4854 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4855 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4856 | goto failed; |
| 4857 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4858 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4859 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4860 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4861 | goto failed; |
| 4862 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4863 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4864 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4865 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4866 | goto failed; |
| 4867 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4868 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4869 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4870 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4871 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4872 | goto failed; |
| 4873 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4874 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4875 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4876 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4877 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4878 | goto failed; |
| 4879 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4880 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4881 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4882 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4883 | goto failed; |
| 4884 | Py_DECREF(value); |
| 4885 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4886 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4887 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4888 | goto failed; |
| 4889 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4890 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4891 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4892 | Py_XDECREF(value); |
| 4893 | Py_XDECREF(result); |
| 4894 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4897 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4898 | ast2obj_arg(void* _o) |
| 4899 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4900 | arg_ty o = (arg_ty)_o; |
| 4901 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4902 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4903 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4904 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4905 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4906 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4907 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4908 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4909 | if (!result) return NULL; |
| 4910 | value = ast2obj_identifier(o->arg); |
| 4911 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4912 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4913 | goto failed; |
| 4914 | Py_DECREF(value); |
| 4915 | value = ast2obj_expr(o->annotation); |
| 4916 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4917 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4918 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4919 | goto failed; |
| 4920 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4921 | value = ast2obj_string(o->type_comment); |
| 4922 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4923 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4924 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4925 | goto failed; |
| 4926 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4927 | value = ast2obj_int(o->lineno); |
| 4928 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4929 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4930 | goto failed; |
| 4931 | Py_DECREF(value); |
| 4932 | value = ast2obj_int(o->col_offset); |
| 4933 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4934 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4935 | goto failed; |
| 4936 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4937 | value = ast2obj_int(o->end_lineno); |
| 4938 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4939 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4940 | goto failed; |
| 4941 | Py_DECREF(value); |
| 4942 | value = ast2obj_int(o->end_col_offset); |
| 4943 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4944 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4945 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4946 | goto failed; |
| 4947 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4948 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4949 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4950 | Py_XDECREF(value); |
| 4951 | Py_XDECREF(result); |
| 4952 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4956 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4957 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4958 | keyword_ty o = (keyword_ty)_o; |
| 4959 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4960 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4961 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4962 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4963 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4964 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4965 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4966 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4967 | if (!result) return NULL; |
| 4968 | value = ast2obj_identifier(o->arg); |
| 4969 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4970 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4971 | goto failed; |
| 4972 | Py_DECREF(value); |
| 4973 | value = ast2obj_expr(o->value); |
| 4974 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4975 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4976 | goto failed; |
| 4977 | Py_DECREF(value); |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 4978 | value = ast2obj_int(o->lineno); |
| 4979 | if (!value) goto failed; |
| 4980 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
| 4981 | goto failed; |
| 4982 | Py_DECREF(value); |
| 4983 | value = ast2obj_int(o->col_offset); |
| 4984 | if (!value) goto failed; |
| 4985 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
| 4986 | goto failed; |
| 4987 | Py_DECREF(value); |
| 4988 | value = ast2obj_int(o->end_lineno); |
| 4989 | if (!value) goto failed; |
| 4990 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
| 4991 | goto failed; |
| 4992 | Py_DECREF(value); |
| 4993 | value = ast2obj_int(o->end_col_offset); |
| 4994 | if (!value) goto failed; |
| 4995 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4996 | < 0) |
| 4997 | goto failed; |
| 4998 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4999 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5000 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5001 | Py_XDECREF(value); |
| 5002 | Py_XDECREF(result); |
| 5003 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5004 | } |
| 5005 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5006 | PyObject* |
| 5007 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5008 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5009 | alias_ty o = (alias_ty)_o; |
| 5010 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5011 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5012 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 5013 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5014 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5015 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5016 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 5017 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5018 | if (!result) return NULL; |
| 5019 | value = ast2obj_identifier(o->name); |
| 5020 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5021 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5022 | goto failed; |
| 5023 | Py_DECREF(value); |
| 5024 | value = ast2obj_identifier(o->asname); |
| 5025 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5026 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5027 | goto failed; |
| 5028 | Py_DECREF(value); |
| 5029 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5030 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5031 | Py_XDECREF(value); |
| 5032 | Py_XDECREF(result); |
| 5033 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5036 | PyObject* |
| 5037 | ast2obj_withitem(void* _o) |
| 5038 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5039 | withitem_ty o = (withitem_ty)_o; |
| 5040 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5041 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5042 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 5043 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5044 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5045 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5046 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 5047 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5048 | if (!result) return NULL; |
| 5049 | value = ast2obj_expr(o->context_expr); |
| 5050 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5051 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 5052 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5053 | goto failed; |
| 5054 | Py_DECREF(value); |
| 5055 | value = ast2obj_expr(o->optional_vars); |
| 5056 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5057 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 5058 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5059 | goto failed; |
| 5060 | Py_DECREF(value); |
| 5061 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5062 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5063 | Py_XDECREF(value); |
| 5064 | Py_XDECREF(result); |
| 5065 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5066 | } |
| 5067 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5068 | PyObject* |
| 5069 | ast2obj_type_ignore(void* _o) |
| 5070 | { |
| 5071 | type_ignore_ty o = (type_ignore_ty)_o; |
| 5072 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5073 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5074 | if (!o) { |
| 5075 | Py_RETURN_NONE; |
| 5076 | } |
| 5077 | |
| 5078 | switch (o->kind) { |
| 5079 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5080 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 5081 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5082 | if (!result) goto failed; |
| 5083 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 5084 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5085 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 5086 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5087 | goto failed; |
| 5088 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5089 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 5090 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5091 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5092 | goto failed; |
| 5093 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5094 | break; |
| 5095 | } |
| 5096 | return result; |
| 5097 | failed: |
| 5098 | Py_XDECREF(value); |
| 5099 | Py_XDECREF(result); |
| 5100 | return NULL; |
| 5101 | } |
| 5102 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5103 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5104 | int |
| 5105 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 5106 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5107 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5108 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5109 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5110 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5111 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5112 | if (obj == Py_None) { |
| 5113 | *out = NULL; |
| 5114 | return 0; |
| 5115 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5116 | tp = astmodulestate_global->Module_type; |
| 5117 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5118 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5119 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5120 | } |
| 5121 | if (isinstance) { |
| 5122 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5123 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5124 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5125 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5126 | return 1; |
| 5127 | } |
| 5128 | if (tmp == NULL) { |
| 5129 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 5130 | return 1; |
| 5131 | } |
| 5132 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5133 | int res; |
| 5134 | Py_ssize_t len; |
| 5135 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5136 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5137 | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5138 | goto failed; |
| 5139 | } |
| 5140 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5141 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5142 | if (body == NULL) goto failed; |
| 5143 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5144 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5145 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5146 | Py_INCREF(tmp2); |
| 5147 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5148 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5149 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5150 | if (len != PyList_GET_SIZE(tmp)) { |
| 5151 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5152 | goto failed; |
| 5153 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5154 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5155 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5156 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5157 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5158 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5159 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5160 | return 1; |
| 5161 | } |
| 5162 | if (tmp == NULL) { |
| 5163 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5164 | return 1; |
| 5165 | } |
| 5166 | else { |
| 5167 | int res; |
| 5168 | Py_ssize_t len; |
| 5169 | Py_ssize_t i; |
| 5170 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5171 | PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5172 | goto failed; |
| 5173 | } |
| 5174 | len = PyList_GET_SIZE(tmp); |
| 5175 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5176 | if (type_ignores == NULL) goto failed; |
| 5177 | for (i = 0; i < len; i++) { |
| 5178 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5179 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5180 | Py_INCREF(tmp2); |
| 5181 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5182 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5183 | if (res != 0) goto failed; |
| 5184 | if (len != PyList_GET_SIZE(tmp)) { |
| 5185 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5186 | goto failed; |
| 5187 | } |
| 5188 | asdl_seq_SET(type_ignores, i, val); |
| 5189 | } |
| 5190 | Py_CLEAR(tmp); |
| 5191 | } |
| 5192 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5193 | if (*out == NULL) goto failed; |
| 5194 | return 0; |
| 5195 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5196 | tp = astmodulestate_global->Interactive_type; |
| 5197 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5198 | if (isinstance == -1) { |
| 5199 | return 1; |
| 5200 | } |
| 5201 | if (isinstance) { |
| 5202 | asdl_seq* body; |
| 5203 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5204 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5205 | return 1; |
| 5206 | } |
| 5207 | if (tmp == NULL) { |
| 5208 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5209 | return 1; |
| 5210 | } |
| 5211 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5212 | int res; |
| 5213 | Py_ssize_t len; |
| 5214 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5215 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5216 | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5217 | goto failed; |
| 5218 | } |
| 5219 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5220 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5221 | if (body == NULL) goto failed; |
| 5222 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5223 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5224 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5225 | Py_INCREF(tmp2); |
| 5226 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5227 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5228 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5229 | if (len != PyList_GET_SIZE(tmp)) { |
| 5230 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5231 | goto failed; |
| 5232 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5233 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5234 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5235 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5236 | } |
| 5237 | *out = Interactive(body, arena); |
| 5238 | if (*out == NULL) goto failed; |
| 5239 | return 0; |
| 5240 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5241 | tp = astmodulestate_global->Expression_type; |
| 5242 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5243 | if (isinstance == -1) { |
| 5244 | return 1; |
| 5245 | } |
| 5246 | if (isinstance) { |
| 5247 | expr_ty body; |
| 5248 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5249 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5250 | return 1; |
| 5251 | } |
| 5252 | if (tmp == NULL) { |
| 5253 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5254 | return 1; |
| 5255 | } |
| 5256 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5257 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5258 | res = obj2ast_expr(tmp, &body, arena); |
| 5259 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5260 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5261 | } |
| 5262 | *out = Expression(body, arena); |
| 5263 | if (*out == NULL) goto failed; |
| 5264 | return 0; |
| 5265 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5266 | tp = astmodulestate_global->FunctionType_type; |
| 5267 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5268 | if (isinstance == -1) { |
| 5269 | return 1; |
| 5270 | } |
| 5271 | if (isinstance) { |
| 5272 | asdl_seq* argtypes; |
| 5273 | expr_ty returns; |
| 5274 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5275 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5276 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5277 | return 1; |
| 5278 | } |
| 5279 | if (tmp == NULL) { |
| 5280 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5281 | return 1; |
| 5282 | } |
| 5283 | else { |
| 5284 | int res; |
| 5285 | Py_ssize_t len; |
| 5286 | Py_ssize_t i; |
| 5287 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5288 | PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5289 | goto failed; |
| 5290 | } |
| 5291 | len = PyList_GET_SIZE(tmp); |
| 5292 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5293 | if (argtypes == NULL) goto failed; |
| 5294 | for (i = 0; i < len; i++) { |
| 5295 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5296 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5297 | Py_INCREF(tmp2); |
| 5298 | res = obj2ast_expr(tmp2, &val, arena); |
| 5299 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5300 | if (res != 0) goto failed; |
| 5301 | if (len != PyList_GET_SIZE(tmp)) { |
| 5302 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5303 | goto failed; |
| 5304 | } |
| 5305 | asdl_seq_SET(argtypes, i, val); |
| 5306 | } |
| 5307 | Py_CLEAR(tmp); |
| 5308 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5309 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5310 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5311 | return 1; |
| 5312 | } |
| 5313 | if (tmp == NULL) { |
| 5314 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5315 | return 1; |
| 5316 | } |
| 5317 | else { |
| 5318 | int res; |
| 5319 | res = obj2ast_expr(tmp, &returns, arena); |
| 5320 | if (res != 0) goto failed; |
| 5321 | Py_CLEAR(tmp); |
| 5322 | } |
| 5323 | *out = FunctionType(argtypes, returns, arena); |
| 5324 | if (*out == NULL) goto failed; |
| 5325 | return 0; |
| 5326 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5327 | |
| 5328 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5329 | failed: |
| 5330 | Py_XDECREF(tmp); |
| 5331 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | int |
| 5335 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5336 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5337 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5338 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5339 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5340 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5341 | int lineno; |
| 5342 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5343 | int end_lineno; |
| 5344 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5345 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5346 | if (obj == Py_None) { |
| 5347 | *out = NULL; |
| 5348 | return 0; |
| 5349 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5350 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5351 | return 1; |
| 5352 | } |
| 5353 | if (tmp == NULL) { |
| 5354 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5355 | return 1; |
| 5356 | } |
| 5357 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5358 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5359 | res = obj2ast_int(tmp, &lineno, arena); |
| 5360 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5361 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5362 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5363 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5364 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5365 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5366 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5367 | if (tmp == NULL) { |
| 5368 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5369 | return 1; |
| 5370 | } |
| 5371 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5372 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5373 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5374 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5375 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5376 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5377 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5378 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5379 | return 1; |
| 5380 | } |
| 5381 | if (tmp == NULL || tmp == Py_None) { |
| 5382 | Py_CLEAR(tmp); |
| 5383 | end_lineno = 0; |
| 5384 | } |
| 5385 | else { |
| 5386 | int res; |
| 5387 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5388 | if (res != 0) goto failed; |
| 5389 | Py_CLEAR(tmp); |
| 5390 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5391 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5392 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5393 | return 1; |
| 5394 | } |
| 5395 | if (tmp == NULL || tmp == Py_None) { |
| 5396 | Py_CLEAR(tmp); |
| 5397 | end_col_offset = 0; |
| 5398 | } |
| 5399 | else { |
| 5400 | int res; |
| 5401 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5402 | if (res != 0) goto failed; |
| 5403 | Py_CLEAR(tmp); |
| 5404 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5405 | tp = astmodulestate_global->FunctionDef_type; |
| 5406 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5407 | if (isinstance == -1) { |
| 5408 | return 1; |
| 5409 | } |
| 5410 | if (isinstance) { |
| 5411 | identifier name; |
| 5412 | arguments_ty args; |
| 5413 | asdl_seq* body; |
| 5414 | asdl_seq* decorator_list; |
| 5415 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5416 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5417 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5418 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5419 | return 1; |
| 5420 | } |
| 5421 | if (tmp == NULL) { |
| 5422 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5423 | return 1; |
| 5424 | } |
| 5425 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5426 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5427 | res = obj2ast_identifier(tmp, &name, arena); |
| 5428 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5429 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5430 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5431 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5432 | return 1; |
| 5433 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5434 | if (tmp == NULL) { |
| 5435 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5436 | return 1; |
| 5437 | } |
| 5438 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5439 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5440 | res = obj2ast_arguments(tmp, &args, arena); |
| 5441 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5442 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5443 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5444 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5445 | return 1; |
| 5446 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5447 | if (tmp == NULL) { |
| 5448 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5449 | return 1; |
| 5450 | } |
| 5451 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5452 | int res; |
| 5453 | Py_ssize_t len; |
| 5454 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5455 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5456 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5457 | goto failed; |
| 5458 | } |
| 5459 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5460 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5461 | if (body == NULL) goto failed; |
| 5462 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5463 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5464 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5465 | Py_INCREF(tmp2); |
| 5466 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5467 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5468 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5469 | if (len != PyList_GET_SIZE(tmp)) { |
| 5470 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5471 | goto failed; |
| 5472 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5473 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5474 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5475 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5476 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5477 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5478 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5479 | return 1; |
| 5480 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5481 | if (tmp == NULL) { |
| 5482 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5483 | return 1; |
| 5484 | } |
| 5485 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5486 | int res; |
| 5487 | Py_ssize_t len; |
| 5488 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5489 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5490 | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5491 | goto failed; |
| 5492 | } |
| 5493 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5494 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5495 | if (decorator_list == NULL) goto failed; |
| 5496 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5497 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5498 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5499 | Py_INCREF(tmp2); |
| 5500 | res = obj2ast_expr(tmp2, &val, arena); |
| 5501 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5502 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5503 | if (len != PyList_GET_SIZE(tmp)) { |
| 5504 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5505 | goto failed; |
| 5506 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5507 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5508 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5509 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5510 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5511 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5512 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5513 | return 1; |
| 5514 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5515 | if (tmp == NULL || tmp == Py_None) { |
| 5516 | Py_CLEAR(tmp); |
| 5517 | returns = NULL; |
| 5518 | } |
| 5519 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5520 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5521 | res = obj2ast_expr(tmp, &returns, arena); |
| 5522 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5523 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5524 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5525 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5526 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5527 | return 1; |
| 5528 | } |
| 5529 | if (tmp == NULL || tmp == Py_None) { |
| 5530 | Py_CLEAR(tmp); |
| 5531 | type_comment = NULL; |
| 5532 | } |
| 5533 | else { |
| 5534 | int res; |
| 5535 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5536 | if (res != 0) goto failed; |
| 5537 | Py_CLEAR(tmp); |
| 5538 | } |
| 5539 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5540 | type_comment, lineno, col_offset, end_lineno, |
| 5541 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5542 | if (*out == NULL) goto failed; |
| 5543 | return 0; |
| 5544 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5545 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5546 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5547 | if (isinstance == -1) { |
| 5548 | return 1; |
| 5549 | } |
| 5550 | if (isinstance) { |
| 5551 | identifier name; |
| 5552 | arguments_ty args; |
| 5553 | asdl_seq* body; |
| 5554 | asdl_seq* decorator_list; |
| 5555 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5556 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5557 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5558 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5559 | return 1; |
| 5560 | } |
| 5561 | if (tmp == NULL) { |
| 5562 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5563 | return 1; |
| 5564 | } |
| 5565 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5566 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5567 | res = obj2ast_identifier(tmp, &name, arena); |
| 5568 | if (res != 0) goto failed; |
| 5569 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5570 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5571 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5572 | return 1; |
| 5573 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5574 | if (tmp == NULL) { |
| 5575 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5576 | return 1; |
| 5577 | } |
| 5578 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5579 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5580 | res = obj2ast_arguments(tmp, &args, arena); |
| 5581 | if (res != 0) goto failed; |
| 5582 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5583 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5584 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5585 | return 1; |
| 5586 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5587 | if (tmp == NULL) { |
| 5588 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5589 | return 1; |
| 5590 | } |
| 5591 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5592 | int res; |
| 5593 | Py_ssize_t len; |
| 5594 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5595 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5596 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5597 | goto failed; |
| 5598 | } |
| 5599 | len = PyList_GET_SIZE(tmp); |
| 5600 | body = _Py_asdl_seq_new(len, arena); |
| 5601 | if (body == NULL) goto failed; |
| 5602 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5603 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5604 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5605 | Py_INCREF(tmp2); |
| 5606 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5607 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5608 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5609 | if (len != PyList_GET_SIZE(tmp)) { |
| 5610 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5611 | goto failed; |
| 5612 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5613 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5614 | } |
| 5615 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5616 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5617 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5618 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5619 | return 1; |
| 5620 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5621 | if (tmp == NULL) { |
| 5622 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5623 | return 1; |
| 5624 | } |
| 5625 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5626 | int res; |
| 5627 | Py_ssize_t len; |
| 5628 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5629 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5630 | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5631 | goto failed; |
| 5632 | } |
| 5633 | len = PyList_GET_SIZE(tmp); |
| 5634 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5635 | if (decorator_list == NULL) goto failed; |
| 5636 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5637 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5638 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5639 | Py_INCREF(tmp2); |
| 5640 | res = obj2ast_expr(tmp2, &val, arena); |
| 5641 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5642 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5643 | if (len != PyList_GET_SIZE(tmp)) { |
| 5644 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5645 | goto failed; |
| 5646 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5647 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5648 | } |
| 5649 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5650 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5651 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5652 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5653 | return 1; |
| 5654 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5655 | if (tmp == NULL || tmp == Py_None) { |
| 5656 | Py_CLEAR(tmp); |
| 5657 | returns = NULL; |
| 5658 | } |
| 5659 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5660 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5661 | res = obj2ast_expr(tmp, &returns, arena); |
| 5662 | if (res != 0) goto failed; |
| 5663 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5664 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5665 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5666 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5667 | return 1; |
| 5668 | } |
| 5669 | if (tmp == NULL || tmp == Py_None) { |
| 5670 | Py_CLEAR(tmp); |
| 5671 | type_comment = NULL; |
| 5672 | } |
| 5673 | else { |
| 5674 | int res; |
| 5675 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5676 | if (res != 0) goto failed; |
| 5677 | Py_CLEAR(tmp); |
| 5678 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5679 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5680 | type_comment, lineno, col_offset, end_lineno, |
| 5681 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5682 | if (*out == NULL) goto failed; |
| 5683 | return 0; |
| 5684 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5685 | tp = astmodulestate_global->ClassDef_type; |
| 5686 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5687 | if (isinstance == -1) { |
| 5688 | return 1; |
| 5689 | } |
| 5690 | if (isinstance) { |
| 5691 | identifier name; |
| 5692 | asdl_seq* bases; |
| 5693 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5694 | asdl_seq* body; |
| 5695 | asdl_seq* decorator_list; |
| 5696 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5697 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5698 | return 1; |
| 5699 | } |
| 5700 | if (tmp == NULL) { |
| 5701 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5702 | return 1; |
| 5703 | } |
| 5704 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5705 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5706 | res = obj2ast_identifier(tmp, &name, arena); |
| 5707 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5708 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5709 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5710 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5711 | return 1; |
| 5712 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5713 | if (tmp == NULL) { |
| 5714 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5715 | return 1; |
| 5716 | } |
| 5717 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5718 | int res; |
| 5719 | Py_ssize_t len; |
| 5720 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5721 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5722 | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5723 | goto failed; |
| 5724 | } |
| 5725 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5726 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5727 | if (bases == NULL) goto failed; |
| 5728 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5729 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5730 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5731 | Py_INCREF(tmp2); |
| 5732 | res = obj2ast_expr(tmp2, &val, arena); |
| 5733 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5734 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5735 | if (len != PyList_GET_SIZE(tmp)) { |
| 5736 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5737 | goto failed; |
| 5738 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5739 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5740 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5741 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5742 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5743 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5744 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5745 | return 1; |
| 5746 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5747 | if (tmp == NULL) { |
| 5748 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5749 | return 1; |
| 5750 | } |
| 5751 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5752 | int res; |
| 5753 | Py_ssize_t len; |
| 5754 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5755 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5756 | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5757 | goto failed; |
| 5758 | } |
| 5759 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5760 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5761 | if (keywords == NULL) goto failed; |
| 5762 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5763 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5764 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5765 | Py_INCREF(tmp2); |
| 5766 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5767 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5768 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5769 | if (len != PyList_GET_SIZE(tmp)) { |
| 5770 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5771 | goto failed; |
| 5772 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5773 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5774 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5775 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5776 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5777 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5778 | return 1; |
| 5779 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5780 | if (tmp == NULL) { |
| 5781 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5782 | return 1; |
| 5783 | } |
| 5784 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5785 | int res; |
| 5786 | Py_ssize_t len; |
| 5787 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5788 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5789 | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5790 | goto failed; |
| 5791 | } |
| 5792 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5793 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5794 | if (body == NULL) goto failed; |
| 5795 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5796 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5797 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5798 | Py_INCREF(tmp2); |
| 5799 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5800 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5801 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5802 | if (len != PyList_GET_SIZE(tmp)) { |
| 5803 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5804 | goto failed; |
| 5805 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5806 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5807 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5808 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5809 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5810 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5811 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5812 | return 1; |
| 5813 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5814 | if (tmp == NULL) { |
| 5815 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5816 | return 1; |
| 5817 | } |
| 5818 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5819 | int res; |
| 5820 | Py_ssize_t len; |
| 5821 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5822 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5823 | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5824 | goto failed; |
| 5825 | } |
| 5826 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5827 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5828 | if (decorator_list == NULL) goto failed; |
| 5829 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5830 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5831 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5832 | Py_INCREF(tmp2); |
| 5833 | res = obj2ast_expr(tmp2, &val, arena); |
| 5834 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5835 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5836 | if (len != PyList_GET_SIZE(tmp)) { |
| 5837 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5838 | goto failed; |
| 5839 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5840 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5841 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5842 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5843 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5844 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5845 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5846 | if (*out == NULL) goto failed; |
| 5847 | return 0; |
| 5848 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5849 | tp = astmodulestate_global->Return_type; |
| 5850 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5851 | if (isinstance == -1) { |
| 5852 | return 1; |
| 5853 | } |
| 5854 | if (isinstance) { |
| 5855 | expr_ty value; |
| 5856 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5857 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5858 | return 1; |
| 5859 | } |
| 5860 | if (tmp == NULL || tmp == Py_None) { |
| 5861 | Py_CLEAR(tmp); |
| 5862 | value = NULL; |
| 5863 | } |
| 5864 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5865 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5866 | res = obj2ast_expr(tmp, &value, arena); |
| 5867 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5868 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5869 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5870 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5871 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5872 | if (*out == NULL) goto failed; |
| 5873 | return 0; |
| 5874 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5875 | tp = astmodulestate_global->Delete_type; |
| 5876 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5877 | if (isinstance == -1) { |
| 5878 | return 1; |
| 5879 | } |
| 5880 | if (isinstance) { |
| 5881 | asdl_seq* targets; |
| 5882 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5883 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5884 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5885 | return 1; |
| 5886 | } |
| 5887 | if (tmp == NULL) { |
| 5888 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5889 | return 1; |
| 5890 | } |
| 5891 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5892 | int res; |
| 5893 | Py_ssize_t len; |
| 5894 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5895 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5896 | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5897 | goto failed; |
| 5898 | } |
| 5899 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5900 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5901 | if (targets == NULL) goto failed; |
| 5902 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5903 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5904 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5905 | Py_INCREF(tmp2); |
| 5906 | res = obj2ast_expr(tmp2, &val, arena); |
| 5907 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5908 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5909 | if (len != PyList_GET_SIZE(tmp)) { |
| 5910 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5911 | goto failed; |
| 5912 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5913 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5914 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5915 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5916 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5917 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5918 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5919 | if (*out == NULL) goto failed; |
| 5920 | return 0; |
| 5921 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5922 | tp = astmodulestate_global->Assign_type; |
| 5923 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5924 | if (isinstance == -1) { |
| 5925 | return 1; |
| 5926 | } |
| 5927 | if (isinstance) { |
| 5928 | asdl_seq* targets; |
| 5929 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5930 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5931 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5932 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5933 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5934 | return 1; |
| 5935 | } |
| 5936 | if (tmp == NULL) { |
| 5937 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5938 | return 1; |
| 5939 | } |
| 5940 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5941 | int res; |
| 5942 | Py_ssize_t len; |
| 5943 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5944 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5945 | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5946 | goto failed; |
| 5947 | } |
| 5948 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5949 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5950 | if (targets == NULL) goto failed; |
| 5951 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5952 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5953 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5954 | Py_INCREF(tmp2); |
| 5955 | res = obj2ast_expr(tmp2, &val, arena); |
| 5956 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5957 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5958 | if (len != PyList_GET_SIZE(tmp)) { |
| 5959 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5960 | goto failed; |
| 5961 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5962 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5963 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5964 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5965 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5966 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5967 | return 1; |
| 5968 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5969 | if (tmp == NULL) { |
| 5970 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5971 | return 1; |
| 5972 | } |
| 5973 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5974 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5975 | res = obj2ast_expr(tmp, &value, arena); |
| 5976 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5977 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5978 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5979 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5980 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5981 | return 1; |
| 5982 | } |
| 5983 | if (tmp == NULL || tmp == Py_None) { |
| 5984 | Py_CLEAR(tmp); |
| 5985 | type_comment = NULL; |
| 5986 | } |
| 5987 | else { |
| 5988 | int res; |
| 5989 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5990 | if (res != 0) goto failed; |
| 5991 | Py_CLEAR(tmp); |
| 5992 | } |
| 5993 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5994 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5995 | if (*out == NULL) goto failed; |
| 5996 | return 0; |
| 5997 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5998 | tp = astmodulestate_global->AugAssign_type; |
| 5999 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6000 | if (isinstance == -1) { |
| 6001 | return 1; |
| 6002 | } |
| 6003 | if (isinstance) { |
| 6004 | expr_ty target; |
| 6005 | operator_ty op; |
| 6006 | expr_ty value; |
| 6007 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6008 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6009 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6010 | return 1; |
| 6011 | } |
| 6012 | if (tmp == NULL) { |
| 6013 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 6014 | return 1; |
| 6015 | } |
| 6016 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6017 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6018 | res = obj2ast_expr(tmp, &target, arena); |
| 6019 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6020 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6021 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6022 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6023 | return 1; |
| 6024 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6025 | if (tmp == NULL) { |
| 6026 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 6027 | return 1; |
| 6028 | } |
| 6029 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6030 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6031 | res = obj2ast_operator(tmp, &op, arena); |
| 6032 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6033 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6034 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6035 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6036 | return 1; |
| 6037 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6038 | if (tmp == NULL) { |
| 6039 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 6040 | return 1; |
| 6041 | } |
| 6042 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6043 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6044 | res = obj2ast_expr(tmp, &value, arena); |
| 6045 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6046 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6047 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6048 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 6049 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6050 | if (*out == NULL) goto failed; |
| 6051 | return 0; |
| 6052 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6053 | tp = astmodulestate_global->AnnAssign_type; |
| 6054 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6055 | if (isinstance == -1) { |
| 6056 | return 1; |
| 6057 | } |
| 6058 | if (isinstance) { |
| 6059 | expr_ty target; |
| 6060 | expr_ty annotation; |
| 6061 | expr_ty value; |
| 6062 | int simple; |
| 6063 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6064 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6065 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6066 | return 1; |
| 6067 | } |
| 6068 | if (tmp == NULL) { |
| 6069 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 6070 | return 1; |
| 6071 | } |
| 6072 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6073 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6074 | res = obj2ast_expr(tmp, &target, arena); |
| 6075 | if (res != 0) goto failed; |
| 6076 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6077 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6078 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 6079 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6080 | return 1; |
| 6081 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6082 | if (tmp == NULL) { |
| 6083 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 6084 | return 1; |
| 6085 | } |
| 6086 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6087 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6088 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6089 | if (res != 0) goto failed; |
| 6090 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6091 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6092 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6093 | return 1; |
| 6094 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6095 | if (tmp == NULL || tmp == Py_None) { |
| 6096 | Py_CLEAR(tmp); |
| 6097 | value = NULL; |
| 6098 | } |
| 6099 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6100 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6101 | res = obj2ast_expr(tmp, &value, arena); |
| 6102 | if (res != 0) goto failed; |
| 6103 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6104 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6105 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6106 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6107 | return 1; |
| 6108 | } |
| 6109 | if (tmp == NULL) { |
| 6110 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6111 | return 1; |
| 6112 | } |
| 6113 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6114 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6115 | res = obj2ast_int(tmp, &simple, arena); |
| 6116 | if (res != 0) goto failed; |
| 6117 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6118 | } |
| 6119 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6120 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6121 | if (*out == NULL) goto failed; |
| 6122 | return 0; |
| 6123 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6124 | tp = astmodulestate_global->For_type; |
| 6125 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6126 | if (isinstance == -1) { |
| 6127 | return 1; |
| 6128 | } |
| 6129 | if (isinstance) { |
| 6130 | expr_ty target; |
| 6131 | expr_ty iter; |
| 6132 | asdl_seq* body; |
| 6133 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6134 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6135 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6136 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6137 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6138 | return 1; |
| 6139 | } |
| 6140 | if (tmp == NULL) { |
| 6141 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6142 | return 1; |
| 6143 | } |
| 6144 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6145 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6146 | res = obj2ast_expr(tmp, &target, arena); |
| 6147 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6148 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6149 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6150 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6151 | return 1; |
| 6152 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6153 | if (tmp == NULL) { |
| 6154 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6155 | return 1; |
| 6156 | } |
| 6157 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6158 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6159 | res = obj2ast_expr(tmp, &iter, arena); |
| 6160 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6161 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6162 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6163 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6164 | return 1; |
| 6165 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6166 | if (tmp == NULL) { |
| 6167 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6168 | return 1; |
| 6169 | } |
| 6170 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6171 | int res; |
| 6172 | Py_ssize_t len; |
| 6173 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6174 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6175 | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6176 | goto failed; |
| 6177 | } |
| 6178 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6179 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6180 | if (body == NULL) goto failed; |
| 6181 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6182 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6183 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6184 | Py_INCREF(tmp2); |
| 6185 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6186 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6187 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6188 | if (len != PyList_GET_SIZE(tmp)) { |
| 6189 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6190 | goto failed; |
| 6191 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6192 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6193 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6194 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6195 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6196 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6197 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6198 | return 1; |
| 6199 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6200 | if (tmp == NULL) { |
| 6201 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6202 | return 1; |
| 6203 | } |
| 6204 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6205 | int res; |
| 6206 | Py_ssize_t len; |
| 6207 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6208 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6209 | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6210 | goto failed; |
| 6211 | } |
| 6212 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6213 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6214 | if (orelse == NULL) goto failed; |
| 6215 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6216 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6217 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6218 | Py_INCREF(tmp2); |
| 6219 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6220 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6221 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6222 | if (len != PyList_GET_SIZE(tmp)) { |
| 6223 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6224 | goto failed; |
| 6225 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6226 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6227 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6228 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6229 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6230 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6231 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6232 | return 1; |
| 6233 | } |
| 6234 | if (tmp == NULL || tmp == Py_None) { |
| 6235 | Py_CLEAR(tmp); |
| 6236 | type_comment = NULL; |
| 6237 | } |
| 6238 | else { |
| 6239 | int res; |
| 6240 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6241 | if (res != 0) goto failed; |
| 6242 | Py_CLEAR(tmp); |
| 6243 | } |
| 6244 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6245 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6246 | if (*out == NULL) goto failed; |
| 6247 | return 0; |
| 6248 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6249 | tp = astmodulestate_global->AsyncFor_type; |
| 6250 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6251 | if (isinstance == -1) { |
| 6252 | return 1; |
| 6253 | } |
| 6254 | if (isinstance) { |
| 6255 | expr_ty target; |
| 6256 | expr_ty iter; |
| 6257 | asdl_seq* body; |
| 6258 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6259 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6260 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6261 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6262 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6263 | return 1; |
| 6264 | } |
| 6265 | if (tmp == NULL) { |
| 6266 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6267 | return 1; |
| 6268 | } |
| 6269 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6270 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6271 | res = obj2ast_expr(tmp, &target, arena); |
| 6272 | if (res != 0) goto failed; |
| 6273 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6274 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6275 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6276 | return 1; |
| 6277 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6278 | if (tmp == NULL) { |
| 6279 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6280 | return 1; |
| 6281 | } |
| 6282 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6283 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6284 | res = obj2ast_expr(tmp, &iter, arena); |
| 6285 | if (res != 0) goto failed; |
| 6286 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6287 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6288 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6289 | return 1; |
| 6290 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6291 | if (tmp == NULL) { |
| 6292 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6293 | return 1; |
| 6294 | } |
| 6295 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6296 | int res; |
| 6297 | Py_ssize_t len; |
| 6298 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6299 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6300 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6301 | goto failed; |
| 6302 | } |
| 6303 | len = PyList_GET_SIZE(tmp); |
| 6304 | body = _Py_asdl_seq_new(len, arena); |
| 6305 | if (body == NULL) goto failed; |
| 6306 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6307 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6308 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6309 | Py_INCREF(tmp2); |
| 6310 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6311 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6312 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6313 | if (len != PyList_GET_SIZE(tmp)) { |
| 6314 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6315 | goto failed; |
| 6316 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6317 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6318 | } |
| 6319 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6320 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6321 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6322 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6323 | return 1; |
| 6324 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6325 | if (tmp == NULL) { |
| 6326 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6327 | return 1; |
| 6328 | } |
| 6329 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6330 | int res; |
| 6331 | Py_ssize_t len; |
| 6332 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6333 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6334 | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6335 | goto failed; |
| 6336 | } |
| 6337 | len = PyList_GET_SIZE(tmp); |
| 6338 | orelse = _Py_asdl_seq_new(len, arena); |
| 6339 | if (orelse == NULL) goto failed; |
| 6340 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6341 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6342 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6343 | Py_INCREF(tmp2); |
| 6344 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6345 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6346 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6347 | if (len != PyList_GET_SIZE(tmp)) { |
| 6348 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6349 | goto failed; |
| 6350 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6351 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6352 | } |
| 6353 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6354 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6355 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6356 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6357 | return 1; |
| 6358 | } |
| 6359 | if (tmp == NULL || tmp == Py_None) { |
| 6360 | Py_CLEAR(tmp); |
| 6361 | type_comment = NULL; |
| 6362 | } |
| 6363 | else { |
| 6364 | int res; |
| 6365 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6366 | if (res != 0) goto failed; |
| 6367 | Py_CLEAR(tmp); |
| 6368 | } |
| 6369 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6370 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6371 | if (*out == NULL) goto failed; |
| 6372 | return 0; |
| 6373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6374 | tp = astmodulestate_global->While_type; |
| 6375 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6376 | if (isinstance == -1) { |
| 6377 | return 1; |
| 6378 | } |
| 6379 | if (isinstance) { |
| 6380 | expr_ty test; |
| 6381 | asdl_seq* body; |
| 6382 | asdl_seq* orelse; |
| 6383 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6384 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6385 | return 1; |
| 6386 | } |
| 6387 | if (tmp == NULL) { |
| 6388 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6389 | return 1; |
| 6390 | } |
| 6391 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6392 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6393 | res = obj2ast_expr(tmp, &test, arena); |
| 6394 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6395 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6396 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6397 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6398 | return 1; |
| 6399 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6400 | if (tmp == NULL) { |
| 6401 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6402 | return 1; |
| 6403 | } |
| 6404 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6405 | int res; |
| 6406 | Py_ssize_t len; |
| 6407 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6408 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6409 | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6410 | goto failed; |
| 6411 | } |
| 6412 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6413 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6414 | if (body == NULL) goto failed; |
| 6415 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6416 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6417 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6418 | Py_INCREF(tmp2); |
| 6419 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6420 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6421 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6422 | if (len != PyList_GET_SIZE(tmp)) { |
| 6423 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6424 | goto failed; |
| 6425 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6426 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6427 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6428 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6429 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6430 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6431 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6432 | return 1; |
| 6433 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6434 | if (tmp == NULL) { |
| 6435 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6436 | return 1; |
| 6437 | } |
| 6438 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6439 | int res; |
| 6440 | Py_ssize_t len; |
| 6441 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6442 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6443 | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6444 | goto failed; |
| 6445 | } |
| 6446 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6447 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6448 | if (orelse == NULL) goto failed; |
| 6449 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6450 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6451 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6452 | Py_INCREF(tmp2); |
| 6453 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6454 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6455 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6456 | if (len != PyList_GET_SIZE(tmp)) { |
| 6457 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6458 | goto failed; |
| 6459 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6460 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6461 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6462 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6463 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6464 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6465 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6466 | if (*out == NULL) goto failed; |
| 6467 | return 0; |
| 6468 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6469 | tp = astmodulestate_global->If_type; |
| 6470 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6471 | if (isinstance == -1) { |
| 6472 | return 1; |
| 6473 | } |
| 6474 | if (isinstance) { |
| 6475 | expr_ty test; |
| 6476 | asdl_seq* body; |
| 6477 | asdl_seq* orelse; |
| 6478 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6479 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6480 | return 1; |
| 6481 | } |
| 6482 | if (tmp == NULL) { |
| 6483 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6484 | return 1; |
| 6485 | } |
| 6486 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6487 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6488 | res = obj2ast_expr(tmp, &test, arena); |
| 6489 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6490 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6491 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6492 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6493 | return 1; |
| 6494 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6495 | if (tmp == NULL) { |
| 6496 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6497 | return 1; |
| 6498 | } |
| 6499 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6500 | int res; |
| 6501 | Py_ssize_t len; |
| 6502 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6503 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6504 | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6505 | goto failed; |
| 6506 | } |
| 6507 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6508 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6509 | if (body == NULL) goto failed; |
| 6510 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6511 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6512 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6513 | Py_INCREF(tmp2); |
| 6514 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6515 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6516 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6517 | if (len != PyList_GET_SIZE(tmp)) { |
| 6518 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6519 | goto failed; |
| 6520 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6521 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6522 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6523 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6524 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6525 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6526 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6527 | return 1; |
| 6528 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6529 | if (tmp == NULL) { |
| 6530 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6531 | return 1; |
| 6532 | } |
| 6533 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6534 | int res; |
| 6535 | Py_ssize_t len; |
| 6536 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6537 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6538 | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6539 | goto failed; |
| 6540 | } |
| 6541 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6542 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6543 | if (orelse == NULL) goto failed; |
| 6544 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6545 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6546 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6547 | Py_INCREF(tmp2); |
| 6548 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6549 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6550 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6551 | if (len != PyList_GET_SIZE(tmp)) { |
| 6552 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6553 | goto failed; |
| 6554 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6555 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6556 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6557 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6558 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6559 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6560 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6561 | if (*out == NULL) goto failed; |
| 6562 | return 0; |
| 6563 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6564 | tp = astmodulestate_global->With_type; |
| 6565 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6566 | if (isinstance == -1) { |
| 6567 | return 1; |
| 6568 | } |
| 6569 | if (isinstance) { |
| 6570 | asdl_seq* items; |
| 6571 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6572 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6573 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6574 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6575 | return 1; |
| 6576 | } |
| 6577 | if (tmp == NULL) { |
| 6578 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6579 | return 1; |
| 6580 | } |
| 6581 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6582 | int res; |
| 6583 | Py_ssize_t len; |
| 6584 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6585 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6586 | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6587 | goto failed; |
| 6588 | } |
| 6589 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6590 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6591 | if (items == NULL) goto failed; |
| 6592 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6593 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6594 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6595 | Py_INCREF(tmp2); |
| 6596 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6597 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6598 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6599 | if (len != PyList_GET_SIZE(tmp)) { |
| 6600 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6601 | goto failed; |
| 6602 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6603 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6604 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6605 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6606 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6607 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6608 | return 1; |
| 6609 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6610 | if (tmp == NULL) { |
| 6611 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6612 | return 1; |
| 6613 | } |
| 6614 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6615 | int res; |
| 6616 | Py_ssize_t len; |
| 6617 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6618 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6619 | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6620 | goto failed; |
| 6621 | } |
| 6622 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6623 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6624 | if (body == NULL) goto failed; |
| 6625 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6626 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6627 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6628 | Py_INCREF(tmp2); |
| 6629 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6630 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6631 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6632 | if (len != PyList_GET_SIZE(tmp)) { |
| 6633 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6634 | goto failed; |
| 6635 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6636 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6637 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6638 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6639 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6640 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6641 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6642 | return 1; |
| 6643 | } |
| 6644 | if (tmp == NULL || tmp == Py_None) { |
| 6645 | Py_CLEAR(tmp); |
| 6646 | type_comment = NULL; |
| 6647 | } |
| 6648 | else { |
| 6649 | int res; |
| 6650 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6651 | if (res != 0) goto failed; |
| 6652 | Py_CLEAR(tmp); |
| 6653 | } |
| 6654 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6655 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6656 | if (*out == NULL) goto failed; |
| 6657 | return 0; |
| 6658 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6659 | tp = astmodulestate_global->AsyncWith_type; |
| 6660 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6661 | if (isinstance == -1) { |
| 6662 | return 1; |
| 6663 | } |
| 6664 | if (isinstance) { |
| 6665 | asdl_seq* items; |
| 6666 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6667 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6668 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6669 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6670 | return 1; |
| 6671 | } |
| 6672 | if (tmp == NULL) { |
| 6673 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6674 | return 1; |
| 6675 | } |
| 6676 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6677 | int res; |
| 6678 | Py_ssize_t len; |
| 6679 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6680 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6681 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6682 | goto failed; |
| 6683 | } |
| 6684 | len = PyList_GET_SIZE(tmp); |
| 6685 | items = _Py_asdl_seq_new(len, arena); |
| 6686 | if (items == NULL) goto failed; |
| 6687 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6688 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6689 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6690 | Py_INCREF(tmp2); |
| 6691 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6692 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6693 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6694 | if (len != PyList_GET_SIZE(tmp)) { |
| 6695 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6696 | goto failed; |
| 6697 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6698 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6699 | } |
| 6700 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6701 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6702 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6703 | return 1; |
| 6704 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6705 | if (tmp == NULL) { |
| 6706 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6707 | return 1; |
| 6708 | } |
| 6709 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6710 | int res; |
| 6711 | Py_ssize_t len; |
| 6712 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6713 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6714 | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6715 | goto failed; |
| 6716 | } |
| 6717 | len = PyList_GET_SIZE(tmp); |
| 6718 | body = _Py_asdl_seq_new(len, arena); |
| 6719 | if (body == NULL) goto failed; |
| 6720 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6721 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6722 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6723 | Py_INCREF(tmp2); |
| 6724 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6725 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6726 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6727 | if (len != PyList_GET_SIZE(tmp)) { |
| 6728 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6729 | goto failed; |
| 6730 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6731 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6732 | } |
| 6733 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6734 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6735 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6736 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6737 | return 1; |
| 6738 | } |
| 6739 | if (tmp == NULL || tmp == Py_None) { |
| 6740 | Py_CLEAR(tmp); |
| 6741 | type_comment = NULL; |
| 6742 | } |
| 6743 | else { |
| 6744 | int res; |
| 6745 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6746 | if (res != 0) goto failed; |
| 6747 | Py_CLEAR(tmp); |
| 6748 | } |
| 6749 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6750 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6751 | if (*out == NULL) goto failed; |
| 6752 | return 0; |
| 6753 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6754 | tp = astmodulestate_global->Raise_type; |
| 6755 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6756 | if (isinstance == -1) { |
| 6757 | return 1; |
| 6758 | } |
| 6759 | if (isinstance) { |
| 6760 | expr_ty exc; |
| 6761 | expr_ty cause; |
| 6762 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6763 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6764 | return 1; |
| 6765 | } |
| 6766 | if (tmp == NULL || tmp == Py_None) { |
| 6767 | Py_CLEAR(tmp); |
| 6768 | exc = NULL; |
| 6769 | } |
| 6770 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6771 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6772 | res = obj2ast_expr(tmp, &exc, arena); |
| 6773 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6774 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6775 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6776 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6777 | return 1; |
| 6778 | } |
| 6779 | if (tmp == NULL || tmp == Py_None) { |
| 6780 | Py_CLEAR(tmp); |
| 6781 | cause = NULL; |
| 6782 | } |
| 6783 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6784 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6785 | res = obj2ast_expr(tmp, &cause, arena); |
| 6786 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6787 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6788 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6789 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6790 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6791 | if (*out == NULL) goto failed; |
| 6792 | return 0; |
| 6793 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6794 | tp = astmodulestate_global->Try_type; |
| 6795 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6796 | if (isinstance == -1) { |
| 6797 | return 1; |
| 6798 | } |
| 6799 | if (isinstance) { |
| 6800 | asdl_seq* body; |
| 6801 | asdl_seq* handlers; |
| 6802 | asdl_seq* orelse; |
| 6803 | asdl_seq* finalbody; |
| 6804 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6805 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6806 | return 1; |
| 6807 | } |
| 6808 | if (tmp == NULL) { |
| 6809 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6810 | return 1; |
| 6811 | } |
| 6812 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6813 | int res; |
| 6814 | Py_ssize_t len; |
| 6815 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6816 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6817 | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6818 | goto failed; |
| 6819 | } |
| 6820 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6821 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6822 | if (body == NULL) goto failed; |
| 6823 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6824 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6825 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6826 | Py_INCREF(tmp2); |
| 6827 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6828 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6829 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6830 | if (len != PyList_GET_SIZE(tmp)) { |
| 6831 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6832 | goto failed; |
| 6833 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6834 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6835 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6836 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6837 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6838 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6839 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6840 | return 1; |
| 6841 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6842 | if (tmp == NULL) { |
| 6843 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6844 | return 1; |
| 6845 | } |
| 6846 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6847 | int res; |
| 6848 | Py_ssize_t len; |
| 6849 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6850 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6851 | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6852 | goto failed; |
| 6853 | } |
| 6854 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6855 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6856 | if (handlers == NULL) goto failed; |
| 6857 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6858 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6859 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6860 | Py_INCREF(tmp2); |
| 6861 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6862 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6863 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6864 | if (len != PyList_GET_SIZE(tmp)) { |
| 6865 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6866 | goto failed; |
| 6867 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6868 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6869 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6870 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6871 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6872 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6873 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6874 | return 1; |
| 6875 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6876 | if (tmp == NULL) { |
| 6877 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6878 | return 1; |
| 6879 | } |
| 6880 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6881 | int res; |
| 6882 | Py_ssize_t len; |
| 6883 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6884 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6885 | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6886 | goto failed; |
| 6887 | } |
| 6888 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6889 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6890 | if (orelse == NULL) goto failed; |
| 6891 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6892 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6893 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6894 | Py_INCREF(tmp2); |
| 6895 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6896 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6897 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6898 | if (len != PyList_GET_SIZE(tmp)) { |
| 6899 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6900 | goto failed; |
| 6901 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6902 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6903 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6904 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6905 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6906 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6907 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6908 | return 1; |
| 6909 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6910 | if (tmp == NULL) { |
| 6911 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6912 | return 1; |
| 6913 | } |
| 6914 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6915 | int res; |
| 6916 | Py_ssize_t len; |
| 6917 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6918 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6919 | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6920 | goto failed; |
| 6921 | } |
| 6922 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6923 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6924 | if (finalbody == NULL) goto failed; |
| 6925 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6926 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6927 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6928 | Py_INCREF(tmp2); |
| 6929 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6930 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6931 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6932 | if (len != PyList_GET_SIZE(tmp)) { |
| 6933 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6934 | goto failed; |
| 6935 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6936 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6937 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6938 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6939 | } |
| 6940 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6941 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6942 | if (*out == NULL) goto failed; |
| 6943 | return 0; |
| 6944 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6945 | tp = astmodulestate_global->Assert_type; |
| 6946 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6947 | if (isinstance == -1) { |
| 6948 | return 1; |
| 6949 | } |
| 6950 | if (isinstance) { |
| 6951 | expr_ty test; |
| 6952 | expr_ty msg; |
| 6953 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6954 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6955 | return 1; |
| 6956 | } |
| 6957 | if (tmp == NULL) { |
| 6958 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6959 | return 1; |
| 6960 | } |
| 6961 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6962 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6963 | res = obj2ast_expr(tmp, &test, arena); |
| 6964 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6965 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6966 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6967 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6968 | return 1; |
| 6969 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6970 | if (tmp == NULL || tmp == Py_None) { |
| 6971 | Py_CLEAR(tmp); |
| 6972 | msg = NULL; |
| 6973 | } |
| 6974 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6975 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6976 | res = obj2ast_expr(tmp, &msg, arena); |
| 6977 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6978 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6979 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6980 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6981 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6982 | if (*out == NULL) goto failed; |
| 6983 | return 0; |
| 6984 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6985 | tp = astmodulestate_global->Import_type; |
| 6986 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6987 | if (isinstance == -1) { |
| 6988 | return 1; |
| 6989 | } |
| 6990 | if (isinstance) { |
| 6991 | asdl_seq* names; |
| 6992 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6993 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6994 | return 1; |
| 6995 | } |
| 6996 | if (tmp == NULL) { |
| 6997 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6998 | return 1; |
| 6999 | } |
| 7000 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7001 | int res; |
| 7002 | Py_ssize_t len; |
| 7003 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7004 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7005 | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7006 | goto failed; |
| 7007 | } |
| 7008 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7009 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7010 | if (names == NULL) goto failed; |
| 7011 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7012 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7013 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7014 | Py_INCREF(tmp2); |
| 7015 | res = obj2ast_alias(tmp2, &val, arena); |
| 7016 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7017 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7018 | if (len != PyList_GET_SIZE(tmp)) { |
| 7019 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 7020 | goto failed; |
| 7021 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7022 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7023 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7024 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7025 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7026 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7027 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7028 | if (*out == NULL) goto failed; |
| 7029 | return 0; |
| 7030 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7031 | tp = astmodulestate_global->ImportFrom_type; |
| 7032 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7033 | if (isinstance == -1) { |
| 7034 | return 1; |
| 7035 | } |
| 7036 | if (isinstance) { |
| 7037 | identifier module; |
| 7038 | asdl_seq* names; |
| 7039 | int level; |
| 7040 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7041 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 7042 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7043 | return 1; |
| 7044 | } |
| 7045 | if (tmp == NULL || tmp == Py_None) { |
| 7046 | Py_CLEAR(tmp); |
| 7047 | module = NULL; |
| 7048 | } |
| 7049 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7050 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7051 | res = obj2ast_identifier(tmp, &module, arena); |
| 7052 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7053 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7054 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7055 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7056 | return 1; |
| 7057 | } |
| 7058 | if (tmp == NULL) { |
| 7059 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 7060 | return 1; |
| 7061 | } |
| 7062 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7063 | int res; |
| 7064 | Py_ssize_t len; |
| 7065 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7066 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7067 | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7068 | goto failed; |
| 7069 | } |
| 7070 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7071 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7072 | if (names == NULL) goto failed; |
| 7073 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7074 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7075 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7076 | Py_INCREF(tmp2); |
| 7077 | res = obj2ast_alias(tmp2, &val, arena); |
| 7078 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7079 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7080 | if (len != PyList_GET_SIZE(tmp)) { |
| 7081 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 7082 | goto failed; |
| 7083 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7084 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7085 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7086 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7087 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7088 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7089 | return 1; |
| 7090 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7091 | if (tmp == NULL || tmp == Py_None) { |
| 7092 | Py_CLEAR(tmp); |
| 7093 | level = 0; |
| 7094 | } |
| 7095 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7096 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7097 | res = obj2ast_int(tmp, &level, arena); |
| 7098 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7099 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7100 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7101 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7102 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7103 | if (*out == NULL) goto failed; |
| 7104 | return 0; |
| 7105 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7106 | tp = astmodulestate_global->Global_type; |
| 7107 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7108 | if (isinstance == -1) { |
| 7109 | return 1; |
| 7110 | } |
| 7111 | if (isinstance) { |
| 7112 | asdl_seq* names; |
| 7113 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7114 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7115 | return 1; |
| 7116 | } |
| 7117 | if (tmp == NULL) { |
| 7118 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7119 | return 1; |
| 7120 | } |
| 7121 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7122 | int res; |
| 7123 | Py_ssize_t len; |
| 7124 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7125 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7126 | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7127 | goto failed; |
| 7128 | } |
| 7129 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7130 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7131 | if (names == NULL) goto failed; |
| 7132 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7133 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7134 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7135 | Py_INCREF(tmp2); |
| 7136 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7137 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7138 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7139 | if (len != PyList_GET_SIZE(tmp)) { |
| 7140 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7141 | goto failed; |
| 7142 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7143 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7144 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7145 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7146 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7147 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7148 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7149 | if (*out == NULL) goto failed; |
| 7150 | return 0; |
| 7151 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7152 | tp = astmodulestate_global->Nonlocal_type; |
| 7153 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7154 | if (isinstance == -1) { |
| 7155 | return 1; |
| 7156 | } |
| 7157 | if (isinstance) { |
| 7158 | asdl_seq* names; |
| 7159 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7160 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7161 | return 1; |
| 7162 | } |
| 7163 | if (tmp == NULL) { |
| 7164 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7165 | return 1; |
| 7166 | } |
| 7167 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7168 | int res; |
| 7169 | Py_ssize_t len; |
| 7170 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7171 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7172 | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7173 | goto failed; |
| 7174 | } |
| 7175 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7176 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7177 | if (names == NULL) goto failed; |
| 7178 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7179 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7180 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7181 | Py_INCREF(tmp2); |
| 7182 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7183 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7184 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7185 | if (len != PyList_GET_SIZE(tmp)) { |
| 7186 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7187 | goto failed; |
| 7188 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7189 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7190 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7191 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7192 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7193 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7194 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7195 | if (*out == NULL) goto failed; |
| 7196 | return 0; |
| 7197 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7198 | tp = astmodulestate_global->Expr_type; |
| 7199 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7200 | if (isinstance == -1) { |
| 7201 | return 1; |
| 7202 | } |
| 7203 | if (isinstance) { |
| 7204 | expr_ty value; |
| 7205 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7206 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7207 | return 1; |
| 7208 | } |
| 7209 | if (tmp == NULL) { |
| 7210 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7211 | return 1; |
| 7212 | } |
| 7213 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7214 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7215 | res = obj2ast_expr(tmp, &value, arena); |
| 7216 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7217 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7218 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7219 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7220 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7221 | if (*out == NULL) goto failed; |
| 7222 | return 0; |
| 7223 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7224 | tp = astmodulestate_global->Pass_type; |
| 7225 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7226 | if (isinstance == -1) { |
| 7227 | return 1; |
| 7228 | } |
| 7229 | if (isinstance) { |
| 7230 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7231 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7232 | if (*out == NULL) goto failed; |
| 7233 | return 0; |
| 7234 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7235 | tp = astmodulestate_global->Break_type; |
| 7236 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7237 | if (isinstance == -1) { |
| 7238 | return 1; |
| 7239 | } |
| 7240 | if (isinstance) { |
| 7241 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7242 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7243 | if (*out == NULL) goto failed; |
| 7244 | return 0; |
| 7245 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7246 | tp = astmodulestate_global->Continue_type; |
| 7247 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7248 | if (isinstance == -1) { |
| 7249 | return 1; |
| 7250 | } |
| 7251 | if (isinstance) { |
| 7252 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7253 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7254 | if (*out == NULL) goto failed; |
| 7255 | return 0; |
| 7256 | } |
| 7257 | |
| 7258 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7259 | failed: |
| 7260 | Py_XDECREF(tmp); |
| 7261 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7262 | } |
| 7263 | |
| 7264 | int |
| 7265 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7266 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7267 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7268 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7269 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7270 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7271 | int lineno; |
| 7272 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7273 | int end_lineno; |
| 7274 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7275 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7276 | if (obj == Py_None) { |
| 7277 | *out = NULL; |
| 7278 | return 0; |
| 7279 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7280 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7281 | return 1; |
| 7282 | } |
| 7283 | if (tmp == NULL) { |
| 7284 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7285 | return 1; |
| 7286 | } |
| 7287 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7288 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7289 | res = obj2ast_int(tmp, &lineno, arena); |
| 7290 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7291 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7292 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7293 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7294 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7295 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7296 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7297 | if (tmp == NULL) { |
| 7298 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7299 | return 1; |
| 7300 | } |
| 7301 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7302 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7303 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7304 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7305 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7306 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7307 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7308 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7309 | return 1; |
| 7310 | } |
| 7311 | if (tmp == NULL || tmp == Py_None) { |
| 7312 | Py_CLEAR(tmp); |
| 7313 | end_lineno = 0; |
| 7314 | } |
| 7315 | else { |
| 7316 | int res; |
| 7317 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7318 | if (res != 0) goto failed; |
| 7319 | Py_CLEAR(tmp); |
| 7320 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7321 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7322 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7323 | return 1; |
| 7324 | } |
| 7325 | if (tmp == NULL || tmp == Py_None) { |
| 7326 | Py_CLEAR(tmp); |
| 7327 | end_col_offset = 0; |
| 7328 | } |
| 7329 | else { |
| 7330 | int res; |
| 7331 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7332 | if (res != 0) goto failed; |
| 7333 | Py_CLEAR(tmp); |
| 7334 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7335 | tp = astmodulestate_global->BoolOp_type; |
| 7336 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7337 | if (isinstance == -1) { |
| 7338 | return 1; |
| 7339 | } |
| 7340 | if (isinstance) { |
| 7341 | boolop_ty op; |
| 7342 | asdl_seq* values; |
| 7343 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7344 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7345 | return 1; |
| 7346 | } |
| 7347 | if (tmp == NULL) { |
| 7348 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7349 | return 1; |
| 7350 | } |
| 7351 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7352 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7353 | res = obj2ast_boolop(tmp, &op, arena); |
| 7354 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7355 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7356 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7357 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7358 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7359 | return 1; |
| 7360 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7361 | if (tmp == NULL) { |
| 7362 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7363 | return 1; |
| 7364 | } |
| 7365 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7366 | int res; |
| 7367 | Py_ssize_t len; |
| 7368 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7369 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7370 | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7371 | goto failed; |
| 7372 | } |
| 7373 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7374 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7375 | if (values == NULL) goto failed; |
| 7376 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7377 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7378 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7379 | Py_INCREF(tmp2); |
| 7380 | res = obj2ast_expr(tmp2, &val, arena); |
| 7381 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7382 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7383 | if (len != PyList_GET_SIZE(tmp)) { |
| 7384 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7385 | goto failed; |
| 7386 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7387 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7388 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7389 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7390 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7391 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7392 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7393 | if (*out == NULL) goto failed; |
| 7394 | return 0; |
| 7395 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7396 | tp = astmodulestate_global->NamedExpr_type; |
| 7397 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7398 | if (isinstance == -1) { |
| 7399 | return 1; |
| 7400 | } |
| 7401 | if (isinstance) { |
| 7402 | expr_ty target; |
| 7403 | expr_ty value; |
| 7404 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7405 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7406 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7407 | return 1; |
| 7408 | } |
| 7409 | if (tmp == NULL) { |
| 7410 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7411 | return 1; |
| 7412 | } |
| 7413 | else { |
| 7414 | int res; |
| 7415 | res = obj2ast_expr(tmp, &target, arena); |
| 7416 | if (res != 0) goto failed; |
| 7417 | Py_CLEAR(tmp); |
| 7418 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7419 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7420 | return 1; |
| 7421 | } |
| 7422 | if (tmp == NULL) { |
| 7423 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7424 | return 1; |
| 7425 | } |
| 7426 | else { |
| 7427 | int res; |
| 7428 | res = obj2ast_expr(tmp, &value, arena); |
| 7429 | if (res != 0) goto failed; |
| 7430 | Py_CLEAR(tmp); |
| 7431 | } |
| 7432 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7433 | end_col_offset, arena); |
| 7434 | if (*out == NULL) goto failed; |
| 7435 | return 0; |
| 7436 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7437 | tp = astmodulestate_global->BinOp_type; |
| 7438 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7439 | if (isinstance == -1) { |
| 7440 | return 1; |
| 7441 | } |
| 7442 | if (isinstance) { |
| 7443 | expr_ty left; |
| 7444 | operator_ty op; |
| 7445 | expr_ty right; |
| 7446 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7447 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7448 | return 1; |
| 7449 | } |
| 7450 | if (tmp == NULL) { |
| 7451 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7452 | return 1; |
| 7453 | } |
| 7454 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7455 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7456 | res = obj2ast_expr(tmp, &left, arena); |
| 7457 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7458 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7459 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7460 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7461 | return 1; |
| 7462 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7463 | if (tmp == NULL) { |
| 7464 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7465 | return 1; |
| 7466 | } |
| 7467 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7468 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7469 | res = obj2ast_operator(tmp, &op, arena); |
| 7470 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7471 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7472 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7473 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7474 | return 1; |
| 7475 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7476 | if (tmp == NULL) { |
| 7477 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7478 | return 1; |
| 7479 | } |
| 7480 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7481 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7482 | res = obj2ast_expr(tmp, &right, arena); |
| 7483 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7484 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7485 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7486 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7487 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7488 | if (*out == NULL) goto failed; |
| 7489 | return 0; |
| 7490 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7491 | tp = astmodulestate_global->UnaryOp_type; |
| 7492 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7493 | if (isinstance == -1) { |
| 7494 | return 1; |
| 7495 | } |
| 7496 | if (isinstance) { |
| 7497 | unaryop_ty op; |
| 7498 | expr_ty operand; |
| 7499 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7500 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7501 | return 1; |
| 7502 | } |
| 7503 | if (tmp == NULL) { |
| 7504 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7505 | return 1; |
| 7506 | } |
| 7507 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7508 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7509 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7510 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7511 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7512 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7513 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7514 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7515 | return 1; |
| 7516 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7517 | if (tmp == NULL) { |
| 7518 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7519 | return 1; |
| 7520 | } |
| 7521 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7522 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7523 | res = obj2ast_expr(tmp, &operand, arena); |
| 7524 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7525 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7526 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7527 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7528 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7529 | if (*out == NULL) goto failed; |
| 7530 | return 0; |
| 7531 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7532 | tp = astmodulestate_global->Lambda_type; |
| 7533 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7534 | if (isinstance == -1) { |
| 7535 | return 1; |
| 7536 | } |
| 7537 | if (isinstance) { |
| 7538 | arguments_ty args; |
| 7539 | expr_ty body; |
| 7540 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7541 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7542 | return 1; |
| 7543 | } |
| 7544 | if (tmp == NULL) { |
| 7545 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7546 | return 1; |
| 7547 | } |
| 7548 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7549 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7550 | res = obj2ast_arguments(tmp, &args, arena); |
| 7551 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7552 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7553 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7554 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7555 | return 1; |
| 7556 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7557 | if (tmp == NULL) { |
| 7558 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7559 | return 1; |
| 7560 | } |
| 7561 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7562 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7563 | res = obj2ast_expr(tmp, &body, arena); |
| 7564 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7565 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7566 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7567 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7568 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7569 | if (*out == NULL) goto failed; |
| 7570 | return 0; |
| 7571 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7572 | tp = astmodulestate_global->IfExp_type; |
| 7573 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7574 | if (isinstance == -1) { |
| 7575 | return 1; |
| 7576 | } |
| 7577 | if (isinstance) { |
| 7578 | expr_ty test; |
| 7579 | expr_ty body; |
| 7580 | expr_ty orelse; |
| 7581 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7582 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7583 | return 1; |
| 7584 | } |
| 7585 | if (tmp == NULL) { |
| 7586 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7587 | return 1; |
| 7588 | } |
| 7589 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7590 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7591 | res = obj2ast_expr(tmp, &test, arena); |
| 7592 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7593 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7594 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7595 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7596 | return 1; |
| 7597 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7598 | if (tmp == NULL) { |
| 7599 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7600 | return 1; |
| 7601 | } |
| 7602 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7603 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7604 | res = obj2ast_expr(tmp, &body, arena); |
| 7605 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7606 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7607 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7608 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7609 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7610 | return 1; |
| 7611 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7612 | if (tmp == NULL) { |
| 7613 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7614 | return 1; |
| 7615 | } |
| 7616 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7617 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7618 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7619 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7620 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7621 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7622 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7623 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7624 | if (*out == NULL) goto failed; |
| 7625 | return 0; |
| 7626 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7627 | tp = astmodulestate_global->Dict_type; |
| 7628 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7629 | if (isinstance == -1) { |
| 7630 | return 1; |
| 7631 | } |
| 7632 | if (isinstance) { |
| 7633 | asdl_seq* keys; |
| 7634 | asdl_seq* values; |
| 7635 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7636 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7637 | return 1; |
| 7638 | } |
| 7639 | if (tmp == NULL) { |
| 7640 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7641 | return 1; |
| 7642 | } |
| 7643 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7644 | int res; |
| 7645 | Py_ssize_t len; |
| 7646 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7647 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7648 | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7649 | goto failed; |
| 7650 | } |
| 7651 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7652 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7653 | if (keys == NULL) goto failed; |
| 7654 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7655 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7656 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7657 | Py_INCREF(tmp2); |
| 7658 | res = obj2ast_expr(tmp2, &val, arena); |
| 7659 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7660 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7661 | if (len != PyList_GET_SIZE(tmp)) { |
| 7662 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7663 | goto failed; |
| 7664 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7665 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7666 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7667 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7668 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7669 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7670 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7671 | return 1; |
| 7672 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7673 | if (tmp == NULL) { |
| 7674 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7675 | return 1; |
| 7676 | } |
| 7677 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7678 | int res; |
| 7679 | Py_ssize_t len; |
| 7680 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7681 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7682 | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7683 | goto failed; |
| 7684 | } |
| 7685 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7686 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7687 | if (values == NULL) goto failed; |
| 7688 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7689 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7690 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7691 | Py_INCREF(tmp2); |
| 7692 | res = obj2ast_expr(tmp2, &val, arena); |
| 7693 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7694 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7695 | if (len != PyList_GET_SIZE(tmp)) { |
| 7696 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7697 | goto failed; |
| 7698 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7699 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7700 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7701 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7702 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7703 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7704 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7705 | if (*out == NULL) goto failed; |
| 7706 | return 0; |
| 7707 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7708 | tp = astmodulestate_global->Set_type; |
| 7709 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7710 | if (isinstance == -1) { |
| 7711 | return 1; |
| 7712 | } |
| 7713 | if (isinstance) { |
| 7714 | asdl_seq* elts; |
| 7715 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7716 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7717 | return 1; |
| 7718 | } |
| 7719 | if (tmp == NULL) { |
| 7720 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7721 | return 1; |
| 7722 | } |
| 7723 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7724 | int res; |
| 7725 | Py_ssize_t len; |
| 7726 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7727 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7728 | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7729 | goto failed; |
| 7730 | } |
| 7731 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7732 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7733 | if (elts == NULL) goto failed; |
| 7734 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7735 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7736 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7737 | Py_INCREF(tmp2); |
| 7738 | res = obj2ast_expr(tmp2, &val, arena); |
| 7739 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7740 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7741 | if (len != PyList_GET_SIZE(tmp)) { |
| 7742 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7743 | goto failed; |
| 7744 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7745 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7746 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7747 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7748 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7749 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7750 | if (*out == NULL) goto failed; |
| 7751 | return 0; |
| 7752 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7753 | tp = astmodulestate_global->ListComp_type; |
| 7754 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7755 | if (isinstance == -1) { |
| 7756 | return 1; |
| 7757 | } |
| 7758 | if (isinstance) { |
| 7759 | expr_ty elt; |
| 7760 | asdl_seq* generators; |
| 7761 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7762 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7763 | return 1; |
| 7764 | } |
| 7765 | if (tmp == NULL) { |
| 7766 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7767 | return 1; |
| 7768 | } |
| 7769 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7770 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7771 | res = obj2ast_expr(tmp, &elt, arena); |
| 7772 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7773 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7774 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7775 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7776 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7777 | return 1; |
| 7778 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7779 | if (tmp == NULL) { |
| 7780 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7781 | return 1; |
| 7782 | } |
| 7783 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7784 | int res; |
| 7785 | Py_ssize_t len; |
| 7786 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7787 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7788 | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7789 | goto failed; |
| 7790 | } |
| 7791 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7792 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7793 | if (generators == NULL) goto failed; |
| 7794 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7795 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7796 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7797 | Py_INCREF(tmp2); |
| 7798 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7799 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7800 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7801 | if (len != PyList_GET_SIZE(tmp)) { |
| 7802 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7803 | goto failed; |
| 7804 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7805 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7806 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7807 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7808 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7809 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7810 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7811 | if (*out == NULL) goto failed; |
| 7812 | return 0; |
| 7813 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7814 | tp = astmodulestate_global->SetComp_type; |
| 7815 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7816 | if (isinstance == -1) { |
| 7817 | return 1; |
| 7818 | } |
| 7819 | if (isinstance) { |
| 7820 | expr_ty elt; |
| 7821 | asdl_seq* generators; |
| 7822 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7823 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7824 | return 1; |
| 7825 | } |
| 7826 | if (tmp == NULL) { |
| 7827 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7828 | return 1; |
| 7829 | } |
| 7830 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7831 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7832 | res = obj2ast_expr(tmp, &elt, arena); |
| 7833 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7834 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7835 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7836 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7837 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7838 | return 1; |
| 7839 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7840 | if (tmp == NULL) { |
| 7841 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7842 | return 1; |
| 7843 | } |
| 7844 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7845 | int res; |
| 7846 | Py_ssize_t len; |
| 7847 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7848 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7849 | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7850 | goto failed; |
| 7851 | } |
| 7852 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7853 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7854 | if (generators == NULL) goto failed; |
| 7855 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7856 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7857 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7858 | Py_INCREF(tmp2); |
| 7859 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7860 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7861 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7862 | if (len != PyList_GET_SIZE(tmp)) { |
| 7863 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7864 | goto failed; |
| 7865 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7866 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7867 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7868 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7869 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7870 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7871 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7872 | if (*out == NULL) goto failed; |
| 7873 | return 0; |
| 7874 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7875 | tp = astmodulestate_global->DictComp_type; |
| 7876 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7877 | if (isinstance == -1) { |
| 7878 | return 1; |
| 7879 | } |
| 7880 | if (isinstance) { |
| 7881 | expr_ty key; |
| 7882 | expr_ty value; |
| 7883 | asdl_seq* generators; |
| 7884 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7885 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7886 | return 1; |
| 7887 | } |
| 7888 | if (tmp == NULL) { |
| 7889 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7890 | return 1; |
| 7891 | } |
| 7892 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7893 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7894 | res = obj2ast_expr(tmp, &key, arena); |
| 7895 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7896 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7897 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7898 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7899 | return 1; |
| 7900 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7901 | if (tmp == NULL) { |
| 7902 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7903 | return 1; |
| 7904 | } |
| 7905 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7906 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7907 | res = obj2ast_expr(tmp, &value, arena); |
| 7908 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7909 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7910 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7911 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7912 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7913 | return 1; |
| 7914 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7915 | if (tmp == NULL) { |
| 7916 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7917 | return 1; |
| 7918 | } |
| 7919 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7920 | int res; |
| 7921 | Py_ssize_t len; |
| 7922 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7923 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7924 | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7925 | goto failed; |
| 7926 | } |
| 7927 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7928 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7929 | if (generators == NULL) goto failed; |
| 7930 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7931 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7932 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7933 | Py_INCREF(tmp2); |
| 7934 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7935 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7936 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7937 | if (len != PyList_GET_SIZE(tmp)) { |
| 7938 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7939 | goto failed; |
| 7940 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7941 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7942 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7943 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7944 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7945 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7946 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7947 | if (*out == NULL) goto failed; |
| 7948 | return 0; |
| 7949 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7950 | tp = astmodulestate_global->GeneratorExp_type; |
| 7951 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7952 | if (isinstance == -1) { |
| 7953 | return 1; |
| 7954 | } |
| 7955 | if (isinstance) { |
| 7956 | expr_ty elt; |
| 7957 | asdl_seq* generators; |
| 7958 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7959 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7960 | return 1; |
| 7961 | } |
| 7962 | if (tmp == NULL) { |
| 7963 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7964 | return 1; |
| 7965 | } |
| 7966 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7967 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7968 | res = obj2ast_expr(tmp, &elt, arena); |
| 7969 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7970 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7971 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7972 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7973 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7974 | return 1; |
| 7975 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7976 | if (tmp == NULL) { |
| 7977 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7978 | return 1; |
| 7979 | } |
| 7980 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7981 | int res; |
| 7982 | Py_ssize_t len; |
| 7983 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7984 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7985 | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7986 | goto failed; |
| 7987 | } |
| 7988 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7989 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7990 | if (generators == NULL) goto failed; |
| 7991 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7992 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7993 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7994 | Py_INCREF(tmp2); |
| 7995 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7996 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7997 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7998 | if (len != PyList_GET_SIZE(tmp)) { |
| 7999 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 8000 | goto failed; |
| 8001 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8002 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8003 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8004 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8005 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8006 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 8007 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8008 | if (*out == NULL) goto failed; |
| 8009 | return 0; |
| 8010 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8011 | tp = astmodulestate_global->Await_type; |
| 8012 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8013 | if (isinstance == -1) { |
| 8014 | return 1; |
| 8015 | } |
| 8016 | if (isinstance) { |
| 8017 | expr_ty value; |
| 8018 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8019 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8020 | return 1; |
| 8021 | } |
| 8022 | if (tmp == NULL) { |
| 8023 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 8024 | return 1; |
| 8025 | } |
| 8026 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8027 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8028 | res = obj2ast_expr(tmp, &value, arena); |
| 8029 | if (res != 0) goto failed; |
| 8030 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8031 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8032 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8033 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8034 | if (*out == NULL) goto failed; |
| 8035 | return 0; |
| 8036 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8037 | tp = astmodulestate_global->Yield_type; |
| 8038 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8039 | if (isinstance == -1) { |
| 8040 | return 1; |
| 8041 | } |
| 8042 | if (isinstance) { |
| 8043 | expr_ty value; |
| 8044 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8045 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8046 | return 1; |
| 8047 | } |
| 8048 | if (tmp == NULL || tmp == Py_None) { |
| 8049 | Py_CLEAR(tmp); |
| 8050 | value = NULL; |
| 8051 | } |
| 8052 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8053 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8054 | res = obj2ast_expr(tmp, &value, arena); |
| 8055 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8056 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8057 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8058 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8059 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8060 | if (*out == NULL) goto failed; |
| 8061 | return 0; |
| 8062 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8063 | tp = astmodulestate_global->YieldFrom_type; |
| 8064 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8065 | if (isinstance == -1) { |
| 8066 | return 1; |
| 8067 | } |
| 8068 | if (isinstance) { |
| 8069 | expr_ty value; |
| 8070 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8071 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8072 | return 1; |
| 8073 | } |
| 8074 | if (tmp == NULL) { |
| 8075 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 8076 | return 1; |
| 8077 | } |
| 8078 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8079 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8080 | res = obj2ast_expr(tmp, &value, arena); |
| 8081 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8082 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8083 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8084 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8085 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8086 | if (*out == NULL) goto failed; |
| 8087 | return 0; |
| 8088 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8089 | tp = astmodulestate_global->Compare_type; |
| 8090 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8091 | if (isinstance == -1) { |
| 8092 | return 1; |
| 8093 | } |
| 8094 | if (isinstance) { |
| 8095 | expr_ty left; |
| 8096 | asdl_int_seq* ops; |
| 8097 | asdl_seq* comparators; |
| 8098 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8099 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8100 | return 1; |
| 8101 | } |
| 8102 | if (tmp == NULL) { |
| 8103 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8104 | return 1; |
| 8105 | } |
| 8106 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8107 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8108 | res = obj2ast_expr(tmp, &left, arena); |
| 8109 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8110 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8111 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8112 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8113 | return 1; |
| 8114 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8115 | if (tmp == NULL) { |
| 8116 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8117 | return 1; |
| 8118 | } |
| 8119 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8120 | int res; |
| 8121 | Py_ssize_t len; |
| 8122 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8123 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8124 | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8125 | goto failed; |
| 8126 | } |
| 8127 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8128 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8129 | if (ops == NULL) goto failed; |
| 8130 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8131 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8132 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8133 | Py_INCREF(tmp2); |
| 8134 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8135 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8136 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8137 | if (len != PyList_GET_SIZE(tmp)) { |
| 8138 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8139 | goto failed; |
| 8140 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8141 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8142 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8143 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8144 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8145 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8146 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8147 | return 1; |
| 8148 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8149 | if (tmp == NULL) { |
| 8150 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8151 | return 1; |
| 8152 | } |
| 8153 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8154 | int res; |
| 8155 | Py_ssize_t len; |
| 8156 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8157 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8158 | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8159 | goto failed; |
| 8160 | } |
| 8161 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8162 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8163 | if (comparators == NULL) goto failed; |
| 8164 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8165 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8166 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8167 | Py_INCREF(tmp2); |
| 8168 | res = obj2ast_expr(tmp2, &val, arena); |
| 8169 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8170 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8171 | if (len != PyList_GET_SIZE(tmp)) { |
| 8172 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8173 | goto failed; |
| 8174 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8175 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8176 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8177 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8178 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8179 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8180 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8181 | if (*out == NULL) goto failed; |
| 8182 | return 0; |
| 8183 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8184 | tp = astmodulestate_global->Call_type; |
| 8185 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8186 | if (isinstance == -1) { |
| 8187 | return 1; |
| 8188 | } |
| 8189 | if (isinstance) { |
| 8190 | expr_ty func; |
| 8191 | asdl_seq* args; |
| 8192 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8193 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8194 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8195 | return 1; |
| 8196 | } |
| 8197 | if (tmp == NULL) { |
| 8198 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8199 | return 1; |
| 8200 | } |
| 8201 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8202 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8203 | res = obj2ast_expr(tmp, &func, arena); |
| 8204 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8205 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8206 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8207 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8208 | return 1; |
| 8209 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8210 | if (tmp == NULL) { |
| 8211 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8212 | return 1; |
| 8213 | } |
| 8214 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8215 | int res; |
| 8216 | Py_ssize_t len; |
| 8217 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8218 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8219 | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8220 | goto failed; |
| 8221 | } |
| 8222 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8223 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8224 | if (args == NULL) goto failed; |
| 8225 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8226 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8227 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8228 | Py_INCREF(tmp2); |
| 8229 | res = obj2ast_expr(tmp2, &val, arena); |
| 8230 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8231 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8232 | if (len != PyList_GET_SIZE(tmp)) { |
| 8233 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8234 | goto failed; |
| 8235 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8236 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8237 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8238 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8239 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8240 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8241 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8242 | return 1; |
| 8243 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8244 | if (tmp == NULL) { |
| 8245 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8246 | return 1; |
| 8247 | } |
| 8248 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8249 | int res; |
| 8250 | Py_ssize_t len; |
| 8251 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8252 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8253 | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8254 | goto failed; |
| 8255 | } |
| 8256 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8257 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8258 | if (keywords == NULL) goto failed; |
| 8259 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8260 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8261 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8262 | Py_INCREF(tmp2); |
| 8263 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8264 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8265 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8266 | if (len != PyList_GET_SIZE(tmp)) { |
| 8267 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8268 | goto failed; |
| 8269 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8270 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8271 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8272 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8273 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8274 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8275 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8276 | if (*out == NULL) goto failed; |
| 8277 | return 0; |
| 8278 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8279 | tp = astmodulestate_global->FormattedValue_type; |
| 8280 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8281 | if (isinstance == -1) { |
| 8282 | return 1; |
| 8283 | } |
| 8284 | if (isinstance) { |
| 8285 | expr_ty value; |
| 8286 | int conversion; |
| 8287 | expr_ty format_spec; |
| 8288 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8289 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8290 | return 1; |
| 8291 | } |
| 8292 | if (tmp == NULL) { |
| 8293 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8294 | return 1; |
| 8295 | } |
| 8296 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8297 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8298 | res = obj2ast_expr(tmp, &value, arena); |
| 8299 | if (res != 0) goto failed; |
| 8300 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8301 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8302 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8303 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8304 | return 1; |
| 8305 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8306 | if (tmp == NULL || tmp == Py_None) { |
| 8307 | Py_CLEAR(tmp); |
| 8308 | conversion = 0; |
| 8309 | } |
| 8310 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8311 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8312 | res = obj2ast_int(tmp, &conversion, arena); |
| 8313 | if (res != 0) goto failed; |
| 8314 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8315 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8316 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8317 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8318 | return 1; |
| 8319 | } |
| 8320 | if (tmp == NULL || tmp == Py_None) { |
| 8321 | Py_CLEAR(tmp); |
| 8322 | format_spec = NULL; |
| 8323 | } |
| 8324 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8325 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8326 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8327 | if (res != 0) goto failed; |
| 8328 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8329 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8330 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8331 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8332 | if (*out == NULL) goto failed; |
| 8333 | return 0; |
| 8334 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8335 | tp = astmodulestate_global->JoinedStr_type; |
| 8336 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8337 | if (isinstance == -1) { |
| 8338 | return 1; |
| 8339 | } |
| 8340 | if (isinstance) { |
| 8341 | asdl_seq* values; |
| 8342 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8343 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8344 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8345 | return 1; |
| 8346 | } |
| 8347 | if (tmp == NULL) { |
| 8348 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8349 | return 1; |
| 8350 | } |
| 8351 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8352 | int res; |
| 8353 | Py_ssize_t len; |
| 8354 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8355 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8356 | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8357 | goto failed; |
| 8358 | } |
| 8359 | len = PyList_GET_SIZE(tmp); |
| 8360 | values = _Py_asdl_seq_new(len, arena); |
| 8361 | if (values == NULL) goto failed; |
| 8362 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8363 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8364 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8365 | Py_INCREF(tmp2); |
| 8366 | res = obj2ast_expr(tmp2, &val, arena); |
| 8367 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8368 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8369 | if (len != PyList_GET_SIZE(tmp)) { |
| 8370 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8371 | goto failed; |
| 8372 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8373 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8374 | } |
| 8375 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8376 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8377 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8378 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8379 | if (*out == NULL) goto failed; |
| 8380 | return 0; |
| 8381 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8382 | tp = astmodulestate_global->Constant_type; |
| 8383 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8384 | if (isinstance == -1) { |
| 8385 | return 1; |
| 8386 | } |
| 8387 | if (isinstance) { |
| 8388 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8389 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8390 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8391 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8392 | return 1; |
| 8393 | } |
| 8394 | if (tmp == NULL) { |
| 8395 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8396 | return 1; |
| 8397 | } |
| 8398 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8399 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8400 | res = obj2ast_constant(tmp, &value, arena); |
| 8401 | if (res != 0) goto failed; |
| 8402 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8403 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8404 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8405 | return 1; |
| 8406 | } |
| 8407 | if (tmp == NULL || tmp == Py_None) { |
| 8408 | Py_CLEAR(tmp); |
| 8409 | kind = NULL; |
| 8410 | } |
| 8411 | else { |
| 8412 | int res; |
| 8413 | res = obj2ast_string(tmp, &kind, arena); |
| 8414 | if (res != 0) goto failed; |
| 8415 | Py_CLEAR(tmp); |
| 8416 | } |
| 8417 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8418 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8419 | if (*out == NULL) goto failed; |
| 8420 | return 0; |
| 8421 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8422 | tp = astmodulestate_global->Attribute_type; |
| 8423 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8424 | if (isinstance == -1) { |
| 8425 | return 1; |
| 8426 | } |
| 8427 | if (isinstance) { |
| 8428 | expr_ty value; |
| 8429 | identifier attr; |
| 8430 | expr_context_ty ctx; |
| 8431 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8432 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8433 | return 1; |
| 8434 | } |
| 8435 | if (tmp == NULL) { |
| 8436 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8437 | return 1; |
| 8438 | } |
| 8439 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8440 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8441 | res = obj2ast_expr(tmp, &value, arena); |
| 8442 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8443 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8444 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8445 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8446 | return 1; |
| 8447 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8448 | if (tmp == NULL) { |
| 8449 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8450 | return 1; |
| 8451 | } |
| 8452 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8453 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8454 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8455 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8456 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8457 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8458 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8459 | return 1; |
| 8460 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8461 | if (tmp == NULL) { |
| 8462 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8463 | return 1; |
| 8464 | } |
| 8465 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8466 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8467 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8468 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8469 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8470 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8471 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8472 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8473 | if (*out == NULL) goto failed; |
| 8474 | return 0; |
| 8475 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8476 | tp = astmodulestate_global->Subscript_type; |
| 8477 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8478 | if (isinstance == -1) { |
| 8479 | return 1; |
| 8480 | } |
| 8481 | if (isinstance) { |
| 8482 | expr_ty value; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8483 | expr_ty slice; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8484 | expr_context_ty ctx; |
| 8485 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8486 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8487 | return 1; |
| 8488 | } |
| 8489 | if (tmp == NULL) { |
| 8490 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8491 | return 1; |
| 8492 | } |
| 8493 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8494 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8495 | res = obj2ast_expr(tmp, &value, arena); |
| 8496 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8497 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8498 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8499 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8500 | return 1; |
| 8501 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8502 | if (tmp == NULL) { |
| 8503 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8504 | return 1; |
| 8505 | } |
| 8506 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8507 | int res; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8508 | res = obj2ast_expr(tmp, &slice, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8509 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8510 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8511 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8512 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8513 | return 1; |
| 8514 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8515 | if (tmp == NULL) { |
| 8516 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8517 | return 1; |
| 8518 | } |
| 8519 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8520 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8521 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8522 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8523 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8524 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8525 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8526 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8527 | if (*out == NULL) goto failed; |
| 8528 | return 0; |
| 8529 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8530 | tp = astmodulestate_global->Starred_type; |
| 8531 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8532 | if (isinstance == -1) { |
| 8533 | return 1; |
| 8534 | } |
| 8535 | if (isinstance) { |
| 8536 | expr_ty value; |
| 8537 | expr_context_ty ctx; |
| 8538 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8539 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8540 | return 1; |
| 8541 | } |
| 8542 | if (tmp == NULL) { |
| 8543 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8544 | return 1; |
| 8545 | } |
| 8546 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8547 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8548 | res = obj2ast_expr(tmp, &value, arena); |
| 8549 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8550 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8551 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8552 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8553 | return 1; |
| 8554 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8555 | if (tmp == NULL) { |
| 8556 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8557 | return 1; |
| 8558 | } |
| 8559 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8560 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8561 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8562 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8563 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8564 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8565 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8566 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8567 | if (*out == NULL) goto failed; |
| 8568 | return 0; |
| 8569 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8570 | tp = astmodulestate_global->Name_type; |
| 8571 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8572 | if (isinstance == -1) { |
| 8573 | return 1; |
| 8574 | } |
| 8575 | if (isinstance) { |
| 8576 | identifier id; |
| 8577 | expr_context_ty ctx; |
| 8578 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8579 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8580 | return 1; |
| 8581 | } |
| 8582 | if (tmp == NULL) { |
| 8583 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8584 | return 1; |
| 8585 | } |
| 8586 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8587 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8588 | res = obj2ast_identifier(tmp, &id, arena); |
| 8589 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8590 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8591 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8592 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8593 | return 1; |
| 8594 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8595 | if (tmp == NULL) { |
| 8596 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8597 | return 1; |
| 8598 | } |
| 8599 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8600 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8601 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8602 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8603 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8604 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8605 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8606 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8607 | if (*out == NULL) goto failed; |
| 8608 | return 0; |
| 8609 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8610 | tp = astmodulestate_global->List_type; |
| 8611 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8612 | if (isinstance == -1) { |
| 8613 | return 1; |
| 8614 | } |
| 8615 | if (isinstance) { |
| 8616 | asdl_seq* elts; |
| 8617 | expr_context_ty ctx; |
| 8618 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8619 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8620 | return 1; |
| 8621 | } |
| 8622 | if (tmp == NULL) { |
| 8623 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8624 | return 1; |
| 8625 | } |
| 8626 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8627 | int res; |
| 8628 | Py_ssize_t len; |
| 8629 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8630 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8631 | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8632 | goto failed; |
| 8633 | } |
| 8634 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8635 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8636 | if (elts == NULL) goto failed; |
| 8637 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8638 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8639 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8640 | Py_INCREF(tmp2); |
| 8641 | res = obj2ast_expr(tmp2, &val, arena); |
| 8642 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8643 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8644 | if (len != PyList_GET_SIZE(tmp)) { |
| 8645 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8646 | goto failed; |
| 8647 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8648 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8649 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8650 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8651 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8652 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8653 | return 1; |
| 8654 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8655 | if (tmp == NULL) { |
| 8656 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8657 | return 1; |
| 8658 | } |
| 8659 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8660 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8661 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8662 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8663 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8664 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8665 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8666 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8667 | if (*out == NULL) goto failed; |
| 8668 | return 0; |
| 8669 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8670 | tp = astmodulestate_global->Tuple_type; |
| 8671 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8672 | if (isinstance == -1) { |
| 8673 | return 1; |
| 8674 | } |
| 8675 | if (isinstance) { |
| 8676 | asdl_seq* elts; |
| 8677 | expr_context_ty ctx; |
| 8678 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8679 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8680 | return 1; |
| 8681 | } |
| 8682 | if (tmp == NULL) { |
| 8683 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8684 | return 1; |
| 8685 | } |
| 8686 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8687 | int res; |
| 8688 | Py_ssize_t len; |
| 8689 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8690 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8691 | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8692 | goto failed; |
| 8693 | } |
| 8694 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8695 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8696 | if (elts == NULL) goto failed; |
| 8697 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8698 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8699 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8700 | Py_INCREF(tmp2); |
| 8701 | res = obj2ast_expr(tmp2, &val, arena); |
| 8702 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8703 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8704 | if (len != PyList_GET_SIZE(tmp)) { |
| 8705 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8706 | goto failed; |
| 8707 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8708 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8709 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8710 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8711 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8712 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8713 | return 1; |
| 8714 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8715 | if (tmp == NULL) { |
| 8716 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8717 | return 1; |
| 8718 | } |
| 8719 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8720 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8721 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8722 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8723 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8724 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8725 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8726 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8727 | if (*out == NULL) goto failed; |
| 8728 | return 0; |
| 8729 | } |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8730 | tp = astmodulestate_global->Slice_type; |
| 8731 | isinstance = PyObject_IsInstance(obj, tp); |
| 8732 | if (isinstance == -1) { |
| 8733 | return 1; |
| 8734 | } |
| 8735 | if (isinstance) { |
| 8736 | expr_ty lower; |
| 8737 | expr_ty upper; |
| 8738 | expr_ty step; |
| 8739 | |
| 8740 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
| 8741 | return 1; |
| 8742 | } |
| 8743 | if (tmp == NULL || tmp == Py_None) { |
| 8744 | Py_CLEAR(tmp); |
| 8745 | lower = NULL; |
| 8746 | } |
| 8747 | else { |
| 8748 | int res; |
| 8749 | res = obj2ast_expr(tmp, &lower, arena); |
| 8750 | if (res != 0) goto failed; |
| 8751 | Py_CLEAR(tmp); |
| 8752 | } |
| 8753 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
| 8754 | return 1; |
| 8755 | } |
| 8756 | if (tmp == NULL || tmp == Py_None) { |
| 8757 | Py_CLEAR(tmp); |
| 8758 | upper = NULL; |
| 8759 | } |
| 8760 | else { |
| 8761 | int res; |
| 8762 | res = obj2ast_expr(tmp, &upper, arena); |
| 8763 | if (res != 0) goto failed; |
| 8764 | Py_CLEAR(tmp); |
| 8765 | } |
| 8766 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
| 8767 | return 1; |
| 8768 | } |
| 8769 | if (tmp == NULL || tmp == Py_None) { |
| 8770 | Py_CLEAR(tmp); |
| 8771 | step = NULL; |
| 8772 | } |
| 8773 | else { |
| 8774 | int res; |
| 8775 | res = obj2ast_expr(tmp, &step, arena); |
| 8776 | if (res != 0) goto failed; |
| 8777 | Py_CLEAR(tmp); |
| 8778 | } |
| 8779 | *out = Slice(lower, upper, step, lineno, col_offset, end_lineno, |
| 8780 | end_col_offset, arena); |
| 8781 | if (*out == NULL) goto failed; |
| 8782 | return 0; |
| 8783 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8784 | |
| 8785 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8786 | failed: |
| 8787 | Py_XDECREF(tmp); |
| 8788 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8789 | } |
| 8790 | |
| 8791 | int |
| 8792 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8793 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8794 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8795 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8796 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8797 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8798 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8799 | } |
| 8800 | if (isinstance) { |
| 8801 | *out = Load; |
| 8802 | return 0; |
| 8803 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8804 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8805 | if (isinstance == -1) { |
| 8806 | return 1; |
| 8807 | } |
| 8808 | if (isinstance) { |
| 8809 | *out = Store; |
| 8810 | return 0; |
| 8811 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8812 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8813 | if (isinstance == -1) { |
| 8814 | return 1; |
| 8815 | } |
| 8816 | if (isinstance) { |
| 8817 | *out = Del; |
| 8818 | return 0; |
| 8819 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8820 | |
| 8821 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8822 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8823 | } |
| 8824 | |
| 8825 | int |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8826 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8827 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8828 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8829 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8830 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8831 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8832 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8833 | } |
| 8834 | if (isinstance) { |
| 8835 | *out = And; |
| 8836 | return 0; |
| 8837 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8838 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8839 | if (isinstance == -1) { |
| 8840 | return 1; |
| 8841 | } |
| 8842 | if (isinstance) { |
| 8843 | *out = Or; |
| 8844 | return 0; |
| 8845 | } |
| 8846 | |
| 8847 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8848 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8849 | } |
| 8850 | |
| 8851 | int |
| 8852 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8853 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8854 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8855 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8856 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8857 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8858 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8859 | } |
| 8860 | if (isinstance) { |
| 8861 | *out = Add; |
| 8862 | return 0; |
| 8863 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8864 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8865 | if (isinstance == -1) { |
| 8866 | return 1; |
| 8867 | } |
| 8868 | if (isinstance) { |
| 8869 | *out = Sub; |
| 8870 | return 0; |
| 8871 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8872 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8873 | if (isinstance == -1) { |
| 8874 | return 1; |
| 8875 | } |
| 8876 | if (isinstance) { |
| 8877 | *out = Mult; |
| 8878 | return 0; |
| 8879 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8880 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8881 | if (isinstance == -1) { |
| 8882 | return 1; |
| 8883 | } |
| 8884 | if (isinstance) { |
| 8885 | *out = MatMult; |
| 8886 | return 0; |
| 8887 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8888 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8889 | if (isinstance == -1) { |
| 8890 | return 1; |
| 8891 | } |
| 8892 | if (isinstance) { |
| 8893 | *out = Div; |
| 8894 | return 0; |
| 8895 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8896 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8897 | if (isinstance == -1) { |
| 8898 | return 1; |
| 8899 | } |
| 8900 | if (isinstance) { |
| 8901 | *out = Mod; |
| 8902 | return 0; |
| 8903 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8904 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8905 | if (isinstance == -1) { |
| 8906 | return 1; |
| 8907 | } |
| 8908 | if (isinstance) { |
| 8909 | *out = Pow; |
| 8910 | return 0; |
| 8911 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8912 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8913 | if (isinstance == -1) { |
| 8914 | return 1; |
| 8915 | } |
| 8916 | if (isinstance) { |
| 8917 | *out = LShift; |
| 8918 | return 0; |
| 8919 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8920 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8921 | if (isinstance == -1) { |
| 8922 | return 1; |
| 8923 | } |
| 8924 | if (isinstance) { |
| 8925 | *out = RShift; |
| 8926 | return 0; |
| 8927 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8928 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8929 | if (isinstance == -1) { |
| 8930 | return 1; |
| 8931 | } |
| 8932 | if (isinstance) { |
| 8933 | *out = BitOr; |
| 8934 | return 0; |
| 8935 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8936 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8937 | if (isinstance == -1) { |
| 8938 | return 1; |
| 8939 | } |
| 8940 | if (isinstance) { |
| 8941 | *out = BitXor; |
| 8942 | return 0; |
| 8943 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8944 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8945 | if (isinstance == -1) { |
| 8946 | return 1; |
| 8947 | } |
| 8948 | if (isinstance) { |
| 8949 | *out = BitAnd; |
| 8950 | return 0; |
| 8951 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8952 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8953 | if (isinstance == -1) { |
| 8954 | return 1; |
| 8955 | } |
| 8956 | if (isinstance) { |
| 8957 | *out = FloorDiv; |
| 8958 | return 0; |
| 8959 | } |
| 8960 | |
| 8961 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8962 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8963 | } |
| 8964 | |
| 8965 | int |
| 8966 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8967 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8968 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8969 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8970 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8971 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8972 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8973 | } |
| 8974 | if (isinstance) { |
| 8975 | *out = Invert; |
| 8976 | return 0; |
| 8977 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8978 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8979 | if (isinstance == -1) { |
| 8980 | return 1; |
| 8981 | } |
| 8982 | if (isinstance) { |
| 8983 | *out = Not; |
| 8984 | return 0; |
| 8985 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8986 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8987 | if (isinstance == -1) { |
| 8988 | return 1; |
| 8989 | } |
| 8990 | if (isinstance) { |
| 8991 | *out = UAdd; |
| 8992 | return 0; |
| 8993 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8994 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8995 | if (isinstance == -1) { |
| 8996 | return 1; |
| 8997 | } |
| 8998 | if (isinstance) { |
| 8999 | *out = USub; |
| 9000 | return 0; |
| 9001 | } |
| 9002 | |
| 9003 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 9004 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9005 | } |
| 9006 | |
| 9007 | int |
| 9008 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 9009 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9010 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9011 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9012 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9013 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9014 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9015 | } |
| 9016 | if (isinstance) { |
| 9017 | *out = Eq; |
| 9018 | return 0; |
| 9019 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9020 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9021 | if (isinstance == -1) { |
| 9022 | return 1; |
| 9023 | } |
| 9024 | if (isinstance) { |
| 9025 | *out = NotEq; |
| 9026 | return 0; |
| 9027 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9028 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9029 | if (isinstance == -1) { |
| 9030 | return 1; |
| 9031 | } |
| 9032 | if (isinstance) { |
| 9033 | *out = Lt; |
| 9034 | return 0; |
| 9035 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9036 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9037 | if (isinstance == -1) { |
| 9038 | return 1; |
| 9039 | } |
| 9040 | if (isinstance) { |
| 9041 | *out = LtE; |
| 9042 | return 0; |
| 9043 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9044 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9045 | if (isinstance == -1) { |
| 9046 | return 1; |
| 9047 | } |
| 9048 | if (isinstance) { |
| 9049 | *out = Gt; |
| 9050 | return 0; |
| 9051 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9052 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9053 | if (isinstance == -1) { |
| 9054 | return 1; |
| 9055 | } |
| 9056 | if (isinstance) { |
| 9057 | *out = GtE; |
| 9058 | return 0; |
| 9059 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9060 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9061 | if (isinstance == -1) { |
| 9062 | return 1; |
| 9063 | } |
| 9064 | if (isinstance) { |
| 9065 | *out = Is; |
| 9066 | return 0; |
| 9067 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9068 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9069 | if (isinstance == -1) { |
| 9070 | return 1; |
| 9071 | } |
| 9072 | if (isinstance) { |
| 9073 | *out = IsNot; |
| 9074 | return 0; |
| 9075 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9076 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9077 | if (isinstance == -1) { |
| 9078 | return 1; |
| 9079 | } |
| 9080 | if (isinstance) { |
| 9081 | *out = In; |
| 9082 | return 0; |
| 9083 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9084 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9085 | if (isinstance == -1) { |
| 9086 | return 1; |
| 9087 | } |
| 9088 | if (isinstance) { |
| 9089 | *out = NotIn; |
| 9090 | return 0; |
| 9091 | } |
| 9092 | |
| 9093 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9094 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9095 | } |
| 9096 | |
| 9097 | int |
| 9098 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9099 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9100 | PyObject* tmp = NULL; |
| 9101 | expr_ty target; |
| 9102 | expr_ty iter; |
| 9103 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9104 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9105 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9106 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9107 | return 1; |
| 9108 | } |
| 9109 | if (tmp == NULL) { |
| 9110 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9111 | return 1; |
| 9112 | } |
| 9113 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9114 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9115 | res = obj2ast_expr(tmp, &target, arena); |
| 9116 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9117 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9118 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9119 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9120 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9121 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9122 | if (tmp == NULL) { |
| 9123 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9124 | return 1; |
| 9125 | } |
| 9126 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9127 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9128 | res = obj2ast_expr(tmp, &iter, arena); |
| 9129 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9130 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9131 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9132 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9133 | return 1; |
| 9134 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9135 | if (tmp == NULL) { |
| 9136 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9137 | return 1; |
| 9138 | } |
| 9139 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9140 | int res; |
| 9141 | Py_ssize_t len; |
| 9142 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9143 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9144 | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9145 | goto failed; |
| 9146 | } |
| 9147 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9148 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9149 | if (ifs == NULL) goto failed; |
| 9150 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9151 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9152 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9153 | Py_INCREF(tmp2); |
| 9154 | res = obj2ast_expr(tmp2, &val, arena); |
| 9155 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9156 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9157 | if (len != PyList_GET_SIZE(tmp)) { |
| 9158 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9159 | goto failed; |
| 9160 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9161 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9162 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9163 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9164 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9165 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9166 | return 1; |
| 9167 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9168 | if (tmp == NULL) { |
| 9169 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9170 | return 1; |
| 9171 | } |
| 9172 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9173 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9174 | res = obj2ast_int(tmp, &is_async, arena); |
| 9175 | if (res != 0) goto failed; |
| 9176 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9177 | } |
| 9178 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9179 | return 0; |
| 9180 | failed: |
| 9181 | Py_XDECREF(tmp); |
| 9182 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9183 | } |
| 9184 | |
| 9185 | int |
| 9186 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9187 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9188 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9189 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9190 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9191 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9192 | int lineno; |
| 9193 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9194 | int end_lineno; |
| 9195 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9196 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9197 | if (obj == Py_None) { |
| 9198 | *out = NULL; |
| 9199 | return 0; |
| 9200 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9201 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9202 | return 1; |
| 9203 | } |
| 9204 | if (tmp == NULL) { |
| 9205 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9206 | return 1; |
| 9207 | } |
| 9208 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9209 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9210 | res = obj2ast_int(tmp, &lineno, arena); |
| 9211 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9212 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9213 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9214 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9215 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9216 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9217 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9218 | if (tmp == NULL) { |
| 9219 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9220 | return 1; |
| 9221 | } |
| 9222 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9223 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9224 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9225 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9226 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9227 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9228 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9229 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9230 | return 1; |
| 9231 | } |
| 9232 | if (tmp == NULL || tmp == Py_None) { |
| 9233 | Py_CLEAR(tmp); |
| 9234 | end_lineno = 0; |
| 9235 | } |
| 9236 | else { |
| 9237 | int res; |
| 9238 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9239 | if (res != 0) goto failed; |
| 9240 | Py_CLEAR(tmp); |
| 9241 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9242 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9243 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9244 | return 1; |
| 9245 | } |
| 9246 | if (tmp == NULL || tmp == Py_None) { |
| 9247 | Py_CLEAR(tmp); |
| 9248 | end_col_offset = 0; |
| 9249 | } |
| 9250 | else { |
| 9251 | int res; |
| 9252 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9253 | if (res != 0) goto failed; |
| 9254 | Py_CLEAR(tmp); |
| 9255 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9256 | tp = astmodulestate_global->ExceptHandler_type; |
| 9257 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9258 | if (isinstance == -1) { |
| 9259 | return 1; |
| 9260 | } |
| 9261 | if (isinstance) { |
| 9262 | expr_ty type; |
| 9263 | identifier name; |
| 9264 | asdl_seq* body; |
| 9265 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9266 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9267 | return 1; |
| 9268 | } |
| 9269 | if (tmp == NULL || tmp == Py_None) { |
| 9270 | Py_CLEAR(tmp); |
| 9271 | type = NULL; |
| 9272 | } |
| 9273 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9274 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9275 | res = obj2ast_expr(tmp, &type, arena); |
| 9276 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9277 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9278 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9279 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9280 | return 1; |
| 9281 | } |
| 9282 | if (tmp == NULL || tmp == Py_None) { |
| 9283 | Py_CLEAR(tmp); |
| 9284 | name = NULL; |
| 9285 | } |
| 9286 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9287 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9288 | res = obj2ast_identifier(tmp, &name, arena); |
| 9289 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9290 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9291 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9292 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9293 | return 1; |
| 9294 | } |
| 9295 | if (tmp == NULL) { |
| 9296 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9297 | return 1; |
| 9298 | } |
| 9299 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9300 | int res; |
| 9301 | Py_ssize_t len; |
| 9302 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9303 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9304 | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9305 | goto failed; |
| 9306 | } |
| 9307 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9308 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9309 | if (body == NULL) goto failed; |
| 9310 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9311 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9312 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9313 | Py_INCREF(tmp2); |
| 9314 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9315 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9316 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9317 | if (len != PyList_GET_SIZE(tmp)) { |
| 9318 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9319 | goto failed; |
| 9320 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9321 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9322 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9323 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9324 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9325 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9326 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9327 | if (*out == NULL) goto failed; |
| 9328 | return 0; |
| 9329 | } |
| 9330 | |
| 9331 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9332 | failed: |
| 9333 | Py_XDECREF(tmp); |
| 9334 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9335 | } |
| 9336 | |
| 9337 | int |
| 9338 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9339 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9340 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9341 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9342 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9343 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9344 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9345 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9346 | arg_ty kwarg; |
| 9347 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9348 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9349 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9350 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9351 | return 1; |
| 9352 | } |
| 9353 | if (tmp == NULL) { |
| 9354 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9355 | return 1; |
| 9356 | } |
| 9357 | else { |
| 9358 | int res; |
| 9359 | Py_ssize_t len; |
| 9360 | Py_ssize_t i; |
| 9361 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9362 | PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9363 | goto failed; |
| 9364 | } |
| 9365 | len = PyList_GET_SIZE(tmp); |
| 9366 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9367 | if (posonlyargs == NULL) goto failed; |
| 9368 | for (i = 0; i < len; i++) { |
| 9369 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9370 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9371 | Py_INCREF(tmp2); |
| 9372 | res = obj2ast_arg(tmp2, &val, arena); |
| 9373 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9374 | if (res != 0) goto failed; |
| 9375 | if (len != PyList_GET_SIZE(tmp)) { |
| 9376 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9377 | goto failed; |
| 9378 | } |
| 9379 | asdl_seq_SET(posonlyargs, i, val); |
| 9380 | } |
| 9381 | Py_CLEAR(tmp); |
| 9382 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9383 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9384 | return 1; |
| 9385 | } |
| 9386 | if (tmp == NULL) { |
| 9387 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9388 | return 1; |
| 9389 | } |
| 9390 | else { |
| 9391 | int res; |
| 9392 | Py_ssize_t len; |
| 9393 | Py_ssize_t i; |
| 9394 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9395 | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9396 | goto failed; |
| 9397 | } |
| 9398 | len = PyList_GET_SIZE(tmp); |
| 9399 | args = _Py_asdl_seq_new(len, arena); |
| 9400 | if (args == NULL) goto failed; |
| 9401 | for (i = 0; i < len; i++) { |
| 9402 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9403 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9404 | Py_INCREF(tmp2); |
| 9405 | res = obj2ast_arg(tmp2, &val, arena); |
| 9406 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9407 | if (res != 0) goto failed; |
| 9408 | if (len != PyList_GET_SIZE(tmp)) { |
| 9409 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9410 | goto failed; |
| 9411 | } |
| 9412 | asdl_seq_SET(args, i, val); |
| 9413 | } |
| 9414 | Py_CLEAR(tmp); |
| 9415 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9416 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9417 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9418 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9419 | if (tmp == NULL || tmp == Py_None) { |
| 9420 | Py_CLEAR(tmp); |
| 9421 | vararg = NULL; |
| 9422 | } |
| 9423 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9424 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9425 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9426 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9427 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9428 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9429 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9430 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9431 | return 1; |
| 9432 | } |
| 9433 | if (tmp == NULL) { |
| 9434 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9435 | return 1; |
| 9436 | } |
| 9437 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9438 | int res; |
| 9439 | Py_ssize_t len; |
| 9440 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9441 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9442 | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9443 | goto failed; |
| 9444 | } |
| 9445 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9446 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9447 | if (kwonlyargs == NULL) goto failed; |
| 9448 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9449 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9450 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9451 | Py_INCREF(tmp2); |
| 9452 | res = obj2ast_arg(tmp2, &val, arena); |
| 9453 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9454 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9455 | if (len != PyList_GET_SIZE(tmp)) { |
| 9456 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9457 | goto failed; |
| 9458 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9459 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9460 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9461 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9462 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9463 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9464 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9465 | return 1; |
| 9466 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9467 | if (tmp == NULL) { |
| 9468 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9469 | return 1; |
| 9470 | } |
| 9471 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9472 | int res; |
| 9473 | Py_ssize_t len; |
| 9474 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9475 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9476 | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9477 | goto failed; |
| 9478 | } |
| 9479 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9480 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9481 | if (kw_defaults == NULL) goto failed; |
| 9482 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9483 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9484 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9485 | Py_INCREF(tmp2); |
| 9486 | res = obj2ast_expr(tmp2, &val, arena); |
| 9487 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9488 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9489 | if (len != PyList_GET_SIZE(tmp)) { |
| 9490 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9491 | goto failed; |
| 9492 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9493 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9494 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9495 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9496 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9497 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9498 | return 1; |
| 9499 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9500 | if (tmp == NULL || tmp == Py_None) { |
| 9501 | Py_CLEAR(tmp); |
| 9502 | kwarg = NULL; |
| 9503 | } |
| 9504 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9505 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9506 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9507 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9508 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9509 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9510 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9511 | return 1; |
| 9512 | } |
| 9513 | if (tmp == NULL) { |
| 9514 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9515 | return 1; |
| 9516 | } |
| 9517 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9518 | int res; |
| 9519 | Py_ssize_t len; |
| 9520 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9521 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9522 | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9523 | goto failed; |
| 9524 | } |
| 9525 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9526 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9527 | if (defaults == NULL) goto failed; |
| 9528 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9529 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9530 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9531 | Py_INCREF(tmp2); |
| 9532 | res = obj2ast_expr(tmp2, &val, arena); |
| 9533 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9534 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9535 | if (len != PyList_GET_SIZE(tmp)) { |
| 9536 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9537 | goto failed; |
| 9538 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9539 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9540 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9541 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9542 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9543 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9544 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9545 | return 0; |
| 9546 | failed: |
| 9547 | Py_XDECREF(tmp); |
| 9548 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9549 | } |
| 9550 | |
| 9551 | int |
| 9552 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9553 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9554 | PyObject* tmp = NULL; |
| 9555 | identifier arg; |
| 9556 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9557 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9558 | int lineno; |
| 9559 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9560 | int end_lineno; |
| 9561 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9562 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9563 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9564 | return 1; |
| 9565 | } |
| 9566 | if (tmp == NULL) { |
| 9567 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9568 | return 1; |
| 9569 | } |
| 9570 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9571 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9572 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9573 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9574 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9575 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9576 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9577 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9578 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9579 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9580 | if (tmp == NULL || tmp == Py_None) { |
| 9581 | Py_CLEAR(tmp); |
| 9582 | annotation = NULL; |
| 9583 | } |
| 9584 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9585 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9586 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9587 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9588 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9589 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9590 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9591 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9592 | return 1; |
| 9593 | } |
| 9594 | if (tmp == NULL || tmp == Py_None) { |
| 9595 | Py_CLEAR(tmp); |
| 9596 | type_comment = NULL; |
| 9597 | } |
| 9598 | else { |
| 9599 | int res; |
| 9600 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9601 | if (res != 0) goto failed; |
| 9602 | Py_CLEAR(tmp); |
| 9603 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9604 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9605 | return 1; |
| 9606 | } |
| 9607 | if (tmp == NULL) { |
| 9608 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9609 | return 1; |
| 9610 | } |
| 9611 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9612 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9613 | res = obj2ast_int(tmp, &lineno, arena); |
| 9614 | if (res != 0) goto failed; |
| 9615 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9616 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9617 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9618 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9619 | return 1; |
| 9620 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9621 | if (tmp == NULL) { |
| 9622 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9623 | return 1; |
| 9624 | } |
| 9625 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9626 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9627 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9628 | if (res != 0) goto failed; |
| 9629 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9630 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9631 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9632 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9633 | return 1; |
| 9634 | } |
| 9635 | if (tmp == NULL || tmp == Py_None) { |
| 9636 | Py_CLEAR(tmp); |
| 9637 | end_lineno = 0; |
| 9638 | } |
| 9639 | else { |
| 9640 | int res; |
| 9641 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9642 | if (res != 0) goto failed; |
| 9643 | Py_CLEAR(tmp); |
| 9644 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9645 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9646 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9647 | return 1; |
| 9648 | } |
| 9649 | if (tmp == NULL || tmp == Py_None) { |
| 9650 | Py_CLEAR(tmp); |
| 9651 | end_col_offset = 0; |
| 9652 | } |
| 9653 | else { |
| 9654 | int res; |
| 9655 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9656 | if (res != 0) goto failed; |
| 9657 | Py_CLEAR(tmp); |
| 9658 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9659 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9660 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9661 | return 0; |
| 9662 | failed: |
| 9663 | Py_XDECREF(tmp); |
| 9664 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9665 | } |
| 9666 | |
| 9667 | int |
| 9668 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9669 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9670 | PyObject* tmp = NULL; |
| 9671 | identifier arg; |
| 9672 | expr_ty value; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 9673 | int lineno; |
| 9674 | int col_offset; |
| 9675 | int end_lineno; |
| 9676 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9677 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9678 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9679 | return 1; |
| 9680 | } |
| 9681 | if (tmp == NULL || tmp == Py_None) { |
| 9682 | Py_CLEAR(tmp); |
| 9683 | arg = NULL; |
| 9684 | } |
| 9685 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9686 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9687 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9688 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9689 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9690 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9691 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9692 | return 1; |
| 9693 | } |
| 9694 | if (tmp == NULL) { |
| 9695 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9696 | return 1; |
| 9697 | } |
| 9698 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9699 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9700 | res = obj2ast_expr(tmp, &value, arena); |
| 9701 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9702 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9703 | } |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 9704 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
| 9705 | return 1; |
| 9706 | } |
| 9707 | if (tmp == NULL) { |
| 9708 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword"); |
| 9709 | return 1; |
| 9710 | } |
| 9711 | else { |
| 9712 | int res; |
| 9713 | res = obj2ast_int(tmp, &lineno, arena); |
| 9714 | if (res != 0) goto failed; |
| 9715 | Py_CLEAR(tmp); |
| 9716 | } |
| 9717 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9718 | { |
| 9719 | return 1; |
| 9720 | } |
| 9721 | if (tmp == NULL) { |
| 9722 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword"); |
| 9723 | return 1; |
| 9724 | } |
| 9725 | else { |
| 9726 | int res; |
| 9727 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9728 | if (res != 0) goto failed; |
| 9729 | Py_CLEAR(tmp); |
| 9730 | } |
| 9731 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9732 | { |
| 9733 | return 1; |
| 9734 | } |
| 9735 | if (tmp == NULL || tmp == Py_None) { |
| 9736 | Py_CLEAR(tmp); |
| 9737 | end_lineno = 0; |
| 9738 | } |
| 9739 | else { |
| 9740 | int res; |
| 9741 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9742 | if (res != 0) goto failed; |
| 9743 | Py_CLEAR(tmp); |
| 9744 | } |
| 9745 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9746 | < 0) { |
| 9747 | return 1; |
| 9748 | } |
| 9749 | if (tmp == NULL || tmp == Py_None) { |
| 9750 | Py_CLEAR(tmp); |
| 9751 | end_col_offset = 0; |
| 9752 | } |
| 9753 | else { |
| 9754 | int res; |
| 9755 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9756 | if (res != 0) goto failed; |
| 9757 | Py_CLEAR(tmp); |
| 9758 | } |
| 9759 | *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset, |
| 9760 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9761 | return 0; |
| 9762 | failed: |
| 9763 | Py_XDECREF(tmp); |
| 9764 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9765 | } |
| 9766 | |
| 9767 | int |
| 9768 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9769 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9770 | PyObject* tmp = NULL; |
| 9771 | identifier name; |
| 9772 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9773 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9774 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9775 | return 1; |
| 9776 | } |
| 9777 | if (tmp == NULL) { |
| 9778 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9779 | return 1; |
| 9780 | } |
| 9781 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9782 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9783 | res = obj2ast_identifier(tmp, &name, arena); |
| 9784 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9785 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9786 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9787 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9788 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9789 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9790 | if (tmp == NULL || tmp == Py_None) { |
| 9791 | Py_CLEAR(tmp); |
| 9792 | asname = NULL; |
| 9793 | } |
| 9794 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9795 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9796 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9797 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9798 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9799 | } |
| 9800 | *out = alias(name, asname, arena); |
| 9801 | return 0; |
| 9802 | failed: |
| 9803 | Py_XDECREF(tmp); |
| 9804 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9805 | } |
| 9806 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9807 | int |
| 9808 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9809 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9810 | PyObject* tmp = NULL; |
| 9811 | expr_ty context_expr; |
| 9812 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9813 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9814 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9815 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9816 | return 1; |
| 9817 | } |
| 9818 | if (tmp == NULL) { |
| 9819 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9820 | return 1; |
| 9821 | } |
| 9822 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9823 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9824 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9825 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9826 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9827 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9828 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9829 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9830 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9831 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9832 | if (tmp == NULL || tmp == Py_None) { |
| 9833 | Py_CLEAR(tmp); |
| 9834 | optional_vars = NULL; |
| 9835 | } |
| 9836 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9837 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9838 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9839 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9840 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9841 | } |
| 9842 | *out = withitem(context_expr, optional_vars, arena); |
| 9843 | return 0; |
| 9844 | failed: |
| 9845 | Py_XDECREF(tmp); |
| 9846 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9847 | } |
| 9848 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9849 | int |
| 9850 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9851 | { |
| 9852 | int isinstance; |
| 9853 | |
| 9854 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9855 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9856 | |
| 9857 | if (obj == Py_None) { |
| 9858 | *out = NULL; |
| 9859 | return 0; |
| 9860 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9861 | tp = astmodulestate_global->TypeIgnore_type; |
| 9862 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9863 | if (isinstance == -1) { |
| 9864 | return 1; |
| 9865 | } |
| 9866 | if (isinstance) { |
| 9867 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9868 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9869 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9870 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9871 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9872 | return 1; |
| 9873 | } |
| 9874 | if (tmp == NULL) { |
| 9875 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9876 | return 1; |
| 9877 | } |
| 9878 | else { |
| 9879 | int res; |
| 9880 | res = obj2ast_int(tmp, &lineno, arena); |
| 9881 | if (res != 0) goto failed; |
| 9882 | Py_CLEAR(tmp); |
| 9883 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9884 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9885 | return 1; |
| 9886 | } |
| 9887 | if (tmp == NULL) { |
| 9888 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9889 | return 1; |
| 9890 | } |
| 9891 | else { |
| 9892 | int res; |
| 9893 | res = obj2ast_string(tmp, &tag, arena); |
| 9894 | if (res != 0) goto failed; |
| 9895 | Py_CLEAR(tmp); |
| 9896 | } |
| 9897 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9898 | if (*out == NULL) goto failed; |
| 9899 | return 0; |
| 9900 | } |
| 9901 | |
| 9902 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9903 | failed: |
| 9904 | Py_XDECREF(tmp); |
| 9905 | return 1; |
| 9906 | } |
| 9907 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9908 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9909 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9910 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9911 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9912 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9913 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9914 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9915 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9916 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9917 | goto error; |
| 9918 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9919 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9920 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9921 | goto error; |
| 9922 | } |
| 9923 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9924 | goto error; |
| 9925 | } |
| 9926 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9927 | goto error; |
| 9928 | } |
| 9929 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9930 | goto error; |
| 9931 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9932 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9933 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9934 | 0) { |
| 9935 | goto error; |
| 9936 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9937 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9938 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9939 | astmodulestate_global->Interactive_type) < 0) { |
| 9940 | goto error; |
| 9941 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9942 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9943 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9944 | astmodulestate_global->Expression_type) < 0) { |
| 9945 | goto error; |
| 9946 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9947 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9948 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9949 | astmodulestate_global->FunctionType_type) < 0) { |
| 9950 | goto error; |
| 9951 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9952 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9953 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9954 | goto error; |
| 9955 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9956 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9957 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9958 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9959 | goto error; |
| 9960 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9961 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9962 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9963 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9964 | goto error; |
| 9965 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9966 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9967 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9968 | < 0) { |
| 9969 | goto error; |
| 9970 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9971 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9972 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9973 | 0) { |
| 9974 | goto error; |
| 9975 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9976 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9977 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9978 | 0) { |
| 9979 | goto error; |
| 9980 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9981 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9982 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9983 | 0) { |
| 9984 | goto error; |
| 9985 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9986 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9987 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9988 | astmodulestate_global->AugAssign_type) < 0) { |
| 9989 | goto error; |
| 9990 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9991 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9992 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9993 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9994 | goto error; |
| 9995 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9996 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9997 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9998 | goto error; |
| 9999 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10000 | Py_INCREF(astmodulestate(m)->For_type); |
| 10001 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10002 | < 0) { |
| 10003 | goto error; |
| 10004 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10005 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10006 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 10007 | goto error; |
| 10008 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10009 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10010 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 10011 | goto error; |
| 10012 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10013 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10014 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 10015 | goto error; |
| 10016 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10017 | Py_INCREF(astmodulestate(m)->With_type); |
| 10018 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10019 | astmodulestate_global->AsyncWith_type) < 0) { |
| 10020 | goto error; |
| 10021 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10022 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10023 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 10024 | goto error; |
| 10025 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10026 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10027 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 10028 | goto error; |
| 10029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10030 | Py_INCREF(astmodulestate(m)->Try_type); |
| 10031 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10032 | 0) { |
| 10033 | goto error; |
| 10034 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10035 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 10036 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10037 | 0) { |
| 10038 | goto error; |
| 10039 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10040 | Py_INCREF(astmodulestate(m)->Import_type); |
| 10041 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10042 | astmodulestate_global->ImportFrom_type) < 0) { |
| 10043 | goto error; |
| 10044 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10045 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 10046 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10047 | 0) { |
| 10048 | goto error; |
| 10049 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10050 | Py_INCREF(astmodulestate(m)->Global_type); |
| 10051 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10052 | < 0) { |
| 10053 | goto error; |
| 10054 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10055 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10056 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { |
| 10057 | goto error; |
| 10058 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10059 | Py_INCREF(astmodulestate(m)->Expr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10060 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 10061 | goto error; |
| 10062 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10063 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10064 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 10065 | goto error; |
| 10066 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10067 | Py_INCREF(astmodulestate(m)->Break_type); |
| 10068 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10069 | < 0) { |
| 10070 | goto error; |
| 10071 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10072 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10073 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 10074 | goto error; |
| 10075 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10076 | Py_INCREF(astmodulestate(m)->expr_type); |
| 10077 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10078 | 0) { |
| 10079 | goto error; |
| 10080 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10081 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 10082 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10083 | astmodulestate_global->NamedExpr_type) < 0) { |
| 10084 | goto error; |
| 10085 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10086 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10087 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 10088 | goto error; |
| 10089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10090 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 10091 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10092 | 0) { |
| 10093 | goto error; |
| 10094 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10095 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 10096 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10097 | 0) { |
| 10098 | goto error; |
| 10099 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10100 | Py_INCREF(astmodulestate(m)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10101 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 10102 | goto error; |
| 10103 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10104 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10105 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 10106 | goto error; |
| 10107 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10108 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10109 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 10110 | goto error; |
| 10111 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10112 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10113 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10114 | < 0) { |
| 10115 | goto error; |
| 10116 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10117 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10118 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10119 | 0) { |
| 10120 | goto error; |
| 10121 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10122 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10123 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10124 | < 0) { |
| 10125 | goto error; |
| 10126 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10127 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10128 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10129 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 10130 | goto error; |
| 10131 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10132 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10133 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 10134 | goto error; |
| 10135 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10136 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10137 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 10138 | goto error; |
| 10139 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10140 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10141 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10142 | astmodulestate_global->YieldFrom_type) < 0) { |
| 10143 | goto error; |
| 10144 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10145 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10146 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10147 | 0) { |
| 10148 | goto error; |
| 10149 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10150 | Py_INCREF(astmodulestate(m)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10151 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 10152 | goto error; |
| 10153 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10154 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10155 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10156 | astmodulestate_global->FormattedValue_type) < 0) { |
| 10157 | goto error; |
| 10158 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10159 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10160 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10161 | astmodulestate_global->JoinedStr_type) < 0) { |
| 10162 | goto error; |
| 10163 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10164 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10165 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10166 | < 0) { |
| 10167 | goto error; |
| 10168 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10169 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10170 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10171 | astmodulestate_global->Attribute_type) < 0) { |
| 10172 | goto error; |
| 10173 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10174 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10175 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10176 | astmodulestate_global->Subscript_type) < 0) { |
| 10177 | goto error; |
| 10178 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10179 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10180 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10181 | 0) { |
| 10182 | goto error; |
| 10183 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10184 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10185 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 10186 | goto error; |
| 10187 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10188 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10189 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10190 | goto error; |
| 10191 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10192 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10193 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10194 | goto error; |
| 10195 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10196 | Py_INCREF(astmodulestate(m)->Tuple_type); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 10197 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10198 | goto error; |
| 10199 | } |
| 10200 | Py_INCREF(astmodulestate(m)->Slice_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10201 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10202 | astmodulestate_global->expr_context_type) < 0) { |
| 10203 | goto error; |
| 10204 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10205 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10206 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10207 | goto error; |
| 10208 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10209 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10210 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10211 | goto error; |
| 10212 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10213 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10214 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10215 | goto error; |
| 10216 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10217 | Py_INCREF(astmodulestate(m)->Del_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10218 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10219 | 0) { |
| 10220 | goto error; |
| 10221 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10222 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10223 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10224 | goto error; |
| 10225 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10226 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10227 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10228 | goto error; |
| 10229 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10230 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10231 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10232 | < 0) { |
| 10233 | goto error; |
| 10234 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10235 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10236 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10237 | goto error; |
| 10238 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10239 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10240 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10241 | goto error; |
| 10242 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10243 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10244 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10245 | goto error; |
| 10246 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10247 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10248 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10249 | 0) { |
| 10250 | goto error; |
| 10251 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10252 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10253 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10254 | goto error; |
| 10255 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10256 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10257 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10258 | goto error; |
| 10259 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10260 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10261 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10262 | goto error; |
| 10263 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10264 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10265 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10266 | 0) { |
| 10267 | goto error; |
| 10268 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10269 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10270 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10271 | 0) { |
| 10272 | goto error; |
| 10273 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10274 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10275 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10276 | goto error; |
| 10277 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10278 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10279 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10280 | 0) { |
| 10281 | goto error; |
| 10282 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10283 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10284 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10285 | 0) { |
| 10286 | goto error; |
| 10287 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10288 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10289 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10290 | < 0) { |
| 10291 | goto error; |
| 10292 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10293 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10294 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10295 | 0) { |
| 10296 | goto error; |
| 10297 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10298 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10299 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10300 | 0) { |
| 10301 | goto error; |
| 10302 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10303 | Py_INCREF(astmodulestate(m)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10304 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10305 | goto error; |
| 10306 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10307 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10308 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10309 | goto error; |
| 10310 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10311 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10312 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10313 | goto error; |
| 10314 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10315 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10316 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10317 | goto error; |
| 10318 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10319 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10320 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10321 | goto error; |
| 10322 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10323 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10324 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10325 | goto error; |
| 10326 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10327 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10328 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10329 | goto error; |
| 10330 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10331 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10332 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10333 | goto error; |
| 10334 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10335 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10336 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10337 | goto error; |
| 10338 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10339 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10340 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10341 | goto error; |
| 10342 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10343 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10344 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10345 | goto error; |
| 10346 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10347 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10348 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10349 | goto error; |
| 10350 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10351 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10352 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10353 | goto error; |
| 10354 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10355 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10356 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10357 | goto error; |
| 10358 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10359 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10360 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10361 | astmodulestate_global->comprehension_type) < 0) { |
| 10362 | goto error; |
| 10363 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10364 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10365 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10366 | astmodulestate_global->excepthandler_type) < 0) { |
| 10367 | goto error; |
| 10368 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10369 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10370 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10371 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10372 | goto error; |
| 10373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10374 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10375 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10376 | astmodulestate_global->arguments_type) < 0) { |
| 10377 | goto error; |
| 10378 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10379 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10380 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10381 | goto error; |
| 10382 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10383 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10384 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10385 | 0) { |
| 10386 | goto error; |
| 10387 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10388 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10389 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10390 | goto error; |
| 10391 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10392 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10393 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10394 | < 0) { |
| 10395 | goto error; |
| 10396 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10397 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10398 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10399 | astmodulestate_global->type_ignore_type) < 0) { |
| 10400 | goto error; |
| 10401 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10402 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10403 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10404 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10405 | goto error; |
| 10406 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10407 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10408 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10409 | error: |
| 10410 | Py_DECREF(m); |
| 10411 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10412 | } |
| 10413 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10414 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10415 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10416 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10417 | if (!init_types()) |
| 10418 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10419 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10420 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10421 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10422 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10423 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10424 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10425 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10426 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10427 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10428 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10429 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10430 | return NULL; |
| 10431 | } |
| 10432 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10433 | req_type[0] = astmodulestate_global->Module_type; |
| 10434 | req_type[1] = astmodulestate_global->Expression_type; |
| 10435 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10436 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10437 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10438 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10439 | if (!init_types()) |
| 10440 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10441 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10442 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10443 | if (isinstance == -1) |
| 10444 | return NULL; |
| 10445 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10446 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10447 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10448 | return NULL; |
| 10449 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10450 | |
| 10451 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10452 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10453 | return NULL; |
| 10454 | else |
| 10455 | return res; |
| 10456 | } |
| 10457 | |
| 10458 | int PyAST_Check(PyObject* obj) |
| 10459 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10460 | if (!init_types()) |
| 10461 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10462 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10463 | } |
| 10464 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10465 | |