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" |
| 7 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8 | typedef struct { |
| 9 | int initialized; |
| 10 | PyObject *AST_type; |
| 11 | PyObject *Add_singleton; |
| 12 | PyObject *Add_type; |
| 13 | PyObject *And_singleton; |
| 14 | PyObject *And_type; |
| 15 | PyObject *AnnAssign_type; |
| 16 | PyObject *Assert_type; |
| 17 | PyObject *Assign_type; |
| 18 | PyObject *AsyncFor_type; |
| 19 | PyObject *AsyncFunctionDef_type; |
| 20 | PyObject *AsyncWith_type; |
| 21 | PyObject *Attribute_type; |
| 22 | PyObject *AugAssign_type; |
| 23 | PyObject *AugLoad_singleton; |
| 24 | PyObject *AugLoad_type; |
| 25 | PyObject *AugStore_singleton; |
| 26 | PyObject *AugStore_type; |
| 27 | PyObject *Await_type; |
| 28 | PyObject *BinOp_type; |
| 29 | PyObject *BitAnd_singleton; |
| 30 | PyObject *BitAnd_type; |
| 31 | PyObject *BitOr_singleton; |
| 32 | PyObject *BitOr_type; |
| 33 | PyObject *BitXor_singleton; |
| 34 | PyObject *BitXor_type; |
| 35 | PyObject *BoolOp_type; |
| 36 | PyObject *Break_type; |
| 37 | PyObject *Call_type; |
| 38 | PyObject *ClassDef_type; |
| 39 | PyObject *Compare_type; |
| 40 | PyObject *Constant_type; |
| 41 | PyObject *Continue_type; |
| 42 | PyObject *Del_singleton; |
| 43 | PyObject *Del_type; |
| 44 | PyObject *Delete_type; |
| 45 | PyObject *DictComp_type; |
| 46 | PyObject *Dict_type; |
| 47 | PyObject *Div_singleton; |
| 48 | PyObject *Div_type; |
| 49 | PyObject *Eq_singleton; |
| 50 | PyObject *Eq_type; |
| 51 | PyObject *ExceptHandler_type; |
| 52 | PyObject *Expr_type; |
| 53 | PyObject *Expression_type; |
| 54 | PyObject *ExtSlice_type; |
| 55 | PyObject *FloorDiv_singleton; |
| 56 | PyObject *FloorDiv_type; |
| 57 | PyObject *For_type; |
| 58 | PyObject *FormattedValue_type; |
| 59 | PyObject *FunctionDef_type; |
| 60 | PyObject *FunctionType_type; |
| 61 | PyObject *GeneratorExp_type; |
| 62 | PyObject *Global_type; |
| 63 | PyObject *GtE_singleton; |
| 64 | PyObject *GtE_type; |
| 65 | PyObject *Gt_singleton; |
| 66 | PyObject *Gt_type; |
| 67 | PyObject *IfExp_type; |
| 68 | PyObject *If_type; |
| 69 | PyObject *ImportFrom_type; |
| 70 | PyObject *Import_type; |
| 71 | PyObject *In_singleton; |
| 72 | PyObject *In_type; |
| 73 | PyObject *Index_type; |
| 74 | PyObject *Interactive_type; |
| 75 | PyObject *Invert_singleton; |
| 76 | PyObject *Invert_type; |
| 77 | PyObject *IsNot_singleton; |
| 78 | PyObject *IsNot_type; |
| 79 | PyObject *Is_singleton; |
| 80 | PyObject *Is_type; |
| 81 | PyObject *JoinedStr_type; |
| 82 | PyObject *LShift_singleton; |
| 83 | PyObject *LShift_type; |
| 84 | PyObject *Lambda_type; |
| 85 | PyObject *ListComp_type; |
| 86 | PyObject *List_type; |
| 87 | PyObject *Load_singleton; |
| 88 | PyObject *Load_type; |
| 89 | PyObject *LtE_singleton; |
| 90 | PyObject *LtE_type; |
| 91 | PyObject *Lt_singleton; |
| 92 | PyObject *Lt_type; |
| 93 | PyObject *MatMult_singleton; |
| 94 | PyObject *MatMult_type; |
| 95 | PyObject *Mod_singleton; |
| 96 | PyObject *Mod_type; |
| 97 | PyObject *Module_type; |
| 98 | PyObject *Mult_singleton; |
| 99 | PyObject *Mult_type; |
| 100 | PyObject *Name_type; |
| 101 | PyObject *NamedExpr_type; |
| 102 | PyObject *Nonlocal_type; |
| 103 | PyObject *NotEq_singleton; |
| 104 | PyObject *NotEq_type; |
| 105 | PyObject *NotIn_singleton; |
| 106 | PyObject *NotIn_type; |
| 107 | PyObject *Not_singleton; |
| 108 | PyObject *Not_type; |
| 109 | PyObject *Or_singleton; |
| 110 | PyObject *Or_type; |
| 111 | PyObject *Param_singleton; |
| 112 | PyObject *Param_type; |
| 113 | PyObject *Pass_type; |
| 114 | PyObject *Pow_singleton; |
| 115 | PyObject *Pow_type; |
| 116 | PyObject *RShift_singleton; |
| 117 | PyObject *RShift_type; |
| 118 | PyObject *Raise_type; |
| 119 | PyObject *Return_type; |
| 120 | PyObject *SetComp_type; |
| 121 | PyObject *Set_type; |
| 122 | PyObject *Slice_type; |
| 123 | PyObject *Starred_type; |
| 124 | PyObject *Store_singleton; |
| 125 | PyObject *Store_type; |
| 126 | PyObject *Sub_singleton; |
| 127 | PyObject *Sub_type; |
| 128 | PyObject *Subscript_type; |
| 129 | PyObject *Suite_type; |
| 130 | PyObject *Try_type; |
| 131 | PyObject *Tuple_type; |
| 132 | PyObject *TypeIgnore_type; |
| 133 | PyObject *UAdd_singleton; |
| 134 | PyObject *UAdd_type; |
| 135 | PyObject *USub_singleton; |
| 136 | PyObject *USub_type; |
| 137 | PyObject *UnaryOp_type; |
| 138 | PyObject *While_type; |
| 139 | PyObject *With_type; |
| 140 | PyObject *YieldFrom_type; |
| 141 | PyObject *Yield_type; |
| 142 | PyObject *__dict__; |
| 143 | PyObject *__module__; |
| 144 | PyObject *_ast; |
| 145 | PyObject *_attributes; |
| 146 | PyObject *_fields; |
| 147 | PyObject *alias_type; |
| 148 | PyObject *annotation; |
| 149 | PyObject *arg; |
| 150 | PyObject *arg_type; |
| 151 | PyObject *args; |
| 152 | PyObject *argtypes; |
| 153 | PyObject *arguments_type; |
| 154 | PyObject *asname; |
| 155 | PyObject *attr; |
| 156 | PyObject *bases; |
| 157 | PyObject *body; |
| 158 | PyObject *boolop_type; |
| 159 | PyObject *cause; |
| 160 | PyObject *cmpop_type; |
| 161 | PyObject *col_offset; |
| 162 | PyObject *comparators; |
| 163 | PyObject *comprehension_type; |
| 164 | PyObject *context_expr; |
| 165 | PyObject *conversion; |
| 166 | PyObject *ctx; |
| 167 | PyObject *decorator_list; |
| 168 | PyObject *defaults; |
| 169 | PyObject *dims; |
| 170 | PyObject *elt; |
| 171 | PyObject *elts; |
| 172 | PyObject *end_col_offset; |
| 173 | PyObject *end_lineno; |
| 174 | PyObject *exc; |
| 175 | PyObject *excepthandler_type; |
| 176 | PyObject *expr_context_type; |
| 177 | PyObject *expr_type; |
| 178 | PyObject *finalbody; |
| 179 | PyObject *format_spec; |
| 180 | PyObject *func; |
| 181 | PyObject *generators; |
| 182 | PyObject *handlers; |
| 183 | PyObject *id; |
| 184 | PyObject *ifs; |
| 185 | PyObject *is_async; |
| 186 | PyObject *items; |
| 187 | PyObject *iter; |
| 188 | PyObject *key; |
| 189 | PyObject *keys; |
| 190 | PyObject *keyword_type; |
| 191 | PyObject *keywords; |
| 192 | PyObject *kind; |
| 193 | PyObject *kw_defaults; |
| 194 | PyObject *kwarg; |
| 195 | PyObject *kwonlyargs; |
| 196 | PyObject *left; |
| 197 | PyObject *level; |
| 198 | PyObject *lineno; |
| 199 | PyObject *lower; |
| 200 | PyObject *mod_type; |
| 201 | PyObject *module; |
| 202 | PyObject *msg; |
| 203 | PyObject *name; |
| 204 | PyObject *names; |
| 205 | PyObject *op; |
| 206 | PyObject *operand; |
| 207 | PyObject *operator_type; |
| 208 | PyObject *ops; |
| 209 | PyObject *optional_vars; |
| 210 | PyObject *orelse; |
| 211 | PyObject *posonlyargs; |
| 212 | PyObject *returns; |
| 213 | PyObject *right; |
| 214 | PyObject *simple; |
| 215 | PyObject *slice; |
| 216 | PyObject *slice_type; |
| 217 | PyObject *step; |
| 218 | PyObject *stmt_type; |
| 219 | PyObject *tag; |
| 220 | PyObject *target; |
| 221 | PyObject *targets; |
| 222 | PyObject *test; |
| 223 | PyObject *type; |
| 224 | PyObject *type_comment; |
| 225 | PyObject *type_ignore_type; |
| 226 | PyObject *type_ignores; |
| 227 | PyObject *unaryop_type; |
| 228 | PyObject *upper; |
| 229 | PyObject *value; |
| 230 | PyObject *values; |
| 231 | PyObject *vararg; |
| 232 | PyObject *withitem_type; |
| 233 | } astmodulestate; |
| 234 | |
| 235 | |
| 236 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 237 | |
| 238 | static int astmodule_clear(PyObject *module) |
| 239 | { |
| 240 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 241 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 242 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 243 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 244 | Py_CLEAR(astmodulestate(module)->And_type); |
| 245 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 246 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 247 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 248 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 249 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 250 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 251 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 252 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
| 253 | Py_CLEAR(astmodulestate(module)->AugLoad_singleton); |
| 254 | Py_CLEAR(astmodulestate(module)->AugLoad_type); |
| 255 | Py_CLEAR(astmodulestate(module)->AugStore_singleton); |
| 256 | Py_CLEAR(astmodulestate(module)->AugStore_type); |
| 257 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 258 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 259 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 260 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 261 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 262 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 263 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 264 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 265 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 266 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 267 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 268 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 269 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 271 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 272 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 273 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 274 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 275 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 276 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 277 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 278 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 279 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 280 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 281 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 282 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 283 | Py_CLEAR(astmodulestate(module)->Expression_type); |
| 284 | Py_CLEAR(astmodulestate(module)->ExtSlice_type); |
| 285 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 286 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 287 | Py_CLEAR(astmodulestate(module)->For_type); |
| 288 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 289 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 290 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 291 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 292 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 293 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 294 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 295 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 296 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 297 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 298 | Py_CLEAR(astmodulestate(module)->If_type); |
| 299 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 300 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 301 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 302 | Py_CLEAR(astmodulestate(module)->In_type); |
| 303 | Py_CLEAR(astmodulestate(module)->Index_type); |
| 304 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 305 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 306 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 307 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 308 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 309 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 310 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 311 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 312 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 313 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 314 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 315 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 316 | Py_CLEAR(astmodulestate(module)->List_type); |
| 317 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 318 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 319 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 320 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 321 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 322 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 323 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 324 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 325 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 326 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 327 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 328 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 329 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 330 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 331 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 332 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 333 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 334 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 335 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 336 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 337 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 338 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 339 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 340 | Py_CLEAR(astmodulestate(module)->Or_type); |
| 341 | Py_CLEAR(astmodulestate(module)->Param_singleton); |
| 342 | Py_CLEAR(astmodulestate(module)->Param_type); |
| 343 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 344 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 345 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 346 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 347 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 348 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 349 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 350 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 351 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 352 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 353 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 354 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 355 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 356 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 357 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 358 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
| 359 | Py_CLEAR(astmodulestate(module)->Suite_type); |
| 360 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 361 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 362 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 363 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 364 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 365 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 366 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 367 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 368 | Py_CLEAR(astmodulestate(module)->While_type); |
| 369 | Py_CLEAR(astmodulestate(module)->With_type); |
| 370 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 371 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 372 | Py_CLEAR(astmodulestate(module)->__dict__); |
| 373 | Py_CLEAR(astmodulestate(module)->__module__); |
| 374 | Py_CLEAR(astmodulestate(module)->_ast); |
| 375 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 376 | Py_CLEAR(astmodulestate(module)->_fields); |
| 377 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 378 | Py_CLEAR(astmodulestate(module)->annotation); |
| 379 | Py_CLEAR(astmodulestate(module)->arg); |
| 380 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 381 | Py_CLEAR(astmodulestate(module)->args); |
| 382 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 383 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 384 | Py_CLEAR(astmodulestate(module)->asname); |
| 385 | Py_CLEAR(astmodulestate(module)->attr); |
| 386 | Py_CLEAR(astmodulestate(module)->bases); |
| 387 | Py_CLEAR(astmodulestate(module)->body); |
| 388 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 389 | Py_CLEAR(astmodulestate(module)->cause); |
| 390 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 391 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 392 | Py_CLEAR(astmodulestate(module)->comparators); |
| 393 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 394 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 395 | Py_CLEAR(astmodulestate(module)->conversion); |
| 396 | Py_CLEAR(astmodulestate(module)->ctx); |
| 397 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 398 | Py_CLEAR(astmodulestate(module)->defaults); |
| 399 | Py_CLEAR(astmodulestate(module)->dims); |
| 400 | Py_CLEAR(astmodulestate(module)->elt); |
| 401 | Py_CLEAR(astmodulestate(module)->elts); |
| 402 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 403 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 404 | Py_CLEAR(astmodulestate(module)->exc); |
| 405 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 406 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 407 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 408 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 409 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 410 | Py_CLEAR(astmodulestate(module)->func); |
| 411 | Py_CLEAR(astmodulestate(module)->generators); |
| 412 | Py_CLEAR(astmodulestate(module)->handlers); |
| 413 | Py_CLEAR(astmodulestate(module)->id); |
| 414 | Py_CLEAR(astmodulestate(module)->ifs); |
| 415 | Py_CLEAR(astmodulestate(module)->is_async); |
| 416 | Py_CLEAR(astmodulestate(module)->items); |
| 417 | Py_CLEAR(astmodulestate(module)->iter); |
| 418 | Py_CLEAR(astmodulestate(module)->key); |
| 419 | Py_CLEAR(astmodulestate(module)->keys); |
| 420 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 421 | Py_CLEAR(astmodulestate(module)->keywords); |
| 422 | Py_CLEAR(astmodulestate(module)->kind); |
| 423 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 424 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 425 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 426 | Py_CLEAR(astmodulestate(module)->left); |
| 427 | Py_CLEAR(astmodulestate(module)->level); |
| 428 | Py_CLEAR(astmodulestate(module)->lineno); |
| 429 | Py_CLEAR(astmodulestate(module)->lower); |
| 430 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 431 | Py_CLEAR(astmodulestate(module)->module); |
| 432 | Py_CLEAR(astmodulestate(module)->msg); |
| 433 | Py_CLEAR(astmodulestate(module)->name); |
| 434 | Py_CLEAR(astmodulestate(module)->names); |
| 435 | Py_CLEAR(astmodulestate(module)->op); |
| 436 | Py_CLEAR(astmodulestate(module)->operand); |
| 437 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 438 | Py_CLEAR(astmodulestate(module)->ops); |
| 439 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 440 | Py_CLEAR(astmodulestate(module)->orelse); |
| 441 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 442 | Py_CLEAR(astmodulestate(module)->returns); |
| 443 | Py_CLEAR(astmodulestate(module)->right); |
| 444 | Py_CLEAR(astmodulestate(module)->simple); |
| 445 | Py_CLEAR(astmodulestate(module)->slice); |
| 446 | Py_CLEAR(astmodulestate(module)->slice_type); |
| 447 | Py_CLEAR(astmodulestate(module)->step); |
| 448 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 449 | Py_CLEAR(astmodulestate(module)->tag); |
| 450 | Py_CLEAR(astmodulestate(module)->target); |
| 451 | Py_CLEAR(astmodulestate(module)->targets); |
| 452 | Py_CLEAR(astmodulestate(module)->test); |
| 453 | Py_CLEAR(astmodulestate(module)->type); |
| 454 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 455 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 456 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 457 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 458 | Py_CLEAR(astmodulestate(module)->upper); |
| 459 | Py_CLEAR(astmodulestate(module)->value); |
| 460 | Py_CLEAR(astmodulestate(module)->values); |
| 461 | Py_CLEAR(astmodulestate(module)->vararg); |
| 462 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 468 | { |
| 469 | Py_VISIT(astmodulestate(module)->AST_type); |
| 470 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 471 | Py_VISIT(astmodulestate(module)->Add_type); |
| 472 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 473 | Py_VISIT(astmodulestate(module)->And_type); |
| 474 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 475 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 476 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 477 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 478 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 479 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 480 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 481 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
| 482 | Py_VISIT(astmodulestate(module)->AugLoad_singleton); |
| 483 | Py_VISIT(astmodulestate(module)->AugLoad_type); |
| 484 | Py_VISIT(astmodulestate(module)->AugStore_singleton); |
| 485 | Py_VISIT(astmodulestate(module)->AugStore_type); |
| 486 | Py_VISIT(astmodulestate(module)->Await_type); |
| 487 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 488 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 489 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 490 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 491 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 492 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 493 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 494 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 495 | Py_VISIT(astmodulestate(module)->Break_type); |
| 496 | Py_VISIT(astmodulestate(module)->Call_type); |
| 497 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 498 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 499 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 500 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 501 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 502 | Py_VISIT(astmodulestate(module)->Del_type); |
| 503 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 504 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 505 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 506 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 507 | Py_VISIT(astmodulestate(module)->Div_type); |
| 508 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 509 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 510 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 511 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 512 | Py_VISIT(astmodulestate(module)->Expression_type); |
| 513 | Py_VISIT(astmodulestate(module)->ExtSlice_type); |
| 514 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 515 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 516 | Py_VISIT(astmodulestate(module)->For_type); |
| 517 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 518 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 519 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 520 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 521 | Py_VISIT(astmodulestate(module)->Global_type); |
| 522 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 523 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 524 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 525 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 526 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 527 | Py_VISIT(astmodulestate(module)->If_type); |
| 528 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 529 | Py_VISIT(astmodulestate(module)->Import_type); |
| 530 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 531 | Py_VISIT(astmodulestate(module)->In_type); |
| 532 | Py_VISIT(astmodulestate(module)->Index_type); |
| 533 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 534 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 535 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 536 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 537 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 538 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 539 | Py_VISIT(astmodulestate(module)->Is_type); |
| 540 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 541 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 542 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 543 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 544 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 545 | Py_VISIT(astmodulestate(module)->List_type); |
| 546 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 547 | Py_VISIT(astmodulestate(module)->Load_type); |
| 548 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 549 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 550 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 551 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 552 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 553 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 554 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 555 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 556 | Py_VISIT(astmodulestate(module)->Module_type); |
| 557 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 558 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 559 | Py_VISIT(astmodulestate(module)->Name_type); |
| 560 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 561 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 562 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 563 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 564 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 565 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 566 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 567 | Py_VISIT(astmodulestate(module)->Not_type); |
| 568 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 569 | Py_VISIT(astmodulestate(module)->Or_type); |
| 570 | Py_VISIT(astmodulestate(module)->Param_singleton); |
| 571 | Py_VISIT(astmodulestate(module)->Param_type); |
| 572 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 573 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 574 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 575 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 576 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 577 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 578 | Py_VISIT(astmodulestate(module)->Return_type); |
| 579 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 580 | Py_VISIT(astmodulestate(module)->Set_type); |
| 581 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 582 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 583 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 584 | Py_VISIT(astmodulestate(module)->Store_type); |
| 585 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 586 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 587 | Py_VISIT(astmodulestate(module)->Subscript_type); |
| 588 | Py_VISIT(astmodulestate(module)->Suite_type); |
| 589 | Py_VISIT(astmodulestate(module)->Try_type); |
| 590 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 591 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 592 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 593 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 594 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 595 | Py_VISIT(astmodulestate(module)->USub_type); |
| 596 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 597 | Py_VISIT(astmodulestate(module)->While_type); |
| 598 | Py_VISIT(astmodulestate(module)->With_type); |
| 599 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 600 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 601 | Py_VISIT(astmodulestate(module)->__dict__); |
| 602 | Py_VISIT(astmodulestate(module)->__module__); |
| 603 | Py_VISIT(astmodulestate(module)->_ast); |
| 604 | Py_VISIT(astmodulestate(module)->_attributes); |
| 605 | Py_VISIT(astmodulestate(module)->_fields); |
| 606 | Py_VISIT(astmodulestate(module)->alias_type); |
| 607 | Py_VISIT(astmodulestate(module)->annotation); |
| 608 | Py_VISIT(astmodulestate(module)->arg); |
| 609 | Py_VISIT(astmodulestate(module)->arg_type); |
| 610 | Py_VISIT(astmodulestate(module)->args); |
| 611 | Py_VISIT(astmodulestate(module)->argtypes); |
| 612 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 613 | Py_VISIT(astmodulestate(module)->asname); |
| 614 | Py_VISIT(astmodulestate(module)->attr); |
| 615 | Py_VISIT(astmodulestate(module)->bases); |
| 616 | Py_VISIT(astmodulestate(module)->body); |
| 617 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 618 | Py_VISIT(astmodulestate(module)->cause); |
| 619 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 620 | Py_VISIT(astmodulestate(module)->col_offset); |
| 621 | Py_VISIT(astmodulestate(module)->comparators); |
| 622 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 623 | Py_VISIT(astmodulestate(module)->context_expr); |
| 624 | Py_VISIT(astmodulestate(module)->conversion); |
| 625 | Py_VISIT(astmodulestate(module)->ctx); |
| 626 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 627 | Py_VISIT(astmodulestate(module)->defaults); |
| 628 | Py_VISIT(astmodulestate(module)->dims); |
| 629 | Py_VISIT(astmodulestate(module)->elt); |
| 630 | Py_VISIT(astmodulestate(module)->elts); |
| 631 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 632 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 633 | Py_VISIT(astmodulestate(module)->exc); |
| 634 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 635 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 636 | Py_VISIT(astmodulestate(module)->expr_type); |
| 637 | Py_VISIT(astmodulestate(module)->finalbody); |
| 638 | Py_VISIT(astmodulestate(module)->format_spec); |
| 639 | Py_VISIT(astmodulestate(module)->func); |
| 640 | Py_VISIT(astmodulestate(module)->generators); |
| 641 | Py_VISIT(astmodulestate(module)->handlers); |
| 642 | Py_VISIT(astmodulestate(module)->id); |
| 643 | Py_VISIT(astmodulestate(module)->ifs); |
| 644 | Py_VISIT(astmodulestate(module)->is_async); |
| 645 | Py_VISIT(astmodulestate(module)->items); |
| 646 | Py_VISIT(astmodulestate(module)->iter); |
| 647 | Py_VISIT(astmodulestate(module)->key); |
| 648 | Py_VISIT(astmodulestate(module)->keys); |
| 649 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 650 | Py_VISIT(astmodulestate(module)->keywords); |
| 651 | Py_VISIT(astmodulestate(module)->kind); |
| 652 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 653 | Py_VISIT(astmodulestate(module)->kwarg); |
| 654 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 655 | Py_VISIT(astmodulestate(module)->left); |
| 656 | Py_VISIT(astmodulestate(module)->level); |
| 657 | Py_VISIT(astmodulestate(module)->lineno); |
| 658 | Py_VISIT(astmodulestate(module)->lower); |
| 659 | Py_VISIT(astmodulestate(module)->mod_type); |
| 660 | Py_VISIT(astmodulestate(module)->module); |
| 661 | Py_VISIT(astmodulestate(module)->msg); |
| 662 | Py_VISIT(astmodulestate(module)->name); |
| 663 | Py_VISIT(astmodulestate(module)->names); |
| 664 | Py_VISIT(astmodulestate(module)->op); |
| 665 | Py_VISIT(astmodulestate(module)->operand); |
| 666 | Py_VISIT(astmodulestate(module)->operator_type); |
| 667 | Py_VISIT(astmodulestate(module)->ops); |
| 668 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 669 | Py_VISIT(astmodulestate(module)->orelse); |
| 670 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 671 | Py_VISIT(astmodulestate(module)->returns); |
| 672 | Py_VISIT(astmodulestate(module)->right); |
| 673 | Py_VISIT(astmodulestate(module)->simple); |
| 674 | Py_VISIT(astmodulestate(module)->slice); |
| 675 | Py_VISIT(astmodulestate(module)->slice_type); |
| 676 | Py_VISIT(astmodulestate(module)->step); |
| 677 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 678 | Py_VISIT(astmodulestate(module)->tag); |
| 679 | Py_VISIT(astmodulestate(module)->target); |
| 680 | Py_VISIT(astmodulestate(module)->targets); |
| 681 | Py_VISIT(astmodulestate(module)->test); |
| 682 | Py_VISIT(astmodulestate(module)->type); |
| 683 | Py_VISIT(astmodulestate(module)->type_comment); |
| 684 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 685 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 686 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 687 | Py_VISIT(astmodulestate(module)->upper); |
| 688 | Py_VISIT(astmodulestate(module)->value); |
| 689 | Py_VISIT(astmodulestate(module)->values); |
| 690 | Py_VISIT(astmodulestate(module)->vararg); |
| 691 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | static void astmodule_free(void* module) { |
| 697 | astmodule_clear((PyObject*)module); |
| 698 | } |
| 699 | |
| 700 | static struct PyModuleDef _astmodule = { |
| 701 | PyModuleDef_HEAD_INIT, |
| 702 | "_ast", |
| 703 | NULL, |
| 704 | sizeof(astmodulestate), |
| 705 | NULL, |
| 706 | NULL, |
| 707 | astmodule_traverse, |
| 708 | astmodule_clear, |
| 709 | astmodule_free, |
| 710 | }; |
| 711 | |
| 712 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 713 | |
| 714 | static int init_identifiers(void) |
| 715 | { |
| 716 | astmodulestate *state = astmodulestate_global; |
| 717 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
| 718 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
| 719 | if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0; |
| 720 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 721 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 722 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 723 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 724 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 725 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 726 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
| 727 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 728 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 729 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 730 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 731 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 732 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 733 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 734 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 735 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 736 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 737 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
| 738 | if ((state->dims = PyUnicode_InternFromString("dims")) == NULL) return 0; |
| 739 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 740 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 741 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 742 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 743 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 744 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 745 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 746 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 747 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 748 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 749 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 750 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 751 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 752 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 753 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 754 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 755 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 756 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 757 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 758 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 759 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 760 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 761 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 762 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 763 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 764 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 765 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 766 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 767 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 768 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 769 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 770 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 771 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 772 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 773 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 774 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 775 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 776 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 777 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 778 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 779 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 780 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 781 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 782 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 783 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 784 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 785 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 786 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 787 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 788 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 789 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 790 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 791 | return 1; |
| 792 | }; |
| 793 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 795 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 796 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 797 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 798 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 799 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 800 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 801 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 802 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 803 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 804 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 805 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 806 | "argtypes", |
| 807 | "returns", |
| 808 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 809 | static const char * const Suite_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 810 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 811 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 812 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 813 | "lineno", |
| 814 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 815 | "end_lineno", |
| 816 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 817 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 818 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 819 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 820 | "name", |
| 821 | "args", |
| 822 | "body", |
| 823 | "decorator_list", |
| 824 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 825 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 826 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 827 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 828 | "name", |
| 829 | "args", |
| 830 | "body", |
| 831 | "decorator_list", |
| 832 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 833 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 834 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 835 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 836 | "name", |
| 837 | "bases", |
| 838 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 839 | "body", |
| 840 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 841 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 842 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 843 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 844 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 845 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 846 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 847 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 848 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 849 | "targets", |
| 850 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 851 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 852 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 853 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 854 | "target", |
| 855 | "op", |
| 856 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 857 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 858 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 859 | "target", |
| 860 | "annotation", |
| 861 | "value", |
| 862 | "simple", |
| 863 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 864 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 865 | "target", |
| 866 | "iter", |
| 867 | "body", |
| 868 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 869 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 870 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 871 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 872 | "target", |
| 873 | "iter", |
| 874 | "body", |
| 875 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 876 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 877 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 878 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 879 | "test", |
| 880 | "body", |
| 881 | "orelse", |
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 If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | "test", |
| 885 | "body", |
| 886 | "orelse", |
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 With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 889 | "items", |
| 890 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 891 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 892 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 893 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 894 | "items", |
| 895 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 896 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 897 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 898 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 899 | "exc", |
| 900 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 901 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 902 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 903 | "body", |
| 904 | "handlers", |
| 905 | "orelse", |
| 906 | "finalbody", |
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 Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 909 | "test", |
| 910 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 911 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 912 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 913 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 914 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 915 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 916 | "module", |
| 917 | "names", |
| 918 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 919 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 920 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 921 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 922 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 923 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 924 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 925 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 926 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 927 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 928 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 929 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 930 | "lineno", |
| 931 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 932 | "end_lineno", |
| 933 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 934 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 935 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 936 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 937 | "op", |
| 938 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 939 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 940 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 941 | "target", |
| 942 | "value", |
| 943 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 944 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 945 | "left", |
| 946 | "op", |
| 947 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 948 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 949 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 950 | "op", |
| 951 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 952 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 953 | static const char * const Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 954 | "args", |
| 955 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 956 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 957 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 958 | "test", |
| 959 | "body", |
| 960 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 961 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 962 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 963 | "keys", |
| 964 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 965 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 966 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 967 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 968 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 969 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 970 | "elt", |
| 971 | "generators", |
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 SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 974 | "elt", |
| 975 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 976 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 977 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 978 | "key", |
| 979 | "value", |
| 980 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 981 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 982 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 983 | "elt", |
| 984 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 985 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 986 | static const char * const Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 987 | "value", |
| 988 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 989 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 990 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 991 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 992 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 993 | "value", |
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 Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 996 | "left", |
| 997 | "ops", |
| 998 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 999 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1000 | static const char * const Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1001 | "func", |
| 1002 | "args", |
| 1003 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1004 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1005 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 1006 | "value", |
| 1007 | "conversion", |
| 1008 | "format_spec", |
| 1009 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1010 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 1011 | "values", |
| 1012 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1013 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1014 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 1015 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1016 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1017 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1018 | "value", |
| 1019 | "attr", |
| 1020 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1021 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1022 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1023 | "value", |
| 1024 | "slice", |
| 1025 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1026 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1027 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1028 | "value", |
| 1029 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1030 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1031 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1032 | "id", |
| 1033 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1034 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1035 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1036 | "elts", |
| 1037 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1038 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1039 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1040 | "elts", |
| 1041 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1042 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1043 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1044 | static PyObject* ast2obj_slice(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1045 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1046 | "lower", |
| 1047 | "upper", |
| 1048 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1049 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1050 | static const char * const ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1051 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1052 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1053 | static const char * const Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1054 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1055 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1056 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1057 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1058 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1059 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1060 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1061 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1062 | "target", |
| 1063 | "iter", |
| 1064 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1065 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1066 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1067 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1068 | "lineno", |
| 1069 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1070 | "end_lineno", |
| 1071 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1072 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1073 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1074 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1075 | "type", |
| 1076 | "name", |
| 1077 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1078 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1079 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1080 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1081 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1082 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1083 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1084 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1085 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1086 | "kwarg", |
| 1087 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1088 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1089 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1090 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1091 | "lineno", |
| 1092 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1093 | "end_lineno", |
| 1094 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1095 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1096 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1097 | "arg", |
| 1098 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1099 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1100 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1101 | static PyObject* ast2obj_keyword(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1102 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1103 | "arg", |
| 1104 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1105 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1106 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1107 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1108 | "name", |
| 1109 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1110 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1111 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1112 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1113 | "context_expr", |
| 1114 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1115 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1116 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1117 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1118 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1119 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1120 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1121 | |
| 1122 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1123 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1124 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1125 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1126 | PyObject *dict; |
| 1127 | } AST_object; |
| 1128 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1129 | static void |
| 1130 | ast_dealloc(AST_object *self) |
| 1131 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1132 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 1133 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1134 | Py_CLEAR(self->dict); |
Antoine Pitrou | 5075074 | 2012-07-08 12:43:32 +0200 | [diff] [blame] | 1135 | Py_TYPE(self)->tp_free(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1136 | } |
| 1137 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1138 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1139 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1140 | { |
| 1141 | Py_VISIT(self->dict); |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1145 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1146 | ast_clear(AST_object *self) |
| 1147 | { |
| 1148 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1149 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1153 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1154 | { |
| 1155 | Py_ssize_t i, numfields = 0; |
| 1156 | int res = -1; |
| 1157 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1158 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1159 | goto cleanup; |
| 1160 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1161 | if (fields) { |
| 1162 | numfields = PySequence_Size(fields); |
| 1163 | if (numfields == -1) |
| 1164 | goto cleanup; |
| 1165 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1166 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1167 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1168 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1169 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1170 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1171 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1172 | numfields, numfields == 1 ? "" : "s"); |
| 1173 | res = -1; |
| 1174 | goto cleanup; |
| 1175 | } |
| 1176 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1177 | /* cannot be reached when fields is NULL */ |
| 1178 | PyObject *name = PySequence_GetItem(fields, i); |
| 1179 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1180 | res = -1; |
| 1181 | goto cleanup; |
| 1182 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1183 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1184 | Py_DECREF(name); |
| 1185 | if (res < 0) |
| 1186 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1187 | } |
| 1188 | if (kw) { |
| 1189 | i = 0; /* needed by PyDict_Next */ |
| 1190 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1191 | res = PyObject_SetAttr(self, key, value); |
| 1192 | if (res < 0) |
| 1193 | goto cleanup; |
| 1194 | } |
| 1195 | } |
| 1196 | cleanup: |
| 1197 | Py_XDECREF(fields); |
| 1198 | return res; |
| 1199 | } |
| 1200 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1201 | /* Pickling support */ |
| 1202 | static PyObject * |
| 1203 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1204 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1205 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1206 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1207 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1208 | } |
| 1209 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1210 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1211 | } |
| 1212 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1213 | } |
| 1214 | |
| 1215 | static PyMethodDef ast_type_methods[] = { |
| 1216 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1217 | {NULL} |
| 1218 | }; |
| 1219 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1220 | static PyGetSetDef ast_type_getsets[] = { |
| 1221 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1222 | {NULL} |
| 1223 | }; |
| 1224 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1225 | static PyType_Slot AST_type_slots[] = { |
| 1226 | {Py_tp_dealloc, ast_dealloc}, |
| 1227 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1228 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1229 | {Py_tp_traverse, ast_traverse}, |
| 1230 | {Py_tp_clear, ast_clear}, |
| 1231 | {Py_tp_methods, ast_type_methods}, |
| 1232 | {Py_tp_getset, ast_type_getsets}, |
| 1233 | {Py_tp_init, ast_type_init}, |
| 1234 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1235 | {Py_tp_new, PyType_GenericNew}, |
| 1236 | {Py_tp_free, PyType_GenericNew}, |
| 1237 | {Py_tp_free, PyObject_GC_Del}, |
| 1238 | {0, 0}, |
| 1239 | }; |
| 1240 | |
| 1241 | static PyType_Spec AST_type_spec = { |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1242 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1243 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1244 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1245 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1246 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1247 | }; |
| 1248 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1249 | static PyObject * |
| 1250 | make_type(const char *type, PyObject* base, const char* const* fields, int num_fields) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1251 | { |
| 1252 | PyObject *fnames, *result; |
| 1253 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1254 | fnames = PyTuple_New(num_fields); |
| 1255 | if (!fnames) return NULL; |
| 1256 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1257 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1258 | if (!field) { |
| 1259 | Py_DECREF(fnames); |
| 1260 | return NULL; |
| 1261 | } |
| 1262 | PyTuple_SET_ITEM(fnames, i, field); |
| 1263 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1264 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 1265 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1266 | astmodulestate_global->_fields, fnames, |
| 1267 | astmodulestate_global->__module__, |
| 1268 | astmodulestate_global->_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1269 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1270 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1273 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1274 | 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] | 1275 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1276 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1277 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1278 | if (!l) |
| 1279 | return 0; |
| 1280 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1281 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1282 | if (!s) { |
| 1283 | Py_DECREF(l); |
| 1284 | return 0; |
| 1285 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1286 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1287 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1288 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1289 | Py_DECREF(l); |
| 1290 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1293 | /* Conversion AST -> Python */ |
| 1294 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1295 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1296 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1297 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1298 | PyObject *result = PyList_New(n); |
| 1299 | PyObject *value; |
| 1300 | if (!result) |
| 1301 | return NULL; |
| 1302 | for (i = 0; i < n; i++) { |
| 1303 | value = func(asdl_seq_GET(seq, i)); |
| 1304 | if (!value) { |
| 1305 | Py_DECREF(result); |
| 1306 | return NULL; |
| 1307 | } |
| 1308 | PyList_SET_ITEM(result, i, value); |
| 1309 | } |
| 1310 | return result; |
| 1311 | } |
| 1312 | |
| 1313 | static PyObject* ast2obj_object(void *o) |
| 1314 | { |
| 1315 | if (!o) |
| 1316 | o = Py_None; |
| 1317 | Py_INCREF((PyObject*)o); |
| 1318 | return (PyObject*)o; |
| 1319 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1320 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1321 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1322 | #define ast2obj_identifier ast2obj_object |
| 1323 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1324 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1325 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1326 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1327 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1328 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1331 | /* Conversion Python -> AST */ |
| 1332 | |
| 1333 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1334 | { |
| 1335 | if (obj == Py_None) |
| 1336 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1337 | if (obj) { |
| 1338 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1339 | *out = NULL; |
| 1340 | return -1; |
| 1341 | } |
| 1342 | Py_INCREF(obj); |
| 1343 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1344 | *out = obj; |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1348 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1349 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1350 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1351 | *out = NULL; |
| 1352 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1353 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1354 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1355 | *out = obj; |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1359 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1360 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1361 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1362 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1363 | return 1; |
| 1364 | } |
| 1365 | return obj2ast_object(obj, out, arena); |
| 1366 | } |
| 1367 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1368 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1369 | { |
| 1370 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1371 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1372 | return 1; |
| 1373 | } |
| 1374 | return obj2ast_object(obj, out, arena); |
| 1375 | } |
| 1376 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1377 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1378 | { |
| 1379 | int i; |
| 1380 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1381 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1382 | return 1; |
| 1383 | } |
| 1384 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1385 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1386 | if (i == -1 && PyErr_Occurred()) |
| 1387 | return 1; |
| 1388 | *out = i; |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1392 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1393 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1394 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1395 | empty_tuple = PyTuple_New(0); |
| 1396 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1397 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1398 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1399 | Py_XDECREF(empty_tuple); |
| 1400 | return -1; |
| 1401 | } |
| 1402 | Py_DECREF(empty_tuple); |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1406 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1407 | static int init_types(void) |
| 1408 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1409 | PyObject *m; |
| 1410 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1411 | m = PyModule_Create(&_astmodule); |
| 1412 | if (!m) return 0; |
| 1413 | PyState_AddModule(m, &_astmodule); |
| 1414 | } |
| 1415 | astmodulestate *state = astmodulestate_global; |
| 1416 | if (state->initialized) return 1; |
| 1417 | if (init_identifiers() < 0) return 0; |
| 1418 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1419 | if (!state->AST_type) return 0; |
| 1420 | ((PyTypeObject*)state->AST_type)->tp_dictoffset = offsetof(AST_object, |
| 1421 | dict); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1422 | if (add_ast_fields() < 0) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1423 | state->mod_type = make_type("mod", state->AST_type, NULL, 0); |
| 1424 | if (!state->mod_type) return 0; |
| 1425 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
| 1426 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2); |
| 1427 | if (!state->Module_type) return 0; |
| 1428 | state->Interactive_type = make_type("Interactive", state->mod_type, |
| 1429 | Interactive_fields, 1); |
| 1430 | if (!state->Interactive_type) return 0; |
| 1431 | state->Expression_type = make_type("Expression", state->mod_type, |
| 1432 | Expression_fields, 1); |
| 1433 | if (!state->Expression_type) return 0; |
| 1434 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
| 1435 | FunctionType_fields, 2); |
| 1436 | if (!state->FunctionType_type) return 0; |
| 1437 | state->Suite_type = make_type("Suite", state->mod_type, Suite_fields, 1); |
| 1438 | if (!state->Suite_type) return 0; |
| 1439 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0); |
| 1440 | if (!state->stmt_type) return 0; |
| 1441 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
| 1442 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
| 1443 | FunctionDef_fields, 6); |
| 1444 | if (!state->FunctionDef_type) return 0; |
| 1445 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1446 | state->stmt_type, |
| 1447 | AsyncFunctionDef_fields, 6); |
| 1448 | if (!state->AsyncFunctionDef_type) return 0; |
| 1449 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
| 1450 | ClassDef_fields, 5); |
| 1451 | if (!state->ClassDef_type) return 0; |
| 1452 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, |
| 1453 | 1); |
| 1454 | if (!state->Return_type) return 0; |
| 1455 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, |
| 1456 | 1); |
| 1457 | if (!state->Delete_type) return 0; |
| 1458 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, |
| 1459 | 3); |
| 1460 | if (!state->Assign_type) return 0; |
| 1461 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
| 1462 | AugAssign_fields, 3); |
| 1463 | if (!state->AugAssign_type) return 0; |
| 1464 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
| 1465 | AnnAssign_fields, 4); |
| 1466 | if (!state->AnnAssign_type) return 0; |
| 1467 | state->For_type = make_type("For", state->stmt_type, For_fields, 5); |
| 1468 | if (!state->For_type) return 0; |
| 1469 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
| 1470 | AsyncFor_fields, 5); |
| 1471 | if (!state->AsyncFor_type) return 0; |
| 1472 | state->While_type = make_type("While", state->stmt_type, While_fields, 3); |
| 1473 | if (!state->While_type) return 0; |
| 1474 | state->If_type = make_type("If", state->stmt_type, If_fields, 3); |
| 1475 | if (!state->If_type) return 0; |
| 1476 | state->With_type = make_type("With", state->stmt_type, With_fields, 3); |
| 1477 | if (!state->With_type) return 0; |
| 1478 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
| 1479 | AsyncWith_fields, 3); |
| 1480 | if (!state->AsyncWith_type) return 0; |
| 1481 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2); |
| 1482 | if (!state->Raise_type) return 0; |
| 1483 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4); |
| 1484 | if (!state->Try_type) return 0; |
| 1485 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, |
| 1486 | 2); |
| 1487 | if (!state->Assert_type) return 0; |
| 1488 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, |
| 1489 | 1); |
| 1490 | if (!state->Import_type) return 0; |
| 1491 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
| 1492 | ImportFrom_fields, 3); |
| 1493 | if (!state->ImportFrom_type) return 0; |
| 1494 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, |
| 1495 | 1); |
| 1496 | if (!state->Global_type) return 0; |
| 1497 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
| 1498 | Nonlocal_fields, 1); |
| 1499 | if (!state->Nonlocal_type) return 0; |
| 1500 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1); |
| 1501 | if (!state->Expr_type) return 0; |
| 1502 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0); |
| 1503 | if (!state->Pass_type) return 0; |
| 1504 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0); |
| 1505 | if (!state->Break_type) return 0; |
| 1506 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0); |
| 1507 | if (!state->Continue_type) return 0; |
| 1508 | state->expr_type = make_type("expr", state->AST_type, NULL, 0); |
| 1509 | if (!state->expr_type) return 0; |
| 1510 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
| 1511 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, |
| 1512 | 2); |
| 1513 | if (!state->BoolOp_type) return 0; |
| 1514 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
| 1515 | NamedExpr_fields, 2); |
| 1516 | if (!state->NamedExpr_type) return 0; |
| 1517 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3); |
| 1518 | if (!state->BinOp_type) return 0; |
| 1519 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
| 1520 | UnaryOp_fields, 2); |
| 1521 | if (!state->UnaryOp_type) return 0; |
| 1522 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, |
| 1523 | 2); |
| 1524 | if (!state->Lambda_type) return 0; |
| 1525 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3); |
| 1526 | if (!state->IfExp_type) return 0; |
| 1527 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2); |
| 1528 | if (!state->Dict_type) return 0; |
| 1529 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1); |
| 1530 | if (!state->Set_type) return 0; |
| 1531 | state->ListComp_type = make_type("ListComp", state->expr_type, |
| 1532 | ListComp_fields, 2); |
| 1533 | if (!state->ListComp_type) return 0; |
| 1534 | state->SetComp_type = make_type("SetComp", state->expr_type, |
| 1535 | SetComp_fields, 2); |
| 1536 | if (!state->SetComp_type) return 0; |
| 1537 | state->DictComp_type = make_type("DictComp", state->expr_type, |
| 1538 | DictComp_fields, 3); |
| 1539 | if (!state->DictComp_type) return 0; |
| 1540 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
| 1541 | GeneratorExp_fields, 2); |
| 1542 | if (!state->GeneratorExp_type) return 0; |
| 1543 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1); |
| 1544 | if (!state->Await_type) return 0; |
| 1545 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1); |
| 1546 | if (!state->Yield_type) return 0; |
| 1547 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
| 1548 | YieldFrom_fields, 1); |
| 1549 | if (!state->YieldFrom_type) return 0; |
| 1550 | state->Compare_type = make_type("Compare", state->expr_type, |
| 1551 | Compare_fields, 3); |
| 1552 | if (!state->Compare_type) return 0; |
| 1553 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3); |
| 1554 | if (!state->Call_type) return 0; |
| 1555 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
| 1556 | FormattedValue_fields, 3); |
| 1557 | if (!state->FormattedValue_type) return 0; |
| 1558 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
| 1559 | JoinedStr_fields, 1); |
| 1560 | if (!state->JoinedStr_type) return 0; |
| 1561 | state->Constant_type = make_type("Constant", state->expr_type, |
| 1562 | Constant_fields, 2); |
| 1563 | if (!state->Constant_type) return 0; |
| 1564 | state->Attribute_type = make_type("Attribute", state->expr_type, |
| 1565 | Attribute_fields, 3); |
| 1566 | if (!state->Attribute_type) return 0; |
| 1567 | state->Subscript_type = make_type("Subscript", state->expr_type, |
| 1568 | Subscript_fields, 3); |
| 1569 | if (!state->Subscript_type) return 0; |
| 1570 | state->Starred_type = make_type("Starred", state->expr_type, |
| 1571 | Starred_fields, 2); |
| 1572 | if (!state->Starred_type) return 0; |
| 1573 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2); |
| 1574 | if (!state->Name_type) return 0; |
| 1575 | state->List_type = make_type("List", state->expr_type, List_fields, 2); |
| 1576 | if (!state->List_type) return 0; |
| 1577 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2); |
| 1578 | if (!state->Tuple_type) return 0; |
| 1579 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
| 1580 | 0); |
| 1581 | if (!state->expr_context_type) return 0; |
| 1582 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
| 1583 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0); |
| 1584 | if (!state->Load_type) return 0; |
| 1585 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1586 | NULL, NULL); |
| 1587 | if (!state->Load_singleton) return 0; |
| 1588 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0); |
| 1589 | if (!state->Store_type) return 0; |
| 1590 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1591 | *)state->Store_type, NULL, NULL); |
| 1592 | if (!state->Store_singleton) return 0; |
| 1593 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0); |
| 1594 | if (!state->Del_type) return 0; |
| 1595 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1596 | NULL, NULL); |
| 1597 | if (!state->Del_singleton) return 0; |
| 1598 | state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL, |
| 1599 | 0); |
| 1600 | if (!state->AugLoad_type) return 0; |
| 1601 | state->AugLoad_singleton = PyType_GenericNew((PyTypeObject |
| 1602 | *)state->AugLoad_type, NULL, |
| 1603 | NULL); |
| 1604 | if (!state->AugLoad_singleton) return 0; |
| 1605 | state->AugStore_type = make_type("AugStore", state->expr_context_type, |
| 1606 | NULL, 0); |
| 1607 | if (!state->AugStore_type) return 0; |
| 1608 | state->AugStore_singleton = PyType_GenericNew((PyTypeObject |
| 1609 | *)state->AugStore_type, NULL, |
| 1610 | NULL); |
| 1611 | if (!state->AugStore_singleton) return 0; |
| 1612 | state->Param_type = make_type("Param", state->expr_context_type, NULL, 0); |
| 1613 | if (!state->Param_type) return 0; |
| 1614 | state->Param_singleton = PyType_GenericNew((PyTypeObject |
| 1615 | *)state->Param_type, NULL, NULL); |
| 1616 | if (!state->Param_singleton) return 0; |
| 1617 | state->slice_type = make_type("slice", state->AST_type, NULL, 0); |
| 1618 | if (!state->slice_type) return 0; |
| 1619 | if (!add_attributes(state->slice_type, NULL, 0)) return 0; |
| 1620 | state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3); |
| 1621 | if (!state->Slice_type) return 0; |
| 1622 | state->ExtSlice_type = make_type("ExtSlice", state->slice_type, |
| 1623 | ExtSlice_fields, 1); |
| 1624 | if (!state->ExtSlice_type) return 0; |
| 1625 | state->Index_type = make_type("Index", state->slice_type, Index_fields, 1); |
| 1626 | if (!state->Index_type) return 0; |
| 1627 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0); |
| 1628 | if (!state->boolop_type) return 0; |
| 1629 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
| 1630 | state->And_type = make_type("And", state->boolop_type, NULL, 0); |
| 1631 | if (!state->And_type) return 0; |
| 1632 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1633 | NULL, NULL); |
| 1634 | if (!state->And_singleton) return 0; |
| 1635 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0); |
| 1636 | if (!state->Or_type) return 0; |
| 1637 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1638 | NULL, NULL); |
| 1639 | if (!state->Or_singleton) return 0; |
| 1640 | state->operator_type = make_type("operator", state->AST_type, NULL, 0); |
| 1641 | if (!state->operator_type) return 0; |
| 1642 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
| 1643 | state->Add_type = make_type("Add", state->operator_type, NULL, 0); |
| 1644 | if (!state->Add_type) return 0; |
| 1645 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1646 | NULL, NULL); |
| 1647 | if (!state->Add_singleton) return 0; |
| 1648 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0); |
| 1649 | if (!state->Sub_type) return 0; |
| 1650 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1651 | NULL, NULL); |
| 1652 | if (!state->Sub_singleton) return 0; |
| 1653 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0); |
| 1654 | if (!state->Mult_type) return 0; |
| 1655 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1656 | NULL, NULL); |
| 1657 | if (!state->Mult_singleton) return 0; |
| 1658 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0); |
| 1659 | if (!state->MatMult_type) return 0; |
| 1660 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1661 | *)state->MatMult_type, NULL, |
| 1662 | NULL); |
| 1663 | if (!state->MatMult_singleton) return 0; |
| 1664 | state->Div_type = make_type("Div", state->operator_type, NULL, 0); |
| 1665 | if (!state->Div_type) return 0; |
| 1666 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1667 | NULL, NULL); |
| 1668 | if (!state->Div_singleton) return 0; |
| 1669 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0); |
| 1670 | if (!state->Mod_type) return 0; |
| 1671 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1672 | NULL, NULL); |
| 1673 | if (!state->Mod_singleton) return 0; |
| 1674 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0); |
| 1675 | if (!state->Pow_type) return 0; |
| 1676 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1677 | NULL, NULL); |
| 1678 | if (!state->Pow_singleton) return 0; |
| 1679 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0); |
| 1680 | if (!state->LShift_type) return 0; |
| 1681 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1682 | *)state->LShift_type, NULL, |
| 1683 | NULL); |
| 1684 | if (!state->LShift_singleton) return 0; |
| 1685 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0); |
| 1686 | if (!state->RShift_type) return 0; |
| 1687 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1688 | *)state->RShift_type, NULL, |
| 1689 | NULL); |
| 1690 | if (!state->RShift_singleton) return 0; |
| 1691 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0); |
| 1692 | if (!state->BitOr_type) return 0; |
| 1693 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1694 | *)state->BitOr_type, NULL, NULL); |
| 1695 | if (!state->BitOr_singleton) return 0; |
| 1696 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0); |
| 1697 | if (!state->BitXor_type) return 0; |
| 1698 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1699 | *)state->BitXor_type, NULL, |
| 1700 | NULL); |
| 1701 | if (!state->BitXor_singleton) return 0; |
| 1702 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0); |
| 1703 | if (!state->BitAnd_type) return 0; |
| 1704 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1705 | *)state->BitAnd_type, NULL, |
| 1706 | NULL); |
| 1707 | if (!state->BitAnd_singleton) return 0; |
| 1708 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0); |
| 1709 | if (!state->FloorDiv_type) return 0; |
| 1710 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1711 | *)state->FloorDiv_type, NULL, |
| 1712 | NULL); |
| 1713 | if (!state->FloorDiv_singleton) return 0; |
| 1714 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0); |
| 1715 | if (!state->unaryop_type) return 0; |
| 1716 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
| 1717 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0); |
| 1718 | if (!state->Invert_type) return 0; |
| 1719 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1720 | *)state->Invert_type, NULL, |
| 1721 | NULL); |
| 1722 | if (!state->Invert_singleton) return 0; |
| 1723 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0); |
| 1724 | if (!state->Not_type) return 0; |
| 1725 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1726 | NULL, NULL); |
| 1727 | if (!state->Not_singleton) return 0; |
| 1728 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0); |
| 1729 | if (!state->UAdd_type) return 0; |
| 1730 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1731 | NULL, NULL); |
| 1732 | if (!state->UAdd_singleton) return 0; |
| 1733 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0); |
| 1734 | if (!state->USub_type) return 0; |
| 1735 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1736 | NULL, NULL); |
| 1737 | if (!state->USub_singleton) return 0; |
| 1738 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0); |
| 1739 | if (!state->cmpop_type) return 0; |
| 1740 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
| 1741 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0); |
| 1742 | if (!state->Eq_type) return 0; |
| 1743 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1744 | NULL, NULL); |
| 1745 | if (!state->Eq_singleton) return 0; |
| 1746 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0); |
| 1747 | if (!state->NotEq_type) return 0; |
| 1748 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1749 | *)state->NotEq_type, NULL, NULL); |
| 1750 | if (!state->NotEq_singleton) return 0; |
| 1751 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0); |
| 1752 | if (!state->Lt_type) return 0; |
| 1753 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1754 | NULL, NULL); |
| 1755 | if (!state->Lt_singleton) return 0; |
| 1756 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0); |
| 1757 | if (!state->LtE_type) return 0; |
| 1758 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1759 | NULL, NULL); |
| 1760 | if (!state->LtE_singleton) return 0; |
| 1761 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0); |
| 1762 | if (!state->Gt_type) return 0; |
| 1763 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1764 | NULL, NULL); |
| 1765 | if (!state->Gt_singleton) return 0; |
| 1766 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0); |
| 1767 | if (!state->GtE_type) return 0; |
| 1768 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1769 | NULL, NULL); |
| 1770 | if (!state->GtE_singleton) return 0; |
| 1771 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0); |
| 1772 | if (!state->Is_type) return 0; |
| 1773 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1774 | NULL, NULL); |
| 1775 | if (!state->Is_singleton) return 0; |
| 1776 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0); |
| 1777 | if (!state->IsNot_type) return 0; |
| 1778 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1779 | *)state->IsNot_type, NULL, NULL); |
| 1780 | if (!state->IsNot_singleton) return 0; |
| 1781 | state->In_type = make_type("In", state->cmpop_type, NULL, 0); |
| 1782 | if (!state->In_type) return 0; |
| 1783 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1784 | NULL, NULL); |
| 1785 | if (!state->In_singleton) return 0; |
| 1786 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0); |
| 1787 | if (!state->NotIn_type) return 0; |
| 1788 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1789 | *)state->NotIn_type, NULL, NULL); |
| 1790 | if (!state->NotIn_singleton) return 0; |
| 1791 | state->comprehension_type = make_type("comprehension", state->AST_type, |
| 1792 | comprehension_fields, 4); |
| 1793 | if (!state->comprehension_type) return 0; |
| 1794 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1795 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
| 1796 | NULL, 0); |
| 1797 | if (!state->excepthandler_type) return 0; |
| 1798 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1799 | 4)) return 0; |
| 1800 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1801 | state->excepthandler_type, |
| 1802 | ExceptHandler_fields, 3); |
| 1803 | if (!state->ExceptHandler_type) return 0; |
| 1804 | state->arguments_type = make_type("arguments", state->AST_type, |
| 1805 | arguments_fields, 7); |
| 1806 | if (!state->arguments_type) return 0; |
| 1807 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
| 1808 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3); |
| 1809 | if (!state->arg_type) return 0; |
| 1810 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
| 1811 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
| 1812 | 2); |
| 1813 | if (!state->keyword_type) return 0; |
| 1814 | if (!add_attributes(state->keyword_type, NULL, 0)) return 0; |
| 1815 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2); |
| 1816 | if (!state->alias_type) return 0; |
| 1817 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
| 1818 | state->withitem_type = make_type("withitem", state->AST_type, |
| 1819 | withitem_fields, 2); |
| 1820 | if (!state->withitem_type) return 0; |
| 1821 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
| 1822 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, |
| 1823 | 0); |
| 1824 | if (!state->type_ignore_type) return 0; |
| 1825 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 1826 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
| 1827 | TypeIgnore_fields, 2); |
| 1828 | if (!state->TypeIgnore_type) return 0; |
| 1829 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1830 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1831 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1832 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1833 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1834 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1835 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1836 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1837 | arena); |
| 1838 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1839 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1840 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1841 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1842 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1843 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1844 | arena); |
| 1845 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1846 | arena); |
| 1847 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1848 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1849 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1850 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1851 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1852 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1853 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1854 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1855 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1856 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1857 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1858 | mod_ty p; |
| 1859 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1860 | if (!p) |
| 1861 | return NULL; |
| 1862 | p->kind = Module_kind; |
| 1863 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1864 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1865 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1869 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1870 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1871 | mod_ty p; |
| 1872 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1873 | if (!p) |
| 1874 | return NULL; |
| 1875 | p->kind = Interactive_kind; |
| 1876 | p->v.Interactive.body = body; |
| 1877 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1881 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1882 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1883 | mod_ty p; |
| 1884 | if (!body) { |
| 1885 | PyErr_SetString(PyExc_ValueError, |
| 1886 | "field body is required for Expression"); |
| 1887 | return NULL; |
| 1888 | } |
| 1889 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1890 | if (!p) |
| 1891 | return NULL; |
| 1892 | p->kind = Expression_kind; |
| 1893 | p->v.Expression.body = body; |
| 1894 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1898 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1899 | { |
| 1900 | mod_ty p; |
| 1901 | if (!returns) { |
| 1902 | PyErr_SetString(PyExc_ValueError, |
| 1903 | "field returns is required for FunctionType"); |
| 1904 | return NULL; |
| 1905 | } |
| 1906 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1907 | if (!p) |
| 1908 | return NULL; |
| 1909 | p->kind = FunctionType_kind; |
| 1910 | p->v.FunctionType.argtypes = argtypes; |
| 1911 | p->v.FunctionType.returns = returns; |
| 1912 | return p; |
| 1913 | } |
| 1914 | |
| 1915 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1916 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1917 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1918 | mod_ty p; |
| 1919 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1920 | if (!p) |
| 1921 | return NULL; |
| 1922 | p->kind = Suite_kind; |
| 1923 | p->v.Suite.body = body; |
| 1924 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | stmt_ty |
| 1928 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1929 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 1930 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1931 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1932 | stmt_ty p; |
| 1933 | if (!name) { |
| 1934 | PyErr_SetString(PyExc_ValueError, |
| 1935 | "field name is required for FunctionDef"); |
| 1936 | return NULL; |
| 1937 | } |
| 1938 | if (!args) { |
| 1939 | PyErr_SetString(PyExc_ValueError, |
| 1940 | "field args is required for FunctionDef"); |
| 1941 | return NULL; |
| 1942 | } |
| 1943 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1944 | if (!p) |
| 1945 | return NULL; |
| 1946 | p->kind = FunctionDef_kind; |
| 1947 | p->v.FunctionDef.name = name; |
| 1948 | p->v.FunctionDef.args = args; |
| 1949 | p->v.FunctionDef.body = body; |
| 1950 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1951 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1952 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1953 | p->lineno = lineno; |
| 1954 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1955 | p->end_lineno = end_lineno; |
| 1956 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1957 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1961 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1962 | * decorator_list, expr_ty returns, string type_comment, int |
| 1963 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1964 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1965 | { |
| 1966 | stmt_ty p; |
| 1967 | if (!name) { |
| 1968 | PyErr_SetString(PyExc_ValueError, |
| 1969 | "field name is required for AsyncFunctionDef"); |
| 1970 | return NULL; |
| 1971 | } |
| 1972 | if (!args) { |
| 1973 | PyErr_SetString(PyExc_ValueError, |
| 1974 | "field args is required for AsyncFunctionDef"); |
| 1975 | return NULL; |
| 1976 | } |
| 1977 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1978 | if (!p) |
| 1979 | return NULL; |
| 1980 | p->kind = AsyncFunctionDef_kind; |
| 1981 | p->v.AsyncFunctionDef.name = name; |
| 1982 | p->v.AsyncFunctionDef.args = args; |
| 1983 | p->v.AsyncFunctionDef.body = body; |
| 1984 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1985 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1986 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1987 | p->lineno = lineno; |
| 1988 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1989 | p->end_lineno = end_lineno; |
| 1990 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1991 | return p; |
| 1992 | } |
| 1993 | |
| 1994 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1995 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1996 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 1997 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1998 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1999 | stmt_ty p; |
| 2000 | if (!name) { |
| 2001 | PyErr_SetString(PyExc_ValueError, |
| 2002 | "field name is required for ClassDef"); |
| 2003 | return NULL; |
| 2004 | } |
| 2005 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2006 | if (!p) |
| 2007 | return NULL; |
| 2008 | p->kind = ClassDef_kind; |
| 2009 | p->v.ClassDef.name = name; |
| 2010 | p->v.ClassDef.bases = bases; |
| 2011 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2012 | p->v.ClassDef.body = body; |
| 2013 | p->v.ClassDef.decorator_list = decorator_list; |
| 2014 | p->lineno = lineno; |
| 2015 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2016 | p->end_lineno = end_lineno; |
| 2017 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2018 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2022 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2023 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2024 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2025 | stmt_ty p; |
| 2026 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2027 | if (!p) |
| 2028 | return NULL; |
| 2029 | p->kind = Return_kind; |
| 2030 | p->v.Return.value = value; |
| 2031 | p->lineno = lineno; |
| 2032 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2033 | p->end_lineno = end_lineno; |
| 2034 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2035 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2039 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2040 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2041 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2042 | stmt_ty p; |
| 2043 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2044 | if (!p) |
| 2045 | return NULL; |
| 2046 | p->kind = Delete_kind; |
| 2047 | p->v.Delete.targets = targets; |
| 2048 | p->lineno = lineno; |
| 2049 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2050 | p->end_lineno = end_lineno; |
| 2051 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2052 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2056 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2057 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2058 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2059 | stmt_ty p; |
| 2060 | if (!value) { |
| 2061 | PyErr_SetString(PyExc_ValueError, |
| 2062 | "field value is required for Assign"); |
| 2063 | return NULL; |
| 2064 | } |
| 2065 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2066 | if (!p) |
| 2067 | return NULL; |
| 2068 | p->kind = Assign_kind; |
| 2069 | p->v.Assign.targets = targets; |
| 2070 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2071 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2072 | p->lineno = lineno; |
| 2073 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2074 | p->end_lineno = end_lineno; |
| 2075 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2076 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2080 | 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] | 2081 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2082 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2083 | stmt_ty p; |
| 2084 | if (!target) { |
| 2085 | PyErr_SetString(PyExc_ValueError, |
| 2086 | "field target is required for AugAssign"); |
| 2087 | return NULL; |
| 2088 | } |
| 2089 | if (!op) { |
| 2090 | PyErr_SetString(PyExc_ValueError, |
| 2091 | "field op is required for AugAssign"); |
| 2092 | return NULL; |
| 2093 | } |
| 2094 | if (!value) { |
| 2095 | PyErr_SetString(PyExc_ValueError, |
| 2096 | "field value is required for AugAssign"); |
| 2097 | return NULL; |
| 2098 | } |
| 2099 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2100 | if (!p) |
| 2101 | return NULL; |
| 2102 | p->kind = AugAssign_kind; |
| 2103 | p->v.AugAssign.target = target; |
| 2104 | p->v.AugAssign.op = op; |
| 2105 | p->v.AugAssign.value = value; |
| 2106 | p->lineno = lineno; |
| 2107 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2108 | p->end_lineno = end_lineno; |
| 2109 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2110 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2114 | 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] | 2115 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2116 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2117 | { |
| 2118 | stmt_ty p; |
| 2119 | if (!target) { |
| 2120 | PyErr_SetString(PyExc_ValueError, |
| 2121 | "field target is required for AnnAssign"); |
| 2122 | return NULL; |
| 2123 | } |
| 2124 | if (!annotation) { |
| 2125 | PyErr_SetString(PyExc_ValueError, |
| 2126 | "field annotation is required for AnnAssign"); |
| 2127 | return NULL; |
| 2128 | } |
| 2129 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2130 | if (!p) |
| 2131 | return NULL; |
| 2132 | p->kind = AnnAssign_kind; |
| 2133 | p->v.AnnAssign.target = target; |
| 2134 | p->v.AnnAssign.annotation = annotation; |
| 2135 | p->v.AnnAssign.value = value; |
| 2136 | p->v.AnnAssign.simple = simple; |
| 2137 | p->lineno = lineno; |
| 2138 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2139 | p->end_lineno = end_lineno; |
| 2140 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2141 | return p; |
| 2142 | } |
| 2143 | |
| 2144 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2145 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2146 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2147 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2148 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2149 | stmt_ty p; |
| 2150 | if (!target) { |
| 2151 | PyErr_SetString(PyExc_ValueError, |
| 2152 | "field target is required for For"); |
| 2153 | return NULL; |
| 2154 | } |
| 2155 | if (!iter) { |
| 2156 | PyErr_SetString(PyExc_ValueError, |
| 2157 | "field iter is required for For"); |
| 2158 | return NULL; |
| 2159 | } |
| 2160 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2161 | if (!p) |
| 2162 | return NULL; |
| 2163 | p->kind = For_kind; |
| 2164 | p->v.For.target = target; |
| 2165 | p->v.For.iter = iter; |
| 2166 | p->v.For.body = body; |
| 2167 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2168 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2169 | p->lineno = lineno; |
| 2170 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2171 | p->end_lineno = end_lineno; |
| 2172 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2173 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2177 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2178 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2179 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2180 | { |
| 2181 | stmt_ty p; |
| 2182 | if (!target) { |
| 2183 | PyErr_SetString(PyExc_ValueError, |
| 2184 | "field target is required for AsyncFor"); |
| 2185 | return NULL; |
| 2186 | } |
| 2187 | if (!iter) { |
| 2188 | PyErr_SetString(PyExc_ValueError, |
| 2189 | "field iter is required for AsyncFor"); |
| 2190 | return NULL; |
| 2191 | } |
| 2192 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2193 | if (!p) |
| 2194 | return NULL; |
| 2195 | p->kind = AsyncFor_kind; |
| 2196 | p->v.AsyncFor.target = target; |
| 2197 | p->v.AsyncFor.iter = iter; |
| 2198 | p->v.AsyncFor.body = body; |
| 2199 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2200 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2201 | p->lineno = lineno; |
| 2202 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2203 | p->end_lineno = end_lineno; |
| 2204 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2205 | return p; |
| 2206 | } |
| 2207 | |
| 2208 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2209 | 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] | 2210 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2211 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2212 | stmt_ty p; |
| 2213 | if (!test) { |
| 2214 | PyErr_SetString(PyExc_ValueError, |
| 2215 | "field test is required for While"); |
| 2216 | return NULL; |
| 2217 | } |
| 2218 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2219 | if (!p) |
| 2220 | return NULL; |
| 2221 | p->kind = While_kind; |
| 2222 | p->v.While.test = test; |
| 2223 | p->v.While.body = body; |
| 2224 | p->v.While.orelse = orelse; |
| 2225 | p->lineno = lineno; |
| 2226 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2227 | p->end_lineno = end_lineno; |
| 2228 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2229 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2233 | 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] | 2234 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2235 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2236 | stmt_ty p; |
| 2237 | if (!test) { |
| 2238 | PyErr_SetString(PyExc_ValueError, |
| 2239 | "field test is required for If"); |
| 2240 | return NULL; |
| 2241 | } |
| 2242 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2243 | if (!p) |
| 2244 | return NULL; |
| 2245 | p->kind = If_kind; |
| 2246 | p->v.If.test = test; |
| 2247 | p->v.If.body = body; |
| 2248 | p->v.If.orelse = orelse; |
| 2249 | p->lineno = lineno; |
| 2250 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2251 | p->end_lineno = end_lineno; |
| 2252 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2253 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2257 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2258 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2259 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2260 | stmt_ty p; |
| 2261 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2262 | if (!p) |
| 2263 | return NULL; |
| 2264 | p->kind = With_kind; |
| 2265 | p->v.With.items = items; |
| 2266 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2267 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2268 | p->lineno = lineno; |
| 2269 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2270 | p->end_lineno = end_lineno; |
| 2271 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2272 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2276 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2277 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2278 | { |
| 2279 | stmt_ty p; |
| 2280 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2281 | if (!p) |
| 2282 | return NULL; |
| 2283 | p->kind = AsyncWith_kind; |
| 2284 | p->v.AsyncWith.items = items; |
| 2285 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2286 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2287 | p->lineno = lineno; |
| 2288 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2289 | p->end_lineno = end_lineno; |
| 2290 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2291 | return p; |
| 2292 | } |
| 2293 | |
| 2294 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2295 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2296 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2297 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2298 | stmt_ty p; |
| 2299 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2300 | if (!p) |
| 2301 | return NULL; |
| 2302 | p->kind = Raise_kind; |
| 2303 | p->v.Raise.exc = exc; |
| 2304 | p->v.Raise.cause = cause; |
| 2305 | p->lineno = lineno; |
| 2306 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2307 | p->end_lineno = end_lineno; |
| 2308 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2309 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2313 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2314 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2315 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2316 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2317 | stmt_ty p; |
| 2318 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2319 | if (!p) |
| 2320 | return NULL; |
| 2321 | p->kind = Try_kind; |
| 2322 | p->v.Try.body = body; |
| 2323 | p->v.Try.handlers = handlers; |
| 2324 | p->v.Try.orelse = orelse; |
| 2325 | p->v.Try.finalbody = finalbody; |
| 2326 | p->lineno = lineno; |
| 2327 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2328 | p->end_lineno = end_lineno; |
| 2329 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2330 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2334 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2335 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2336 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2337 | stmt_ty p; |
| 2338 | if (!test) { |
| 2339 | PyErr_SetString(PyExc_ValueError, |
| 2340 | "field test is required for Assert"); |
| 2341 | return NULL; |
| 2342 | } |
| 2343 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2344 | if (!p) |
| 2345 | return NULL; |
| 2346 | p->kind = Assert_kind; |
| 2347 | p->v.Assert.test = test; |
| 2348 | p->v.Assert.msg = msg; |
| 2349 | p->lineno = lineno; |
| 2350 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2351 | p->end_lineno = end_lineno; |
| 2352 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2353 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2357 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2358 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2359 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2360 | stmt_ty p; |
| 2361 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2362 | if (!p) |
| 2363 | return NULL; |
| 2364 | p->kind = Import_kind; |
| 2365 | p->v.Import.names = names; |
| 2366 | p->lineno = lineno; |
| 2367 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2368 | p->end_lineno = end_lineno; |
| 2369 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2370 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2374 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2375 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2376 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2377 | stmt_ty p; |
| 2378 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2379 | if (!p) |
| 2380 | return NULL; |
| 2381 | p->kind = ImportFrom_kind; |
| 2382 | p->v.ImportFrom.module = module; |
| 2383 | p->v.ImportFrom.names = names; |
| 2384 | p->v.ImportFrom.level = level; |
| 2385 | p->lineno = lineno; |
| 2386 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2387 | p->end_lineno = end_lineno; |
| 2388 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2389 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2393 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2394 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2395 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2396 | stmt_ty p; |
| 2397 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2398 | if (!p) |
| 2399 | return NULL; |
| 2400 | p->kind = Global_kind; |
| 2401 | p->v.Global.names = names; |
| 2402 | p->lineno = lineno; |
| 2403 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2404 | p->end_lineno = end_lineno; |
| 2405 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2406 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2410 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2411 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2412 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2413 | stmt_ty p; |
| 2414 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2415 | if (!p) |
| 2416 | return NULL; |
| 2417 | p->kind = Nonlocal_kind; |
| 2418 | p->v.Nonlocal.names = names; |
| 2419 | p->lineno = lineno; |
| 2420 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2421 | p->end_lineno = end_lineno; |
| 2422 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2423 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2427 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2428 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2429 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2430 | stmt_ty p; |
| 2431 | if (!value) { |
| 2432 | PyErr_SetString(PyExc_ValueError, |
| 2433 | "field value is required for Expr"); |
| 2434 | return NULL; |
| 2435 | } |
| 2436 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2437 | if (!p) |
| 2438 | return NULL; |
| 2439 | p->kind = Expr_kind; |
| 2440 | p->v.Expr.value = value; |
| 2441 | p->lineno = lineno; |
| 2442 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2443 | p->end_lineno = end_lineno; |
| 2444 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2445 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2449 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2450 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2451 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2452 | stmt_ty p; |
| 2453 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2454 | if (!p) |
| 2455 | return NULL; |
| 2456 | p->kind = Pass_kind; |
| 2457 | p->lineno = lineno; |
| 2458 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2459 | p->end_lineno = end_lineno; |
| 2460 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2461 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2465 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2466 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2467 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2468 | stmt_ty p; |
| 2469 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2470 | if (!p) |
| 2471 | return NULL; |
| 2472 | p->kind = Break_kind; |
| 2473 | p->lineno = lineno; |
| 2474 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2475 | p->end_lineno = end_lineno; |
| 2476 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2477 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2481 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2482 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2483 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2484 | stmt_ty p; |
| 2485 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2486 | if (!p) |
| 2487 | return NULL; |
| 2488 | p->kind = Continue_kind; |
| 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; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2493 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2497 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2498 | end_lineno, 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 | expr_ty p; |
| 2501 | if (!op) { |
| 2502 | PyErr_SetString(PyExc_ValueError, |
| 2503 | "field op is required for BoolOp"); |
| 2504 | return NULL; |
| 2505 | } |
| 2506 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2507 | if (!p) |
| 2508 | return NULL; |
| 2509 | p->kind = BoolOp_kind; |
| 2510 | p->v.BoolOp.op = op; |
| 2511 | p->v.BoolOp.values = values; |
| 2512 | p->lineno = lineno; |
| 2513 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2514 | p->end_lineno = end_lineno; |
| 2515 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2516 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2520 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2521 | end_lineno, int end_col_offset, PyArena *arena) |
| 2522 | { |
| 2523 | expr_ty p; |
| 2524 | if (!target) { |
| 2525 | PyErr_SetString(PyExc_ValueError, |
| 2526 | "field target is required for NamedExpr"); |
| 2527 | return NULL; |
| 2528 | } |
| 2529 | if (!value) { |
| 2530 | PyErr_SetString(PyExc_ValueError, |
| 2531 | "field value is required for NamedExpr"); |
| 2532 | return NULL; |
| 2533 | } |
| 2534 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2535 | if (!p) |
| 2536 | return NULL; |
| 2537 | p->kind = NamedExpr_kind; |
| 2538 | p->v.NamedExpr.target = target; |
| 2539 | p->v.NamedExpr.value = value; |
| 2540 | p->lineno = lineno; |
| 2541 | p->col_offset = col_offset; |
| 2542 | p->end_lineno = end_lineno; |
| 2543 | p->end_col_offset = end_col_offset; |
| 2544 | return p; |
| 2545 | } |
| 2546 | |
| 2547 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2548 | 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] | 2549 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2550 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2551 | expr_ty p; |
| 2552 | if (!left) { |
| 2553 | PyErr_SetString(PyExc_ValueError, |
| 2554 | "field left is required for BinOp"); |
| 2555 | return NULL; |
| 2556 | } |
| 2557 | if (!op) { |
| 2558 | PyErr_SetString(PyExc_ValueError, |
| 2559 | "field op is required for BinOp"); |
| 2560 | return NULL; |
| 2561 | } |
| 2562 | if (!right) { |
| 2563 | PyErr_SetString(PyExc_ValueError, |
| 2564 | "field right is required for BinOp"); |
| 2565 | return NULL; |
| 2566 | } |
| 2567 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2568 | if (!p) |
| 2569 | return NULL; |
| 2570 | p->kind = BinOp_kind; |
| 2571 | p->v.BinOp.left = left; |
| 2572 | p->v.BinOp.op = op; |
| 2573 | p->v.BinOp.right = right; |
| 2574 | p->lineno = lineno; |
| 2575 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2576 | p->end_lineno = end_lineno; |
| 2577 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2578 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2582 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2583 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2584 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2585 | expr_ty p; |
| 2586 | if (!op) { |
| 2587 | PyErr_SetString(PyExc_ValueError, |
| 2588 | "field op is required for UnaryOp"); |
| 2589 | return NULL; |
| 2590 | } |
| 2591 | if (!operand) { |
| 2592 | PyErr_SetString(PyExc_ValueError, |
| 2593 | "field operand is required for UnaryOp"); |
| 2594 | return NULL; |
| 2595 | } |
| 2596 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2597 | if (!p) |
| 2598 | return NULL; |
| 2599 | p->kind = UnaryOp_kind; |
| 2600 | p->v.UnaryOp.op = op; |
| 2601 | p->v.UnaryOp.operand = operand; |
| 2602 | p->lineno = lineno; |
| 2603 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2604 | p->end_lineno = end_lineno; |
| 2605 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2606 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2610 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2611 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2612 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2613 | expr_ty p; |
| 2614 | if (!args) { |
| 2615 | PyErr_SetString(PyExc_ValueError, |
| 2616 | "field args is required for Lambda"); |
| 2617 | return NULL; |
| 2618 | } |
| 2619 | if (!body) { |
| 2620 | PyErr_SetString(PyExc_ValueError, |
| 2621 | "field body is required for Lambda"); |
| 2622 | return NULL; |
| 2623 | } |
| 2624 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2625 | if (!p) |
| 2626 | return NULL; |
| 2627 | p->kind = Lambda_kind; |
| 2628 | p->v.Lambda.args = args; |
| 2629 | p->v.Lambda.body = body; |
| 2630 | p->lineno = lineno; |
| 2631 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2632 | p->end_lineno = end_lineno; |
| 2633 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2634 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2638 | 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] | 2639 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2640 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2641 | expr_ty p; |
| 2642 | if (!test) { |
| 2643 | PyErr_SetString(PyExc_ValueError, |
| 2644 | "field test is required for IfExp"); |
| 2645 | return NULL; |
| 2646 | } |
| 2647 | if (!body) { |
| 2648 | PyErr_SetString(PyExc_ValueError, |
| 2649 | "field body is required for IfExp"); |
| 2650 | return NULL; |
| 2651 | } |
| 2652 | if (!orelse) { |
| 2653 | PyErr_SetString(PyExc_ValueError, |
| 2654 | "field orelse is required for IfExp"); |
| 2655 | return NULL; |
| 2656 | } |
| 2657 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2658 | if (!p) |
| 2659 | return NULL; |
| 2660 | p->kind = IfExp_kind; |
| 2661 | p->v.IfExp.test = test; |
| 2662 | p->v.IfExp.body = body; |
| 2663 | p->v.IfExp.orelse = orelse; |
| 2664 | p->lineno = lineno; |
| 2665 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2666 | p->end_lineno = end_lineno; |
| 2667 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2668 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2672 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2673 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2674 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2675 | expr_ty p; |
| 2676 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2677 | if (!p) |
| 2678 | return NULL; |
| 2679 | p->kind = Dict_kind; |
| 2680 | p->v.Dict.keys = keys; |
| 2681 | p->v.Dict.values = values; |
| 2682 | p->lineno = lineno; |
| 2683 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2684 | p->end_lineno = end_lineno; |
| 2685 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2686 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2690 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2691 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2692 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2693 | expr_ty p; |
| 2694 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2695 | if (!p) |
| 2696 | return NULL; |
| 2697 | p->kind = Set_kind; |
| 2698 | p->v.Set.elts = elts; |
| 2699 | p->lineno = lineno; |
| 2700 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2701 | p->end_lineno = end_lineno; |
| 2702 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2703 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2707 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2708 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2709 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2710 | expr_ty p; |
| 2711 | if (!elt) { |
| 2712 | PyErr_SetString(PyExc_ValueError, |
| 2713 | "field elt is required for ListComp"); |
| 2714 | return NULL; |
| 2715 | } |
| 2716 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2717 | if (!p) |
| 2718 | return NULL; |
| 2719 | p->kind = ListComp_kind; |
| 2720 | p->v.ListComp.elt = elt; |
| 2721 | p->v.ListComp.generators = generators; |
| 2722 | p->lineno = lineno; |
| 2723 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2724 | p->end_lineno = end_lineno; |
| 2725 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2726 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2730 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2731 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2732 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2733 | expr_ty p; |
| 2734 | if (!elt) { |
| 2735 | PyErr_SetString(PyExc_ValueError, |
| 2736 | "field elt is required for SetComp"); |
| 2737 | return NULL; |
| 2738 | } |
| 2739 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2740 | if (!p) |
| 2741 | return NULL; |
| 2742 | p->kind = SetComp_kind; |
| 2743 | p->v.SetComp.elt = elt; |
| 2744 | p->v.SetComp.generators = generators; |
| 2745 | p->lineno = lineno; |
| 2746 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2747 | p->end_lineno = end_lineno; |
| 2748 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2749 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2753 | 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] | 2754 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2755 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2756 | expr_ty p; |
| 2757 | if (!key) { |
| 2758 | PyErr_SetString(PyExc_ValueError, |
| 2759 | "field key is required for DictComp"); |
| 2760 | return NULL; |
| 2761 | } |
| 2762 | if (!value) { |
| 2763 | PyErr_SetString(PyExc_ValueError, |
| 2764 | "field value is required for DictComp"); |
| 2765 | return NULL; |
| 2766 | } |
| 2767 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2768 | if (!p) |
| 2769 | return NULL; |
| 2770 | p->kind = DictComp_kind; |
| 2771 | p->v.DictComp.key = key; |
| 2772 | p->v.DictComp.value = value; |
| 2773 | p->v.DictComp.generators = generators; |
| 2774 | p->lineno = lineno; |
| 2775 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2776 | p->end_lineno = end_lineno; |
| 2777 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2778 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2782 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2783 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2784 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2785 | expr_ty p; |
| 2786 | if (!elt) { |
| 2787 | PyErr_SetString(PyExc_ValueError, |
| 2788 | "field elt is required for GeneratorExp"); |
| 2789 | return NULL; |
| 2790 | } |
| 2791 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2792 | if (!p) |
| 2793 | return NULL; |
| 2794 | p->kind = GeneratorExp_kind; |
| 2795 | p->v.GeneratorExp.elt = elt; |
| 2796 | p->v.GeneratorExp.generators = generators; |
| 2797 | p->lineno = lineno; |
| 2798 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2799 | p->end_lineno = end_lineno; |
| 2800 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2801 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2805 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2806 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2807 | { |
| 2808 | expr_ty p; |
| 2809 | if (!value) { |
| 2810 | PyErr_SetString(PyExc_ValueError, |
| 2811 | "field value is required for Await"); |
| 2812 | return NULL; |
| 2813 | } |
| 2814 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2815 | if (!p) |
| 2816 | return NULL; |
| 2817 | p->kind = Await_kind; |
| 2818 | p->v.Await.value = value; |
| 2819 | p->lineno = lineno; |
| 2820 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2821 | p->end_lineno = end_lineno; |
| 2822 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2823 | return p; |
| 2824 | } |
| 2825 | |
| 2826 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2827 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2828 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2829 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2830 | expr_ty p; |
| 2831 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2832 | if (!p) |
| 2833 | return NULL; |
| 2834 | p->kind = Yield_kind; |
| 2835 | p->v.Yield.value = value; |
| 2836 | p->lineno = lineno; |
| 2837 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2838 | p->end_lineno = end_lineno; |
| 2839 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2840 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2844 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2845 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2846 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2847 | expr_ty p; |
| 2848 | if (!value) { |
| 2849 | PyErr_SetString(PyExc_ValueError, |
| 2850 | "field value is required for YieldFrom"); |
| 2851 | return NULL; |
| 2852 | } |
| 2853 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2854 | if (!p) |
| 2855 | return NULL; |
| 2856 | p->kind = YieldFrom_kind; |
| 2857 | p->v.YieldFrom.value = value; |
| 2858 | p->lineno = lineno; |
| 2859 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2860 | p->end_lineno = end_lineno; |
| 2861 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2862 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2866 | 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] | 2867 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2868 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2869 | expr_ty p; |
| 2870 | if (!left) { |
| 2871 | PyErr_SetString(PyExc_ValueError, |
| 2872 | "field left is required for Compare"); |
| 2873 | return NULL; |
| 2874 | } |
| 2875 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2876 | if (!p) |
| 2877 | return NULL; |
| 2878 | p->kind = Compare_kind; |
| 2879 | p->v.Compare.left = left; |
| 2880 | p->v.Compare.ops = ops; |
| 2881 | p->v.Compare.comparators = comparators; |
| 2882 | p->lineno = lineno; |
| 2883 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2884 | p->end_lineno = end_lineno; |
| 2885 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2886 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2890 | 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] | 2891 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2892 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2893 | expr_ty p; |
| 2894 | if (!func) { |
| 2895 | PyErr_SetString(PyExc_ValueError, |
| 2896 | "field func is required for Call"); |
| 2897 | return NULL; |
| 2898 | } |
| 2899 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2900 | if (!p) |
| 2901 | return NULL; |
| 2902 | p->kind = Call_kind; |
| 2903 | p->v.Call.func = func; |
| 2904 | p->v.Call.args = args; |
| 2905 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2906 | p->lineno = lineno; |
| 2907 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2908 | p->end_lineno = end_lineno; |
| 2909 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2910 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 2914 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2915 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2916 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2917 | { |
| 2918 | expr_ty p; |
| 2919 | if (!value) { |
| 2920 | PyErr_SetString(PyExc_ValueError, |
| 2921 | "field value is required for FormattedValue"); |
| 2922 | return NULL; |
| 2923 | } |
| 2924 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2925 | if (!p) |
| 2926 | return NULL; |
| 2927 | p->kind = FormattedValue_kind; |
| 2928 | p->v.FormattedValue.value = value; |
| 2929 | p->v.FormattedValue.conversion = conversion; |
| 2930 | p->v.FormattedValue.format_spec = format_spec; |
| 2931 | p->lineno = lineno; |
| 2932 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2933 | p->end_lineno = end_lineno; |
| 2934 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2935 | return p; |
| 2936 | } |
| 2937 | |
| 2938 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2939 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2940 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2941 | { |
| 2942 | expr_ty p; |
| 2943 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2944 | if (!p) |
| 2945 | return NULL; |
| 2946 | p->kind = JoinedStr_kind; |
| 2947 | p->v.JoinedStr.values = values; |
| 2948 | p->lineno = lineno; |
| 2949 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2950 | p->end_lineno = end_lineno; |
| 2951 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2952 | return p; |
| 2953 | } |
| 2954 | |
| 2955 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2956 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 2957 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2958 | { |
| 2959 | expr_ty p; |
| 2960 | if (!value) { |
| 2961 | PyErr_SetString(PyExc_ValueError, |
| 2962 | "field value is required for Constant"); |
| 2963 | return NULL; |
| 2964 | } |
| 2965 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2966 | if (!p) |
| 2967 | return NULL; |
| 2968 | p->kind = Constant_kind; |
| 2969 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2970 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2971 | p->lineno = lineno; |
| 2972 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2973 | p->end_lineno = end_lineno; |
| 2974 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2975 | return p; |
| 2976 | } |
| 2977 | |
| 2978 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2979 | 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] | 2980 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2981 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2982 | expr_ty p; |
| 2983 | if (!value) { |
| 2984 | PyErr_SetString(PyExc_ValueError, |
| 2985 | "field value is required for Attribute"); |
| 2986 | return NULL; |
| 2987 | } |
| 2988 | if (!attr) { |
| 2989 | PyErr_SetString(PyExc_ValueError, |
| 2990 | "field attr is required for Attribute"); |
| 2991 | return NULL; |
| 2992 | } |
| 2993 | if (!ctx) { |
| 2994 | PyErr_SetString(PyExc_ValueError, |
| 2995 | "field ctx is required for Attribute"); |
| 2996 | return NULL; |
| 2997 | } |
| 2998 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2999 | if (!p) |
| 3000 | return NULL; |
| 3001 | p->kind = Attribute_kind; |
| 3002 | p->v.Attribute.value = value; |
| 3003 | p->v.Attribute.attr = attr; |
| 3004 | p->v.Attribute.ctx = ctx; |
| 3005 | p->lineno = lineno; |
| 3006 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3007 | p->end_lineno = end_lineno; |
| 3008 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3009 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3013 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3014 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3015 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3016 | expr_ty p; |
| 3017 | if (!value) { |
| 3018 | PyErr_SetString(PyExc_ValueError, |
| 3019 | "field value is required for Subscript"); |
| 3020 | return NULL; |
| 3021 | } |
| 3022 | if (!slice) { |
| 3023 | PyErr_SetString(PyExc_ValueError, |
| 3024 | "field slice is required for Subscript"); |
| 3025 | return NULL; |
| 3026 | } |
| 3027 | if (!ctx) { |
| 3028 | PyErr_SetString(PyExc_ValueError, |
| 3029 | "field ctx is required for Subscript"); |
| 3030 | return NULL; |
| 3031 | } |
| 3032 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3033 | if (!p) |
| 3034 | return NULL; |
| 3035 | p->kind = Subscript_kind; |
| 3036 | p->v.Subscript.value = value; |
| 3037 | p->v.Subscript.slice = slice; |
| 3038 | p->v.Subscript.ctx = ctx; |
| 3039 | p->lineno = lineno; |
| 3040 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3041 | p->end_lineno = end_lineno; |
| 3042 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3043 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3047 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3048 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3049 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3050 | expr_ty p; |
| 3051 | if (!value) { |
| 3052 | PyErr_SetString(PyExc_ValueError, |
| 3053 | "field value is required for Starred"); |
| 3054 | return NULL; |
| 3055 | } |
| 3056 | if (!ctx) { |
| 3057 | PyErr_SetString(PyExc_ValueError, |
| 3058 | "field ctx is required for Starred"); |
| 3059 | return NULL; |
| 3060 | } |
| 3061 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3062 | if (!p) |
| 3063 | return NULL; |
| 3064 | p->kind = Starred_kind; |
| 3065 | p->v.Starred.value = value; |
| 3066 | p->v.Starred.ctx = ctx; |
| 3067 | p->lineno = lineno; |
| 3068 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3069 | p->end_lineno = end_lineno; |
| 3070 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3071 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3075 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3076 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3077 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3078 | expr_ty p; |
| 3079 | if (!id) { |
| 3080 | PyErr_SetString(PyExc_ValueError, |
| 3081 | "field id is required for Name"); |
| 3082 | return NULL; |
| 3083 | } |
| 3084 | if (!ctx) { |
| 3085 | PyErr_SetString(PyExc_ValueError, |
| 3086 | "field ctx is required for Name"); |
| 3087 | return NULL; |
| 3088 | } |
| 3089 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3090 | if (!p) |
| 3091 | return NULL; |
| 3092 | p->kind = Name_kind; |
| 3093 | p->v.Name.id = id; |
| 3094 | p->v.Name.ctx = ctx; |
| 3095 | p->lineno = lineno; |
| 3096 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3097 | p->end_lineno = end_lineno; |
| 3098 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3099 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3103 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3104 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3105 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3106 | expr_ty p; |
| 3107 | if (!ctx) { |
| 3108 | PyErr_SetString(PyExc_ValueError, |
| 3109 | "field ctx is required for List"); |
| 3110 | return NULL; |
| 3111 | } |
| 3112 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3113 | if (!p) |
| 3114 | return NULL; |
| 3115 | p->kind = List_kind; |
| 3116 | p->v.List.elts = elts; |
| 3117 | p->v.List.ctx = ctx; |
| 3118 | p->lineno = lineno; |
| 3119 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3120 | p->end_lineno = end_lineno; |
| 3121 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3122 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3126 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3127 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3128 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3129 | expr_ty p; |
| 3130 | if (!ctx) { |
| 3131 | PyErr_SetString(PyExc_ValueError, |
| 3132 | "field ctx is required for Tuple"); |
| 3133 | return NULL; |
| 3134 | } |
| 3135 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3136 | if (!p) |
| 3137 | return NULL; |
| 3138 | p->kind = Tuple_kind; |
| 3139 | p->v.Tuple.elts = elts; |
| 3140 | p->v.Tuple.ctx = ctx; |
| 3141 | p->lineno = lineno; |
| 3142 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3143 | p->end_lineno = end_lineno; |
| 3144 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3145 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3149 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3150 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3151 | slice_ty p; |
| 3152 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3153 | if (!p) |
| 3154 | return NULL; |
| 3155 | p->kind = Slice_kind; |
| 3156 | p->v.Slice.lower = lower; |
| 3157 | p->v.Slice.upper = upper; |
| 3158 | p->v.Slice.step = step; |
| 3159 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3163 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3164 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3165 | slice_ty p; |
| 3166 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3167 | if (!p) |
| 3168 | return NULL; |
| 3169 | p->kind = ExtSlice_kind; |
| 3170 | p->v.ExtSlice.dims = dims; |
| 3171 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3175 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3176 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3177 | slice_ty p; |
| 3178 | if (!value) { |
| 3179 | PyErr_SetString(PyExc_ValueError, |
| 3180 | "field value is required for Index"); |
| 3181 | return NULL; |
| 3182 | } |
| 3183 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3184 | if (!p) |
| 3185 | return NULL; |
| 3186 | p->kind = Index_kind; |
| 3187 | p->v.Index.value = value; |
| 3188 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3192 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3193 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3194 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3195 | comprehension_ty p; |
| 3196 | if (!target) { |
| 3197 | PyErr_SetString(PyExc_ValueError, |
| 3198 | "field target is required for comprehension"); |
| 3199 | return NULL; |
| 3200 | } |
| 3201 | if (!iter) { |
| 3202 | PyErr_SetString(PyExc_ValueError, |
| 3203 | "field iter is required for comprehension"); |
| 3204 | return NULL; |
| 3205 | } |
| 3206 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3207 | if (!p) |
| 3208 | return NULL; |
| 3209 | p->target = target; |
| 3210 | p->iter = iter; |
| 3211 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3212 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3213 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3217 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3218 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3219 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3220 | excepthandler_ty p; |
| 3221 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3222 | if (!p) |
| 3223 | return NULL; |
| 3224 | p->kind = ExceptHandler_kind; |
| 3225 | p->v.ExceptHandler.type = type; |
| 3226 | p->v.ExceptHandler.name = name; |
| 3227 | p->v.ExceptHandler.body = body; |
| 3228 | p->lineno = lineno; |
| 3229 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3230 | p->end_lineno = end_lineno; |
| 3231 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3232 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3236 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3237 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3238 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3239 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3240 | arguments_ty p; |
| 3241 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3242 | if (!p) |
| 3243 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3244 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3245 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3246 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3247 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3248 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3249 | p->kwarg = kwarg; |
| 3250 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3251 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3252 | } |
| 3253 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3254 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3255 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3256 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3257 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3258 | arg_ty p; |
| 3259 | if (!arg) { |
| 3260 | PyErr_SetString(PyExc_ValueError, |
| 3261 | "field arg is required for arg"); |
| 3262 | return NULL; |
| 3263 | } |
| 3264 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3265 | if (!p) |
| 3266 | return NULL; |
| 3267 | p->arg = arg; |
| 3268 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3269 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3270 | p->lineno = lineno; |
| 3271 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3272 | p->end_lineno = end_lineno; |
| 3273 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3274 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3277 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3278 | keyword(identifier arg, expr_ty value, 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 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3281 | if (!value) { |
| 3282 | PyErr_SetString(PyExc_ValueError, |
| 3283 | "field value is required for keyword"); |
| 3284 | return NULL; |
| 3285 | } |
| 3286 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3287 | if (!p) |
| 3288 | return NULL; |
| 3289 | p->arg = arg; |
| 3290 | p->value = value; |
| 3291 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3295 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3296 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3297 | alias_ty p; |
| 3298 | if (!name) { |
| 3299 | PyErr_SetString(PyExc_ValueError, |
| 3300 | "field name is required for alias"); |
| 3301 | return NULL; |
| 3302 | } |
| 3303 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3304 | if (!p) |
| 3305 | return NULL; |
| 3306 | p->name = name; |
| 3307 | p->asname = asname; |
| 3308 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3311 | withitem_ty |
| 3312 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3313 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3314 | withitem_ty p; |
| 3315 | if (!context_expr) { |
| 3316 | PyErr_SetString(PyExc_ValueError, |
| 3317 | "field context_expr is required for withitem"); |
| 3318 | return NULL; |
| 3319 | } |
| 3320 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3321 | if (!p) |
| 3322 | return NULL; |
| 3323 | p->context_expr = context_expr; |
| 3324 | p->optional_vars = optional_vars; |
| 3325 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3326 | } |
| 3327 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3328 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3329 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3330 | { |
| 3331 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3332 | if (!tag) { |
| 3333 | PyErr_SetString(PyExc_ValueError, |
| 3334 | "field tag is required for TypeIgnore"); |
| 3335 | return NULL; |
| 3336 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3337 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3338 | if (!p) |
| 3339 | return NULL; |
| 3340 | p->kind = TypeIgnore_kind; |
| 3341 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3342 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3343 | return p; |
| 3344 | } |
| 3345 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3346 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3347 | PyObject* |
| 3348 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3349 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3350 | mod_ty o = (mod_ty)_o; |
| 3351 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3352 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3353 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3354 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3355 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3356 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3357 | switch (o->kind) { |
| 3358 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3359 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3360 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3361 | if (!result) goto failed; |
| 3362 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3363 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3364 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3365 | goto failed; |
| 3366 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3367 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3368 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3369 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3370 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3371 | goto failed; |
| 3372 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3373 | break; |
| 3374 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3375 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3376 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3377 | if (!result) goto failed; |
| 3378 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3379 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3380 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3381 | goto failed; |
| 3382 | Py_DECREF(value); |
| 3383 | break; |
| 3384 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3385 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3386 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3387 | if (!result) goto failed; |
| 3388 | value = ast2obj_expr(o->v.Expression.body); |
| 3389 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3390 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3391 | goto failed; |
| 3392 | Py_DECREF(value); |
| 3393 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3394 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3395 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3396 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3397 | if (!result) goto failed; |
| 3398 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3399 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3400 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3401 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3402 | goto failed; |
| 3403 | Py_DECREF(value); |
| 3404 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3405 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3406 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3407 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3408 | goto failed; |
| 3409 | Py_DECREF(value); |
| 3410 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3411 | case Suite_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3412 | tp = (PyTypeObject *)astmodulestate_global->Suite_type; |
| 3413 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3414 | if (!result) goto failed; |
| 3415 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 3416 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3417 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3418 | goto failed; |
| 3419 | Py_DECREF(value); |
| 3420 | break; |
| 3421 | } |
| 3422 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3423 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3424 | Py_XDECREF(value); |
| 3425 | Py_XDECREF(result); |
| 3426 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3427 | } |
| 3428 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3429 | PyObject* |
| 3430 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3431 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3432 | stmt_ty o = (stmt_ty)_o; |
| 3433 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3434 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3435 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3436 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3437 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3438 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3439 | switch (o->kind) { |
| 3440 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3441 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3442 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3443 | if (!result) goto failed; |
| 3444 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3445 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3446 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3447 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3448 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3449 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3450 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3451 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3452 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3453 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3454 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3455 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3456 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3457 | goto failed; |
| 3458 | Py_DECREF(value); |
| 3459 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3460 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3461 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3462 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3463 | goto failed; |
| 3464 | Py_DECREF(value); |
| 3465 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3466 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3467 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3468 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3469 | goto failed; |
| 3470 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3471 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3472 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3473 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3474 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3475 | goto failed; |
| 3476 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3477 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3478 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3479 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3480 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3481 | if (!result) goto failed; |
| 3482 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3483 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3484 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3485 | goto failed; |
| 3486 | Py_DECREF(value); |
| 3487 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3488 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3489 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3490 | goto failed; |
| 3491 | Py_DECREF(value); |
| 3492 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3493 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3494 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3495 | goto failed; |
| 3496 | Py_DECREF(value); |
| 3497 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3498 | ast2obj_expr); |
| 3499 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3500 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3501 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3502 | goto failed; |
| 3503 | Py_DECREF(value); |
| 3504 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3505 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3506 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3507 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3508 | goto failed; |
| 3509 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3510 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3511 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3512 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3513 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3514 | goto failed; |
| 3515 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3516 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3517 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3518 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3519 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3520 | if (!result) goto failed; |
| 3521 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3522 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3523 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3524 | goto failed; |
| 3525 | Py_DECREF(value); |
| 3526 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3527 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3528 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3529 | goto failed; |
| 3530 | Py_DECREF(value); |
| 3531 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3532 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3533 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3534 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3535 | goto failed; |
| 3536 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3537 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3538 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3539 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3540 | goto failed; |
| 3541 | Py_DECREF(value); |
| 3542 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3543 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3544 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3545 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3546 | goto failed; |
| 3547 | Py_DECREF(value); |
| 3548 | break; |
| 3549 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3550 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3551 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3552 | if (!result) goto failed; |
| 3553 | value = ast2obj_expr(o->v.Return.value); |
| 3554 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3555 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3556 | goto failed; |
| 3557 | Py_DECREF(value); |
| 3558 | break; |
| 3559 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3560 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3561 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3562 | if (!result) goto failed; |
| 3563 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3564 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3565 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3566 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3567 | goto failed; |
| 3568 | Py_DECREF(value); |
| 3569 | break; |
| 3570 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3571 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3572 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3573 | if (!result) goto failed; |
| 3574 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3575 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3576 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3577 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3578 | goto failed; |
| 3579 | Py_DECREF(value); |
| 3580 | value = ast2obj_expr(o->v.Assign.value); |
| 3581 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3582 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3583 | goto failed; |
| 3584 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3585 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3586 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3587 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3588 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3589 | goto failed; |
| 3590 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3591 | break; |
| 3592 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3593 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3594 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3595 | if (!result) goto failed; |
| 3596 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3597 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3598 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3599 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3600 | goto failed; |
| 3601 | Py_DECREF(value); |
| 3602 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3603 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3604 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3605 | goto failed; |
| 3606 | Py_DECREF(value); |
| 3607 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3608 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3609 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3610 | goto failed; |
| 3611 | Py_DECREF(value); |
| 3612 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3613 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3614 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3615 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3616 | if (!result) goto failed; |
| 3617 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3618 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3619 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3620 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3621 | goto failed; |
| 3622 | Py_DECREF(value); |
| 3623 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3624 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3625 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3626 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3627 | goto failed; |
| 3628 | Py_DECREF(value); |
| 3629 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3630 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3631 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3632 | goto failed; |
| 3633 | Py_DECREF(value); |
| 3634 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3635 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3636 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3637 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3638 | goto failed; |
| 3639 | Py_DECREF(value); |
| 3640 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3641 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3642 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3643 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3644 | if (!result) goto failed; |
| 3645 | value = ast2obj_expr(o->v.For.target); |
| 3646 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3647 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3648 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3649 | goto failed; |
| 3650 | Py_DECREF(value); |
| 3651 | value = ast2obj_expr(o->v.For.iter); |
| 3652 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3653 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3654 | goto failed; |
| 3655 | Py_DECREF(value); |
| 3656 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3657 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3658 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3659 | goto failed; |
| 3660 | Py_DECREF(value); |
| 3661 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3662 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3663 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3664 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3665 | goto failed; |
| 3666 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3667 | value = ast2obj_string(o->v.For.type_comment); |
| 3668 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3669 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3670 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3671 | goto failed; |
| 3672 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3673 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3674 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3675 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3676 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3677 | if (!result) goto failed; |
| 3678 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3679 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3680 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3681 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3682 | goto failed; |
| 3683 | Py_DECREF(value); |
| 3684 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3685 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3686 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3687 | goto failed; |
| 3688 | Py_DECREF(value); |
| 3689 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3690 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3691 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3692 | goto failed; |
| 3693 | Py_DECREF(value); |
| 3694 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3695 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3696 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3697 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3698 | goto failed; |
| 3699 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3700 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3701 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3702 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3703 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3704 | goto failed; |
| 3705 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3706 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3707 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3708 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3709 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3710 | if (!result) goto failed; |
| 3711 | value = ast2obj_expr(o->v.While.test); |
| 3712 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3713 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3714 | goto failed; |
| 3715 | Py_DECREF(value); |
| 3716 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3717 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3718 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3719 | goto failed; |
| 3720 | Py_DECREF(value); |
| 3721 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3722 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3723 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3724 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3725 | goto failed; |
| 3726 | Py_DECREF(value); |
| 3727 | break; |
| 3728 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3729 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3730 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3731 | if (!result) goto failed; |
| 3732 | value = ast2obj_expr(o->v.If.test); |
| 3733 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3734 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3735 | goto failed; |
| 3736 | Py_DECREF(value); |
| 3737 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3738 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3739 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3740 | goto failed; |
| 3741 | Py_DECREF(value); |
| 3742 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3743 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3744 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3745 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3746 | goto failed; |
| 3747 | Py_DECREF(value); |
| 3748 | break; |
| 3749 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3750 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3751 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3752 | if (!result) goto failed; |
| 3753 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3754 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3755 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3756 | goto failed; |
| 3757 | Py_DECREF(value); |
| 3758 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3759 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3760 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3761 | goto failed; |
| 3762 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3763 | value = ast2obj_string(o->v.With.type_comment); |
| 3764 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3765 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3766 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3767 | goto failed; |
| 3768 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3769 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3770 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3771 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3772 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3773 | if (!result) goto failed; |
| 3774 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3775 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3776 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3777 | goto failed; |
| 3778 | Py_DECREF(value); |
| 3779 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3780 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3781 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3782 | goto failed; |
| 3783 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3784 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3785 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3786 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3787 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3788 | goto failed; |
| 3789 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3790 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3791 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3792 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3793 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3794 | if (!result) goto failed; |
| 3795 | value = ast2obj_expr(o->v.Raise.exc); |
| 3796 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3797 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3798 | goto failed; |
| 3799 | Py_DECREF(value); |
| 3800 | value = ast2obj_expr(o->v.Raise.cause); |
| 3801 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3802 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3803 | goto failed; |
| 3804 | Py_DECREF(value); |
| 3805 | break; |
| 3806 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3807 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3808 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3809 | if (!result) goto failed; |
| 3810 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3811 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3812 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3813 | goto failed; |
| 3814 | Py_DECREF(value); |
| 3815 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3816 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3817 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3818 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3819 | goto failed; |
| 3820 | Py_DECREF(value); |
| 3821 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3822 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3823 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3824 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3825 | goto failed; |
| 3826 | Py_DECREF(value); |
| 3827 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3828 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3829 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3830 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3831 | goto failed; |
| 3832 | Py_DECREF(value); |
| 3833 | break; |
| 3834 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3835 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3836 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3837 | if (!result) goto failed; |
| 3838 | value = ast2obj_expr(o->v.Assert.test); |
| 3839 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3840 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3841 | goto failed; |
| 3842 | Py_DECREF(value); |
| 3843 | value = ast2obj_expr(o->v.Assert.msg); |
| 3844 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3845 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3846 | goto failed; |
| 3847 | Py_DECREF(value); |
| 3848 | break; |
| 3849 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3850 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 3851 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3852 | if (!result) goto failed; |
| 3853 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3854 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3855 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3856 | goto failed; |
| 3857 | Py_DECREF(value); |
| 3858 | break; |
| 3859 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3860 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 3861 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3862 | if (!result) goto failed; |
| 3863 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3864 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3865 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 3866 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3867 | goto failed; |
| 3868 | Py_DECREF(value); |
| 3869 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3870 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3871 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3872 | goto failed; |
| 3873 | Py_DECREF(value); |
| 3874 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3875 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3876 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3877 | goto failed; |
| 3878 | Py_DECREF(value); |
| 3879 | break; |
| 3880 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3881 | tp = (PyTypeObject *)astmodulestate_global->Global_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_list(o->v.Global.names, ast2obj_identifier); |
| 3885 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3886 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3887 | goto failed; |
| 3888 | Py_DECREF(value); |
| 3889 | break; |
| 3890 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3891 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 3892 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3893 | if (!result) goto failed; |
| 3894 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3895 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3896 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3897 | goto failed; |
| 3898 | Py_DECREF(value); |
| 3899 | break; |
| 3900 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3901 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 3902 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3903 | if (!result) goto failed; |
| 3904 | value = ast2obj_expr(o->v.Expr.value); |
| 3905 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3906 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | goto failed; |
| 3908 | Py_DECREF(value); |
| 3909 | break; |
| 3910 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3911 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 3912 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3913 | if (!result) goto failed; |
| 3914 | break; |
| 3915 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3916 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 3917 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3918 | if (!result) goto failed; |
| 3919 | break; |
| 3920 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3921 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 3922 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3923 | if (!result) goto failed; |
| 3924 | break; |
| 3925 | } |
| 3926 | value = ast2obj_int(o->lineno); |
| 3927 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3928 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3929 | goto failed; |
| 3930 | Py_DECREF(value); |
| 3931 | value = ast2obj_int(o->col_offset); |
| 3932 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3933 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3934 | goto failed; |
| 3935 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3936 | value = ast2obj_int(o->end_lineno); |
| 3937 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3938 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3939 | goto failed; |
| 3940 | Py_DECREF(value); |
| 3941 | value = ast2obj_int(o->end_col_offset); |
| 3942 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3943 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 3944 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3945 | goto failed; |
| 3946 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3947 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3948 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3949 | Py_XDECREF(value); |
| 3950 | Py_XDECREF(result); |
| 3951 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3954 | PyObject* |
| 3955 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3956 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3957 | expr_ty o = (expr_ty)_o; |
| 3958 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3959 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3960 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3961 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3962 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3963 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3964 | switch (o->kind) { |
| 3965 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3966 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 3967 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3968 | if (!result) goto failed; |
| 3969 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3970 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3971 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3972 | goto failed; |
| 3973 | Py_DECREF(value); |
| 3974 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3975 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3976 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 3977 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3978 | goto failed; |
| 3979 | Py_DECREF(value); |
| 3980 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3981 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3982 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 3983 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3984 | if (!result) goto failed; |
| 3985 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3986 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3987 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3988 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3989 | goto failed; |
| 3990 | Py_DECREF(value); |
| 3991 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 3992 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3993 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3994 | goto failed; |
| 3995 | Py_DECREF(value); |
| 3996 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3997 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3998 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 3999 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4000 | if (!result) goto failed; |
| 4001 | value = ast2obj_expr(o->v.BinOp.left); |
| 4002 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4003 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4004 | goto failed; |
| 4005 | Py_DECREF(value); |
| 4006 | value = ast2obj_operator(o->v.BinOp.op); |
| 4007 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4008 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4009 | goto failed; |
| 4010 | Py_DECREF(value); |
| 4011 | value = ast2obj_expr(o->v.BinOp.right); |
| 4012 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4013 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4014 | goto failed; |
| 4015 | Py_DECREF(value); |
| 4016 | break; |
| 4017 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4018 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4019 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4020 | if (!result) goto failed; |
| 4021 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4022 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4023 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4024 | goto failed; |
| 4025 | Py_DECREF(value); |
| 4026 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4027 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4028 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4029 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4030 | goto failed; |
| 4031 | Py_DECREF(value); |
| 4032 | break; |
| 4033 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4034 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4035 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4036 | if (!result) goto failed; |
| 4037 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4038 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4039 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4040 | goto failed; |
| 4041 | Py_DECREF(value); |
| 4042 | value = ast2obj_expr(o->v.Lambda.body); |
| 4043 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4044 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4045 | goto failed; |
| 4046 | Py_DECREF(value); |
| 4047 | break; |
| 4048 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4049 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4050 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4051 | if (!result) goto failed; |
| 4052 | value = ast2obj_expr(o->v.IfExp.test); |
| 4053 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4054 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4055 | goto failed; |
| 4056 | Py_DECREF(value); |
| 4057 | value = ast2obj_expr(o->v.IfExp.body); |
| 4058 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4059 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4060 | goto failed; |
| 4061 | Py_DECREF(value); |
| 4062 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4063 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4064 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4065 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4066 | goto failed; |
| 4067 | Py_DECREF(value); |
| 4068 | break; |
| 4069 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4070 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4071 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4072 | if (!result) goto failed; |
| 4073 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4074 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4075 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4076 | goto failed; |
| 4077 | Py_DECREF(value); |
| 4078 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4079 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4080 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4081 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4082 | goto failed; |
| 4083 | Py_DECREF(value); |
| 4084 | break; |
| 4085 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4086 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4087 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4088 | if (!result) goto failed; |
| 4089 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4090 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4091 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4092 | goto failed; |
| 4093 | Py_DECREF(value); |
| 4094 | break; |
| 4095 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4096 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4097 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4098 | if (!result) goto failed; |
| 4099 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4100 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4101 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4102 | goto failed; |
| 4103 | Py_DECREF(value); |
| 4104 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4105 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4106 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4107 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4108 | goto failed; |
| 4109 | Py_DECREF(value); |
| 4110 | break; |
| 4111 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4112 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4113 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4114 | if (!result) goto failed; |
| 4115 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4116 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4117 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4118 | goto failed; |
| 4119 | Py_DECREF(value); |
| 4120 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4121 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4122 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4123 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4124 | goto failed; |
| 4125 | Py_DECREF(value); |
| 4126 | break; |
| 4127 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4128 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4129 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4130 | if (!result) goto failed; |
| 4131 | value = ast2obj_expr(o->v.DictComp.key); |
| 4132 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4133 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4134 | goto failed; |
| 4135 | Py_DECREF(value); |
| 4136 | value = ast2obj_expr(o->v.DictComp.value); |
| 4137 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4138 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4139 | goto failed; |
| 4140 | Py_DECREF(value); |
| 4141 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4142 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4143 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4144 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4145 | goto failed; |
| 4146 | Py_DECREF(value); |
| 4147 | break; |
| 4148 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4149 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4150 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4151 | if (!result) goto failed; |
| 4152 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4153 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4154 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4155 | goto failed; |
| 4156 | Py_DECREF(value); |
| 4157 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4158 | ast2obj_comprehension); |
| 4159 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4160 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4161 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4162 | goto failed; |
| 4163 | Py_DECREF(value); |
| 4164 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4165 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4166 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4167 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4168 | if (!result) goto failed; |
| 4169 | value = ast2obj_expr(o->v.Await.value); |
| 4170 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4171 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4172 | goto failed; |
| 4173 | Py_DECREF(value); |
| 4174 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4175 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4176 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4177 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4178 | if (!result) goto failed; |
| 4179 | value = ast2obj_expr(o->v.Yield.value); |
| 4180 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4181 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4182 | goto failed; |
| 4183 | Py_DECREF(value); |
| 4184 | break; |
| 4185 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4186 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4187 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4188 | if (!result) goto failed; |
| 4189 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4190 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4191 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4192 | goto failed; |
| 4193 | Py_DECREF(value); |
| 4194 | break; |
| 4195 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4196 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4197 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4198 | if (!result) goto failed; |
| 4199 | value = ast2obj_expr(o->v.Compare.left); |
| 4200 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4201 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4202 | goto failed; |
| 4203 | Py_DECREF(value); |
| 4204 | { |
| 4205 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4206 | value = PyList_New(n); |
| 4207 | if (!value) goto failed; |
| 4208 | for(i = 0; i < n; i++) |
| 4209 | 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] | 4210 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4211 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4212 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4213 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4214 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4215 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4216 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4217 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4218 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4219 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4220 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4221 | break; |
| 4222 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4223 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4224 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4225 | if (!result) goto failed; |
| 4226 | value = ast2obj_expr(o->v.Call.func); |
| 4227 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4228 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4229 | goto failed; |
| 4230 | Py_DECREF(value); |
| 4231 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4232 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4233 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4234 | goto failed; |
| 4235 | Py_DECREF(value); |
| 4236 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4237 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4238 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4239 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4240 | goto failed; |
| 4241 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4242 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4243 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4244 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4245 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4246 | if (!result) goto failed; |
| 4247 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4248 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4249 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4250 | goto failed; |
| 4251 | Py_DECREF(value); |
| 4252 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4253 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4254 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4255 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4256 | goto failed; |
| 4257 | Py_DECREF(value); |
| 4258 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4259 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4260 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4261 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4262 | goto failed; |
| 4263 | Py_DECREF(value); |
| 4264 | break; |
| 4265 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4266 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4267 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4268 | if (!result) goto failed; |
| 4269 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4270 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4271 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4272 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4273 | goto failed; |
| 4274 | Py_DECREF(value); |
| 4275 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4276 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4277 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4278 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4279 | if (!result) goto failed; |
| 4280 | value = ast2obj_constant(o->v.Constant.value); |
| 4281 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4282 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4283 | goto failed; |
| 4284 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4285 | value = ast2obj_string(o->v.Constant.kind); |
| 4286 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4287 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4288 | goto failed; |
| 4289 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4290 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4291 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4292 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4293 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4294 | if (!result) goto failed; |
| 4295 | value = ast2obj_expr(o->v.Attribute.value); |
| 4296 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4297 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4298 | goto failed; |
| 4299 | Py_DECREF(value); |
| 4300 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4301 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4302 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4303 | goto failed; |
| 4304 | Py_DECREF(value); |
| 4305 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4306 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4307 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4308 | goto failed; |
| 4309 | Py_DECREF(value); |
| 4310 | break; |
| 4311 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4312 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4313 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4314 | if (!result) goto failed; |
| 4315 | value = ast2obj_expr(o->v.Subscript.value); |
| 4316 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4317 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4318 | goto failed; |
| 4319 | Py_DECREF(value); |
| 4320 | value = ast2obj_slice(o->v.Subscript.slice); |
| 4321 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4322 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4323 | goto failed; |
| 4324 | Py_DECREF(value); |
| 4325 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4326 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4327 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4328 | goto failed; |
| 4329 | Py_DECREF(value); |
| 4330 | break; |
| 4331 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4332 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4333 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4334 | if (!result) goto failed; |
| 4335 | value = ast2obj_expr(o->v.Starred.value); |
| 4336 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4337 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4338 | goto failed; |
| 4339 | Py_DECREF(value); |
| 4340 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4341 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4342 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4343 | goto failed; |
| 4344 | Py_DECREF(value); |
| 4345 | break; |
| 4346 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4347 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4348 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4349 | if (!result) goto failed; |
| 4350 | value = ast2obj_identifier(o->v.Name.id); |
| 4351 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4352 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4353 | goto failed; |
| 4354 | Py_DECREF(value); |
| 4355 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4356 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4357 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4358 | goto failed; |
| 4359 | Py_DECREF(value); |
| 4360 | break; |
| 4361 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4362 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4363 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4364 | if (!result) goto failed; |
| 4365 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4366 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4367 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4368 | goto failed; |
| 4369 | Py_DECREF(value); |
| 4370 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4371 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4372 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4373 | goto failed; |
| 4374 | Py_DECREF(value); |
| 4375 | break; |
| 4376 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4377 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4378 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4379 | if (!result) goto failed; |
| 4380 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4381 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4382 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4383 | goto failed; |
| 4384 | Py_DECREF(value); |
| 4385 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4386 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4387 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4388 | goto failed; |
| 4389 | Py_DECREF(value); |
| 4390 | break; |
| 4391 | } |
| 4392 | value = ast2obj_int(o->lineno); |
| 4393 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4394 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4395 | goto failed; |
| 4396 | Py_DECREF(value); |
| 4397 | value = ast2obj_int(o->col_offset); |
| 4398 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4399 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4400 | goto failed; |
| 4401 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4402 | value = ast2obj_int(o->end_lineno); |
| 4403 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4404 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4405 | goto failed; |
| 4406 | Py_DECREF(value); |
| 4407 | value = ast2obj_int(o->end_col_offset); |
| 4408 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4409 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4410 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4411 | goto failed; |
| 4412 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4413 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4414 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4415 | Py_XDECREF(value); |
| 4416 | Py_XDECREF(result); |
| 4417 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4418 | } |
| 4419 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4420 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4421 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4422 | switch(o) { |
| 4423 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4424 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4425 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4426 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4427 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4428 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4429 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4430 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4431 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4432 | case AugLoad: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4433 | Py_INCREF(astmodulestate_global->AugLoad_singleton); |
| 4434 | return astmodulestate_global->AugLoad_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4435 | case AugStore: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4436 | Py_INCREF(astmodulestate_global->AugStore_singleton); |
| 4437 | return astmodulestate_global->AugStore_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4438 | case Param: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4439 | Py_INCREF(astmodulestate_global->Param_singleton); |
| 4440 | return astmodulestate_global->Param_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4441 | default: |
| 4442 | /* should never happen, but just in case ... */ |
| 4443 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 4444 | return NULL; |
| 4445 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4446 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4447 | PyObject* |
| 4448 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4449 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4450 | slice_ty o = (slice_ty)_o; |
| 4451 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4452 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4453 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4454 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4455 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4456 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4457 | switch (o->kind) { |
| 4458 | case Slice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4459 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4460 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4461 | if (!result) goto failed; |
| 4462 | value = ast2obj_expr(o->v.Slice.lower); |
| 4463 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4464 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | goto failed; |
| 4466 | Py_DECREF(value); |
| 4467 | value = ast2obj_expr(o->v.Slice.upper); |
| 4468 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4469 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4470 | goto failed; |
| 4471 | Py_DECREF(value); |
| 4472 | value = ast2obj_expr(o->v.Slice.step); |
| 4473 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4474 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4475 | goto failed; |
| 4476 | Py_DECREF(value); |
| 4477 | break; |
| 4478 | case ExtSlice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4479 | tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type; |
| 4480 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4481 | if (!result) goto failed; |
| 4482 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 4483 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4484 | if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4485 | goto failed; |
| 4486 | Py_DECREF(value); |
| 4487 | break; |
| 4488 | case Index_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4489 | tp = (PyTypeObject *)astmodulestate_global->Index_type; |
| 4490 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4491 | if (!result) goto failed; |
| 4492 | value = ast2obj_expr(o->v.Index.value); |
| 4493 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4494 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4495 | goto failed; |
| 4496 | Py_DECREF(value); |
| 4497 | break; |
| 4498 | } |
| 4499 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4500 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4501 | Py_XDECREF(value); |
| 4502 | Py_XDECREF(result); |
| 4503 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4504 | } |
| 4505 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4506 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4507 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4508 | switch(o) { |
| 4509 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4510 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4511 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4512 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4513 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4514 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4515 | default: |
| 4516 | /* should never happen, but just in case ... */ |
| 4517 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 4518 | return NULL; |
| 4519 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4520 | } |
| 4521 | PyObject* ast2obj_operator(operator_ty o) |
| 4522 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4523 | switch(o) { |
| 4524 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4525 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4526 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4527 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4528 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4529 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4530 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4531 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4532 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4533 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4534 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4535 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4536 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4537 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4538 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4539 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4540 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4541 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4542 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4543 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4544 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4545 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4546 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4547 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4548 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4549 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4550 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4551 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4552 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4553 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4554 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4555 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4556 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4557 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4558 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4559 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4560 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4561 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4562 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4563 | default: |
| 4564 | /* should never happen, but just in case ... */ |
| 4565 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 4566 | return NULL; |
| 4567 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4568 | } |
| 4569 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4570 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4571 | switch(o) { |
| 4572 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4573 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4574 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4575 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4576 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4577 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4578 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4579 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4580 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4581 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4582 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4583 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4584 | default: |
| 4585 | /* should never happen, but just in case ... */ |
| 4586 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 4587 | return NULL; |
| 4588 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4589 | } |
| 4590 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4591 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4592 | switch(o) { |
| 4593 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4594 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4595 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4596 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4597 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4598 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4599 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4600 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4601 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4602 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4603 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4604 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4605 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4606 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4607 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4608 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4609 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4610 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4611 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4612 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4613 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4614 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4615 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4616 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4617 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4618 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4619 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4620 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4621 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4622 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4623 | default: |
| 4624 | /* should never happen, but just in case ... */ |
| 4625 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 4626 | return NULL; |
| 4627 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4628 | } |
| 4629 | PyObject* |
| 4630 | ast2obj_comprehension(void* _o) |
| 4631 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4632 | comprehension_ty o = (comprehension_ty)_o; |
| 4633 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4634 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4635 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4636 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4637 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4638 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4639 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4640 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4641 | if (!result) return NULL; |
| 4642 | value = ast2obj_expr(o->target); |
| 4643 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4644 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4645 | goto failed; |
| 4646 | Py_DECREF(value); |
| 4647 | value = ast2obj_expr(o->iter); |
| 4648 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4649 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4650 | goto failed; |
| 4651 | Py_DECREF(value); |
| 4652 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4653 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4654 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4655 | goto failed; |
| 4656 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4657 | value = ast2obj_int(o->is_async); |
| 4658 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4659 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4660 | goto failed; |
| 4661 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4662 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4663 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4664 | Py_XDECREF(value); |
| 4665 | Py_XDECREF(result); |
| 4666 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4667 | } |
| 4668 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4669 | PyObject* |
| 4670 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4671 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4672 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4673 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4674 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4675 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4676 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4677 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4678 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4679 | switch (o->kind) { |
| 4680 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4681 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4682 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4683 | if (!result) goto failed; |
| 4684 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4685 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4686 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4687 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4688 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4689 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4690 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4691 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4692 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4693 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4694 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4695 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4696 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4697 | goto failed; |
| 4698 | Py_DECREF(value); |
| 4699 | break; |
| 4700 | } |
| 4701 | value = ast2obj_int(o->lineno); |
| 4702 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4703 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4704 | goto failed; |
| 4705 | Py_DECREF(value); |
| 4706 | value = ast2obj_int(o->col_offset); |
| 4707 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4708 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4709 | goto failed; |
| 4710 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4711 | value = ast2obj_int(o->end_lineno); |
| 4712 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4713 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4714 | goto failed; |
| 4715 | Py_DECREF(value); |
| 4716 | value = ast2obj_int(o->end_col_offset); |
| 4717 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4718 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4719 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4720 | goto failed; |
| 4721 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4722 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4723 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4724 | Py_XDECREF(value); |
| 4725 | Py_XDECREF(result); |
| 4726 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4727 | } |
| 4728 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4729 | PyObject* |
| 4730 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4731 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4732 | arguments_ty o = (arguments_ty)_o; |
| 4733 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4734 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4735 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4736 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4737 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4738 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4739 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4740 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4741 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4742 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4743 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4744 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4745 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4746 | goto failed; |
| 4747 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4748 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4749 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4750 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4751 | goto failed; |
| 4752 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4753 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4754 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4755 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4756 | goto failed; |
| 4757 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4758 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4759 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4760 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4761 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4762 | goto failed; |
| 4763 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4764 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4765 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4766 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4767 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4768 | goto failed; |
| 4769 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4770 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4771 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4772 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4773 | goto failed; |
| 4774 | Py_DECREF(value); |
| 4775 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4776 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4777 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4778 | goto failed; |
| 4779 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4780 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4781 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4782 | Py_XDECREF(value); |
| 4783 | Py_XDECREF(result); |
| 4784 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4785 | } |
| 4786 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4787 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4788 | ast2obj_arg(void* _o) |
| 4789 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4790 | arg_ty o = (arg_ty)_o; |
| 4791 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4792 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4793 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4794 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4795 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4796 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4797 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4798 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4799 | if (!result) return NULL; |
| 4800 | value = ast2obj_identifier(o->arg); |
| 4801 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4802 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4803 | goto failed; |
| 4804 | Py_DECREF(value); |
| 4805 | value = ast2obj_expr(o->annotation); |
| 4806 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4807 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4808 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4809 | goto failed; |
| 4810 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4811 | value = ast2obj_string(o->type_comment); |
| 4812 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4813 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4814 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4815 | goto failed; |
| 4816 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4817 | value = ast2obj_int(o->lineno); |
| 4818 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4819 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4820 | goto failed; |
| 4821 | Py_DECREF(value); |
| 4822 | value = ast2obj_int(o->col_offset); |
| 4823 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4824 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4825 | goto failed; |
| 4826 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4827 | value = ast2obj_int(o->end_lineno); |
| 4828 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4829 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4830 | goto failed; |
| 4831 | Py_DECREF(value); |
| 4832 | value = ast2obj_int(o->end_col_offset); |
| 4833 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4834 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4835 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4836 | goto failed; |
| 4837 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4838 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4839 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4840 | Py_XDECREF(value); |
| 4841 | Py_XDECREF(result); |
| 4842 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4846 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4847 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4848 | keyword_ty o = (keyword_ty)_o; |
| 4849 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4850 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4851 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4852 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4853 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4854 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4855 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4856 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4857 | if (!result) return NULL; |
| 4858 | value = ast2obj_identifier(o->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->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4861 | goto failed; |
| 4862 | Py_DECREF(value); |
| 4863 | value = ast2obj_expr(o->value); |
| 4864 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4865 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4866 | goto failed; |
| 4867 | Py_DECREF(value); |
| 4868 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4869 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4870 | Py_XDECREF(value); |
| 4871 | Py_XDECREF(result); |
| 4872 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4873 | } |
| 4874 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4875 | PyObject* |
| 4876 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4877 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4878 | alias_ty o = (alias_ty)_o; |
| 4879 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4880 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4881 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4882 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4883 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4884 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4885 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 4886 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4887 | if (!result) return NULL; |
| 4888 | value = ast2obj_identifier(o->name); |
| 4889 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4890 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4891 | goto failed; |
| 4892 | Py_DECREF(value); |
| 4893 | value = ast2obj_identifier(o->asname); |
| 4894 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4895 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4896 | goto failed; |
| 4897 | Py_DECREF(value); |
| 4898 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4899 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4900 | Py_XDECREF(value); |
| 4901 | Py_XDECREF(result); |
| 4902 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4905 | PyObject* |
| 4906 | ast2obj_withitem(void* _o) |
| 4907 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4908 | withitem_ty o = (withitem_ty)_o; |
| 4909 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4910 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4911 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4912 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4913 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4914 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4915 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 4916 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4917 | if (!result) return NULL; |
| 4918 | value = ast2obj_expr(o->context_expr); |
| 4919 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4920 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 4921 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4922 | goto failed; |
| 4923 | Py_DECREF(value); |
| 4924 | value = ast2obj_expr(o->optional_vars); |
| 4925 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4926 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 4927 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4928 | goto failed; |
| 4929 | Py_DECREF(value); |
| 4930 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4931 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4932 | Py_XDECREF(value); |
| 4933 | Py_XDECREF(result); |
| 4934 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4935 | } |
| 4936 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4937 | PyObject* |
| 4938 | ast2obj_type_ignore(void* _o) |
| 4939 | { |
| 4940 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4941 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4942 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4943 | if (!o) { |
| 4944 | Py_RETURN_NONE; |
| 4945 | } |
| 4946 | |
| 4947 | switch (o->kind) { |
| 4948 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4949 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 4950 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4951 | if (!result) goto failed; |
| 4952 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4953 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4954 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 4955 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4956 | goto failed; |
| 4957 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4958 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 4959 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4960 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4961 | goto failed; |
| 4962 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4963 | break; |
| 4964 | } |
| 4965 | return result; |
| 4966 | failed: |
| 4967 | Py_XDECREF(value); |
| 4968 | Py_XDECREF(result); |
| 4969 | return NULL; |
| 4970 | } |
| 4971 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4972 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4973 | int |
| 4974 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4975 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4976 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4977 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4978 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4979 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4980 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4981 | if (obj == Py_None) { |
| 4982 | *out = NULL; |
| 4983 | return 0; |
| 4984 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4985 | tp = astmodulestate_global->Module_type; |
| 4986 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4987 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4988 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4989 | } |
| 4990 | if (isinstance) { |
| 4991 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4992 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4993 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4994 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4995 | return 1; |
| 4996 | } |
| 4997 | if (tmp == NULL) { |
| 4998 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4999 | return 1; |
| 5000 | } |
| 5001 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5002 | int res; |
| 5003 | Py_ssize_t len; |
| 5004 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5005 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5006 | 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] | 5007 | goto failed; |
| 5008 | } |
| 5009 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5010 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5011 | if (body == NULL) goto failed; |
| 5012 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5013 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5014 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5015 | Py_INCREF(tmp2); |
| 5016 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5017 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5018 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5019 | if (len != PyList_GET_SIZE(tmp)) { |
| 5020 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5021 | goto failed; |
| 5022 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5023 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5024 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5025 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5026 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5027 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5028 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5029 | return 1; |
| 5030 | } |
| 5031 | if (tmp == NULL) { |
| 5032 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5033 | return 1; |
| 5034 | } |
| 5035 | else { |
| 5036 | int res; |
| 5037 | Py_ssize_t len; |
| 5038 | Py_ssize_t i; |
| 5039 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5040 | 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] | 5041 | goto failed; |
| 5042 | } |
| 5043 | len = PyList_GET_SIZE(tmp); |
| 5044 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5045 | if (type_ignores == NULL) goto failed; |
| 5046 | for (i = 0; i < len; i++) { |
| 5047 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5048 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5049 | Py_INCREF(tmp2); |
| 5050 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5051 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5052 | if (res != 0) goto failed; |
| 5053 | if (len != PyList_GET_SIZE(tmp)) { |
| 5054 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5055 | goto failed; |
| 5056 | } |
| 5057 | asdl_seq_SET(type_ignores, i, val); |
| 5058 | } |
| 5059 | Py_CLEAR(tmp); |
| 5060 | } |
| 5061 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5062 | if (*out == NULL) goto failed; |
| 5063 | return 0; |
| 5064 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5065 | tp = astmodulestate_global->Interactive_type; |
| 5066 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5067 | if (isinstance == -1) { |
| 5068 | return 1; |
| 5069 | } |
| 5070 | if (isinstance) { |
| 5071 | asdl_seq* body; |
| 5072 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5073 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5074 | return 1; |
| 5075 | } |
| 5076 | if (tmp == NULL) { |
| 5077 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5078 | return 1; |
| 5079 | } |
| 5080 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5081 | int res; |
| 5082 | Py_ssize_t len; |
| 5083 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5084 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5085 | 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] | 5086 | goto failed; |
| 5087 | } |
| 5088 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5089 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5090 | if (body == NULL) goto failed; |
| 5091 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5092 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5093 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5094 | Py_INCREF(tmp2); |
| 5095 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5096 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5097 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5098 | if (len != PyList_GET_SIZE(tmp)) { |
| 5099 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5100 | goto failed; |
| 5101 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5102 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5103 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5104 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5105 | } |
| 5106 | *out = Interactive(body, arena); |
| 5107 | if (*out == NULL) goto failed; |
| 5108 | return 0; |
| 5109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5110 | tp = astmodulestate_global->Expression_type; |
| 5111 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5112 | if (isinstance == -1) { |
| 5113 | return 1; |
| 5114 | } |
| 5115 | if (isinstance) { |
| 5116 | expr_ty body; |
| 5117 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5118 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5119 | return 1; |
| 5120 | } |
| 5121 | if (tmp == NULL) { |
| 5122 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5123 | return 1; |
| 5124 | } |
| 5125 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5126 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5127 | res = obj2ast_expr(tmp, &body, arena); |
| 5128 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5129 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5130 | } |
| 5131 | *out = Expression(body, arena); |
| 5132 | if (*out == NULL) goto failed; |
| 5133 | return 0; |
| 5134 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5135 | tp = astmodulestate_global->FunctionType_type; |
| 5136 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5137 | if (isinstance == -1) { |
| 5138 | return 1; |
| 5139 | } |
| 5140 | if (isinstance) { |
| 5141 | asdl_seq* argtypes; |
| 5142 | expr_ty returns; |
| 5143 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5144 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5145 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5146 | return 1; |
| 5147 | } |
| 5148 | if (tmp == NULL) { |
| 5149 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5150 | return 1; |
| 5151 | } |
| 5152 | else { |
| 5153 | int res; |
| 5154 | Py_ssize_t len; |
| 5155 | Py_ssize_t i; |
| 5156 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5157 | 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] | 5158 | goto failed; |
| 5159 | } |
| 5160 | len = PyList_GET_SIZE(tmp); |
| 5161 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5162 | if (argtypes == NULL) goto failed; |
| 5163 | for (i = 0; i < len; i++) { |
| 5164 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5165 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5166 | Py_INCREF(tmp2); |
| 5167 | res = obj2ast_expr(tmp2, &val, arena); |
| 5168 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5169 | if (res != 0) goto failed; |
| 5170 | if (len != PyList_GET_SIZE(tmp)) { |
| 5171 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5172 | goto failed; |
| 5173 | } |
| 5174 | asdl_seq_SET(argtypes, i, val); |
| 5175 | } |
| 5176 | Py_CLEAR(tmp); |
| 5177 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5178 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5179 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5180 | return 1; |
| 5181 | } |
| 5182 | if (tmp == NULL) { |
| 5183 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5184 | return 1; |
| 5185 | } |
| 5186 | else { |
| 5187 | int res; |
| 5188 | res = obj2ast_expr(tmp, &returns, arena); |
| 5189 | if (res != 0) goto failed; |
| 5190 | Py_CLEAR(tmp); |
| 5191 | } |
| 5192 | *out = FunctionType(argtypes, returns, arena); |
| 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->Suite_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 Suite"); |
| 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, "Suite 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, "Suite 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 = Suite(body, arena); |
| 5238 | if (*out == NULL) goto failed; |
| 5239 | return 0; |
| 5240 | } |
| 5241 | |
| 5242 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5243 | failed: |
| 5244 | Py_XDECREF(tmp); |
| 5245 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | int |
| 5249 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5250 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5251 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5252 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5253 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5254 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5255 | int lineno; |
| 5256 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5257 | int end_lineno; |
| 5258 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5259 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5260 | if (obj == Py_None) { |
| 5261 | *out = NULL; |
| 5262 | return 0; |
| 5263 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5264 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5265 | return 1; |
| 5266 | } |
| 5267 | if (tmp == NULL) { |
| 5268 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5269 | return 1; |
| 5270 | } |
| 5271 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5272 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5273 | res = obj2ast_int(tmp, &lineno, arena); |
| 5274 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5275 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5276 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5277 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5278 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5279 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5280 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5281 | if (tmp == NULL) { |
| 5282 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5283 | return 1; |
| 5284 | } |
| 5285 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5286 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5287 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5288 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5289 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5290 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5291 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5292 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5293 | return 1; |
| 5294 | } |
| 5295 | if (tmp == NULL || tmp == Py_None) { |
| 5296 | Py_CLEAR(tmp); |
| 5297 | end_lineno = 0; |
| 5298 | } |
| 5299 | else { |
| 5300 | int res; |
| 5301 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5302 | if (res != 0) goto failed; |
| 5303 | Py_CLEAR(tmp); |
| 5304 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5305 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5306 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5307 | return 1; |
| 5308 | } |
| 5309 | if (tmp == NULL || tmp == Py_None) { |
| 5310 | Py_CLEAR(tmp); |
| 5311 | end_col_offset = 0; |
| 5312 | } |
| 5313 | else { |
| 5314 | int res; |
| 5315 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5316 | if (res != 0) goto failed; |
| 5317 | Py_CLEAR(tmp); |
| 5318 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5319 | tp = astmodulestate_global->FunctionDef_type; |
| 5320 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5321 | if (isinstance == -1) { |
| 5322 | return 1; |
| 5323 | } |
| 5324 | if (isinstance) { |
| 5325 | identifier name; |
| 5326 | arguments_ty args; |
| 5327 | asdl_seq* body; |
| 5328 | asdl_seq* decorator_list; |
| 5329 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5330 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5331 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5332 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5333 | return 1; |
| 5334 | } |
| 5335 | if (tmp == NULL) { |
| 5336 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5337 | return 1; |
| 5338 | } |
| 5339 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5340 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5341 | res = obj2ast_identifier(tmp, &name, arena); |
| 5342 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5343 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5344 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5345 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5346 | return 1; |
| 5347 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5348 | if (tmp == NULL) { |
| 5349 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5350 | return 1; |
| 5351 | } |
| 5352 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5353 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5354 | res = obj2ast_arguments(tmp, &args, arena); |
| 5355 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5356 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5357 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5358 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5359 | return 1; |
| 5360 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5361 | if (tmp == NULL) { |
| 5362 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5363 | return 1; |
| 5364 | } |
| 5365 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5366 | int res; |
| 5367 | Py_ssize_t len; |
| 5368 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5369 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5370 | 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] | 5371 | goto failed; |
| 5372 | } |
| 5373 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5374 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5375 | if (body == NULL) goto failed; |
| 5376 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5377 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5378 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5379 | Py_INCREF(tmp2); |
| 5380 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5381 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5382 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5383 | if (len != PyList_GET_SIZE(tmp)) { |
| 5384 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5385 | goto failed; |
| 5386 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5387 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5388 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5389 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5390 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5391 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5392 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5393 | return 1; |
| 5394 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5395 | if (tmp == NULL) { |
| 5396 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5397 | return 1; |
| 5398 | } |
| 5399 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5400 | int res; |
| 5401 | Py_ssize_t len; |
| 5402 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5403 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5404 | 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] | 5405 | goto failed; |
| 5406 | } |
| 5407 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5408 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5409 | if (decorator_list == NULL) goto failed; |
| 5410 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5411 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5412 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5413 | Py_INCREF(tmp2); |
| 5414 | res = obj2ast_expr(tmp2, &val, arena); |
| 5415 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5416 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5417 | if (len != PyList_GET_SIZE(tmp)) { |
| 5418 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5419 | goto failed; |
| 5420 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5421 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5422 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5423 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5424 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5425 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5426 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5427 | return 1; |
| 5428 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5429 | if (tmp == NULL || tmp == Py_None) { |
| 5430 | Py_CLEAR(tmp); |
| 5431 | returns = NULL; |
| 5432 | } |
| 5433 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5434 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5435 | res = obj2ast_expr(tmp, &returns, arena); |
| 5436 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5437 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5438 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5439 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5440 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5441 | return 1; |
| 5442 | } |
| 5443 | if (tmp == NULL || tmp == Py_None) { |
| 5444 | Py_CLEAR(tmp); |
| 5445 | type_comment = NULL; |
| 5446 | } |
| 5447 | else { |
| 5448 | int res; |
| 5449 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5450 | if (res != 0) goto failed; |
| 5451 | Py_CLEAR(tmp); |
| 5452 | } |
| 5453 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5454 | type_comment, lineno, col_offset, end_lineno, |
| 5455 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5456 | if (*out == NULL) goto failed; |
| 5457 | return 0; |
| 5458 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5459 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5460 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5461 | if (isinstance == -1) { |
| 5462 | return 1; |
| 5463 | } |
| 5464 | if (isinstance) { |
| 5465 | identifier name; |
| 5466 | arguments_ty args; |
| 5467 | asdl_seq* body; |
| 5468 | asdl_seq* decorator_list; |
| 5469 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5470 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5471 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5472 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5473 | return 1; |
| 5474 | } |
| 5475 | if (tmp == NULL) { |
| 5476 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5477 | return 1; |
| 5478 | } |
| 5479 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5480 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5481 | res = obj2ast_identifier(tmp, &name, arena); |
| 5482 | if (res != 0) goto failed; |
| 5483 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5484 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5485 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5486 | return 1; |
| 5487 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5488 | if (tmp == NULL) { |
| 5489 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5490 | return 1; |
| 5491 | } |
| 5492 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5493 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5494 | res = obj2ast_arguments(tmp, &args, arena); |
| 5495 | if (res != 0) goto failed; |
| 5496 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5497 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5498 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5499 | return 1; |
| 5500 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5501 | if (tmp == NULL) { |
| 5502 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5503 | return 1; |
| 5504 | } |
| 5505 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5506 | int res; |
| 5507 | Py_ssize_t len; |
| 5508 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5509 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5510 | 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] | 5511 | goto failed; |
| 5512 | } |
| 5513 | len = PyList_GET_SIZE(tmp); |
| 5514 | body = _Py_asdl_seq_new(len, arena); |
| 5515 | if (body == NULL) goto failed; |
| 5516 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5517 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5518 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5519 | Py_INCREF(tmp2); |
| 5520 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5521 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5522 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5523 | if (len != PyList_GET_SIZE(tmp)) { |
| 5524 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5525 | goto failed; |
| 5526 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5527 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5528 | } |
| 5529 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5530 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5531 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5532 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5533 | return 1; |
| 5534 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5535 | if (tmp == NULL) { |
| 5536 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5537 | return 1; |
| 5538 | } |
| 5539 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5540 | int res; |
| 5541 | Py_ssize_t len; |
| 5542 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5543 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5544 | 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] | 5545 | goto failed; |
| 5546 | } |
| 5547 | len = PyList_GET_SIZE(tmp); |
| 5548 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5549 | if (decorator_list == NULL) goto failed; |
| 5550 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5551 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5552 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5553 | Py_INCREF(tmp2); |
| 5554 | res = obj2ast_expr(tmp2, &val, arena); |
| 5555 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5556 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5557 | if (len != PyList_GET_SIZE(tmp)) { |
| 5558 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5559 | goto failed; |
| 5560 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5561 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5562 | } |
| 5563 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5564 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5565 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5566 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5567 | return 1; |
| 5568 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5569 | if (tmp == NULL || tmp == Py_None) { |
| 5570 | Py_CLEAR(tmp); |
| 5571 | returns = NULL; |
| 5572 | } |
| 5573 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5574 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5575 | res = obj2ast_expr(tmp, &returns, arena); |
| 5576 | if (res != 0) goto failed; |
| 5577 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5578 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5579 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5580 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5581 | return 1; |
| 5582 | } |
| 5583 | if (tmp == NULL || tmp == Py_None) { |
| 5584 | Py_CLEAR(tmp); |
| 5585 | type_comment = NULL; |
| 5586 | } |
| 5587 | else { |
| 5588 | int res; |
| 5589 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5590 | if (res != 0) goto failed; |
| 5591 | Py_CLEAR(tmp); |
| 5592 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5593 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5594 | type_comment, lineno, col_offset, end_lineno, |
| 5595 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5596 | if (*out == NULL) goto failed; |
| 5597 | return 0; |
| 5598 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5599 | tp = astmodulestate_global->ClassDef_type; |
| 5600 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5601 | if (isinstance == -1) { |
| 5602 | return 1; |
| 5603 | } |
| 5604 | if (isinstance) { |
| 5605 | identifier name; |
| 5606 | asdl_seq* bases; |
| 5607 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5608 | asdl_seq* body; |
| 5609 | asdl_seq* decorator_list; |
| 5610 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5611 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5612 | return 1; |
| 5613 | } |
| 5614 | if (tmp == NULL) { |
| 5615 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5616 | return 1; |
| 5617 | } |
| 5618 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5619 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5620 | res = obj2ast_identifier(tmp, &name, arena); |
| 5621 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5622 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5623 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5624 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5625 | return 1; |
| 5626 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5627 | if (tmp == NULL) { |
| 5628 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5629 | return 1; |
| 5630 | } |
| 5631 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5632 | int res; |
| 5633 | Py_ssize_t len; |
| 5634 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5635 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5636 | 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] | 5637 | goto failed; |
| 5638 | } |
| 5639 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5640 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5641 | if (bases == NULL) goto failed; |
| 5642 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5643 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5644 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5645 | Py_INCREF(tmp2); |
| 5646 | res = obj2ast_expr(tmp2, &val, arena); |
| 5647 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5648 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5649 | if (len != PyList_GET_SIZE(tmp)) { |
| 5650 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5651 | goto failed; |
| 5652 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5653 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5654 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5655 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5656 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5657 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5658 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5659 | return 1; |
| 5660 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5661 | if (tmp == NULL) { |
| 5662 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5663 | return 1; |
| 5664 | } |
| 5665 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5666 | int res; |
| 5667 | Py_ssize_t len; |
| 5668 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5669 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5670 | 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] | 5671 | goto failed; |
| 5672 | } |
| 5673 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5674 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5675 | if (keywords == NULL) goto failed; |
| 5676 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5677 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5678 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5679 | Py_INCREF(tmp2); |
| 5680 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5681 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5682 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5683 | if (len != PyList_GET_SIZE(tmp)) { |
| 5684 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5685 | goto failed; |
| 5686 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5687 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5688 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5689 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5690 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5691 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5692 | return 1; |
| 5693 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5694 | if (tmp == NULL) { |
| 5695 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5696 | return 1; |
| 5697 | } |
| 5698 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5699 | int res; |
| 5700 | Py_ssize_t len; |
| 5701 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5702 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5703 | 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] | 5704 | goto failed; |
| 5705 | } |
| 5706 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5707 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5708 | if (body == NULL) goto failed; |
| 5709 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5710 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5711 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5712 | Py_INCREF(tmp2); |
| 5713 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5714 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5715 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5716 | if (len != PyList_GET_SIZE(tmp)) { |
| 5717 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5718 | goto failed; |
| 5719 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5720 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5721 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5722 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5723 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5724 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5725 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5726 | return 1; |
| 5727 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5728 | if (tmp == NULL) { |
| 5729 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5730 | return 1; |
| 5731 | } |
| 5732 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5733 | int res; |
| 5734 | Py_ssize_t len; |
| 5735 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5736 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5737 | 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] | 5738 | goto failed; |
| 5739 | } |
| 5740 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5741 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5742 | if (decorator_list == NULL) goto failed; |
| 5743 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5744 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5745 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5746 | Py_INCREF(tmp2); |
| 5747 | res = obj2ast_expr(tmp2, &val, arena); |
| 5748 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5749 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5750 | if (len != PyList_GET_SIZE(tmp)) { |
| 5751 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5752 | goto failed; |
| 5753 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5754 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5755 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5756 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5757 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5758 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5759 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5760 | if (*out == NULL) goto failed; |
| 5761 | return 0; |
| 5762 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5763 | tp = astmodulestate_global->Return_type; |
| 5764 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5765 | if (isinstance == -1) { |
| 5766 | return 1; |
| 5767 | } |
| 5768 | if (isinstance) { |
| 5769 | expr_ty value; |
| 5770 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5771 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5772 | return 1; |
| 5773 | } |
| 5774 | if (tmp == NULL || tmp == Py_None) { |
| 5775 | Py_CLEAR(tmp); |
| 5776 | value = NULL; |
| 5777 | } |
| 5778 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5779 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5780 | res = obj2ast_expr(tmp, &value, arena); |
| 5781 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5782 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5783 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5784 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5785 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5786 | if (*out == NULL) goto failed; |
| 5787 | return 0; |
| 5788 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5789 | tp = astmodulestate_global->Delete_type; |
| 5790 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5791 | if (isinstance == -1) { |
| 5792 | return 1; |
| 5793 | } |
| 5794 | if (isinstance) { |
| 5795 | asdl_seq* targets; |
| 5796 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5797 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5798 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5799 | return 1; |
| 5800 | } |
| 5801 | if (tmp == NULL) { |
| 5802 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5803 | return 1; |
| 5804 | } |
| 5805 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5806 | int res; |
| 5807 | Py_ssize_t len; |
| 5808 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5809 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5810 | 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] | 5811 | goto failed; |
| 5812 | } |
| 5813 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5814 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5815 | if (targets == NULL) goto failed; |
| 5816 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5817 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5818 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5819 | Py_INCREF(tmp2); |
| 5820 | res = obj2ast_expr(tmp2, &val, arena); |
| 5821 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5822 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5823 | if (len != PyList_GET_SIZE(tmp)) { |
| 5824 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5825 | goto failed; |
| 5826 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5827 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5828 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5829 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5830 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5831 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5832 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5833 | if (*out == NULL) goto failed; |
| 5834 | return 0; |
| 5835 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5836 | tp = astmodulestate_global->Assign_type; |
| 5837 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5838 | if (isinstance == -1) { |
| 5839 | return 1; |
| 5840 | } |
| 5841 | if (isinstance) { |
| 5842 | asdl_seq* targets; |
| 5843 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5844 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5845 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5846 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5847 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5848 | return 1; |
| 5849 | } |
| 5850 | if (tmp == NULL) { |
| 5851 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5852 | return 1; |
| 5853 | } |
| 5854 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5855 | int res; |
| 5856 | Py_ssize_t len; |
| 5857 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5858 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5859 | 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] | 5860 | goto failed; |
| 5861 | } |
| 5862 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5863 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5864 | if (targets == NULL) goto failed; |
| 5865 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5866 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5867 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5868 | Py_INCREF(tmp2); |
| 5869 | res = obj2ast_expr(tmp2, &val, arena); |
| 5870 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5871 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5872 | if (len != PyList_GET_SIZE(tmp)) { |
| 5873 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5874 | goto failed; |
| 5875 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5876 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5877 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5878 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5879 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5880 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5881 | return 1; |
| 5882 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5883 | if (tmp == NULL) { |
| 5884 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5885 | return 1; |
| 5886 | } |
| 5887 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5888 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5889 | res = obj2ast_expr(tmp, &value, arena); |
| 5890 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5891 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5892 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5893 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5894 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5895 | return 1; |
| 5896 | } |
| 5897 | if (tmp == NULL || tmp == Py_None) { |
| 5898 | Py_CLEAR(tmp); |
| 5899 | type_comment = NULL; |
| 5900 | } |
| 5901 | else { |
| 5902 | int res; |
| 5903 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5904 | if (res != 0) goto failed; |
| 5905 | Py_CLEAR(tmp); |
| 5906 | } |
| 5907 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5908 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5909 | if (*out == NULL) goto failed; |
| 5910 | return 0; |
| 5911 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5912 | tp = astmodulestate_global->AugAssign_type; |
| 5913 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5914 | if (isinstance == -1) { |
| 5915 | return 1; |
| 5916 | } |
| 5917 | if (isinstance) { |
| 5918 | expr_ty target; |
| 5919 | operator_ty op; |
| 5920 | expr_ty value; |
| 5921 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5922 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5923 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5924 | return 1; |
| 5925 | } |
| 5926 | if (tmp == NULL) { |
| 5927 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5928 | return 1; |
| 5929 | } |
| 5930 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5931 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5932 | res = obj2ast_expr(tmp, &target, arena); |
| 5933 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5934 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5935 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5936 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5937 | return 1; |
| 5938 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5939 | if (tmp == NULL) { |
| 5940 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5941 | return 1; |
| 5942 | } |
| 5943 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5944 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5945 | res = obj2ast_operator(tmp, &op, arena); |
| 5946 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5947 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5949 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5950 | return 1; |
| 5951 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5952 | if (tmp == NULL) { |
| 5953 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5954 | return 1; |
| 5955 | } |
| 5956 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5957 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | res = obj2ast_expr(tmp, &value, arena); |
| 5959 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5960 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5961 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5962 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5963 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5964 | if (*out == NULL) goto failed; |
| 5965 | return 0; |
| 5966 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5967 | tp = astmodulestate_global->AnnAssign_type; |
| 5968 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5969 | if (isinstance == -1) { |
| 5970 | return 1; |
| 5971 | } |
| 5972 | if (isinstance) { |
| 5973 | expr_ty target; |
| 5974 | expr_ty annotation; |
| 5975 | expr_ty value; |
| 5976 | int simple; |
| 5977 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5978 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5979 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5980 | return 1; |
| 5981 | } |
| 5982 | if (tmp == NULL) { |
| 5983 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 5984 | return 1; |
| 5985 | } |
| 5986 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5987 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5988 | res = obj2ast_expr(tmp, &target, arena); |
| 5989 | if (res != 0) goto failed; |
| 5990 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5991 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5992 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 5993 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5994 | return 1; |
| 5995 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5996 | if (tmp == NULL) { |
| 5997 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 5998 | return 1; |
| 5999 | } |
| 6000 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6001 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6002 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6003 | if (res != 0) goto failed; |
| 6004 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6005 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6006 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6007 | return 1; |
| 6008 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6009 | if (tmp == NULL || tmp == Py_None) { |
| 6010 | Py_CLEAR(tmp); |
| 6011 | value = NULL; |
| 6012 | } |
| 6013 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6014 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6015 | res = obj2ast_expr(tmp, &value, arena); |
| 6016 | if (res != 0) goto failed; |
| 6017 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6018 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6019 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6020 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6021 | return 1; |
| 6022 | } |
| 6023 | if (tmp == NULL) { |
| 6024 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6025 | return 1; |
| 6026 | } |
| 6027 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6028 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6029 | res = obj2ast_int(tmp, &simple, arena); |
| 6030 | if (res != 0) goto failed; |
| 6031 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6032 | } |
| 6033 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6034 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6035 | if (*out == NULL) goto failed; |
| 6036 | return 0; |
| 6037 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6038 | tp = astmodulestate_global->For_type; |
| 6039 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6040 | if (isinstance == -1) { |
| 6041 | return 1; |
| 6042 | } |
| 6043 | if (isinstance) { |
| 6044 | expr_ty target; |
| 6045 | expr_ty iter; |
| 6046 | asdl_seq* body; |
| 6047 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6048 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6049 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6050 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6051 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6052 | return 1; |
| 6053 | } |
| 6054 | if (tmp == NULL) { |
| 6055 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6056 | return 1; |
| 6057 | } |
| 6058 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6059 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6060 | res = obj2ast_expr(tmp, &target, arena); |
| 6061 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6062 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6063 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6064 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6065 | return 1; |
| 6066 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6067 | if (tmp == NULL) { |
| 6068 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6069 | return 1; |
| 6070 | } |
| 6071 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6072 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6073 | res = obj2ast_expr(tmp, &iter, arena); |
| 6074 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6075 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6076 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6077 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6078 | return 1; |
| 6079 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6080 | if (tmp == NULL) { |
| 6081 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6082 | return 1; |
| 6083 | } |
| 6084 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6085 | int res; |
| 6086 | Py_ssize_t len; |
| 6087 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6088 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6089 | 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] | 6090 | goto failed; |
| 6091 | } |
| 6092 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6093 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6094 | if (body == NULL) goto failed; |
| 6095 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6096 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6097 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6098 | Py_INCREF(tmp2); |
| 6099 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6100 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6101 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6102 | if (len != PyList_GET_SIZE(tmp)) { |
| 6103 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6104 | goto failed; |
| 6105 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6106 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6107 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6108 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6110 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6111 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6112 | return 1; |
| 6113 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6114 | if (tmp == NULL) { |
| 6115 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6116 | return 1; |
| 6117 | } |
| 6118 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6119 | int res; |
| 6120 | Py_ssize_t len; |
| 6121 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6122 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6123 | 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] | 6124 | goto failed; |
| 6125 | } |
| 6126 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6127 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6128 | if (orelse == NULL) goto failed; |
| 6129 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6130 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6131 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6132 | Py_INCREF(tmp2); |
| 6133 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6134 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6135 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6136 | if (len != PyList_GET_SIZE(tmp)) { |
| 6137 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6138 | goto failed; |
| 6139 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6140 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6141 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6142 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6143 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6144 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6145 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6146 | return 1; |
| 6147 | } |
| 6148 | if (tmp == NULL || tmp == Py_None) { |
| 6149 | Py_CLEAR(tmp); |
| 6150 | type_comment = NULL; |
| 6151 | } |
| 6152 | else { |
| 6153 | int res; |
| 6154 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6155 | if (res != 0) goto failed; |
| 6156 | Py_CLEAR(tmp); |
| 6157 | } |
| 6158 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6159 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6160 | if (*out == NULL) goto failed; |
| 6161 | return 0; |
| 6162 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6163 | tp = astmodulestate_global->AsyncFor_type; |
| 6164 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6165 | if (isinstance == -1) { |
| 6166 | return 1; |
| 6167 | } |
| 6168 | if (isinstance) { |
| 6169 | expr_ty target; |
| 6170 | expr_ty iter; |
| 6171 | asdl_seq* body; |
| 6172 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6173 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6174 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6175 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6176 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6177 | return 1; |
| 6178 | } |
| 6179 | if (tmp == NULL) { |
| 6180 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6181 | return 1; |
| 6182 | } |
| 6183 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6184 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6185 | res = obj2ast_expr(tmp, &target, arena); |
| 6186 | if (res != 0) goto failed; |
| 6187 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6188 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6189 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6190 | return 1; |
| 6191 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6192 | if (tmp == NULL) { |
| 6193 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6194 | return 1; |
| 6195 | } |
| 6196 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6197 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6198 | res = obj2ast_expr(tmp, &iter, arena); |
| 6199 | if (res != 0) goto failed; |
| 6200 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6201 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6202 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6203 | return 1; |
| 6204 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6205 | if (tmp == NULL) { |
| 6206 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6207 | return 1; |
| 6208 | } |
| 6209 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6210 | int res; |
| 6211 | Py_ssize_t len; |
| 6212 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6213 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6214 | 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] | 6215 | goto failed; |
| 6216 | } |
| 6217 | len = PyList_GET_SIZE(tmp); |
| 6218 | body = _Py_asdl_seq_new(len, arena); |
| 6219 | if (body == NULL) goto failed; |
| 6220 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6221 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6222 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6223 | Py_INCREF(tmp2); |
| 6224 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6225 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6226 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6227 | if (len != PyList_GET_SIZE(tmp)) { |
| 6228 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6229 | goto failed; |
| 6230 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6231 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6232 | } |
| 6233 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6234 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6235 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6236 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6237 | return 1; |
| 6238 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6239 | if (tmp == NULL) { |
| 6240 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6241 | return 1; |
| 6242 | } |
| 6243 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6244 | int res; |
| 6245 | Py_ssize_t len; |
| 6246 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6247 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6248 | 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] | 6249 | goto failed; |
| 6250 | } |
| 6251 | len = PyList_GET_SIZE(tmp); |
| 6252 | orelse = _Py_asdl_seq_new(len, arena); |
| 6253 | if (orelse == NULL) goto failed; |
| 6254 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6255 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6256 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6257 | Py_INCREF(tmp2); |
| 6258 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6259 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6260 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6261 | if (len != PyList_GET_SIZE(tmp)) { |
| 6262 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6263 | goto failed; |
| 6264 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6265 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6266 | } |
| 6267 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6268 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6269 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6270 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6271 | return 1; |
| 6272 | } |
| 6273 | if (tmp == NULL || tmp == Py_None) { |
| 6274 | Py_CLEAR(tmp); |
| 6275 | type_comment = NULL; |
| 6276 | } |
| 6277 | else { |
| 6278 | int res; |
| 6279 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6280 | if (res != 0) goto failed; |
| 6281 | Py_CLEAR(tmp); |
| 6282 | } |
| 6283 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6284 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6285 | if (*out == NULL) goto failed; |
| 6286 | return 0; |
| 6287 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6288 | tp = astmodulestate_global->While_type; |
| 6289 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6290 | if (isinstance == -1) { |
| 6291 | return 1; |
| 6292 | } |
| 6293 | if (isinstance) { |
| 6294 | expr_ty test; |
| 6295 | asdl_seq* body; |
| 6296 | asdl_seq* orelse; |
| 6297 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6298 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6299 | return 1; |
| 6300 | } |
| 6301 | if (tmp == NULL) { |
| 6302 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6303 | return 1; |
| 6304 | } |
| 6305 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6306 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6307 | res = obj2ast_expr(tmp, &test, arena); |
| 6308 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6309 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6310 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6311 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6312 | return 1; |
| 6313 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6314 | if (tmp == NULL) { |
| 6315 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6316 | return 1; |
| 6317 | } |
| 6318 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6319 | int res; |
| 6320 | Py_ssize_t len; |
| 6321 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6322 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6323 | 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] | 6324 | goto failed; |
| 6325 | } |
| 6326 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6327 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6328 | if (body == NULL) goto failed; |
| 6329 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6330 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6331 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6332 | Py_INCREF(tmp2); |
| 6333 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6334 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6335 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6336 | if (len != PyList_GET_SIZE(tmp)) { |
| 6337 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6338 | goto failed; |
| 6339 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6340 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6341 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6342 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6343 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6344 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6345 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6346 | return 1; |
| 6347 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6348 | if (tmp == NULL) { |
| 6349 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6350 | return 1; |
| 6351 | } |
| 6352 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6353 | int res; |
| 6354 | Py_ssize_t len; |
| 6355 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6356 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6357 | 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] | 6358 | goto failed; |
| 6359 | } |
| 6360 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6361 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6362 | if (orelse == NULL) goto failed; |
| 6363 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6364 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6365 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6366 | Py_INCREF(tmp2); |
| 6367 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6368 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6369 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6370 | if (len != PyList_GET_SIZE(tmp)) { |
| 6371 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6372 | goto failed; |
| 6373 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6374 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6375 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6376 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6377 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6378 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6379 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6380 | if (*out == NULL) goto failed; |
| 6381 | return 0; |
| 6382 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6383 | tp = astmodulestate_global->If_type; |
| 6384 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6385 | if (isinstance == -1) { |
| 6386 | return 1; |
| 6387 | } |
| 6388 | if (isinstance) { |
| 6389 | expr_ty test; |
| 6390 | asdl_seq* body; |
| 6391 | asdl_seq* orelse; |
| 6392 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6393 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6394 | return 1; |
| 6395 | } |
| 6396 | if (tmp == NULL) { |
| 6397 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6398 | return 1; |
| 6399 | } |
| 6400 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6401 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6402 | res = obj2ast_expr(tmp, &test, arena); |
| 6403 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6404 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6405 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6406 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6407 | return 1; |
| 6408 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6409 | if (tmp == NULL) { |
| 6410 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6411 | return 1; |
| 6412 | } |
| 6413 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6414 | int res; |
| 6415 | Py_ssize_t len; |
| 6416 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6417 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6418 | 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] | 6419 | goto failed; |
| 6420 | } |
| 6421 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6422 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6423 | if (body == NULL) goto failed; |
| 6424 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6425 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6426 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6427 | Py_INCREF(tmp2); |
| 6428 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6429 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6430 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6431 | if (len != PyList_GET_SIZE(tmp)) { |
| 6432 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6433 | goto failed; |
| 6434 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6435 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6436 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6437 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6438 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6439 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6440 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6441 | return 1; |
| 6442 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6443 | if (tmp == NULL) { |
| 6444 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6445 | return 1; |
| 6446 | } |
| 6447 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6448 | int res; |
| 6449 | Py_ssize_t len; |
| 6450 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6451 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6452 | 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] | 6453 | goto failed; |
| 6454 | } |
| 6455 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6456 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6457 | if (orelse == NULL) goto failed; |
| 6458 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6459 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6460 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6461 | Py_INCREF(tmp2); |
| 6462 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6463 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6464 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6465 | if (len != PyList_GET_SIZE(tmp)) { |
| 6466 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6467 | goto failed; |
| 6468 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6469 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6470 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6471 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6472 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6473 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6474 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6475 | if (*out == NULL) goto failed; |
| 6476 | return 0; |
| 6477 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6478 | tp = astmodulestate_global->With_type; |
| 6479 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6480 | if (isinstance == -1) { |
| 6481 | return 1; |
| 6482 | } |
| 6483 | if (isinstance) { |
| 6484 | asdl_seq* items; |
| 6485 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6486 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6487 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6488 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6489 | return 1; |
| 6490 | } |
| 6491 | if (tmp == NULL) { |
| 6492 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6493 | return 1; |
| 6494 | } |
| 6495 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6496 | int res; |
| 6497 | Py_ssize_t len; |
| 6498 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6499 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6500 | 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] | 6501 | goto failed; |
| 6502 | } |
| 6503 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6504 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6505 | if (items == NULL) goto failed; |
| 6506 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6507 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6508 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6509 | Py_INCREF(tmp2); |
| 6510 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6511 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6512 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6513 | if (len != PyList_GET_SIZE(tmp)) { |
| 6514 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6515 | goto failed; |
| 6516 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6517 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6518 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6519 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6520 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6521 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6522 | return 1; |
| 6523 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6524 | if (tmp == NULL) { |
| 6525 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6526 | return 1; |
| 6527 | } |
| 6528 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6529 | int res; |
| 6530 | Py_ssize_t len; |
| 6531 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6532 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6533 | 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] | 6534 | goto failed; |
| 6535 | } |
| 6536 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6537 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6538 | if (body == NULL) goto failed; |
| 6539 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6540 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6541 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6542 | Py_INCREF(tmp2); |
| 6543 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6544 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6545 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6546 | if (len != PyList_GET_SIZE(tmp)) { |
| 6547 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6548 | goto failed; |
| 6549 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6550 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6551 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6552 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6553 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6554 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6555 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6556 | return 1; |
| 6557 | } |
| 6558 | if (tmp == NULL || tmp == Py_None) { |
| 6559 | Py_CLEAR(tmp); |
| 6560 | type_comment = NULL; |
| 6561 | } |
| 6562 | else { |
| 6563 | int res; |
| 6564 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6565 | if (res != 0) goto failed; |
| 6566 | Py_CLEAR(tmp); |
| 6567 | } |
| 6568 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6569 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6570 | if (*out == NULL) goto failed; |
| 6571 | return 0; |
| 6572 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6573 | tp = astmodulestate_global->AsyncWith_type; |
| 6574 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6575 | if (isinstance == -1) { |
| 6576 | return 1; |
| 6577 | } |
| 6578 | if (isinstance) { |
| 6579 | asdl_seq* items; |
| 6580 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6581 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6582 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6583 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6584 | return 1; |
| 6585 | } |
| 6586 | if (tmp == NULL) { |
| 6587 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6588 | return 1; |
| 6589 | } |
| 6590 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6591 | int res; |
| 6592 | Py_ssize_t len; |
| 6593 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6594 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6595 | 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] | 6596 | goto failed; |
| 6597 | } |
| 6598 | len = PyList_GET_SIZE(tmp); |
| 6599 | items = _Py_asdl_seq_new(len, arena); |
| 6600 | if (items == NULL) goto failed; |
| 6601 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6602 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6603 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6604 | Py_INCREF(tmp2); |
| 6605 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6606 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6607 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6608 | if (len != PyList_GET_SIZE(tmp)) { |
| 6609 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6610 | goto failed; |
| 6611 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6612 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6613 | } |
| 6614 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6615 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6616 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6617 | return 1; |
| 6618 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6619 | if (tmp == NULL) { |
| 6620 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6621 | return 1; |
| 6622 | } |
| 6623 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6624 | int res; |
| 6625 | Py_ssize_t len; |
| 6626 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6627 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6628 | 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] | 6629 | goto failed; |
| 6630 | } |
| 6631 | len = PyList_GET_SIZE(tmp); |
| 6632 | body = _Py_asdl_seq_new(len, arena); |
| 6633 | if (body == NULL) goto failed; |
| 6634 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6635 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6636 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6637 | Py_INCREF(tmp2); |
| 6638 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6639 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6640 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6641 | if (len != PyList_GET_SIZE(tmp)) { |
| 6642 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6643 | goto failed; |
| 6644 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6645 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6646 | } |
| 6647 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6648 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6649 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6650 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6651 | return 1; |
| 6652 | } |
| 6653 | if (tmp == NULL || tmp == Py_None) { |
| 6654 | Py_CLEAR(tmp); |
| 6655 | type_comment = NULL; |
| 6656 | } |
| 6657 | else { |
| 6658 | int res; |
| 6659 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6660 | if (res != 0) goto failed; |
| 6661 | Py_CLEAR(tmp); |
| 6662 | } |
| 6663 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6664 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6665 | if (*out == NULL) goto failed; |
| 6666 | return 0; |
| 6667 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6668 | tp = astmodulestate_global->Raise_type; |
| 6669 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6670 | if (isinstance == -1) { |
| 6671 | return 1; |
| 6672 | } |
| 6673 | if (isinstance) { |
| 6674 | expr_ty exc; |
| 6675 | expr_ty cause; |
| 6676 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6677 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6678 | return 1; |
| 6679 | } |
| 6680 | if (tmp == NULL || tmp == Py_None) { |
| 6681 | Py_CLEAR(tmp); |
| 6682 | exc = NULL; |
| 6683 | } |
| 6684 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6685 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6686 | res = obj2ast_expr(tmp, &exc, arena); |
| 6687 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6688 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6689 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6690 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6691 | return 1; |
| 6692 | } |
| 6693 | if (tmp == NULL || tmp == Py_None) { |
| 6694 | Py_CLEAR(tmp); |
| 6695 | cause = NULL; |
| 6696 | } |
| 6697 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6698 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6699 | res = obj2ast_expr(tmp, &cause, arena); |
| 6700 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6701 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6702 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6703 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6704 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6705 | if (*out == NULL) goto failed; |
| 6706 | return 0; |
| 6707 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6708 | tp = astmodulestate_global->Try_type; |
| 6709 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6710 | if (isinstance == -1) { |
| 6711 | return 1; |
| 6712 | } |
| 6713 | if (isinstance) { |
| 6714 | asdl_seq* body; |
| 6715 | asdl_seq* handlers; |
| 6716 | asdl_seq* orelse; |
| 6717 | asdl_seq* finalbody; |
| 6718 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6719 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6720 | return 1; |
| 6721 | } |
| 6722 | if (tmp == NULL) { |
| 6723 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6724 | return 1; |
| 6725 | } |
| 6726 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6727 | int res; |
| 6728 | Py_ssize_t len; |
| 6729 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6730 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6731 | 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] | 6732 | goto failed; |
| 6733 | } |
| 6734 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6735 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6736 | if (body == NULL) goto failed; |
| 6737 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6738 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6739 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6740 | Py_INCREF(tmp2); |
| 6741 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6742 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6743 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6744 | if (len != PyList_GET_SIZE(tmp)) { |
| 6745 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6746 | goto failed; |
| 6747 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6748 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6749 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6750 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6751 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6752 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6753 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6754 | return 1; |
| 6755 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6756 | if (tmp == NULL) { |
| 6757 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6758 | return 1; |
| 6759 | } |
| 6760 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6761 | int res; |
| 6762 | Py_ssize_t len; |
| 6763 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6764 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6765 | 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] | 6766 | goto failed; |
| 6767 | } |
| 6768 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6769 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6770 | if (handlers == NULL) goto failed; |
| 6771 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6772 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6773 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6774 | Py_INCREF(tmp2); |
| 6775 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6776 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6777 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6778 | if (len != PyList_GET_SIZE(tmp)) { |
| 6779 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6780 | goto failed; |
| 6781 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6782 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6783 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6784 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6785 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6786 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6787 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6788 | return 1; |
| 6789 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6790 | if (tmp == NULL) { |
| 6791 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6792 | return 1; |
| 6793 | } |
| 6794 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6795 | int res; |
| 6796 | Py_ssize_t len; |
| 6797 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6798 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6799 | 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] | 6800 | goto failed; |
| 6801 | } |
| 6802 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6803 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6804 | if (orelse == NULL) goto failed; |
| 6805 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6806 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6807 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6808 | Py_INCREF(tmp2); |
| 6809 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6810 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6811 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6812 | if (len != PyList_GET_SIZE(tmp)) { |
| 6813 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6814 | goto failed; |
| 6815 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6816 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6817 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6818 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6819 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6820 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6821 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6822 | return 1; |
| 6823 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6824 | if (tmp == NULL) { |
| 6825 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6826 | return 1; |
| 6827 | } |
| 6828 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6829 | int res; |
| 6830 | Py_ssize_t len; |
| 6831 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6832 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6833 | 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] | 6834 | goto failed; |
| 6835 | } |
| 6836 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6837 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6838 | if (finalbody == NULL) goto failed; |
| 6839 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6840 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6841 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6842 | Py_INCREF(tmp2); |
| 6843 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6844 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6845 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6846 | if (len != PyList_GET_SIZE(tmp)) { |
| 6847 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6848 | goto failed; |
| 6849 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6850 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6851 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6852 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6853 | } |
| 6854 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6855 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6856 | if (*out == NULL) goto failed; |
| 6857 | return 0; |
| 6858 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6859 | tp = astmodulestate_global->Assert_type; |
| 6860 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6861 | if (isinstance == -1) { |
| 6862 | return 1; |
| 6863 | } |
| 6864 | if (isinstance) { |
| 6865 | expr_ty test; |
| 6866 | expr_ty msg; |
| 6867 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6868 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6869 | return 1; |
| 6870 | } |
| 6871 | if (tmp == NULL) { |
| 6872 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6873 | return 1; |
| 6874 | } |
| 6875 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6876 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6877 | res = obj2ast_expr(tmp, &test, arena); |
| 6878 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6879 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6880 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6881 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6882 | return 1; |
| 6883 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6884 | if (tmp == NULL || tmp == Py_None) { |
| 6885 | Py_CLEAR(tmp); |
| 6886 | msg = NULL; |
| 6887 | } |
| 6888 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6889 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6890 | res = obj2ast_expr(tmp, &msg, arena); |
| 6891 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6892 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6893 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6894 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6895 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6896 | if (*out == NULL) goto failed; |
| 6897 | return 0; |
| 6898 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6899 | tp = astmodulestate_global->Import_type; |
| 6900 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6901 | if (isinstance == -1) { |
| 6902 | return 1; |
| 6903 | } |
| 6904 | if (isinstance) { |
| 6905 | asdl_seq* names; |
| 6906 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6907 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6908 | return 1; |
| 6909 | } |
| 6910 | if (tmp == NULL) { |
| 6911 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 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, "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] | 6920 | goto failed; |
| 6921 | } |
| 6922 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6923 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6924 | if (names == NULL) goto failed; |
| 6925 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6926 | alias_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_alias(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, "Import field \"names\" 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(names, 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 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6940 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6941 | 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->ImportFrom_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 | identifier module; |
| 6952 | asdl_seq* names; |
| 6953 | int level; |
| 6954 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6955 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 6956 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6957 | return 1; |
| 6958 | } |
| 6959 | if (tmp == NULL || tmp == Py_None) { |
| 6960 | Py_CLEAR(tmp); |
| 6961 | module = NULL; |
| 6962 | } |
| 6963 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6964 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6965 | res = obj2ast_identifier(tmp, &module, arena); |
| 6966 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6967 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6968 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6969 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6970 | return 1; |
| 6971 | } |
| 6972 | if (tmp == NULL) { |
| 6973 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 6974 | return 1; |
| 6975 | } |
| 6976 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6977 | int res; |
| 6978 | Py_ssize_t len; |
| 6979 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6980 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6981 | 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] | 6982 | goto failed; |
| 6983 | } |
| 6984 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6985 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6986 | if (names == NULL) goto failed; |
| 6987 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6988 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6989 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6990 | Py_INCREF(tmp2); |
| 6991 | res = obj2ast_alias(tmp2, &val, arena); |
| 6992 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6993 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6994 | if (len != PyList_GET_SIZE(tmp)) { |
| 6995 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 6996 | goto failed; |
| 6997 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6998 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6999 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7000 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7001 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7002 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7003 | return 1; |
| 7004 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7005 | if (tmp == NULL || tmp == Py_None) { |
| 7006 | Py_CLEAR(tmp); |
| 7007 | level = 0; |
| 7008 | } |
| 7009 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7010 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7011 | res = obj2ast_int(tmp, &level, arena); |
| 7012 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7013 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7014 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7015 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7016 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7017 | if (*out == NULL) goto failed; |
| 7018 | return 0; |
| 7019 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7020 | tp = astmodulestate_global->Global_type; |
| 7021 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7022 | if (isinstance == -1) { |
| 7023 | return 1; |
| 7024 | } |
| 7025 | if (isinstance) { |
| 7026 | asdl_seq* names; |
| 7027 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7028 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7029 | return 1; |
| 7030 | } |
| 7031 | if (tmp == NULL) { |
| 7032 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7033 | return 1; |
| 7034 | } |
| 7035 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7036 | int res; |
| 7037 | Py_ssize_t len; |
| 7038 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7039 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7040 | 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] | 7041 | goto failed; |
| 7042 | } |
| 7043 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7044 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7045 | if (names == NULL) goto failed; |
| 7046 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7047 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7048 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7049 | Py_INCREF(tmp2); |
| 7050 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7051 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7052 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7053 | if (len != PyList_GET_SIZE(tmp)) { |
| 7054 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7055 | goto failed; |
| 7056 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7057 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7058 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7059 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7060 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7061 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7062 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7063 | if (*out == NULL) goto failed; |
| 7064 | return 0; |
| 7065 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7066 | tp = astmodulestate_global->Nonlocal_type; |
| 7067 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7068 | if (isinstance == -1) { |
| 7069 | return 1; |
| 7070 | } |
| 7071 | if (isinstance) { |
| 7072 | asdl_seq* names; |
| 7073 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7074 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7075 | return 1; |
| 7076 | } |
| 7077 | if (tmp == NULL) { |
| 7078 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7079 | return 1; |
| 7080 | } |
| 7081 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7082 | int res; |
| 7083 | Py_ssize_t len; |
| 7084 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7085 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7086 | 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] | 7087 | goto failed; |
| 7088 | } |
| 7089 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7090 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7091 | if (names == NULL) goto failed; |
| 7092 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7093 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7094 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7095 | Py_INCREF(tmp2); |
| 7096 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7097 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7098 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7099 | if (len != PyList_GET_SIZE(tmp)) { |
| 7100 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7101 | goto failed; |
| 7102 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7103 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7104 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7105 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7106 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7107 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7108 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7109 | if (*out == NULL) goto failed; |
| 7110 | return 0; |
| 7111 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7112 | tp = astmodulestate_global->Expr_type; |
| 7113 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7114 | if (isinstance == -1) { |
| 7115 | return 1; |
| 7116 | } |
| 7117 | if (isinstance) { |
| 7118 | expr_ty value; |
| 7119 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7120 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7121 | return 1; |
| 7122 | } |
| 7123 | if (tmp == NULL) { |
| 7124 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7125 | return 1; |
| 7126 | } |
| 7127 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7128 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7129 | res = obj2ast_expr(tmp, &value, arena); |
| 7130 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7131 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7132 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7133 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7134 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7135 | if (*out == NULL) goto failed; |
| 7136 | return 0; |
| 7137 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7138 | tp = astmodulestate_global->Pass_type; |
| 7139 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7140 | if (isinstance == -1) { |
| 7141 | return 1; |
| 7142 | } |
| 7143 | if (isinstance) { |
| 7144 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7145 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7146 | if (*out == NULL) goto failed; |
| 7147 | return 0; |
| 7148 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7149 | tp = astmodulestate_global->Break_type; |
| 7150 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7151 | if (isinstance == -1) { |
| 7152 | return 1; |
| 7153 | } |
| 7154 | if (isinstance) { |
| 7155 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7156 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7157 | if (*out == NULL) goto failed; |
| 7158 | return 0; |
| 7159 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7160 | tp = astmodulestate_global->Continue_type; |
| 7161 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7162 | if (isinstance == -1) { |
| 7163 | return 1; |
| 7164 | } |
| 7165 | if (isinstance) { |
| 7166 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7167 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7168 | if (*out == NULL) goto failed; |
| 7169 | return 0; |
| 7170 | } |
| 7171 | |
| 7172 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7173 | failed: |
| 7174 | Py_XDECREF(tmp); |
| 7175 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7176 | } |
| 7177 | |
| 7178 | int |
| 7179 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7180 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7181 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7182 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7183 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7184 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7185 | int lineno; |
| 7186 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7187 | int end_lineno; |
| 7188 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7189 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7190 | if (obj == Py_None) { |
| 7191 | *out = NULL; |
| 7192 | return 0; |
| 7193 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7194 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7195 | return 1; |
| 7196 | } |
| 7197 | if (tmp == NULL) { |
| 7198 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7199 | return 1; |
| 7200 | } |
| 7201 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7202 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7203 | res = obj2ast_int(tmp, &lineno, arena); |
| 7204 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7205 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7206 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7207 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7208 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7209 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7210 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7211 | if (tmp == NULL) { |
| 7212 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7213 | return 1; |
| 7214 | } |
| 7215 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7216 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7217 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7218 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7219 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7220 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7221 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7222 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7223 | return 1; |
| 7224 | } |
| 7225 | if (tmp == NULL || tmp == Py_None) { |
| 7226 | Py_CLEAR(tmp); |
| 7227 | end_lineno = 0; |
| 7228 | } |
| 7229 | else { |
| 7230 | int res; |
| 7231 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7232 | if (res != 0) goto failed; |
| 7233 | Py_CLEAR(tmp); |
| 7234 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7235 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7236 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7237 | return 1; |
| 7238 | } |
| 7239 | if (tmp == NULL || tmp == Py_None) { |
| 7240 | Py_CLEAR(tmp); |
| 7241 | end_col_offset = 0; |
| 7242 | } |
| 7243 | else { |
| 7244 | int res; |
| 7245 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7246 | if (res != 0) goto failed; |
| 7247 | Py_CLEAR(tmp); |
| 7248 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7249 | tp = astmodulestate_global->BoolOp_type; |
| 7250 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7251 | if (isinstance == -1) { |
| 7252 | return 1; |
| 7253 | } |
| 7254 | if (isinstance) { |
| 7255 | boolop_ty op; |
| 7256 | asdl_seq* values; |
| 7257 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7258 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7259 | return 1; |
| 7260 | } |
| 7261 | if (tmp == NULL) { |
| 7262 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7263 | return 1; |
| 7264 | } |
| 7265 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7266 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7267 | res = obj2ast_boolop(tmp, &op, arena); |
| 7268 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7269 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7270 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7271 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7272 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7273 | return 1; |
| 7274 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7275 | if (tmp == NULL) { |
| 7276 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7277 | return 1; |
| 7278 | } |
| 7279 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7280 | int res; |
| 7281 | Py_ssize_t len; |
| 7282 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7283 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7284 | 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] | 7285 | goto failed; |
| 7286 | } |
| 7287 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7288 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7289 | if (values == NULL) goto failed; |
| 7290 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7291 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7292 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7293 | Py_INCREF(tmp2); |
| 7294 | res = obj2ast_expr(tmp2, &val, arena); |
| 7295 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7296 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7297 | if (len != PyList_GET_SIZE(tmp)) { |
| 7298 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7299 | goto failed; |
| 7300 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7301 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7302 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7303 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7304 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7305 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7306 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7307 | if (*out == NULL) goto failed; |
| 7308 | return 0; |
| 7309 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7310 | tp = astmodulestate_global->NamedExpr_type; |
| 7311 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7312 | if (isinstance == -1) { |
| 7313 | return 1; |
| 7314 | } |
| 7315 | if (isinstance) { |
| 7316 | expr_ty target; |
| 7317 | expr_ty value; |
| 7318 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7319 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7320 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7321 | return 1; |
| 7322 | } |
| 7323 | if (tmp == NULL) { |
| 7324 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7325 | return 1; |
| 7326 | } |
| 7327 | else { |
| 7328 | int res; |
| 7329 | res = obj2ast_expr(tmp, &target, arena); |
| 7330 | if (res != 0) goto failed; |
| 7331 | Py_CLEAR(tmp); |
| 7332 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7333 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7334 | return 1; |
| 7335 | } |
| 7336 | if (tmp == NULL) { |
| 7337 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7338 | return 1; |
| 7339 | } |
| 7340 | else { |
| 7341 | int res; |
| 7342 | res = obj2ast_expr(tmp, &value, arena); |
| 7343 | if (res != 0) goto failed; |
| 7344 | Py_CLEAR(tmp); |
| 7345 | } |
| 7346 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7347 | end_col_offset, arena); |
| 7348 | if (*out == NULL) goto failed; |
| 7349 | return 0; |
| 7350 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7351 | tp = astmodulestate_global->BinOp_type; |
| 7352 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7353 | if (isinstance == -1) { |
| 7354 | return 1; |
| 7355 | } |
| 7356 | if (isinstance) { |
| 7357 | expr_ty left; |
| 7358 | operator_ty op; |
| 7359 | expr_ty right; |
| 7360 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7361 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7362 | return 1; |
| 7363 | } |
| 7364 | if (tmp == NULL) { |
| 7365 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7366 | return 1; |
| 7367 | } |
| 7368 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7369 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7370 | res = obj2ast_expr(tmp, &left, arena); |
| 7371 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7372 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7374 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7375 | return 1; |
| 7376 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7377 | if (tmp == NULL) { |
| 7378 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7379 | return 1; |
| 7380 | } |
| 7381 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7382 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7383 | res = obj2ast_operator(tmp, &op, arena); |
| 7384 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7385 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7386 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7387 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7388 | return 1; |
| 7389 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7390 | if (tmp == NULL) { |
| 7391 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7392 | return 1; |
| 7393 | } |
| 7394 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7395 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7396 | res = obj2ast_expr(tmp, &right, arena); |
| 7397 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7398 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7399 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7400 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7401 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7402 | if (*out == NULL) goto failed; |
| 7403 | return 0; |
| 7404 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7405 | tp = astmodulestate_global->UnaryOp_type; |
| 7406 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7407 | if (isinstance == -1) { |
| 7408 | return 1; |
| 7409 | } |
| 7410 | if (isinstance) { |
| 7411 | unaryop_ty op; |
| 7412 | expr_ty operand; |
| 7413 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7414 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7415 | return 1; |
| 7416 | } |
| 7417 | if (tmp == NULL) { |
| 7418 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7419 | return 1; |
| 7420 | } |
| 7421 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7422 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7423 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7424 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7425 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7426 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7427 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7428 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7429 | return 1; |
| 7430 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7431 | if (tmp == NULL) { |
| 7432 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7433 | return 1; |
| 7434 | } |
| 7435 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7436 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7437 | res = obj2ast_expr(tmp, &operand, arena); |
| 7438 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7439 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7440 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7441 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7442 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7443 | if (*out == NULL) goto failed; |
| 7444 | return 0; |
| 7445 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7446 | tp = astmodulestate_global->Lambda_type; |
| 7447 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7448 | if (isinstance == -1) { |
| 7449 | return 1; |
| 7450 | } |
| 7451 | if (isinstance) { |
| 7452 | arguments_ty args; |
| 7453 | expr_ty body; |
| 7454 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7455 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7456 | return 1; |
| 7457 | } |
| 7458 | if (tmp == NULL) { |
| 7459 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7460 | return 1; |
| 7461 | } |
| 7462 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7463 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7464 | res = obj2ast_arguments(tmp, &args, arena); |
| 7465 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7466 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7467 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7468 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7469 | return 1; |
| 7470 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7471 | if (tmp == NULL) { |
| 7472 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7473 | return 1; |
| 7474 | } |
| 7475 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7476 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7477 | res = obj2ast_expr(tmp, &body, arena); |
| 7478 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7479 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7480 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7481 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7482 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7483 | if (*out == NULL) goto failed; |
| 7484 | return 0; |
| 7485 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7486 | tp = astmodulestate_global->IfExp_type; |
| 7487 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7488 | if (isinstance == -1) { |
| 7489 | return 1; |
| 7490 | } |
| 7491 | if (isinstance) { |
| 7492 | expr_ty test; |
| 7493 | expr_ty body; |
| 7494 | expr_ty orelse; |
| 7495 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7496 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7497 | return 1; |
| 7498 | } |
| 7499 | if (tmp == NULL) { |
| 7500 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7501 | return 1; |
| 7502 | } |
| 7503 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7504 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7505 | res = obj2ast_expr(tmp, &test, arena); |
| 7506 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7507 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7508 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7509 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7510 | return 1; |
| 7511 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7512 | if (tmp == NULL) { |
| 7513 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7514 | return 1; |
| 7515 | } |
| 7516 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7517 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7518 | res = obj2ast_expr(tmp, &body, arena); |
| 7519 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7520 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7521 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7522 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7523 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7524 | return 1; |
| 7525 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7526 | if (tmp == NULL) { |
| 7527 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7528 | return 1; |
| 7529 | } |
| 7530 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7531 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7532 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7533 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7534 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7535 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7536 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7537 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7538 | if (*out == NULL) goto failed; |
| 7539 | return 0; |
| 7540 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7541 | tp = astmodulestate_global->Dict_type; |
| 7542 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7543 | if (isinstance == -1) { |
| 7544 | return 1; |
| 7545 | } |
| 7546 | if (isinstance) { |
| 7547 | asdl_seq* keys; |
| 7548 | asdl_seq* values; |
| 7549 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7550 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7551 | return 1; |
| 7552 | } |
| 7553 | if (tmp == NULL) { |
| 7554 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7555 | return 1; |
| 7556 | } |
| 7557 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7558 | int res; |
| 7559 | Py_ssize_t len; |
| 7560 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7561 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7562 | 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] | 7563 | goto failed; |
| 7564 | } |
| 7565 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7566 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7567 | if (keys == NULL) goto failed; |
| 7568 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7569 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7570 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7571 | Py_INCREF(tmp2); |
| 7572 | res = obj2ast_expr(tmp2, &val, arena); |
| 7573 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7574 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7575 | if (len != PyList_GET_SIZE(tmp)) { |
| 7576 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7577 | goto failed; |
| 7578 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7579 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7580 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7581 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7582 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7583 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7584 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7585 | return 1; |
| 7586 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7587 | if (tmp == NULL) { |
| 7588 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7589 | return 1; |
| 7590 | } |
| 7591 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7592 | int res; |
| 7593 | Py_ssize_t len; |
| 7594 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7595 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7596 | 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] | 7597 | goto failed; |
| 7598 | } |
| 7599 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7600 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7601 | if (values == NULL) goto failed; |
| 7602 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7603 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7604 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7605 | Py_INCREF(tmp2); |
| 7606 | res = obj2ast_expr(tmp2, &val, arena); |
| 7607 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7608 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7609 | if (len != PyList_GET_SIZE(tmp)) { |
| 7610 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7611 | goto failed; |
| 7612 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7613 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7614 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7615 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7616 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7617 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7618 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7619 | if (*out == NULL) goto failed; |
| 7620 | return 0; |
| 7621 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7622 | tp = astmodulestate_global->Set_type; |
| 7623 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7624 | if (isinstance == -1) { |
| 7625 | return 1; |
| 7626 | } |
| 7627 | if (isinstance) { |
| 7628 | asdl_seq* elts; |
| 7629 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7630 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7631 | return 1; |
| 7632 | } |
| 7633 | if (tmp == NULL) { |
| 7634 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7635 | return 1; |
| 7636 | } |
| 7637 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7638 | int res; |
| 7639 | Py_ssize_t len; |
| 7640 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7641 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7642 | 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] | 7643 | goto failed; |
| 7644 | } |
| 7645 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7646 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7647 | if (elts == NULL) goto failed; |
| 7648 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7649 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7650 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7651 | Py_INCREF(tmp2); |
| 7652 | res = obj2ast_expr(tmp2, &val, arena); |
| 7653 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7654 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7655 | if (len != PyList_GET_SIZE(tmp)) { |
| 7656 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7657 | goto failed; |
| 7658 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7659 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7660 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7661 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7662 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7663 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7664 | if (*out == NULL) goto failed; |
| 7665 | return 0; |
| 7666 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7667 | tp = astmodulestate_global->ListComp_type; |
| 7668 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7669 | if (isinstance == -1) { |
| 7670 | return 1; |
| 7671 | } |
| 7672 | if (isinstance) { |
| 7673 | expr_ty elt; |
| 7674 | asdl_seq* generators; |
| 7675 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7676 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7677 | return 1; |
| 7678 | } |
| 7679 | if (tmp == NULL) { |
| 7680 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7681 | return 1; |
| 7682 | } |
| 7683 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7684 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7685 | res = obj2ast_expr(tmp, &elt, arena); |
| 7686 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7687 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7688 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7689 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7690 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7691 | return 1; |
| 7692 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7693 | if (tmp == NULL) { |
| 7694 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7695 | return 1; |
| 7696 | } |
| 7697 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7698 | int res; |
| 7699 | Py_ssize_t len; |
| 7700 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7701 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7702 | 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] | 7703 | goto failed; |
| 7704 | } |
| 7705 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7706 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7707 | if (generators == NULL) goto failed; |
| 7708 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7709 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7710 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7711 | Py_INCREF(tmp2); |
| 7712 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7713 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7714 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7715 | if (len != PyList_GET_SIZE(tmp)) { |
| 7716 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7717 | goto failed; |
| 7718 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7719 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7720 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7721 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7722 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7723 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7724 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7725 | if (*out == NULL) goto failed; |
| 7726 | return 0; |
| 7727 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7728 | tp = astmodulestate_global->SetComp_type; |
| 7729 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7730 | if (isinstance == -1) { |
| 7731 | return 1; |
| 7732 | } |
| 7733 | if (isinstance) { |
| 7734 | expr_ty elt; |
| 7735 | asdl_seq* generators; |
| 7736 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7737 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7738 | return 1; |
| 7739 | } |
| 7740 | if (tmp == NULL) { |
| 7741 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7742 | return 1; |
| 7743 | } |
| 7744 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7745 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7746 | res = obj2ast_expr(tmp, &elt, arena); |
| 7747 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7748 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7749 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7750 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7751 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7752 | return 1; |
| 7753 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7754 | if (tmp == NULL) { |
| 7755 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7756 | return 1; |
| 7757 | } |
| 7758 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7759 | int res; |
| 7760 | Py_ssize_t len; |
| 7761 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7762 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7763 | 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] | 7764 | goto failed; |
| 7765 | } |
| 7766 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7767 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7768 | if (generators == NULL) goto failed; |
| 7769 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7770 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7771 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7772 | Py_INCREF(tmp2); |
| 7773 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7774 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7775 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7776 | if (len != PyList_GET_SIZE(tmp)) { |
| 7777 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7778 | goto failed; |
| 7779 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7780 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7781 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7782 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7783 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7784 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7785 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7786 | if (*out == NULL) goto failed; |
| 7787 | return 0; |
| 7788 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7789 | tp = astmodulestate_global->DictComp_type; |
| 7790 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7791 | if (isinstance == -1) { |
| 7792 | return 1; |
| 7793 | } |
| 7794 | if (isinstance) { |
| 7795 | expr_ty key; |
| 7796 | expr_ty value; |
| 7797 | asdl_seq* generators; |
| 7798 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7799 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7800 | return 1; |
| 7801 | } |
| 7802 | if (tmp == NULL) { |
| 7803 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7804 | return 1; |
| 7805 | } |
| 7806 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7807 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7808 | res = obj2ast_expr(tmp, &key, arena); |
| 7809 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7810 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7811 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7812 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7813 | return 1; |
| 7814 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7815 | if (tmp == NULL) { |
| 7816 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7817 | return 1; |
| 7818 | } |
| 7819 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7820 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7821 | res = obj2ast_expr(tmp, &value, arena); |
| 7822 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7823 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7824 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7825 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7826 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7827 | return 1; |
| 7828 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7829 | if (tmp == NULL) { |
| 7830 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7831 | return 1; |
| 7832 | } |
| 7833 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7834 | int res; |
| 7835 | Py_ssize_t len; |
| 7836 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7837 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7838 | 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] | 7839 | goto failed; |
| 7840 | } |
| 7841 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7842 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7843 | if (generators == NULL) goto failed; |
| 7844 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7845 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7846 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7847 | Py_INCREF(tmp2); |
| 7848 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7849 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7850 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7851 | if (len != PyList_GET_SIZE(tmp)) { |
| 7852 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7853 | goto failed; |
| 7854 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7855 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7856 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7857 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7858 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7859 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7860 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7861 | if (*out == NULL) goto failed; |
| 7862 | return 0; |
| 7863 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7864 | tp = astmodulestate_global->GeneratorExp_type; |
| 7865 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7866 | if (isinstance == -1) { |
| 7867 | return 1; |
| 7868 | } |
| 7869 | if (isinstance) { |
| 7870 | expr_ty elt; |
| 7871 | asdl_seq* generators; |
| 7872 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7873 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7874 | return 1; |
| 7875 | } |
| 7876 | if (tmp == NULL) { |
| 7877 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7878 | return 1; |
| 7879 | } |
| 7880 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7881 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7882 | res = obj2ast_expr(tmp, &elt, arena); |
| 7883 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7884 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7885 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7886 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7887 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7888 | return 1; |
| 7889 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7890 | if (tmp == NULL) { |
| 7891 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7892 | return 1; |
| 7893 | } |
| 7894 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7895 | int res; |
| 7896 | Py_ssize_t len; |
| 7897 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7898 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7899 | 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] | 7900 | goto failed; |
| 7901 | } |
| 7902 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7903 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7904 | if (generators == NULL) goto failed; |
| 7905 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7906 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7907 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7908 | Py_INCREF(tmp2); |
| 7909 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7910 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7911 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7912 | if (len != PyList_GET_SIZE(tmp)) { |
| 7913 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7914 | goto failed; |
| 7915 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7916 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7917 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7918 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7919 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7920 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7921 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7922 | if (*out == NULL) goto failed; |
| 7923 | return 0; |
| 7924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7925 | tp = astmodulestate_global->Await_type; |
| 7926 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7927 | if (isinstance == -1) { |
| 7928 | return 1; |
| 7929 | } |
| 7930 | if (isinstance) { |
| 7931 | expr_ty value; |
| 7932 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7933 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7934 | return 1; |
| 7935 | } |
| 7936 | if (tmp == NULL) { |
| 7937 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 7938 | return 1; |
| 7939 | } |
| 7940 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7941 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7942 | res = obj2ast_expr(tmp, &value, arena); |
| 7943 | if (res != 0) goto failed; |
| 7944 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7945 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7946 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7947 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7948 | if (*out == NULL) goto failed; |
| 7949 | return 0; |
| 7950 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7951 | tp = astmodulestate_global->Yield_type; |
| 7952 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7953 | if (isinstance == -1) { |
| 7954 | return 1; |
| 7955 | } |
| 7956 | if (isinstance) { |
| 7957 | expr_ty value; |
| 7958 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7959 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7960 | return 1; |
| 7961 | } |
| 7962 | if (tmp == NULL || tmp == Py_None) { |
| 7963 | Py_CLEAR(tmp); |
| 7964 | value = NULL; |
| 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, &value, arena); |
| 7969 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7970 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7971 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7972 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7973 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7974 | if (*out == NULL) goto failed; |
| 7975 | return 0; |
| 7976 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7977 | tp = astmodulestate_global->YieldFrom_type; |
| 7978 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7979 | if (isinstance == -1) { |
| 7980 | return 1; |
| 7981 | } |
| 7982 | if (isinstance) { |
| 7983 | expr_ty value; |
| 7984 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7985 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7986 | return 1; |
| 7987 | } |
| 7988 | if (tmp == NULL) { |
| 7989 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 7990 | return 1; |
| 7991 | } |
| 7992 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7993 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7994 | res = obj2ast_expr(tmp, &value, arena); |
| 7995 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7996 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7997 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7998 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7999 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8000 | if (*out == NULL) goto failed; |
| 8001 | return 0; |
| 8002 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8003 | tp = astmodulestate_global->Compare_type; |
| 8004 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8005 | if (isinstance == -1) { |
| 8006 | return 1; |
| 8007 | } |
| 8008 | if (isinstance) { |
| 8009 | expr_ty left; |
| 8010 | asdl_int_seq* ops; |
| 8011 | asdl_seq* comparators; |
| 8012 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8013 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8014 | return 1; |
| 8015 | } |
| 8016 | if (tmp == NULL) { |
| 8017 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8018 | return 1; |
| 8019 | } |
| 8020 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8021 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8022 | res = obj2ast_expr(tmp, &left, arena); |
| 8023 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8024 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8025 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8026 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8027 | return 1; |
| 8028 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8029 | if (tmp == NULL) { |
| 8030 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8031 | return 1; |
| 8032 | } |
| 8033 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8034 | int res; |
| 8035 | Py_ssize_t len; |
| 8036 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8037 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8038 | 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] | 8039 | goto failed; |
| 8040 | } |
| 8041 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8042 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8043 | if (ops == NULL) goto failed; |
| 8044 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8045 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8046 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8047 | Py_INCREF(tmp2); |
| 8048 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8049 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8050 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8051 | if (len != PyList_GET_SIZE(tmp)) { |
| 8052 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8053 | goto failed; |
| 8054 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8055 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8056 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8057 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8058 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8059 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8060 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8061 | return 1; |
| 8062 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8063 | if (tmp == NULL) { |
| 8064 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8065 | return 1; |
| 8066 | } |
| 8067 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8068 | int res; |
| 8069 | Py_ssize_t len; |
| 8070 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8071 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8072 | 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] | 8073 | goto failed; |
| 8074 | } |
| 8075 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8076 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8077 | if (comparators == NULL) goto failed; |
| 8078 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8079 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8080 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8081 | Py_INCREF(tmp2); |
| 8082 | res = obj2ast_expr(tmp2, &val, arena); |
| 8083 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8084 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8085 | if (len != PyList_GET_SIZE(tmp)) { |
| 8086 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8087 | goto failed; |
| 8088 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8089 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8090 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8091 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8092 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8093 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8094 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8095 | if (*out == NULL) goto failed; |
| 8096 | return 0; |
| 8097 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8098 | tp = astmodulestate_global->Call_type; |
| 8099 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8100 | if (isinstance == -1) { |
| 8101 | return 1; |
| 8102 | } |
| 8103 | if (isinstance) { |
| 8104 | expr_ty func; |
| 8105 | asdl_seq* args; |
| 8106 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8107 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8108 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8109 | return 1; |
| 8110 | } |
| 8111 | if (tmp == NULL) { |
| 8112 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8113 | return 1; |
| 8114 | } |
| 8115 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8116 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8117 | res = obj2ast_expr(tmp, &func, arena); |
| 8118 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8119 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8120 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8121 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8122 | return 1; |
| 8123 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8124 | if (tmp == NULL) { |
| 8125 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8126 | return 1; |
| 8127 | } |
| 8128 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8129 | int res; |
| 8130 | Py_ssize_t len; |
| 8131 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8132 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8133 | 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] | 8134 | goto failed; |
| 8135 | } |
| 8136 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8137 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8138 | if (args == NULL) goto failed; |
| 8139 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8140 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8141 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8142 | Py_INCREF(tmp2); |
| 8143 | res = obj2ast_expr(tmp2, &val, arena); |
| 8144 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8145 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8146 | if (len != PyList_GET_SIZE(tmp)) { |
| 8147 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8148 | goto failed; |
| 8149 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8150 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8151 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8152 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8153 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8154 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8155 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8156 | return 1; |
| 8157 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8158 | if (tmp == NULL) { |
| 8159 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8160 | return 1; |
| 8161 | } |
| 8162 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8163 | int res; |
| 8164 | Py_ssize_t len; |
| 8165 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8166 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8167 | 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] | 8168 | goto failed; |
| 8169 | } |
| 8170 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8171 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8172 | if (keywords == NULL) goto failed; |
| 8173 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8174 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8175 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8176 | Py_INCREF(tmp2); |
| 8177 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8178 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8179 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8180 | if (len != PyList_GET_SIZE(tmp)) { |
| 8181 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8182 | goto failed; |
| 8183 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8184 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8185 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8186 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8187 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8188 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8189 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8190 | if (*out == NULL) goto failed; |
| 8191 | return 0; |
| 8192 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8193 | tp = astmodulestate_global->FormattedValue_type; |
| 8194 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8195 | if (isinstance == -1) { |
| 8196 | return 1; |
| 8197 | } |
| 8198 | if (isinstance) { |
| 8199 | expr_ty value; |
| 8200 | int conversion; |
| 8201 | expr_ty format_spec; |
| 8202 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8203 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8204 | return 1; |
| 8205 | } |
| 8206 | if (tmp == NULL) { |
| 8207 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8208 | return 1; |
| 8209 | } |
| 8210 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8211 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8212 | res = obj2ast_expr(tmp, &value, arena); |
| 8213 | if (res != 0) goto failed; |
| 8214 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8215 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8216 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8217 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8218 | return 1; |
| 8219 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8220 | if (tmp == NULL || tmp == Py_None) { |
| 8221 | Py_CLEAR(tmp); |
| 8222 | conversion = 0; |
| 8223 | } |
| 8224 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8225 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8226 | res = obj2ast_int(tmp, &conversion, arena); |
| 8227 | if (res != 0) goto failed; |
| 8228 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8229 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8230 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8231 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8232 | return 1; |
| 8233 | } |
| 8234 | if (tmp == NULL || tmp == Py_None) { |
| 8235 | Py_CLEAR(tmp); |
| 8236 | format_spec = NULL; |
| 8237 | } |
| 8238 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8239 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8240 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8241 | if (res != 0) goto failed; |
| 8242 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8243 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8244 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8245 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8246 | if (*out == NULL) goto failed; |
| 8247 | return 0; |
| 8248 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8249 | tp = astmodulestate_global->JoinedStr_type; |
| 8250 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8251 | if (isinstance == -1) { |
| 8252 | return 1; |
| 8253 | } |
| 8254 | if (isinstance) { |
| 8255 | asdl_seq* values; |
| 8256 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8257 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8258 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8259 | return 1; |
| 8260 | } |
| 8261 | if (tmp == NULL) { |
| 8262 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8263 | return 1; |
| 8264 | } |
| 8265 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8266 | int res; |
| 8267 | Py_ssize_t len; |
| 8268 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8269 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8270 | 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] | 8271 | goto failed; |
| 8272 | } |
| 8273 | len = PyList_GET_SIZE(tmp); |
| 8274 | values = _Py_asdl_seq_new(len, arena); |
| 8275 | if (values == NULL) goto failed; |
| 8276 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8277 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8278 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8279 | Py_INCREF(tmp2); |
| 8280 | res = obj2ast_expr(tmp2, &val, arena); |
| 8281 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8282 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8283 | if (len != PyList_GET_SIZE(tmp)) { |
| 8284 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8285 | goto failed; |
| 8286 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8287 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8288 | } |
| 8289 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8290 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8291 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8292 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8293 | if (*out == NULL) goto failed; |
| 8294 | return 0; |
| 8295 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8296 | tp = astmodulestate_global->Constant_type; |
| 8297 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8298 | if (isinstance == -1) { |
| 8299 | return 1; |
| 8300 | } |
| 8301 | if (isinstance) { |
| 8302 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8303 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8304 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8305 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8306 | return 1; |
| 8307 | } |
| 8308 | if (tmp == NULL) { |
| 8309 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8310 | return 1; |
| 8311 | } |
| 8312 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8313 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8314 | res = obj2ast_constant(tmp, &value, arena); |
| 8315 | if (res != 0) goto failed; |
| 8316 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8318 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8319 | return 1; |
| 8320 | } |
| 8321 | if (tmp == NULL || tmp == Py_None) { |
| 8322 | Py_CLEAR(tmp); |
| 8323 | kind = NULL; |
| 8324 | } |
| 8325 | else { |
| 8326 | int res; |
| 8327 | res = obj2ast_string(tmp, &kind, arena); |
| 8328 | if (res != 0) goto failed; |
| 8329 | Py_CLEAR(tmp); |
| 8330 | } |
| 8331 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8332 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8333 | if (*out == NULL) goto failed; |
| 8334 | return 0; |
| 8335 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8336 | tp = astmodulestate_global->Attribute_type; |
| 8337 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8338 | if (isinstance == -1) { |
| 8339 | return 1; |
| 8340 | } |
| 8341 | if (isinstance) { |
| 8342 | expr_ty value; |
| 8343 | identifier attr; |
| 8344 | expr_context_ty ctx; |
| 8345 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8346 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8347 | return 1; |
| 8348 | } |
| 8349 | if (tmp == NULL) { |
| 8350 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8351 | return 1; |
| 8352 | } |
| 8353 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8354 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8355 | res = obj2ast_expr(tmp, &value, arena); |
| 8356 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8357 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8358 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8359 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8360 | return 1; |
| 8361 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8362 | if (tmp == NULL) { |
| 8363 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8364 | return 1; |
| 8365 | } |
| 8366 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8367 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8368 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8369 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8370 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8371 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8372 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8373 | return 1; |
| 8374 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8375 | if (tmp == NULL) { |
| 8376 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8377 | return 1; |
| 8378 | } |
| 8379 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8380 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8381 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8382 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8383 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8384 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8385 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8386 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8387 | if (*out == NULL) goto failed; |
| 8388 | return 0; |
| 8389 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8390 | tp = astmodulestate_global->Subscript_type; |
| 8391 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8392 | if (isinstance == -1) { |
| 8393 | return 1; |
| 8394 | } |
| 8395 | if (isinstance) { |
| 8396 | expr_ty value; |
| 8397 | slice_ty slice; |
| 8398 | expr_context_ty ctx; |
| 8399 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8400 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8401 | return 1; |
| 8402 | } |
| 8403 | if (tmp == NULL) { |
| 8404 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8405 | return 1; |
| 8406 | } |
| 8407 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8408 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8409 | res = obj2ast_expr(tmp, &value, arena); |
| 8410 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8411 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8412 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8413 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8414 | return 1; |
| 8415 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8416 | if (tmp == NULL) { |
| 8417 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8418 | return 1; |
| 8419 | } |
| 8420 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8421 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8422 | res = obj2ast_slice(tmp, &slice, arena); |
| 8423 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8424 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8425 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8426 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8427 | return 1; |
| 8428 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8429 | if (tmp == NULL) { |
| 8430 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8431 | return 1; |
| 8432 | } |
| 8433 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8434 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8435 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8436 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8437 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8438 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8439 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8440 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8441 | if (*out == NULL) goto failed; |
| 8442 | return 0; |
| 8443 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8444 | tp = astmodulestate_global->Starred_type; |
| 8445 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8446 | if (isinstance == -1) { |
| 8447 | return 1; |
| 8448 | } |
| 8449 | if (isinstance) { |
| 8450 | expr_ty value; |
| 8451 | expr_context_ty ctx; |
| 8452 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8453 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8454 | return 1; |
| 8455 | } |
| 8456 | if (tmp == NULL) { |
| 8457 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8458 | return 1; |
| 8459 | } |
| 8460 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8461 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8462 | res = obj2ast_expr(tmp, &value, arena); |
| 8463 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8464 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8465 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8466 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8467 | return 1; |
| 8468 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8469 | if (tmp == NULL) { |
| 8470 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8471 | return 1; |
| 8472 | } |
| 8473 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8474 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8475 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8476 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8477 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8478 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8479 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8480 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8481 | if (*out == NULL) goto failed; |
| 8482 | return 0; |
| 8483 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8484 | tp = astmodulestate_global->Name_type; |
| 8485 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8486 | if (isinstance == -1) { |
| 8487 | return 1; |
| 8488 | } |
| 8489 | if (isinstance) { |
| 8490 | identifier id; |
| 8491 | expr_context_ty ctx; |
| 8492 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8493 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8494 | return 1; |
| 8495 | } |
| 8496 | if (tmp == NULL) { |
| 8497 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8498 | return 1; |
| 8499 | } |
| 8500 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8501 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8502 | res = obj2ast_identifier(tmp, &id, arena); |
| 8503 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8504 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8505 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8506 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8507 | return 1; |
| 8508 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8509 | if (tmp == NULL) { |
| 8510 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8511 | return 1; |
| 8512 | } |
| 8513 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8514 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8515 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8516 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8517 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8518 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8519 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8520 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8521 | if (*out == NULL) goto failed; |
| 8522 | return 0; |
| 8523 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8524 | tp = astmodulestate_global->List_type; |
| 8525 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8526 | if (isinstance == -1) { |
| 8527 | return 1; |
| 8528 | } |
| 8529 | if (isinstance) { |
| 8530 | asdl_seq* elts; |
| 8531 | expr_context_ty ctx; |
| 8532 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8533 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8534 | return 1; |
| 8535 | } |
| 8536 | if (tmp == NULL) { |
| 8537 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8538 | return 1; |
| 8539 | } |
| 8540 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8541 | int res; |
| 8542 | Py_ssize_t len; |
| 8543 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8544 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8545 | 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] | 8546 | goto failed; |
| 8547 | } |
| 8548 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8549 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8550 | if (elts == NULL) goto failed; |
| 8551 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8552 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8553 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8554 | Py_INCREF(tmp2); |
| 8555 | res = obj2ast_expr(tmp2, &val, arena); |
| 8556 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8557 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8558 | if (len != PyList_GET_SIZE(tmp)) { |
| 8559 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8560 | goto failed; |
| 8561 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8562 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8563 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8564 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8565 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8566 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8567 | return 1; |
| 8568 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8569 | if (tmp == NULL) { |
| 8570 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8571 | return 1; |
| 8572 | } |
| 8573 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8574 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8575 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8576 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8577 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8578 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8579 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8580 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8581 | if (*out == NULL) goto failed; |
| 8582 | return 0; |
| 8583 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8584 | tp = astmodulestate_global->Tuple_type; |
| 8585 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8586 | if (isinstance == -1) { |
| 8587 | return 1; |
| 8588 | } |
| 8589 | if (isinstance) { |
| 8590 | asdl_seq* elts; |
| 8591 | expr_context_ty ctx; |
| 8592 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8593 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8594 | return 1; |
| 8595 | } |
| 8596 | if (tmp == NULL) { |
| 8597 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8598 | return 1; |
| 8599 | } |
| 8600 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8601 | int res; |
| 8602 | Py_ssize_t len; |
| 8603 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8604 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8605 | 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] | 8606 | goto failed; |
| 8607 | } |
| 8608 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8609 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8610 | if (elts == NULL) goto failed; |
| 8611 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8612 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8613 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8614 | Py_INCREF(tmp2); |
| 8615 | res = obj2ast_expr(tmp2, &val, arena); |
| 8616 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8617 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8618 | if (len != PyList_GET_SIZE(tmp)) { |
| 8619 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8620 | goto failed; |
| 8621 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8622 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8623 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8624 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8625 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8626 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8627 | return 1; |
| 8628 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8629 | if (tmp == NULL) { |
| 8630 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8631 | return 1; |
| 8632 | } |
| 8633 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8634 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8635 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8636 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8637 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8638 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8639 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8640 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8641 | if (*out == NULL) goto failed; |
| 8642 | return 0; |
| 8643 | } |
| 8644 | |
| 8645 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8646 | failed: |
| 8647 | Py_XDECREF(tmp); |
| 8648 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8649 | } |
| 8650 | |
| 8651 | int |
| 8652 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8653 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8654 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8655 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8656 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8657 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8658 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8659 | } |
| 8660 | if (isinstance) { |
| 8661 | *out = Load; |
| 8662 | return 0; |
| 8663 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8664 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8665 | if (isinstance == -1) { |
| 8666 | return 1; |
| 8667 | } |
| 8668 | if (isinstance) { |
| 8669 | *out = Store; |
| 8670 | return 0; |
| 8671 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8672 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8673 | if (isinstance == -1) { |
| 8674 | return 1; |
| 8675 | } |
| 8676 | if (isinstance) { |
| 8677 | *out = Del; |
| 8678 | return 0; |
| 8679 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8680 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8681 | if (isinstance == -1) { |
| 8682 | return 1; |
| 8683 | } |
| 8684 | if (isinstance) { |
| 8685 | *out = AugLoad; |
| 8686 | return 0; |
| 8687 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8688 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8689 | if (isinstance == -1) { |
| 8690 | return 1; |
| 8691 | } |
| 8692 | if (isinstance) { |
| 8693 | *out = AugStore; |
| 8694 | return 0; |
| 8695 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8696 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8697 | if (isinstance == -1) { |
| 8698 | return 1; |
| 8699 | } |
| 8700 | if (isinstance) { |
| 8701 | *out = Param; |
| 8702 | return 0; |
| 8703 | } |
| 8704 | |
| 8705 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8706 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8707 | } |
| 8708 | |
| 8709 | int |
| 8710 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 8711 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8712 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8713 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8714 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8715 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8716 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8717 | if (obj == Py_None) { |
| 8718 | *out = NULL; |
| 8719 | return 0; |
| 8720 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8721 | tp = astmodulestate_global->Slice_type; |
| 8722 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8723 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8724 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8725 | } |
| 8726 | if (isinstance) { |
| 8727 | expr_ty lower; |
| 8728 | expr_ty upper; |
| 8729 | expr_ty step; |
| 8730 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8731 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8732 | return 1; |
| 8733 | } |
| 8734 | if (tmp == NULL || tmp == Py_None) { |
| 8735 | Py_CLEAR(tmp); |
| 8736 | lower = NULL; |
| 8737 | } |
| 8738 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8739 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8740 | res = obj2ast_expr(tmp, &lower, arena); |
| 8741 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8742 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8743 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8744 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8745 | return 1; |
| 8746 | } |
| 8747 | if (tmp == NULL || tmp == Py_None) { |
| 8748 | Py_CLEAR(tmp); |
| 8749 | upper = NULL; |
| 8750 | } |
| 8751 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8752 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8753 | res = obj2ast_expr(tmp, &upper, arena); |
| 8754 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8755 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8756 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8757 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8758 | return 1; |
| 8759 | } |
| 8760 | if (tmp == NULL || tmp == Py_None) { |
| 8761 | Py_CLEAR(tmp); |
| 8762 | step = NULL; |
| 8763 | } |
| 8764 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8765 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8766 | res = obj2ast_expr(tmp, &step, arena); |
| 8767 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8768 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8769 | } |
| 8770 | *out = Slice(lower, upper, step, arena); |
| 8771 | if (*out == NULL) goto failed; |
| 8772 | return 0; |
| 8773 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8774 | tp = astmodulestate_global->ExtSlice_type; |
| 8775 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8776 | if (isinstance == -1) { |
| 8777 | return 1; |
| 8778 | } |
| 8779 | if (isinstance) { |
| 8780 | asdl_seq* dims; |
| 8781 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8782 | if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8783 | return 1; |
| 8784 | } |
| 8785 | if (tmp == NULL) { |
| 8786 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 8787 | return 1; |
| 8788 | } |
| 8789 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8790 | int res; |
| 8791 | Py_ssize_t len; |
| 8792 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8793 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8794 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8795 | goto failed; |
| 8796 | } |
| 8797 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8798 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8799 | if (dims == NULL) goto failed; |
| 8800 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8801 | slice_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8802 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8803 | Py_INCREF(tmp2); |
| 8804 | res = obj2ast_slice(tmp2, &val, arena); |
| 8805 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8806 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8807 | if (len != PyList_GET_SIZE(tmp)) { |
| 8808 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 8809 | goto failed; |
| 8810 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8811 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8812 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8813 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8814 | } |
| 8815 | *out = ExtSlice(dims, arena); |
| 8816 | if (*out == NULL) goto failed; |
| 8817 | return 0; |
| 8818 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8819 | tp = astmodulestate_global->Index_type; |
| 8820 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8821 | if (isinstance == -1) { |
| 8822 | return 1; |
| 8823 | } |
| 8824 | if (isinstance) { |
| 8825 | expr_ty value; |
| 8826 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8827 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8828 | return 1; |
| 8829 | } |
| 8830 | if (tmp == NULL) { |
| 8831 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 8832 | return 1; |
| 8833 | } |
| 8834 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8835 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8836 | res = obj2ast_expr(tmp, &value, arena); |
| 8837 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8838 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8839 | } |
| 8840 | *out = Index(value, arena); |
| 8841 | if (*out == NULL) goto failed; |
| 8842 | return 0; |
| 8843 | } |
| 8844 | |
| 8845 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 8846 | failed: |
| 8847 | Py_XDECREF(tmp); |
| 8848 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8849 | } |
| 8850 | |
| 8851 | int |
| 8852 | obj2ast_boolop(PyObject* obj, boolop_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->And_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 = And; |
| 8862 | return 0; |
| 8863 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8864 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_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 = Or; |
| 8870 | return 0; |
| 8871 | } |
| 8872 | |
| 8873 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8874 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8875 | } |
| 8876 | |
| 8877 | int |
| 8878 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8879 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8880 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8881 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8882 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8883 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8884 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8885 | } |
| 8886 | if (isinstance) { |
| 8887 | *out = Add; |
| 8888 | return 0; |
| 8889 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8890 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8891 | if (isinstance == -1) { |
| 8892 | return 1; |
| 8893 | } |
| 8894 | if (isinstance) { |
| 8895 | *out = Sub; |
| 8896 | return 0; |
| 8897 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8898 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8899 | if (isinstance == -1) { |
| 8900 | return 1; |
| 8901 | } |
| 8902 | if (isinstance) { |
| 8903 | *out = Mult; |
| 8904 | return 0; |
| 8905 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8906 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8907 | if (isinstance == -1) { |
| 8908 | return 1; |
| 8909 | } |
| 8910 | if (isinstance) { |
| 8911 | *out = MatMult; |
| 8912 | return 0; |
| 8913 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8914 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8915 | if (isinstance == -1) { |
| 8916 | return 1; |
| 8917 | } |
| 8918 | if (isinstance) { |
| 8919 | *out = Div; |
| 8920 | return 0; |
| 8921 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8922 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8923 | if (isinstance == -1) { |
| 8924 | return 1; |
| 8925 | } |
| 8926 | if (isinstance) { |
| 8927 | *out = Mod; |
| 8928 | return 0; |
| 8929 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8930 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8931 | if (isinstance == -1) { |
| 8932 | return 1; |
| 8933 | } |
| 8934 | if (isinstance) { |
| 8935 | *out = Pow; |
| 8936 | return 0; |
| 8937 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8938 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8939 | if (isinstance == -1) { |
| 8940 | return 1; |
| 8941 | } |
| 8942 | if (isinstance) { |
| 8943 | *out = LShift; |
| 8944 | return 0; |
| 8945 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8946 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8947 | if (isinstance == -1) { |
| 8948 | return 1; |
| 8949 | } |
| 8950 | if (isinstance) { |
| 8951 | *out = RShift; |
| 8952 | return 0; |
| 8953 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8954 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8955 | if (isinstance == -1) { |
| 8956 | return 1; |
| 8957 | } |
| 8958 | if (isinstance) { |
| 8959 | *out = BitOr; |
| 8960 | return 0; |
| 8961 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8962 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8963 | if (isinstance == -1) { |
| 8964 | return 1; |
| 8965 | } |
| 8966 | if (isinstance) { |
| 8967 | *out = BitXor; |
| 8968 | return 0; |
| 8969 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8970 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8971 | if (isinstance == -1) { |
| 8972 | return 1; |
| 8973 | } |
| 8974 | if (isinstance) { |
| 8975 | *out = BitAnd; |
| 8976 | return 0; |
| 8977 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8978 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_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 = FloorDiv; |
| 8984 | return 0; |
| 8985 | } |
| 8986 | |
| 8987 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8988 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8989 | } |
| 8990 | |
| 8991 | int |
| 8992 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8993 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8994 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8995 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8996 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8997 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8998 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8999 | } |
| 9000 | if (isinstance) { |
| 9001 | *out = Invert; |
| 9002 | return 0; |
| 9003 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9004 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9005 | if (isinstance == -1) { |
| 9006 | return 1; |
| 9007 | } |
| 9008 | if (isinstance) { |
| 9009 | *out = Not; |
| 9010 | return 0; |
| 9011 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9012 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9013 | if (isinstance == -1) { |
| 9014 | return 1; |
| 9015 | } |
| 9016 | if (isinstance) { |
| 9017 | *out = UAdd; |
| 9018 | return 0; |
| 9019 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9020 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_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 = USub; |
| 9026 | return 0; |
| 9027 | } |
| 9028 | |
| 9029 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 9030 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9031 | } |
| 9032 | |
| 9033 | int |
| 9034 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 9035 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9036 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9037 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9038 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9039 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9040 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9041 | } |
| 9042 | if (isinstance) { |
| 9043 | *out = Eq; |
| 9044 | return 0; |
| 9045 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9046 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9047 | if (isinstance == -1) { |
| 9048 | return 1; |
| 9049 | } |
| 9050 | if (isinstance) { |
| 9051 | *out = NotEq; |
| 9052 | return 0; |
| 9053 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9054 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9055 | if (isinstance == -1) { |
| 9056 | return 1; |
| 9057 | } |
| 9058 | if (isinstance) { |
| 9059 | *out = Lt; |
| 9060 | return 0; |
| 9061 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9062 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9063 | if (isinstance == -1) { |
| 9064 | return 1; |
| 9065 | } |
| 9066 | if (isinstance) { |
| 9067 | *out = LtE; |
| 9068 | return 0; |
| 9069 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9070 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9071 | if (isinstance == -1) { |
| 9072 | return 1; |
| 9073 | } |
| 9074 | if (isinstance) { |
| 9075 | *out = Gt; |
| 9076 | return 0; |
| 9077 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9078 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9079 | if (isinstance == -1) { |
| 9080 | return 1; |
| 9081 | } |
| 9082 | if (isinstance) { |
| 9083 | *out = GtE; |
| 9084 | return 0; |
| 9085 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9086 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9087 | if (isinstance == -1) { |
| 9088 | return 1; |
| 9089 | } |
| 9090 | if (isinstance) { |
| 9091 | *out = Is; |
| 9092 | return 0; |
| 9093 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9094 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9095 | if (isinstance == -1) { |
| 9096 | return 1; |
| 9097 | } |
| 9098 | if (isinstance) { |
| 9099 | *out = IsNot; |
| 9100 | return 0; |
| 9101 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9102 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9103 | if (isinstance == -1) { |
| 9104 | return 1; |
| 9105 | } |
| 9106 | if (isinstance) { |
| 9107 | *out = In; |
| 9108 | return 0; |
| 9109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9110 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9111 | if (isinstance == -1) { |
| 9112 | return 1; |
| 9113 | } |
| 9114 | if (isinstance) { |
| 9115 | *out = NotIn; |
| 9116 | return 0; |
| 9117 | } |
| 9118 | |
| 9119 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9120 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9121 | } |
| 9122 | |
| 9123 | int |
| 9124 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9125 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9126 | PyObject* tmp = NULL; |
| 9127 | expr_ty target; |
| 9128 | expr_ty iter; |
| 9129 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9130 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9131 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9132 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9133 | return 1; |
| 9134 | } |
| 9135 | if (tmp == NULL) { |
| 9136 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9137 | return 1; |
| 9138 | } |
| 9139 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9140 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9141 | res = obj2ast_expr(tmp, &target, arena); |
| 9142 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9143 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9144 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9145 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9146 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9147 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9148 | if (tmp == NULL) { |
| 9149 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9150 | return 1; |
| 9151 | } |
| 9152 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9153 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9154 | res = obj2ast_expr(tmp, &iter, arena); |
| 9155 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9156 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9157 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9158 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9159 | return 1; |
| 9160 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9161 | if (tmp == NULL) { |
| 9162 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9163 | return 1; |
| 9164 | } |
| 9165 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9166 | int res; |
| 9167 | Py_ssize_t len; |
| 9168 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9169 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9170 | 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] | 9171 | goto failed; |
| 9172 | } |
| 9173 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9174 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9175 | if (ifs == NULL) goto failed; |
| 9176 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9177 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9178 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9179 | Py_INCREF(tmp2); |
| 9180 | res = obj2ast_expr(tmp2, &val, arena); |
| 9181 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9182 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9183 | if (len != PyList_GET_SIZE(tmp)) { |
| 9184 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9185 | goto failed; |
| 9186 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9187 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9188 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9189 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9191 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9192 | return 1; |
| 9193 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9194 | if (tmp == NULL) { |
| 9195 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9196 | return 1; |
| 9197 | } |
| 9198 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9199 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9200 | res = obj2ast_int(tmp, &is_async, arena); |
| 9201 | if (res != 0) goto failed; |
| 9202 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9203 | } |
| 9204 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9205 | return 0; |
| 9206 | failed: |
| 9207 | Py_XDECREF(tmp); |
| 9208 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9209 | } |
| 9210 | |
| 9211 | int |
| 9212 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9213 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9214 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9215 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9216 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9217 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9218 | int lineno; |
| 9219 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9220 | int end_lineno; |
| 9221 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9222 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9223 | if (obj == Py_None) { |
| 9224 | *out = NULL; |
| 9225 | return 0; |
| 9226 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9227 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9228 | return 1; |
| 9229 | } |
| 9230 | if (tmp == NULL) { |
| 9231 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9232 | return 1; |
| 9233 | } |
| 9234 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9235 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9236 | res = obj2ast_int(tmp, &lineno, arena); |
| 9237 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9238 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9239 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9240 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9241 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9242 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9243 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9244 | if (tmp == NULL) { |
| 9245 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9246 | return 1; |
| 9247 | } |
| 9248 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9249 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9250 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9251 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9252 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9253 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9254 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9255 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9256 | return 1; |
| 9257 | } |
| 9258 | if (tmp == NULL || tmp == Py_None) { |
| 9259 | Py_CLEAR(tmp); |
| 9260 | end_lineno = 0; |
| 9261 | } |
| 9262 | else { |
| 9263 | int res; |
| 9264 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9265 | if (res != 0) goto failed; |
| 9266 | Py_CLEAR(tmp); |
| 9267 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9268 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9269 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9270 | return 1; |
| 9271 | } |
| 9272 | if (tmp == NULL || tmp == Py_None) { |
| 9273 | Py_CLEAR(tmp); |
| 9274 | end_col_offset = 0; |
| 9275 | } |
| 9276 | else { |
| 9277 | int res; |
| 9278 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9279 | if (res != 0) goto failed; |
| 9280 | Py_CLEAR(tmp); |
| 9281 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9282 | tp = astmodulestate_global->ExceptHandler_type; |
| 9283 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9284 | if (isinstance == -1) { |
| 9285 | return 1; |
| 9286 | } |
| 9287 | if (isinstance) { |
| 9288 | expr_ty type; |
| 9289 | identifier name; |
| 9290 | asdl_seq* body; |
| 9291 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9292 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9293 | return 1; |
| 9294 | } |
| 9295 | if (tmp == NULL || tmp == Py_None) { |
| 9296 | Py_CLEAR(tmp); |
| 9297 | type = NULL; |
| 9298 | } |
| 9299 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9300 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9301 | res = obj2ast_expr(tmp, &type, arena); |
| 9302 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9303 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9304 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9305 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9306 | return 1; |
| 9307 | } |
| 9308 | if (tmp == NULL || tmp == Py_None) { |
| 9309 | Py_CLEAR(tmp); |
| 9310 | name = NULL; |
| 9311 | } |
| 9312 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9313 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9314 | res = obj2ast_identifier(tmp, &name, arena); |
| 9315 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9316 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9318 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9319 | return 1; |
| 9320 | } |
| 9321 | if (tmp == NULL) { |
| 9322 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9323 | return 1; |
| 9324 | } |
| 9325 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9326 | int res; |
| 9327 | Py_ssize_t len; |
| 9328 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9329 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9330 | 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] | 9331 | goto failed; |
| 9332 | } |
| 9333 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9334 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9335 | if (body == NULL) goto failed; |
| 9336 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9337 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9338 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9339 | Py_INCREF(tmp2); |
| 9340 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9341 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9342 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9343 | if (len != PyList_GET_SIZE(tmp)) { |
| 9344 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9345 | goto failed; |
| 9346 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9347 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9348 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9349 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9350 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9351 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9352 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9353 | if (*out == NULL) goto failed; |
| 9354 | return 0; |
| 9355 | } |
| 9356 | |
| 9357 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9358 | failed: |
| 9359 | Py_XDECREF(tmp); |
| 9360 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9361 | } |
| 9362 | |
| 9363 | int |
| 9364 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9365 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9366 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9367 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9368 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9369 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9370 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9371 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9372 | arg_ty kwarg; |
| 9373 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9374 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9375 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9376 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9377 | return 1; |
| 9378 | } |
| 9379 | if (tmp == NULL) { |
| 9380 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9381 | return 1; |
| 9382 | } |
| 9383 | else { |
| 9384 | int res; |
| 9385 | Py_ssize_t len; |
| 9386 | Py_ssize_t i; |
| 9387 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9388 | 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] | 9389 | goto failed; |
| 9390 | } |
| 9391 | len = PyList_GET_SIZE(tmp); |
| 9392 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9393 | if (posonlyargs == NULL) goto failed; |
| 9394 | for (i = 0; i < len; i++) { |
| 9395 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9396 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9397 | Py_INCREF(tmp2); |
| 9398 | res = obj2ast_arg(tmp2, &val, arena); |
| 9399 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9400 | if (res != 0) goto failed; |
| 9401 | if (len != PyList_GET_SIZE(tmp)) { |
| 9402 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9403 | goto failed; |
| 9404 | } |
| 9405 | asdl_seq_SET(posonlyargs, i, val); |
| 9406 | } |
| 9407 | Py_CLEAR(tmp); |
| 9408 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9409 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9410 | return 1; |
| 9411 | } |
| 9412 | if (tmp == NULL) { |
| 9413 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9414 | return 1; |
| 9415 | } |
| 9416 | else { |
| 9417 | int res; |
| 9418 | Py_ssize_t len; |
| 9419 | Py_ssize_t i; |
| 9420 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9421 | 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] | 9422 | goto failed; |
| 9423 | } |
| 9424 | len = PyList_GET_SIZE(tmp); |
| 9425 | args = _Py_asdl_seq_new(len, arena); |
| 9426 | if (args == NULL) goto failed; |
| 9427 | for (i = 0; i < len; i++) { |
| 9428 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9429 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9430 | Py_INCREF(tmp2); |
| 9431 | res = obj2ast_arg(tmp2, &val, arena); |
| 9432 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9433 | if (res != 0) goto failed; |
| 9434 | if (len != PyList_GET_SIZE(tmp)) { |
| 9435 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9436 | goto failed; |
| 9437 | } |
| 9438 | asdl_seq_SET(args, i, val); |
| 9439 | } |
| 9440 | Py_CLEAR(tmp); |
| 9441 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9442 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9443 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9444 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9445 | if (tmp == NULL || tmp == Py_None) { |
| 9446 | Py_CLEAR(tmp); |
| 9447 | vararg = NULL; |
| 9448 | } |
| 9449 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9450 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9451 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9452 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9453 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9454 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9455 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9456 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9457 | return 1; |
| 9458 | } |
| 9459 | if (tmp == NULL) { |
| 9460 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9461 | return 1; |
| 9462 | } |
| 9463 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9464 | int res; |
| 9465 | Py_ssize_t len; |
| 9466 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9467 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9468 | 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] | 9469 | goto failed; |
| 9470 | } |
| 9471 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9472 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9473 | if (kwonlyargs == NULL) goto failed; |
| 9474 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9475 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9476 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9477 | Py_INCREF(tmp2); |
| 9478 | res = obj2ast_arg(tmp2, &val, arena); |
| 9479 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9480 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9481 | if (len != PyList_GET_SIZE(tmp)) { |
| 9482 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9483 | goto failed; |
| 9484 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9485 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9486 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9487 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9488 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9489 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9490 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9491 | return 1; |
| 9492 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9493 | if (tmp == NULL) { |
| 9494 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9495 | return 1; |
| 9496 | } |
| 9497 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9498 | int res; |
| 9499 | Py_ssize_t len; |
| 9500 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9501 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9502 | 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] | 9503 | goto failed; |
| 9504 | } |
| 9505 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9506 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9507 | if (kw_defaults == NULL) goto failed; |
| 9508 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9509 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9510 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9511 | Py_INCREF(tmp2); |
| 9512 | res = obj2ast_expr(tmp2, &val, arena); |
| 9513 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9514 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9515 | if (len != PyList_GET_SIZE(tmp)) { |
| 9516 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9517 | goto failed; |
| 9518 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9519 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9520 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9521 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9522 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9523 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9524 | return 1; |
| 9525 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9526 | if (tmp == NULL || tmp == Py_None) { |
| 9527 | Py_CLEAR(tmp); |
| 9528 | kwarg = NULL; |
| 9529 | } |
| 9530 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9531 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9532 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9533 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9534 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9535 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9536 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9537 | return 1; |
| 9538 | } |
| 9539 | if (tmp == NULL) { |
| 9540 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9541 | return 1; |
| 9542 | } |
| 9543 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9544 | int res; |
| 9545 | Py_ssize_t len; |
| 9546 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9547 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9548 | 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] | 9549 | goto failed; |
| 9550 | } |
| 9551 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9552 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9553 | if (defaults == NULL) goto failed; |
| 9554 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9555 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9556 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9557 | Py_INCREF(tmp2); |
| 9558 | res = obj2ast_expr(tmp2, &val, arena); |
| 9559 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9560 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9561 | if (len != PyList_GET_SIZE(tmp)) { |
| 9562 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9563 | goto failed; |
| 9564 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9565 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9566 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9567 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9568 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9569 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9570 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9571 | return 0; |
| 9572 | failed: |
| 9573 | Py_XDECREF(tmp); |
| 9574 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9575 | } |
| 9576 | |
| 9577 | int |
| 9578 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9579 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9580 | PyObject* tmp = NULL; |
| 9581 | identifier arg; |
| 9582 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9583 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9584 | int lineno; |
| 9585 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9586 | int end_lineno; |
| 9587 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9588 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9589 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9590 | return 1; |
| 9591 | } |
| 9592 | if (tmp == NULL) { |
| 9593 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9594 | return 1; |
| 9595 | } |
| 9596 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9597 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9598 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9599 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9600 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9601 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9602 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9603 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9604 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9605 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9606 | if (tmp == NULL || tmp == Py_None) { |
| 9607 | Py_CLEAR(tmp); |
| 9608 | annotation = NULL; |
| 9609 | } |
| 9610 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9611 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9612 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9613 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9614 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9615 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9616 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9617 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9618 | return 1; |
| 9619 | } |
| 9620 | if (tmp == NULL || tmp == Py_None) { |
| 9621 | Py_CLEAR(tmp); |
| 9622 | type_comment = NULL; |
| 9623 | } |
| 9624 | else { |
| 9625 | int res; |
| 9626 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9627 | if (res != 0) goto failed; |
| 9628 | Py_CLEAR(tmp); |
| 9629 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9630 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9631 | return 1; |
| 9632 | } |
| 9633 | if (tmp == NULL) { |
| 9634 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9635 | return 1; |
| 9636 | } |
| 9637 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9638 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9639 | res = obj2ast_int(tmp, &lineno, arena); |
| 9640 | if (res != 0) goto failed; |
| 9641 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9642 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9643 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9644 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9645 | return 1; |
| 9646 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9647 | if (tmp == NULL) { |
| 9648 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9649 | return 1; |
| 9650 | } |
| 9651 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9652 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9653 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9654 | if (res != 0) goto failed; |
| 9655 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9656 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9657 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9658 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9659 | return 1; |
| 9660 | } |
| 9661 | if (tmp == NULL || tmp == Py_None) { |
| 9662 | Py_CLEAR(tmp); |
| 9663 | end_lineno = 0; |
| 9664 | } |
| 9665 | else { |
| 9666 | int res; |
| 9667 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9668 | if (res != 0) goto failed; |
| 9669 | Py_CLEAR(tmp); |
| 9670 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9671 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9672 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9673 | return 1; |
| 9674 | } |
| 9675 | if (tmp == NULL || tmp == Py_None) { |
| 9676 | Py_CLEAR(tmp); |
| 9677 | end_col_offset = 0; |
| 9678 | } |
| 9679 | else { |
| 9680 | int res; |
| 9681 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9682 | if (res != 0) goto failed; |
| 9683 | Py_CLEAR(tmp); |
| 9684 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9685 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9686 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9687 | return 0; |
| 9688 | failed: |
| 9689 | Py_XDECREF(tmp); |
| 9690 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9691 | } |
| 9692 | |
| 9693 | int |
| 9694 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9695 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9696 | PyObject* tmp = NULL; |
| 9697 | identifier arg; |
| 9698 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9699 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9700 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9701 | return 1; |
| 9702 | } |
| 9703 | if (tmp == NULL || tmp == Py_None) { |
| 9704 | Py_CLEAR(tmp); |
| 9705 | arg = NULL; |
| 9706 | } |
| 9707 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9708 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9709 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9710 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9711 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9712 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9713 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9714 | return 1; |
| 9715 | } |
| 9716 | if (tmp == NULL) { |
| 9717 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9718 | return 1; |
| 9719 | } |
| 9720 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9721 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9722 | res = obj2ast_expr(tmp, &value, arena); |
| 9723 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9724 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9725 | } |
| 9726 | *out = keyword(arg, value, arena); |
| 9727 | return 0; |
| 9728 | failed: |
| 9729 | Py_XDECREF(tmp); |
| 9730 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9731 | } |
| 9732 | |
| 9733 | int |
| 9734 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9735 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9736 | PyObject* tmp = NULL; |
| 9737 | identifier name; |
| 9738 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9739 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9740 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9741 | return 1; |
| 9742 | } |
| 9743 | if (tmp == NULL) { |
| 9744 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9745 | return 1; |
| 9746 | } |
| 9747 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9748 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9749 | res = obj2ast_identifier(tmp, &name, arena); |
| 9750 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9751 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9752 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9753 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9754 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9755 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9756 | if (tmp == NULL || tmp == Py_None) { |
| 9757 | Py_CLEAR(tmp); |
| 9758 | asname = NULL; |
| 9759 | } |
| 9760 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9761 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9762 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9763 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9764 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9765 | } |
| 9766 | *out = alias(name, asname, arena); |
| 9767 | return 0; |
| 9768 | failed: |
| 9769 | Py_XDECREF(tmp); |
| 9770 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9771 | } |
| 9772 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9773 | int |
| 9774 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9775 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9776 | PyObject* tmp = NULL; |
| 9777 | expr_ty context_expr; |
| 9778 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9779 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9780 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9781 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9782 | return 1; |
| 9783 | } |
| 9784 | if (tmp == NULL) { |
| 9785 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9786 | return 1; |
| 9787 | } |
| 9788 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9789 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9790 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9791 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9792 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9793 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9794 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9795 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9796 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9797 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9798 | if (tmp == NULL || tmp == Py_None) { |
| 9799 | Py_CLEAR(tmp); |
| 9800 | optional_vars = NULL; |
| 9801 | } |
| 9802 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9803 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9804 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9805 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9806 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9807 | } |
| 9808 | *out = withitem(context_expr, optional_vars, arena); |
| 9809 | return 0; |
| 9810 | failed: |
| 9811 | Py_XDECREF(tmp); |
| 9812 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9813 | } |
| 9814 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9815 | int |
| 9816 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9817 | { |
| 9818 | int isinstance; |
| 9819 | |
| 9820 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9821 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9822 | |
| 9823 | if (obj == Py_None) { |
| 9824 | *out = NULL; |
| 9825 | return 0; |
| 9826 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9827 | tp = astmodulestate_global->TypeIgnore_type; |
| 9828 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9829 | if (isinstance == -1) { |
| 9830 | return 1; |
| 9831 | } |
| 9832 | if (isinstance) { |
| 9833 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9834 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9835 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9836 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9837 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9838 | return 1; |
| 9839 | } |
| 9840 | if (tmp == NULL) { |
| 9841 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9842 | return 1; |
| 9843 | } |
| 9844 | else { |
| 9845 | int res; |
| 9846 | res = obj2ast_int(tmp, &lineno, arena); |
| 9847 | if (res != 0) goto failed; |
| 9848 | Py_CLEAR(tmp); |
| 9849 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9850 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9851 | return 1; |
| 9852 | } |
| 9853 | if (tmp == NULL) { |
| 9854 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9855 | return 1; |
| 9856 | } |
| 9857 | else { |
| 9858 | int res; |
| 9859 | res = obj2ast_string(tmp, &tag, arena); |
| 9860 | if (res != 0) goto failed; |
| 9861 | Py_CLEAR(tmp); |
| 9862 | } |
| 9863 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9864 | if (*out == NULL) goto failed; |
| 9865 | return 0; |
| 9866 | } |
| 9867 | |
| 9868 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9869 | failed: |
| 9870 | Py_XDECREF(tmp); |
| 9871 | return 1; |
| 9872 | } |
| 9873 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9874 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9875 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9876 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9877 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9878 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9879 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9880 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9881 | if (!m) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9882 | Py_INCREF(astmodulestate(m)->AST_type); |
| 9883 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) |
| 9884 | return NULL; |
Matthias Bussonnier | 565b4f1 | 2019-05-21 13:12:03 -0700 | [diff] [blame] | 9885 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) |
| 9886 | return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9887 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9888 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9889 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) |
| 9890 | return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9891 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) |
| 9892 | return NULL; |
| 9893 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9894 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9895 | 0) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9896 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9897 | if (PyModule_AddObject(m, "Interactive", |
| 9898 | astmodulestate_global->Interactive_type) < 0) return NULL; |
| 9899 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9900 | if (PyModule_AddObject(m, "Expression", |
| 9901 | astmodulestate_global->Expression_type) < 0) return NULL; |
| 9902 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9903 | if (PyModule_AddObject(m, "FunctionType", |
| 9904 | astmodulestate_global->FunctionType_type) < 0) return NULL; |
| 9905 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
| 9906 | if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9907 | return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9908 | Py_INCREF(astmodulestate(m)->Suite_type); |
| 9909 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9910 | return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9911 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9912 | if (PyModule_AddObject(m, "FunctionDef", |
| 9913 | astmodulestate_global->FunctionDef_type) < 0) return NULL; |
| 9914 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9915 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
| 9916 | astmodulestate_global->AsyncFunctionDef_type) < 0) return NULL; |
| 9917 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9918 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9919 | < 0) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9920 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9921 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9922 | 0) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9923 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9924 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
| 9925 | 0) return NULL; |
| 9926 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9927 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
| 9928 | 0) return NULL; |
| 9929 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9930 | if (PyModule_AddObject(m, "AugAssign", |
| 9931 | astmodulestate_global->AugAssign_type) < 0) return NULL; |
| 9932 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9933 | if (PyModule_AddObject(m, "AnnAssign", |
| 9934 | astmodulestate_global->AnnAssign_type) < 0) return NULL; |
| 9935 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
| 9936 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9937 | return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9938 | Py_INCREF(astmodulestate(m)->For_type); |
| 9939 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
| 9940 | < 0) return NULL; |
| 9941 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
| 9942 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) |
| 9943 | return NULL; |
| 9944 | Py_INCREF(astmodulestate(m)->While_type); |
| 9945 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) return |
| 9946 | NULL; |
| 9947 | Py_INCREF(astmodulestate(m)->If_type); |
| 9948 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) |
| 9949 | return NULL; |
| 9950 | Py_INCREF(astmodulestate(m)->With_type); |
| 9951 | if (PyModule_AddObject(m, "AsyncWith", |
| 9952 | astmodulestate_global->AsyncWith_type) < 0) return NULL; |
| 9953 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
| 9954 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) |
| 9955 | return NULL; |
| 9956 | Py_INCREF(astmodulestate(m)->Raise_type); |
| 9957 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) |
| 9958 | return NULL; |
| 9959 | Py_INCREF(astmodulestate(m)->Try_type); |
| 9960 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
| 9961 | 0) return NULL; |
| 9962 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 9963 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
| 9964 | 0) return NULL; |
| 9965 | Py_INCREF(astmodulestate(m)->Import_type); |
| 9966 | if (PyModule_AddObject(m, "ImportFrom", |
| 9967 | astmodulestate_global->ImportFrom_type) < 0) return NULL; |
| 9968 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 9969 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
| 9970 | 0) return NULL; |
| 9971 | Py_INCREF(astmodulestate(m)->Global_type); |
| 9972 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
| 9973 | < 0) return NULL; |
| 9974 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
| 9975 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) |
| 9976 | return NULL; |
| 9977 | Py_INCREF(astmodulestate(m)->Expr_type); |
| 9978 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) |
| 9979 | return NULL; |
| 9980 | Py_INCREF(astmodulestate(m)->Pass_type); |
| 9981 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) |
| 9982 | return NULL; |
| 9983 | Py_INCREF(astmodulestate(m)->Break_type); |
| 9984 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
| 9985 | < 0) return NULL; |
| 9986 | Py_INCREF(astmodulestate(m)->Continue_type); |
| 9987 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) |
| 9988 | return NULL; |
| 9989 | Py_INCREF(astmodulestate(m)->expr_type); |
| 9990 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
| 9991 | 0) return NULL; |
| 9992 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 9993 | if (PyModule_AddObject(m, "NamedExpr", |
| 9994 | astmodulestate_global->NamedExpr_type) < 0) return NULL; |
| 9995 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
| 9996 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) |
| 9997 | return NULL; |
| 9998 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 9999 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
| 10000 | 0) return NULL; |
| 10001 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 10002 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
| 10003 | 0) return NULL; |
| 10004 | Py_INCREF(astmodulestate(m)->Lambda_type); |
| 10005 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) |
| 10006 | return NULL; |
| 10007 | Py_INCREF(astmodulestate(m)->IfExp_type); |
| 10008 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) |
| 10009 | return NULL; |
| 10010 | Py_INCREF(astmodulestate(m)->Dict_type); |
| 10011 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) |
| 10012 | return NULL; |
| 10013 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10014 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
| 10015 | < 0) return NULL; |
| 10016 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10017 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
| 10018 | 0) return NULL; |
| 10019 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10020 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
| 10021 | < 0) return NULL; |
| 10022 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10023 | if (PyModule_AddObject(m, "GeneratorExp", |
| 10024 | astmodulestate_global->GeneratorExp_type) < 0) return NULL; |
| 10025 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
| 10026 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) |
| 10027 | return NULL; |
| 10028 | Py_INCREF(astmodulestate(m)->Await_type); |
| 10029 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) |
| 10030 | return NULL; |
| 10031 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10032 | if (PyModule_AddObject(m, "YieldFrom", |
| 10033 | astmodulestate_global->YieldFrom_type) < 0) return NULL; |
| 10034 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10035 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
| 10036 | 0) return NULL; |
| 10037 | Py_INCREF(astmodulestate(m)->Compare_type); |
| 10038 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) |
| 10039 | return NULL; |
| 10040 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10041 | if (PyModule_AddObject(m, "FormattedValue", |
| 10042 | astmodulestate_global->FormattedValue_type) < 0) return NULL; |
| 10043 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10044 | if (PyModule_AddObject(m, "JoinedStr", |
| 10045 | astmodulestate_global->JoinedStr_type) < 0) return NULL; |
| 10046 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10047 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
| 10048 | < 0) return NULL; |
| 10049 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10050 | if (PyModule_AddObject(m, "Attribute", |
| 10051 | astmodulestate_global->Attribute_type) < 0) return NULL; |
| 10052 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10053 | if (PyModule_AddObject(m, "Subscript", |
| 10054 | astmodulestate_global->Subscript_type) < 0) return NULL; |
| 10055 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10056 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
| 10057 | 0) return NULL; |
| 10058 | Py_INCREF(astmodulestate(m)->Starred_type); |
| 10059 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) |
| 10060 | return NULL; |
| 10061 | Py_INCREF(astmodulestate(m)->Name_type); |
| 10062 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) |
| 10063 | return NULL; |
| 10064 | Py_INCREF(astmodulestate(m)->List_type); |
| 10065 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) |
| 10066 | return NULL; |
| 10067 | Py_INCREF(astmodulestate(m)->Tuple_type); |
| 10068 | if (PyModule_AddObject(m, "expr_context", |
| 10069 | astmodulestate_global->expr_context_type) < 0) return NULL; |
| 10070 | Py_INCREF(astmodulestate(m)->expr_context_type); |
| 10071 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) |
| 10072 | return NULL; |
| 10073 | Py_INCREF(astmodulestate(m)->Load_type); |
| 10074 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) |
| 10075 | return NULL; |
| 10076 | Py_INCREF(astmodulestate(m)->Store_type); |
| 10077 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) |
| 10078 | return NULL; |
| 10079 | Py_INCREF(astmodulestate(m)->Del_type); |
| 10080 | if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) < |
| 10081 | 0) return NULL; |
| 10082 | Py_INCREF(astmodulestate(m)->AugLoad_type); |
| 10083 | if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type) |
| 10084 | < 0) return NULL; |
| 10085 | Py_INCREF(astmodulestate(m)->AugStore_type); |
| 10086 | if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) |
| 10087 | return NULL; |
| 10088 | Py_INCREF(astmodulestate(m)->Param_type); |
| 10089 | if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0) |
| 10090 | return NULL; |
| 10091 | Py_INCREF(astmodulestate(m)->slice_type); |
| 10092 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) |
| 10093 | return NULL; |
| 10094 | Py_INCREF(astmodulestate(m)->Slice_type); |
| 10095 | if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type) |
| 10096 | < 0) return NULL; |
| 10097 | Py_INCREF(astmodulestate(m)->ExtSlice_type); |
| 10098 | if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0) |
| 10099 | return NULL; |
| 10100 | Py_INCREF(astmodulestate(m)->Index_type); |
| 10101 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
| 10102 | 0) return NULL; |
| 10103 | Py_INCREF(astmodulestate(m)->boolop_type); |
| 10104 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) |
| 10105 | return NULL; |
| 10106 | Py_INCREF(astmodulestate(m)->And_type); |
| 10107 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) return |
| 10108 | NULL; |
| 10109 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10110 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
| 10111 | < 0) return NULL; |
| 10112 | Py_INCREF(astmodulestate(m)->operator_type); |
| 10113 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) |
| 10114 | return NULL; |
| 10115 | Py_INCREF(astmodulestate(m)->Add_type); |
| 10116 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) |
| 10117 | return NULL; |
| 10118 | Py_INCREF(astmodulestate(m)->Sub_type); |
| 10119 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) |
| 10120 | return NULL; |
| 10121 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10122 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
| 10123 | 0) return NULL; |
| 10124 | Py_INCREF(astmodulestate(m)->MatMult_type); |
| 10125 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) |
| 10126 | return NULL; |
| 10127 | Py_INCREF(astmodulestate(m)->Div_type); |
| 10128 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) |
| 10129 | return NULL; |
| 10130 | Py_INCREF(astmodulestate(m)->Mod_type); |
| 10131 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) |
| 10132 | return NULL; |
| 10133 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10134 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
| 10135 | 0) return NULL; |
| 10136 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10137 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
| 10138 | 0) return NULL; |
| 10139 | Py_INCREF(astmodulestate(m)->RShift_type); |
| 10140 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) |
| 10141 | return NULL; |
| 10142 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10143 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
| 10144 | 0) return NULL; |
| 10145 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10146 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
| 10147 | 0) return NULL; |
| 10148 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10149 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
| 10150 | < 0) return NULL; |
| 10151 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10152 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
| 10153 | 0) return NULL; |
| 10154 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10155 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
| 10156 | 0) return NULL; |
| 10157 | Py_INCREF(astmodulestate(m)->Invert_type); |
| 10158 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) |
| 10159 | return NULL; |
| 10160 | Py_INCREF(astmodulestate(m)->Not_type); |
| 10161 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) |
| 10162 | return NULL; |
| 10163 | Py_INCREF(astmodulestate(m)->UAdd_type); |
| 10164 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) |
| 10165 | return NULL; |
| 10166 | Py_INCREF(astmodulestate(m)->USub_type); |
| 10167 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) |
| 10168 | return NULL; |
| 10169 | Py_INCREF(astmodulestate(m)->cmpop_type); |
| 10170 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) return |
| 10171 | NULL; |
| 10172 | Py_INCREF(astmodulestate(m)->Eq_type); |
| 10173 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) |
| 10174 | return NULL; |
| 10175 | Py_INCREF(astmodulestate(m)->NotEq_type); |
| 10176 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) return |
| 10177 | NULL; |
| 10178 | Py_INCREF(astmodulestate(m)->Lt_type); |
| 10179 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) |
| 10180 | return NULL; |
| 10181 | Py_INCREF(astmodulestate(m)->LtE_type); |
| 10182 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) return |
| 10183 | NULL; |
| 10184 | Py_INCREF(astmodulestate(m)->Gt_type); |
| 10185 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) |
| 10186 | return NULL; |
| 10187 | Py_INCREF(astmodulestate(m)->GtE_type); |
| 10188 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) return |
| 10189 | NULL; |
| 10190 | Py_INCREF(astmodulestate(m)->Is_type); |
| 10191 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) |
| 10192 | return NULL; |
| 10193 | Py_INCREF(astmodulestate(m)->IsNot_type); |
| 10194 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) return |
| 10195 | NULL; |
| 10196 | Py_INCREF(astmodulestate(m)->In_type); |
| 10197 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) |
| 10198 | return NULL; |
| 10199 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10200 | if (PyModule_AddObject(m, "comprehension", |
| 10201 | astmodulestate_global->comprehension_type) < 0) return NULL; |
| 10202 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10203 | if (PyModule_AddObject(m, "excepthandler", |
| 10204 | astmodulestate_global->excepthandler_type) < 0) return NULL; |
| 10205 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10206 | if (PyModule_AddObject(m, "ExceptHandler", |
| 10207 | astmodulestate_global->ExceptHandler_type) < 0) return NULL; |
| 10208 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10209 | if (PyModule_AddObject(m, "arguments", |
| 10210 | astmodulestate_global->arguments_type) < 0) return NULL; |
| 10211 | Py_INCREF(astmodulestate(m)->arguments_type); |
| 10212 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) |
| 10213 | return NULL; |
| 10214 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10215 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
| 10216 | 0) return NULL; |
| 10217 | Py_INCREF(astmodulestate(m)->keyword_type); |
| 10218 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) |
| 10219 | return NULL; |
| 10220 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10221 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
| 10222 | < 0) return NULL; |
| 10223 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10224 | if (PyModule_AddObject(m, "type_ignore", |
| 10225 | astmodulestate_global->type_ignore_type) < 0) return NULL; |
| 10226 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10227 | if (PyModule_AddObject(m, "TypeIgnore", |
| 10228 | astmodulestate_global->TypeIgnore_type) < 0) return NULL; |
| 10229 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10230 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10231 | } |
| 10232 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10233 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10234 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10235 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10236 | if (!init_types()) |
| 10237 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10238 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10239 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10240 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10241 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10242 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10243 | { |
| 10244 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10245 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10246 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10247 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10248 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10249 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10250 | return NULL; |
| 10251 | } |
| 10252 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10253 | req_type[0] = astmodulestate_global->Module_type; |
| 10254 | req_type[1] = astmodulestate_global->Expression_type; |
| 10255 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10256 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10257 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10258 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10259 | if (!init_types()) |
| 10260 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10261 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10262 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10263 | if (isinstance == -1) |
| 10264 | return NULL; |
| 10265 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10266 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10267 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10268 | return NULL; |
| 10269 | } |
| 10270 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10271 | return NULL; |
| 10272 | else |
| 10273 | return res; |
| 10274 | } |
| 10275 | |
| 10276 | int PyAST_Check(PyObject* obj) |
| 10277 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10278 | if (!init_types()) |
| 10279 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10280 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10281 | } |
| 10282 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10283 | |