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 */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1133 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1134 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1135 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1136 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1137 | assert(free_func != NULL); |
| 1138 | free_func(self); |
| 1139 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1140 | } |
| 1141 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1142 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1143 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1144 | { |
| 1145 | Py_VISIT(self->dict); |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1149 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1150 | ast_clear(AST_object *self) |
| 1151 | { |
| 1152 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1153 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1157 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1158 | { |
| 1159 | Py_ssize_t i, numfields = 0; |
| 1160 | int res = -1; |
| 1161 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1162 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1163 | goto cleanup; |
| 1164 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1165 | if (fields) { |
| 1166 | numfields = PySequence_Size(fields); |
| 1167 | if (numfields == -1) |
| 1168 | goto cleanup; |
| 1169 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1170 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1171 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1172 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1173 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1174 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1175 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1176 | numfields, numfields == 1 ? "" : "s"); |
| 1177 | res = -1; |
| 1178 | goto cleanup; |
| 1179 | } |
| 1180 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1181 | /* cannot be reached when fields is NULL */ |
| 1182 | PyObject *name = PySequence_GetItem(fields, i); |
| 1183 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1184 | res = -1; |
| 1185 | goto cleanup; |
| 1186 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1187 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1188 | Py_DECREF(name); |
| 1189 | if (res < 0) |
| 1190 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1191 | } |
| 1192 | if (kw) { |
| 1193 | i = 0; /* needed by PyDict_Next */ |
| 1194 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1195 | res = PyObject_SetAttr(self, key, value); |
| 1196 | if (res < 0) |
| 1197 | goto cleanup; |
| 1198 | } |
| 1199 | } |
| 1200 | cleanup: |
| 1201 | Py_XDECREF(fields); |
| 1202 | return res; |
| 1203 | } |
| 1204 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1205 | /* Pickling support */ |
| 1206 | static PyObject * |
| 1207 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1208 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1209 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1210 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1211 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1212 | } |
| 1213 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1214 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1215 | } |
| 1216 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1217 | } |
| 1218 | |
| 1219 | static PyMethodDef ast_type_methods[] = { |
| 1220 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1221 | {NULL} |
| 1222 | }; |
| 1223 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1224 | static PyGetSetDef ast_type_getsets[] = { |
| 1225 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1226 | {NULL} |
| 1227 | }; |
| 1228 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1229 | static PyType_Slot AST_type_slots[] = { |
| 1230 | {Py_tp_dealloc, ast_dealloc}, |
| 1231 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1232 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1233 | {Py_tp_traverse, ast_traverse}, |
| 1234 | {Py_tp_clear, ast_clear}, |
| 1235 | {Py_tp_methods, ast_type_methods}, |
| 1236 | {Py_tp_getset, ast_type_getsets}, |
| 1237 | {Py_tp_init, ast_type_init}, |
| 1238 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1239 | {Py_tp_new, PyType_GenericNew}, |
| 1240 | {Py_tp_free, PyType_GenericNew}, |
| 1241 | {Py_tp_free, PyObject_GC_Del}, |
| 1242 | {0, 0}, |
| 1243 | }; |
| 1244 | |
| 1245 | static PyType_Spec AST_type_spec = { |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1246 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1247 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1248 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1249 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1250 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1251 | }; |
| 1252 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1253 | static PyObject * |
| 1254 | 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] | 1255 | { |
| 1256 | PyObject *fnames, *result; |
| 1257 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1258 | fnames = PyTuple_New(num_fields); |
| 1259 | if (!fnames) return NULL; |
| 1260 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1261 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1262 | if (!field) { |
| 1263 | Py_DECREF(fnames); |
| 1264 | return NULL; |
| 1265 | } |
| 1266 | PyTuple_SET_ITEM(fnames, i, field); |
| 1267 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1268 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 1269 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1270 | astmodulestate_global->_fields, fnames, |
| 1271 | astmodulestate_global->__module__, |
| 1272 | astmodulestate_global->_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1273 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1274 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1277 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1278 | 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] | 1279 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1280 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1281 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1282 | if (!l) |
| 1283 | return 0; |
| 1284 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1285 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1286 | if (!s) { |
| 1287 | Py_DECREF(l); |
| 1288 | return 0; |
| 1289 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1290 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1291 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1292 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1293 | Py_DECREF(l); |
| 1294 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1297 | /* Conversion AST -> Python */ |
| 1298 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1299 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1300 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1301 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1302 | PyObject *result = PyList_New(n); |
| 1303 | PyObject *value; |
| 1304 | if (!result) |
| 1305 | return NULL; |
| 1306 | for (i = 0; i < n; i++) { |
| 1307 | value = func(asdl_seq_GET(seq, i)); |
| 1308 | if (!value) { |
| 1309 | Py_DECREF(result); |
| 1310 | return NULL; |
| 1311 | } |
| 1312 | PyList_SET_ITEM(result, i, value); |
| 1313 | } |
| 1314 | return result; |
| 1315 | } |
| 1316 | |
| 1317 | static PyObject* ast2obj_object(void *o) |
| 1318 | { |
| 1319 | if (!o) |
| 1320 | o = Py_None; |
| 1321 | Py_INCREF((PyObject*)o); |
| 1322 | return (PyObject*)o; |
| 1323 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1324 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1325 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1326 | #define ast2obj_identifier ast2obj_object |
| 1327 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1328 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1329 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1330 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1331 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1332 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1335 | /* Conversion Python -> AST */ |
| 1336 | |
| 1337 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1338 | { |
| 1339 | if (obj == Py_None) |
| 1340 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1341 | if (obj) { |
| 1342 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1343 | *out = NULL; |
| 1344 | return -1; |
| 1345 | } |
| 1346 | Py_INCREF(obj); |
| 1347 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1348 | *out = obj; |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1352 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1353 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1354 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1355 | *out = NULL; |
| 1356 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1357 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1358 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1359 | *out = obj; |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1363 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1364 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1365 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1366 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1367 | return 1; |
| 1368 | } |
| 1369 | return obj2ast_object(obj, out, arena); |
| 1370 | } |
| 1371 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1372 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1373 | { |
| 1374 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1375 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1376 | return 1; |
| 1377 | } |
| 1378 | return obj2ast_object(obj, out, arena); |
| 1379 | } |
| 1380 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1381 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1382 | { |
| 1383 | int i; |
| 1384 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1385 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1386 | return 1; |
| 1387 | } |
| 1388 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1389 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1390 | if (i == -1 && PyErr_Occurred()) |
| 1391 | return 1; |
| 1392 | *out = i; |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1396 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1397 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1398 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1399 | empty_tuple = PyTuple_New(0); |
| 1400 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1401 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1402 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1403 | Py_XDECREF(empty_tuple); |
| 1404 | return -1; |
| 1405 | } |
| 1406 | Py_DECREF(empty_tuple); |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1410 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1411 | static int init_types(void) |
| 1412 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1413 | PyObject *m; |
| 1414 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1415 | m = PyModule_Create(&_astmodule); |
| 1416 | if (!m) return 0; |
| 1417 | PyState_AddModule(m, &_astmodule); |
| 1418 | } |
| 1419 | astmodulestate *state = astmodulestate_global; |
| 1420 | if (state->initialized) return 1; |
| 1421 | if (init_identifiers() < 0) return 0; |
| 1422 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1423 | if (!state->AST_type) return 0; |
| 1424 | ((PyTypeObject*)state->AST_type)->tp_dictoffset = offsetof(AST_object, |
| 1425 | dict); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1426 | if (add_ast_fields() < 0) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1427 | state->mod_type = make_type("mod", state->AST_type, NULL, 0); |
| 1428 | if (!state->mod_type) return 0; |
| 1429 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
| 1430 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2); |
| 1431 | if (!state->Module_type) return 0; |
| 1432 | state->Interactive_type = make_type("Interactive", state->mod_type, |
| 1433 | Interactive_fields, 1); |
| 1434 | if (!state->Interactive_type) return 0; |
| 1435 | state->Expression_type = make_type("Expression", state->mod_type, |
| 1436 | Expression_fields, 1); |
| 1437 | if (!state->Expression_type) return 0; |
| 1438 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
| 1439 | FunctionType_fields, 2); |
| 1440 | if (!state->FunctionType_type) return 0; |
| 1441 | state->Suite_type = make_type("Suite", state->mod_type, Suite_fields, 1); |
| 1442 | if (!state->Suite_type) return 0; |
| 1443 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0); |
| 1444 | if (!state->stmt_type) return 0; |
| 1445 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
| 1446 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
| 1447 | FunctionDef_fields, 6); |
| 1448 | if (!state->FunctionDef_type) return 0; |
| 1449 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1450 | state->stmt_type, |
| 1451 | AsyncFunctionDef_fields, 6); |
| 1452 | if (!state->AsyncFunctionDef_type) return 0; |
| 1453 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
| 1454 | ClassDef_fields, 5); |
| 1455 | if (!state->ClassDef_type) return 0; |
| 1456 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, |
| 1457 | 1); |
| 1458 | if (!state->Return_type) return 0; |
| 1459 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, |
| 1460 | 1); |
| 1461 | if (!state->Delete_type) return 0; |
| 1462 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, |
| 1463 | 3); |
| 1464 | if (!state->Assign_type) return 0; |
| 1465 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
| 1466 | AugAssign_fields, 3); |
| 1467 | if (!state->AugAssign_type) return 0; |
| 1468 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
| 1469 | AnnAssign_fields, 4); |
| 1470 | if (!state->AnnAssign_type) return 0; |
| 1471 | state->For_type = make_type("For", state->stmt_type, For_fields, 5); |
| 1472 | if (!state->For_type) return 0; |
| 1473 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
| 1474 | AsyncFor_fields, 5); |
| 1475 | if (!state->AsyncFor_type) return 0; |
| 1476 | state->While_type = make_type("While", state->stmt_type, While_fields, 3); |
| 1477 | if (!state->While_type) return 0; |
| 1478 | state->If_type = make_type("If", state->stmt_type, If_fields, 3); |
| 1479 | if (!state->If_type) return 0; |
| 1480 | state->With_type = make_type("With", state->stmt_type, With_fields, 3); |
| 1481 | if (!state->With_type) return 0; |
| 1482 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
| 1483 | AsyncWith_fields, 3); |
| 1484 | if (!state->AsyncWith_type) return 0; |
| 1485 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2); |
| 1486 | if (!state->Raise_type) return 0; |
| 1487 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4); |
| 1488 | if (!state->Try_type) return 0; |
| 1489 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, |
| 1490 | 2); |
| 1491 | if (!state->Assert_type) return 0; |
| 1492 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, |
| 1493 | 1); |
| 1494 | if (!state->Import_type) return 0; |
| 1495 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
| 1496 | ImportFrom_fields, 3); |
| 1497 | if (!state->ImportFrom_type) return 0; |
| 1498 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, |
| 1499 | 1); |
| 1500 | if (!state->Global_type) return 0; |
| 1501 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
| 1502 | Nonlocal_fields, 1); |
| 1503 | if (!state->Nonlocal_type) return 0; |
| 1504 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1); |
| 1505 | if (!state->Expr_type) return 0; |
| 1506 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0); |
| 1507 | if (!state->Pass_type) return 0; |
| 1508 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0); |
| 1509 | if (!state->Break_type) return 0; |
| 1510 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0); |
| 1511 | if (!state->Continue_type) return 0; |
| 1512 | state->expr_type = make_type("expr", state->AST_type, NULL, 0); |
| 1513 | if (!state->expr_type) return 0; |
| 1514 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
| 1515 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, |
| 1516 | 2); |
| 1517 | if (!state->BoolOp_type) return 0; |
| 1518 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
| 1519 | NamedExpr_fields, 2); |
| 1520 | if (!state->NamedExpr_type) return 0; |
| 1521 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3); |
| 1522 | if (!state->BinOp_type) return 0; |
| 1523 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
| 1524 | UnaryOp_fields, 2); |
| 1525 | if (!state->UnaryOp_type) return 0; |
| 1526 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, |
| 1527 | 2); |
| 1528 | if (!state->Lambda_type) return 0; |
| 1529 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3); |
| 1530 | if (!state->IfExp_type) return 0; |
| 1531 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2); |
| 1532 | if (!state->Dict_type) return 0; |
| 1533 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1); |
| 1534 | if (!state->Set_type) return 0; |
| 1535 | state->ListComp_type = make_type("ListComp", state->expr_type, |
| 1536 | ListComp_fields, 2); |
| 1537 | if (!state->ListComp_type) return 0; |
| 1538 | state->SetComp_type = make_type("SetComp", state->expr_type, |
| 1539 | SetComp_fields, 2); |
| 1540 | if (!state->SetComp_type) return 0; |
| 1541 | state->DictComp_type = make_type("DictComp", state->expr_type, |
| 1542 | DictComp_fields, 3); |
| 1543 | if (!state->DictComp_type) return 0; |
| 1544 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
| 1545 | GeneratorExp_fields, 2); |
| 1546 | if (!state->GeneratorExp_type) return 0; |
| 1547 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1); |
| 1548 | if (!state->Await_type) return 0; |
| 1549 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1); |
| 1550 | if (!state->Yield_type) return 0; |
| 1551 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
| 1552 | YieldFrom_fields, 1); |
| 1553 | if (!state->YieldFrom_type) return 0; |
| 1554 | state->Compare_type = make_type("Compare", state->expr_type, |
| 1555 | Compare_fields, 3); |
| 1556 | if (!state->Compare_type) return 0; |
| 1557 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3); |
| 1558 | if (!state->Call_type) return 0; |
| 1559 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
| 1560 | FormattedValue_fields, 3); |
| 1561 | if (!state->FormattedValue_type) return 0; |
| 1562 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
| 1563 | JoinedStr_fields, 1); |
| 1564 | if (!state->JoinedStr_type) return 0; |
| 1565 | state->Constant_type = make_type("Constant", state->expr_type, |
| 1566 | Constant_fields, 2); |
| 1567 | if (!state->Constant_type) return 0; |
| 1568 | state->Attribute_type = make_type("Attribute", state->expr_type, |
| 1569 | Attribute_fields, 3); |
| 1570 | if (!state->Attribute_type) return 0; |
| 1571 | state->Subscript_type = make_type("Subscript", state->expr_type, |
| 1572 | Subscript_fields, 3); |
| 1573 | if (!state->Subscript_type) return 0; |
| 1574 | state->Starred_type = make_type("Starred", state->expr_type, |
| 1575 | Starred_fields, 2); |
| 1576 | if (!state->Starred_type) return 0; |
| 1577 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2); |
| 1578 | if (!state->Name_type) return 0; |
| 1579 | state->List_type = make_type("List", state->expr_type, List_fields, 2); |
| 1580 | if (!state->List_type) return 0; |
| 1581 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2); |
| 1582 | if (!state->Tuple_type) return 0; |
| 1583 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
| 1584 | 0); |
| 1585 | if (!state->expr_context_type) return 0; |
| 1586 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
| 1587 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0); |
| 1588 | if (!state->Load_type) return 0; |
| 1589 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1590 | NULL, NULL); |
| 1591 | if (!state->Load_singleton) return 0; |
| 1592 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0); |
| 1593 | if (!state->Store_type) return 0; |
| 1594 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1595 | *)state->Store_type, NULL, NULL); |
| 1596 | if (!state->Store_singleton) return 0; |
| 1597 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0); |
| 1598 | if (!state->Del_type) return 0; |
| 1599 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1600 | NULL, NULL); |
| 1601 | if (!state->Del_singleton) return 0; |
| 1602 | state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL, |
| 1603 | 0); |
| 1604 | if (!state->AugLoad_type) return 0; |
| 1605 | state->AugLoad_singleton = PyType_GenericNew((PyTypeObject |
| 1606 | *)state->AugLoad_type, NULL, |
| 1607 | NULL); |
| 1608 | if (!state->AugLoad_singleton) return 0; |
| 1609 | state->AugStore_type = make_type("AugStore", state->expr_context_type, |
| 1610 | NULL, 0); |
| 1611 | if (!state->AugStore_type) return 0; |
| 1612 | state->AugStore_singleton = PyType_GenericNew((PyTypeObject |
| 1613 | *)state->AugStore_type, NULL, |
| 1614 | NULL); |
| 1615 | if (!state->AugStore_singleton) return 0; |
| 1616 | state->Param_type = make_type("Param", state->expr_context_type, NULL, 0); |
| 1617 | if (!state->Param_type) return 0; |
| 1618 | state->Param_singleton = PyType_GenericNew((PyTypeObject |
| 1619 | *)state->Param_type, NULL, NULL); |
| 1620 | if (!state->Param_singleton) return 0; |
| 1621 | state->slice_type = make_type("slice", state->AST_type, NULL, 0); |
| 1622 | if (!state->slice_type) return 0; |
| 1623 | if (!add_attributes(state->slice_type, NULL, 0)) return 0; |
| 1624 | state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3); |
| 1625 | if (!state->Slice_type) return 0; |
| 1626 | state->ExtSlice_type = make_type("ExtSlice", state->slice_type, |
| 1627 | ExtSlice_fields, 1); |
| 1628 | if (!state->ExtSlice_type) return 0; |
| 1629 | state->Index_type = make_type("Index", state->slice_type, Index_fields, 1); |
| 1630 | if (!state->Index_type) return 0; |
| 1631 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0); |
| 1632 | if (!state->boolop_type) return 0; |
| 1633 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
| 1634 | state->And_type = make_type("And", state->boolop_type, NULL, 0); |
| 1635 | if (!state->And_type) return 0; |
| 1636 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1637 | NULL, NULL); |
| 1638 | if (!state->And_singleton) return 0; |
| 1639 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0); |
| 1640 | if (!state->Or_type) return 0; |
| 1641 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1642 | NULL, NULL); |
| 1643 | if (!state->Or_singleton) return 0; |
| 1644 | state->operator_type = make_type("operator", state->AST_type, NULL, 0); |
| 1645 | if (!state->operator_type) return 0; |
| 1646 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
| 1647 | state->Add_type = make_type("Add", state->operator_type, NULL, 0); |
| 1648 | if (!state->Add_type) return 0; |
| 1649 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1650 | NULL, NULL); |
| 1651 | if (!state->Add_singleton) return 0; |
| 1652 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0); |
| 1653 | if (!state->Sub_type) return 0; |
| 1654 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1655 | NULL, NULL); |
| 1656 | if (!state->Sub_singleton) return 0; |
| 1657 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0); |
| 1658 | if (!state->Mult_type) return 0; |
| 1659 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1660 | NULL, NULL); |
| 1661 | if (!state->Mult_singleton) return 0; |
| 1662 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0); |
| 1663 | if (!state->MatMult_type) return 0; |
| 1664 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1665 | *)state->MatMult_type, NULL, |
| 1666 | NULL); |
| 1667 | if (!state->MatMult_singleton) return 0; |
| 1668 | state->Div_type = make_type("Div", state->operator_type, NULL, 0); |
| 1669 | if (!state->Div_type) return 0; |
| 1670 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1671 | NULL, NULL); |
| 1672 | if (!state->Div_singleton) return 0; |
| 1673 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0); |
| 1674 | if (!state->Mod_type) return 0; |
| 1675 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1676 | NULL, NULL); |
| 1677 | if (!state->Mod_singleton) return 0; |
| 1678 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0); |
| 1679 | if (!state->Pow_type) return 0; |
| 1680 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1681 | NULL, NULL); |
| 1682 | if (!state->Pow_singleton) return 0; |
| 1683 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0); |
| 1684 | if (!state->LShift_type) return 0; |
| 1685 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1686 | *)state->LShift_type, NULL, |
| 1687 | NULL); |
| 1688 | if (!state->LShift_singleton) return 0; |
| 1689 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0); |
| 1690 | if (!state->RShift_type) return 0; |
| 1691 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1692 | *)state->RShift_type, NULL, |
| 1693 | NULL); |
| 1694 | if (!state->RShift_singleton) return 0; |
| 1695 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0); |
| 1696 | if (!state->BitOr_type) return 0; |
| 1697 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1698 | *)state->BitOr_type, NULL, NULL); |
| 1699 | if (!state->BitOr_singleton) return 0; |
| 1700 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0); |
| 1701 | if (!state->BitXor_type) return 0; |
| 1702 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1703 | *)state->BitXor_type, NULL, |
| 1704 | NULL); |
| 1705 | if (!state->BitXor_singleton) return 0; |
| 1706 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0); |
| 1707 | if (!state->BitAnd_type) return 0; |
| 1708 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1709 | *)state->BitAnd_type, NULL, |
| 1710 | NULL); |
| 1711 | if (!state->BitAnd_singleton) return 0; |
| 1712 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0); |
| 1713 | if (!state->FloorDiv_type) return 0; |
| 1714 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1715 | *)state->FloorDiv_type, NULL, |
| 1716 | NULL); |
| 1717 | if (!state->FloorDiv_singleton) return 0; |
| 1718 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0); |
| 1719 | if (!state->unaryop_type) return 0; |
| 1720 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
| 1721 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0); |
| 1722 | if (!state->Invert_type) return 0; |
| 1723 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1724 | *)state->Invert_type, NULL, |
| 1725 | NULL); |
| 1726 | if (!state->Invert_singleton) return 0; |
| 1727 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0); |
| 1728 | if (!state->Not_type) return 0; |
| 1729 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1730 | NULL, NULL); |
| 1731 | if (!state->Not_singleton) return 0; |
| 1732 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0); |
| 1733 | if (!state->UAdd_type) return 0; |
| 1734 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1735 | NULL, NULL); |
| 1736 | if (!state->UAdd_singleton) return 0; |
| 1737 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0); |
| 1738 | if (!state->USub_type) return 0; |
| 1739 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1740 | NULL, NULL); |
| 1741 | if (!state->USub_singleton) return 0; |
| 1742 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0); |
| 1743 | if (!state->cmpop_type) return 0; |
| 1744 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
| 1745 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0); |
| 1746 | if (!state->Eq_type) return 0; |
| 1747 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1748 | NULL, NULL); |
| 1749 | if (!state->Eq_singleton) return 0; |
| 1750 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0); |
| 1751 | if (!state->NotEq_type) return 0; |
| 1752 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1753 | *)state->NotEq_type, NULL, NULL); |
| 1754 | if (!state->NotEq_singleton) return 0; |
| 1755 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0); |
| 1756 | if (!state->Lt_type) return 0; |
| 1757 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1758 | NULL, NULL); |
| 1759 | if (!state->Lt_singleton) return 0; |
| 1760 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0); |
| 1761 | if (!state->LtE_type) return 0; |
| 1762 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1763 | NULL, NULL); |
| 1764 | if (!state->LtE_singleton) return 0; |
| 1765 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0); |
| 1766 | if (!state->Gt_type) return 0; |
| 1767 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1768 | NULL, NULL); |
| 1769 | if (!state->Gt_singleton) return 0; |
| 1770 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0); |
| 1771 | if (!state->GtE_type) return 0; |
| 1772 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1773 | NULL, NULL); |
| 1774 | if (!state->GtE_singleton) return 0; |
| 1775 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0); |
| 1776 | if (!state->Is_type) return 0; |
| 1777 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1778 | NULL, NULL); |
| 1779 | if (!state->Is_singleton) return 0; |
| 1780 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0); |
| 1781 | if (!state->IsNot_type) return 0; |
| 1782 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1783 | *)state->IsNot_type, NULL, NULL); |
| 1784 | if (!state->IsNot_singleton) return 0; |
| 1785 | state->In_type = make_type("In", state->cmpop_type, NULL, 0); |
| 1786 | if (!state->In_type) return 0; |
| 1787 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1788 | NULL, NULL); |
| 1789 | if (!state->In_singleton) return 0; |
| 1790 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0); |
| 1791 | if (!state->NotIn_type) return 0; |
| 1792 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1793 | *)state->NotIn_type, NULL, NULL); |
| 1794 | if (!state->NotIn_singleton) return 0; |
| 1795 | state->comprehension_type = make_type("comprehension", state->AST_type, |
| 1796 | comprehension_fields, 4); |
| 1797 | if (!state->comprehension_type) return 0; |
| 1798 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1799 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
| 1800 | NULL, 0); |
| 1801 | if (!state->excepthandler_type) return 0; |
| 1802 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1803 | 4)) return 0; |
| 1804 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1805 | state->excepthandler_type, |
| 1806 | ExceptHandler_fields, 3); |
| 1807 | if (!state->ExceptHandler_type) return 0; |
| 1808 | state->arguments_type = make_type("arguments", state->AST_type, |
| 1809 | arguments_fields, 7); |
| 1810 | if (!state->arguments_type) return 0; |
| 1811 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
| 1812 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3); |
| 1813 | if (!state->arg_type) return 0; |
| 1814 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
| 1815 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
| 1816 | 2); |
| 1817 | if (!state->keyword_type) return 0; |
| 1818 | if (!add_attributes(state->keyword_type, NULL, 0)) return 0; |
| 1819 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2); |
| 1820 | if (!state->alias_type) return 0; |
| 1821 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
| 1822 | state->withitem_type = make_type("withitem", state->AST_type, |
| 1823 | withitem_fields, 2); |
| 1824 | if (!state->withitem_type) return 0; |
| 1825 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
| 1826 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, |
| 1827 | 0); |
| 1828 | if (!state->type_ignore_type) return 0; |
| 1829 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 1830 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
| 1831 | TypeIgnore_fields, 2); |
| 1832 | if (!state->TypeIgnore_type) return 0; |
| 1833 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1834 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1835 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1836 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1837 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1838 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1839 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1840 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1841 | arena); |
| 1842 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1843 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1844 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1845 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1846 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1847 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1848 | arena); |
| 1849 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1850 | arena); |
| 1851 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1852 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1853 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1854 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1855 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1856 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1857 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1858 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1859 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1860 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1861 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1862 | mod_ty p; |
| 1863 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1864 | if (!p) |
| 1865 | return NULL; |
| 1866 | p->kind = Module_kind; |
| 1867 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1868 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1869 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1873 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1874 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1875 | mod_ty p; |
| 1876 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1877 | if (!p) |
| 1878 | return NULL; |
| 1879 | p->kind = Interactive_kind; |
| 1880 | p->v.Interactive.body = body; |
| 1881 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1885 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1886 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1887 | mod_ty p; |
| 1888 | if (!body) { |
| 1889 | PyErr_SetString(PyExc_ValueError, |
| 1890 | "field body is required for Expression"); |
| 1891 | return NULL; |
| 1892 | } |
| 1893 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1894 | if (!p) |
| 1895 | return NULL; |
| 1896 | p->kind = Expression_kind; |
| 1897 | p->v.Expression.body = body; |
| 1898 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1902 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1903 | { |
| 1904 | mod_ty p; |
| 1905 | if (!returns) { |
| 1906 | PyErr_SetString(PyExc_ValueError, |
| 1907 | "field returns is required for FunctionType"); |
| 1908 | return NULL; |
| 1909 | } |
| 1910 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1911 | if (!p) |
| 1912 | return NULL; |
| 1913 | p->kind = FunctionType_kind; |
| 1914 | p->v.FunctionType.argtypes = argtypes; |
| 1915 | p->v.FunctionType.returns = returns; |
| 1916 | return p; |
| 1917 | } |
| 1918 | |
| 1919 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1920 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1921 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1922 | mod_ty p; |
| 1923 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1924 | if (!p) |
| 1925 | return NULL; |
| 1926 | p->kind = Suite_kind; |
| 1927 | p->v.Suite.body = body; |
| 1928 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | stmt_ty |
| 1932 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1933 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 1934 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1935 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1936 | stmt_ty p; |
| 1937 | if (!name) { |
| 1938 | PyErr_SetString(PyExc_ValueError, |
| 1939 | "field name is required for FunctionDef"); |
| 1940 | return NULL; |
| 1941 | } |
| 1942 | if (!args) { |
| 1943 | PyErr_SetString(PyExc_ValueError, |
| 1944 | "field args is required for FunctionDef"); |
| 1945 | return NULL; |
| 1946 | } |
| 1947 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1948 | if (!p) |
| 1949 | return NULL; |
| 1950 | p->kind = FunctionDef_kind; |
| 1951 | p->v.FunctionDef.name = name; |
| 1952 | p->v.FunctionDef.args = args; |
| 1953 | p->v.FunctionDef.body = body; |
| 1954 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1955 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1956 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1957 | p->lineno = lineno; |
| 1958 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1959 | p->end_lineno = end_lineno; |
| 1960 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1961 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1965 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1966 | * decorator_list, expr_ty returns, string type_comment, int |
| 1967 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1968 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1969 | { |
| 1970 | stmt_ty p; |
| 1971 | if (!name) { |
| 1972 | PyErr_SetString(PyExc_ValueError, |
| 1973 | "field name is required for AsyncFunctionDef"); |
| 1974 | return NULL; |
| 1975 | } |
| 1976 | if (!args) { |
| 1977 | PyErr_SetString(PyExc_ValueError, |
| 1978 | "field args is required for AsyncFunctionDef"); |
| 1979 | return NULL; |
| 1980 | } |
| 1981 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1982 | if (!p) |
| 1983 | return NULL; |
| 1984 | p->kind = AsyncFunctionDef_kind; |
| 1985 | p->v.AsyncFunctionDef.name = name; |
| 1986 | p->v.AsyncFunctionDef.args = args; |
| 1987 | p->v.AsyncFunctionDef.body = body; |
| 1988 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1989 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1990 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1991 | p->lineno = lineno; |
| 1992 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1993 | p->end_lineno = end_lineno; |
| 1994 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1995 | return p; |
| 1996 | } |
| 1997 | |
| 1998 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 1999 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2000 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2001 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2002 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2003 | stmt_ty p; |
| 2004 | if (!name) { |
| 2005 | PyErr_SetString(PyExc_ValueError, |
| 2006 | "field name is required for ClassDef"); |
| 2007 | return NULL; |
| 2008 | } |
| 2009 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2010 | if (!p) |
| 2011 | return NULL; |
| 2012 | p->kind = ClassDef_kind; |
| 2013 | p->v.ClassDef.name = name; |
| 2014 | p->v.ClassDef.bases = bases; |
| 2015 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2016 | p->v.ClassDef.body = body; |
| 2017 | p->v.ClassDef.decorator_list = decorator_list; |
| 2018 | p->lineno = lineno; |
| 2019 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2020 | p->end_lineno = end_lineno; |
| 2021 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2022 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2026 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2027 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2028 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2029 | stmt_ty p; |
| 2030 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2031 | if (!p) |
| 2032 | return NULL; |
| 2033 | p->kind = Return_kind; |
| 2034 | p->v.Return.value = value; |
| 2035 | p->lineno = lineno; |
| 2036 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2037 | p->end_lineno = end_lineno; |
| 2038 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2039 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2043 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2044 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2045 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2046 | stmt_ty p; |
| 2047 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2048 | if (!p) |
| 2049 | return NULL; |
| 2050 | p->kind = Delete_kind; |
| 2051 | p->v.Delete.targets = targets; |
| 2052 | p->lineno = lineno; |
| 2053 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2054 | p->end_lineno = end_lineno; |
| 2055 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2056 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2060 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2061 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2062 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2063 | stmt_ty p; |
| 2064 | if (!value) { |
| 2065 | PyErr_SetString(PyExc_ValueError, |
| 2066 | "field value is required for Assign"); |
| 2067 | return NULL; |
| 2068 | } |
| 2069 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2070 | if (!p) |
| 2071 | return NULL; |
| 2072 | p->kind = Assign_kind; |
| 2073 | p->v.Assign.targets = targets; |
| 2074 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2075 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2076 | p->lineno = lineno; |
| 2077 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2078 | p->end_lineno = end_lineno; |
| 2079 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2080 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2084 | 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] | 2085 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2086 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2087 | stmt_ty p; |
| 2088 | if (!target) { |
| 2089 | PyErr_SetString(PyExc_ValueError, |
| 2090 | "field target is required for AugAssign"); |
| 2091 | return NULL; |
| 2092 | } |
| 2093 | if (!op) { |
| 2094 | PyErr_SetString(PyExc_ValueError, |
| 2095 | "field op is required for AugAssign"); |
| 2096 | return NULL; |
| 2097 | } |
| 2098 | if (!value) { |
| 2099 | PyErr_SetString(PyExc_ValueError, |
| 2100 | "field value is required for AugAssign"); |
| 2101 | return NULL; |
| 2102 | } |
| 2103 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2104 | if (!p) |
| 2105 | return NULL; |
| 2106 | p->kind = AugAssign_kind; |
| 2107 | p->v.AugAssign.target = target; |
| 2108 | p->v.AugAssign.op = op; |
| 2109 | p->v.AugAssign.value = value; |
| 2110 | p->lineno = lineno; |
| 2111 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2112 | p->end_lineno = end_lineno; |
| 2113 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2114 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2118 | 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] | 2119 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2120 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2121 | { |
| 2122 | stmt_ty p; |
| 2123 | if (!target) { |
| 2124 | PyErr_SetString(PyExc_ValueError, |
| 2125 | "field target is required for AnnAssign"); |
| 2126 | return NULL; |
| 2127 | } |
| 2128 | if (!annotation) { |
| 2129 | PyErr_SetString(PyExc_ValueError, |
| 2130 | "field annotation is required for AnnAssign"); |
| 2131 | return NULL; |
| 2132 | } |
| 2133 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2134 | if (!p) |
| 2135 | return NULL; |
| 2136 | p->kind = AnnAssign_kind; |
| 2137 | p->v.AnnAssign.target = target; |
| 2138 | p->v.AnnAssign.annotation = annotation; |
| 2139 | p->v.AnnAssign.value = value; |
| 2140 | p->v.AnnAssign.simple = simple; |
| 2141 | p->lineno = lineno; |
| 2142 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2143 | p->end_lineno = end_lineno; |
| 2144 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2145 | return p; |
| 2146 | } |
| 2147 | |
| 2148 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2149 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2150 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2151 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2152 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2153 | stmt_ty p; |
| 2154 | if (!target) { |
| 2155 | PyErr_SetString(PyExc_ValueError, |
| 2156 | "field target is required for For"); |
| 2157 | return NULL; |
| 2158 | } |
| 2159 | if (!iter) { |
| 2160 | PyErr_SetString(PyExc_ValueError, |
| 2161 | "field iter is required for For"); |
| 2162 | return NULL; |
| 2163 | } |
| 2164 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2165 | if (!p) |
| 2166 | return NULL; |
| 2167 | p->kind = For_kind; |
| 2168 | p->v.For.target = target; |
| 2169 | p->v.For.iter = iter; |
| 2170 | p->v.For.body = body; |
| 2171 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2172 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2173 | p->lineno = lineno; |
| 2174 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2175 | p->end_lineno = end_lineno; |
| 2176 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2177 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2181 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2182 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2183 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2184 | { |
| 2185 | stmt_ty p; |
| 2186 | if (!target) { |
| 2187 | PyErr_SetString(PyExc_ValueError, |
| 2188 | "field target is required for AsyncFor"); |
| 2189 | return NULL; |
| 2190 | } |
| 2191 | if (!iter) { |
| 2192 | PyErr_SetString(PyExc_ValueError, |
| 2193 | "field iter is required for AsyncFor"); |
| 2194 | return NULL; |
| 2195 | } |
| 2196 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2197 | if (!p) |
| 2198 | return NULL; |
| 2199 | p->kind = AsyncFor_kind; |
| 2200 | p->v.AsyncFor.target = target; |
| 2201 | p->v.AsyncFor.iter = iter; |
| 2202 | p->v.AsyncFor.body = body; |
| 2203 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2204 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2205 | p->lineno = lineno; |
| 2206 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2207 | p->end_lineno = end_lineno; |
| 2208 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2209 | return p; |
| 2210 | } |
| 2211 | |
| 2212 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2213 | 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] | 2214 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2215 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2216 | stmt_ty p; |
| 2217 | if (!test) { |
| 2218 | PyErr_SetString(PyExc_ValueError, |
| 2219 | "field test is required for While"); |
| 2220 | return NULL; |
| 2221 | } |
| 2222 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2223 | if (!p) |
| 2224 | return NULL; |
| 2225 | p->kind = While_kind; |
| 2226 | p->v.While.test = test; |
| 2227 | p->v.While.body = body; |
| 2228 | p->v.While.orelse = orelse; |
| 2229 | p->lineno = lineno; |
| 2230 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2231 | p->end_lineno = end_lineno; |
| 2232 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2233 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2237 | 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] | 2238 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2239 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2240 | stmt_ty p; |
| 2241 | if (!test) { |
| 2242 | PyErr_SetString(PyExc_ValueError, |
| 2243 | "field test is required for If"); |
| 2244 | return NULL; |
| 2245 | } |
| 2246 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2247 | if (!p) |
| 2248 | return NULL; |
| 2249 | p->kind = If_kind; |
| 2250 | p->v.If.test = test; |
| 2251 | p->v.If.body = body; |
| 2252 | p->v.If.orelse = orelse; |
| 2253 | p->lineno = lineno; |
| 2254 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2255 | p->end_lineno = end_lineno; |
| 2256 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2257 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2261 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2262 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2263 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2264 | stmt_ty p; |
| 2265 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2266 | if (!p) |
| 2267 | return NULL; |
| 2268 | p->kind = With_kind; |
| 2269 | p->v.With.items = items; |
| 2270 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2271 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2272 | p->lineno = lineno; |
| 2273 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2274 | p->end_lineno = end_lineno; |
| 2275 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2276 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2280 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2281 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2282 | { |
| 2283 | stmt_ty p; |
| 2284 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2285 | if (!p) |
| 2286 | return NULL; |
| 2287 | p->kind = AsyncWith_kind; |
| 2288 | p->v.AsyncWith.items = items; |
| 2289 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2290 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2291 | p->lineno = lineno; |
| 2292 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2293 | p->end_lineno = end_lineno; |
| 2294 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2295 | return p; |
| 2296 | } |
| 2297 | |
| 2298 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2299 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2300 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2301 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2302 | stmt_ty p; |
| 2303 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2304 | if (!p) |
| 2305 | return NULL; |
| 2306 | p->kind = Raise_kind; |
| 2307 | p->v.Raise.exc = exc; |
| 2308 | p->v.Raise.cause = cause; |
| 2309 | p->lineno = lineno; |
| 2310 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2311 | p->end_lineno = end_lineno; |
| 2312 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2313 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2317 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2318 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2319 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2320 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2321 | stmt_ty p; |
| 2322 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2323 | if (!p) |
| 2324 | return NULL; |
| 2325 | p->kind = Try_kind; |
| 2326 | p->v.Try.body = body; |
| 2327 | p->v.Try.handlers = handlers; |
| 2328 | p->v.Try.orelse = orelse; |
| 2329 | p->v.Try.finalbody = finalbody; |
| 2330 | p->lineno = lineno; |
| 2331 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2332 | p->end_lineno = end_lineno; |
| 2333 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2334 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2338 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2339 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2340 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2341 | stmt_ty p; |
| 2342 | if (!test) { |
| 2343 | PyErr_SetString(PyExc_ValueError, |
| 2344 | "field test is required for Assert"); |
| 2345 | return NULL; |
| 2346 | } |
| 2347 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2348 | if (!p) |
| 2349 | return NULL; |
| 2350 | p->kind = Assert_kind; |
| 2351 | p->v.Assert.test = test; |
| 2352 | p->v.Assert.msg = msg; |
| 2353 | p->lineno = lineno; |
| 2354 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2355 | p->end_lineno = end_lineno; |
| 2356 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2357 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2361 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2362 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2363 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2364 | stmt_ty p; |
| 2365 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2366 | if (!p) |
| 2367 | return NULL; |
| 2368 | p->kind = Import_kind; |
| 2369 | p->v.Import.names = names; |
| 2370 | p->lineno = lineno; |
| 2371 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2372 | p->end_lineno = end_lineno; |
| 2373 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2374 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2378 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2379 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2380 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2381 | stmt_ty p; |
| 2382 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2383 | if (!p) |
| 2384 | return NULL; |
| 2385 | p->kind = ImportFrom_kind; |
| 2386 | p->v.ImportFrom.module = module; |
| 2387 | p->v.ImportFrom.names = names; |
| 2388 | p->v.ImportFrom.level = level; |
| 2389 | p->lineno = lineno; |
| 2390 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2391 | p->end_lineno = end_lineno; |
| 2392 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2393 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2397 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2398 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2399 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2400 | stmt_ty p; |
| 2401 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2402 | if (!p) |
| 2403 | return NULL; |
| 2404 | p->kind = Global_kind; |
| 2405 | p->v.Global.names = names; |
| 2406 | p->lineno = lineno; |
| 2407 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2408 | p->end_lineno = end_lineno; |
| 2409 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2410 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2414 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2415 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2416 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2417 | stmt_ty p; |
| 2418 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2419 | if (!p) |
| 2420 | return NULL; |
| 2421 | p->kind = Nonlocal_kind; |
| 2422 | p->v.Nonlocal.names = names; |
| 2423 | p->lineno = lineno; |
| 2424 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2425 | p->end_lineno = end_lineno; |
| 2426 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2427 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2431 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2432 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2433 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2434 | stmt_ty p; |
| 2435 | if (!value) { |
| 2436 | PyErr_SetString(PyExc_ValueError, |
| 2437 | "field value is required for Expr"); |
| 2438 | return NULL; |
| 2439 | } |
| 2440 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2441 | if (!p) |
| 2442 | return NULL; |
| 2443 | p->kind = Expr_kind; |
| 2444 | p->v.Expr.value = value; |
| 2445 | p->lineno = lineno; |
| 2446 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2447 | p->end_lineno = end_lineno; |
| 2448 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2449 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2453 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2454 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2455 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2456 | stmt_ty p; |
| 2457 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2458 | if (!p) |
| 2459 | return NULL; |
| 2460 | p->kind = Pass_kind; |
| 2461 | p->lineno = lineno; |
| 2462 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2463 | p->end_lineno = end_lineno; |
| 2464 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2465 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2469 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2470 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2471 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2472 | stmt_ty p; |
| 2473 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2474 | if (!p) |
| 2475 | return NULL; |
| 2476 | p->kind = Break_kind; |
| 2477 | p->lineno = lineno; |
| 2478 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2479 | p->end_lineno = end_lineno; |
| 2480 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2481 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2485 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2486 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2487 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2488 | stmt_ty p; |
| 2489 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2490 | if (!p) |
| 2491 | return NULL; |
| 2492 | p->kind = Continue_kind; |
| 2493 | p->lineno = lineno; |
| 2494 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2495 | p->end_lineno = end_lineno; |
| 2496 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2497 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2501 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2502 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2503 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2504 | expr_ty p; |
| 2505 | if (!op) { |
| 2506 | PyErr_SetString(PyExc_ValueError, |
| 2507 | "field op is required for BoolOp"); |
| 2508 | return NULL; |
| 2509 | } |
| 2510 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2511 | if (!p) |
| 2512 | return NULL; |
| 2513 | p->kind = BoolOp_kind; |
| 2514 | p->v.BoolOp.op = op; |
| 2515 | p->v.BoolOp.values = values; |
| 2516 | p->lineno = lineno; |
| 2517 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2518 | p->end_lineno = end_lineno; |
| 2519 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2520 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2524 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2525 | end_lineno, int end_col_offset, PyArena *arena) |
| 2526 | { |
| 2527 | expr_ty p; |
| 2528 | if (!target) { |
| 2529 | PyErr_SetString(PyExc_ValueError, |
| 2530 | "field target is required for NamedExpr"); |
| 2531 | return NULL; |
| 2532 | } |
| 2533 | if (!value) { |
| 2534 | PyErr_SetString(PyExc_ValueError, |
| 2535 | "field value is required for NamedExpr"); |
| 2536 | return NULL; |
| 2537 | } |
| 2538 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2539 | if (!p) |
| 2540 | return NULL; |
| 2541 | p->kind = NamedExpr_kind; |
| 2542 | p->v.NamedExpr.target = target; |
| 2543 | p->v.NamedExpr.value = value; |
| 2544 | p->lineno = lineno; |
| 2545 | p->col_offset = col_offset; |
| 2546 | p->end_lineno = end_lineno; |
| 2547 | p->end_col_offset = end_col_offset; |
| 2548 | return p; |
| 2549 | } |
| 2550 | |
| 2551 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2552 | 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] | 2553 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2554 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2555 | expr_ty p; |
| 2556 | if (!left) { |
| 2557 | PyErr_SetString(PyExc_ValueError, |
| 2558 | "field left is required for BinOp"); |
| 2559 | return NULL; |
| 2560 | } |
| 2561 | if (!op) { |
| 2562 | PyErr_SetString(PyExc_ValueError, |
| 2563 | "field op is required for BinOp"); |
| 2564 | return NULL; |
| 2565 | } |
| 2566 | if (!right) { |
| 2567 | PyErr_SetString(PyExc_ValueError, |
| 2568 | "field right is required for BinOp"); |
| 2569 | return NULL; |
| 2570 | } |
| 2571 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2572 | if (!p) |
| 2573 | return NULL; |
| 2574 | p->kind = BinOp_kind; |
| 2575 | p->v.BinOp.left = left; |
| 2576 | p->v.BinOp.op = op; |
| 2577 | p->v.BinOp.right = right; |
| 2578 | p->lineno = lineno; |
| 2579 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2580 | p->end_lineno = end_lineno; |
| 2581 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2582 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2586 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2587 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2588 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2589 | expr_ty p; |
| 2590 | if (!op) { |
| 2591 | PyErr_SetString(PyExc_ValueError, |
| 2592 | "field op is required for UnaryOp"); |
| 2593 | return NULL; |
| 2594 | } |
| 2595 | if (!operand) { |
| 2596 | PyErr_SetString(PyExc_ValueError, |
| 2597 | "field operand is required for UnaryOp"); |
| 2598 | return NULL; |
| 2599 | } |
| 2600 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2601 | if (!p) |
| 2602 | return NULL; |
| 2603 | p->kind = UnaryOp_kind; |
| 2604 | p->v.UnaryOp.op = op; |
| 2605 | p->v.UnaryOp.operand = operand; |
| 2606 | p->lineno = lineno; |
| 2607 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2608 | p->end_lineno = end_lineno; |
| 2609 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2610 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2614 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2615 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2616 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2617 | expr_ty p; |
| 2618 | if (!args) { |
| 2619 | PyErr_SetString(PyExc_ValueError, |
| 2620 | "field args is required for Lambda"); |
| 2621 | return NULL; |
| 2622 | } |
| 2623 | if (!body) { |
| 2624 | PyErr_SetString(PyExc_ValueError, |
| 2625 | "field body is required for Lambda"); |
| 2626 | return NULL; |
| 2627 | } |
| 2628 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2629 | if (!p) |
| 2630 | return NULL; |
| 2631 | p->kind = Lambda_kind; |
| 2632 | p->v.Lambda.args = args; |
| 2633 | p->v.Lambda.body = body; |
| 2634 | p->lineno = lineno; |
| 2635 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2636 | p->end_lineno = end_lineno; |
| 2637 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2638 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2642 | 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] | 2643 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2644 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2645 | expr_ty p; |
| 2646 | if (!test) { |
| 2647 | PyErr_SetString(PyExc_ValueError, |
| 2648 | "field test is required for IfExp"); |
| 2649 | return NULL; |
| 2650 | } |
| 2651 | if (!body) { |
| 2652 | PyErr_SetString(PyExc_ValueError, |
| 2653 | "field body is required for IfExp"); |
| 2654 | return NULL; |
| 2655 | } |
| 2656 | if (!orelse) { |
| 2657 | PyErr_SetString(PyExc_ValueError, |
| 2658 | "field orelse is required for IfExp"); |
| 2659 | return NULL; |
| 2660 | } |
| 2661 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2662 | if (!p) |
| 2663 | return NULL; |
| 2664 | p->kind = IfExp_kind; |
| 2665 | p->v.IfExp.test = test; |
| 2666 | p->v.IfExp.body = body; |
| 2667 | p->v.IfExp.orelse = orelse; |
| 2668 | p->lineno = lineno; |
| 2669 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2670 | p->end_lineno = end_lineno; |
| 2671 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2672 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2676 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2677 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2678 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2679 | expr_ty p; |
| 2680 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2681 | if (!p) |
| 2682 | return NULL; |
| 2683 | p->kind = Dict_kind; |
| 2684 | p->v.Dict.keys = keys; |
| 2685 | p->v.Dict.values = values; |
| 2686 | p->lineno = lineno; |
| 2687 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2688 | p->end_lineno = end_lineno; |
| 2689 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2690 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2694 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2695 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2696 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2697 | expr_ty p; |
| 2698 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2699 | if (!p) |
| 2700 | return NULL; |
| 2701 | p->kind = Set_kind; |
| 2702 | p->v.Set.elts = elts; |
| 2703 | p->lineno = lineno; |
| 2704 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2705 | p->end_lineno = end_lineno; |
| 2706 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2707 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2711 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2712 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2713 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2714 | expr_ty p; |
| 2715 | if (!elt) { |
| 2716 | PyErr_SetString(PyExc_ValueError, |
| 2717 | "field elt is required for ListComp"); |
| 2718 | return NULL; |
| 2719 | } |
| 2720 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2721 | if (!p) |
| 2722 | return NULL; |
| 2723 | p->kind = ListComp_kind; |
| 2724 | p->v.ListComp.elt = elt; |
| 2725 | p->v.ListComp.generators = generators; |
| 2726 | p->lineno = lineno; |
| 2727 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2728 | p->end_lineno = end_lineno; |
| 2729 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2730 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2734 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2735 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2736 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2737 | expr_ty p; |
| 2738 | if (!elt) { |
| 2739 | PyErr_SetString(PyExc_ValueError, |
| 2740 | "field elt is required for SetComp"); |
| 2741 | return NULL; |
| 2742 | } |
| 2743 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2744 | if (!p) |
| 2745 | return NULL; |
| 2746 | p->kind = SetComp_kind; |
| 2747 | p->v.SetComp.elt = elt; |
| 2748 | p->v.SetComp.generators = generators; |
| 2749 | p->lineno = lineno; |
| 2750 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2751 | p->end_lineno = end_lineno; |
| 2752 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2753 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2757 | 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] | 2758 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2759 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2760 | expr_ty p; |
| 2761 | if (!key) { |
| 2762 | PyErr_SetString(PyExc_ValueError, |
| 2763 | "field key is required for DictComp"); |
| 2764 | return NULL; |
| 2765 | } |
| 2766 | if (!value) { |
| 2767 | PyErr_SetString(PyExc_ValueError, |
| 2768 | "field value is required for DictComp"); |
| 2769 | return NULL; |
| 2770 | } |
| 2771 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2772 | if (!p) |
| 2773 | return NULL; |
| 2774 | p->kind = DictComp_kind; |
| 2775 | p->v.DictComp.key = key; |
| 2776 | p->v.DictComp.value = value; |
| 2777 | p->v.DictComp.generators = generators; |
| 2778 | p->lineno = lineno; |
| 2779 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2780 | p->end_lineno = end_lineno; |
| 2781 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2782 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2786 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2787 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2788 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2789 | expr_ty p; |
| 2790 | if (!elt) { |
| 2791 | PyErr_SetString(PyExc_ValueError, |
| 2792 | "field elt is required for GeneratorExp"); |
| 2793 | return NULL; |
| 2794 | } |
| 2795 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2796 | if (!p) |
| 2797 | return NULL; |
| 2798 | p->kind = GeneratorExp_kind; |
| 2799 | p->v.GeneratorExp.elt = elt; |
| 2800 | p->v.GeneratorExp.generators = generators; |
| 2801 | p->lineno = lineno; |
| 2802 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2803 | p->end_lineno = end_lineno; |
| 2804 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2805 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2809 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2810 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2811 | { |
| 2812 | expr_ty p; |
| 2813 | if (!value) { |
| 2814 | PyErr_SetString(PyExc_ValueError, |
| 2815 | "field value is required for Await"); |
| 2816 | return NULL; |
| 2817 | } |
| 2818 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2819 | if (!p) |
| 2820 | return NULL; |
| 2821 | p->kind = Await_kind; |
| 2822 | p->v.Await.value = value; |
| 2823 | p->lineno = lineno; |
| 2824 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2825 | p->end_lineno = end_lineno; |
| 2826 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2827 | return p; |
| 2828 | } |
| 2829 | |
| 2830 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2831 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2832 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2833 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2834 | expr_ty p; |
| 2835 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2836 | if (!p) |
| 2837 | return NULL; |
| 2838 | p->kind = Yield_kind; |
| 2839 | p->v.Yield.value = value; |
| 2840 | p->lineno = lineno; |
| 2841 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2842 | p->end_lineno = end_lineno; |
| 2843 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2844 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2848 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2849 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2850 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2851 | expr_ty p; |
| 2852 | if (!value) { |
| 2853 | PyErr_SetString(PyExc_ValueError, |
| 2854 | "field value is required for YieldFrom"); |
| 2855 | return NULL; |
| 2856 | } |
| 2857 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2858 | if (!p) |
| 2859 | return NULL; |
| 2860 | p->kind = YieldFrom_kind; |
| 2861 | p->v.YieldFrom.value = value; |
| 2862 | p->lineno = lineno; |
| 2863 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2864 | p->end_lineno = end_lineno; |
| 2865 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2866 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2870 | 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] | 2871 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2872 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2873 | expr_ty p; |
| 2874 | if (!left) { |
| 2875 | PyErr_SetString(PyExc_ValueError, |
| 2876 | "field left is required for Compare"); |
| 2877 | return NULL; |
| 2878 | } |
| 2879 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2880 | if (!p) |
| 2881 | return NULL; |
| 2882 | p->kind = Compare_kind; |
| 2883 | p->v.Compare.left = left; |
| 2884 | p->v.Compare.ops = ops; |
| 2885 | p->v.Compare.comparators = comparators; |
| 2886 | p->lineno = lineno; |
| 2887 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2888 | p->end_lineno = end_lineno; |
| 2889 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2890 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2894 | 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] | 2895 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2896 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2897 | expr_ty p; |
| 2898 | if (!func) { |
| 2899 | PyErr_SetString(PyExc_ValueError, |
| 2900 | "field func is required for Call"); |
| 2901 | return NULL; |
| 2902 | } |
| 2903 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2904 | if (!p) |
| 2905 | return NULL; |
| 2906 | p->kind = Call_kind; |
| 2907 | p->v.Call.func = func; |
| 2908 | p->v.Call.args = args; |
| 2909 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2910 | p->lineno = lineno; |
| 2911 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2912 | p->end_lineno = end_lineno; |
| 2913 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2914 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 2918 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2919 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2920 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2921 | { |
| 2922 | expr_ty p; |
| 2923 | if (!value) { |
| 2924 | PyErr_SetString(PyExc_ValueError, |
| 2925 | "field value is required for FormattedValue"); |
| 2926 | return NULL; |
| 2927 | } |
| 2928 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2929 | if (!p) |
| 2930 | return NULL; |
| 2931 | p->kind = FormattedValue_kind; |
| 2932 | p->v.FormattedValue.value = value; |
| 2933 | p->v.FormattedValue.conversion = conversion; |
| 2934 | p->v.FormattedValue.format_spec = format_spec; |
| 2935 | p->lineno = lineno; |
| 2936 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2937 | p->end_lineno = end_lineno; |
| 2938 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2939 | return p; |
| 2940 | } |
| 2941 | |
| 2942 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2943 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2944 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2945 | { |
| 2946 | expr_ty p; |
| 2947 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2948 | if (!p) |
| 2949 | return NULL; |
| 2950 | p->kind = JoinedStr_kind; |
| 2951 | p->v.JoinedStr.values = values; |
| 2952 | p->lineno = lineno; |
| 2953 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2954 | p->end_lineno = end_lineno; |
| 2955 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2956 | return p; |
| 2957 | } |
| 2958 | |
| 2959 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2960 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 2961 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2962 | { |
| 2963 | expr_ty p; |
| 2964 | if (!value) { |
| 2965 | PyErr_SetString(PyExc_ValueError, |
| 2966 | "field value is required for Constant"); |
| 2967 | return NULL; |
| 2968 | } |
| 2969 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2970 | if (!p) |
| 2971 | return NULL; |
| 2972 | p->kind = Constant_kind; |
| 2973 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2974 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2975 | p->lineno = lineno; |
| 2976 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2977 | p->end_lineno = end_lineno; |
| 2978 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2979 | return p; |
| 2980 | } |
| 2981 | |
| 2982 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2983 | 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] | 2984 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2985 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2986 | expr_ty p; |
| 2987 | if (!value) { |
| 2988 | PyErr_SetString(PyExc_ValueError, |
| 2989 | "field value is required for Attribute"); |
| 2990 | return NULL; |
| 2991 | } |
| 2992 | if (!attr) { |
| 2993 | PyErr_SetString(PyExc_ValueError, |
| 2994 | "field attr is required for Attribute"); |
| 2995 | return NULL; |
| 2996 | } |
| 2997 | if (!ctx) { |
| 2998 | PyErr_SetString(PyExc_ValueError, |
| 2999 | "field ctx is required for Attribute"); |
| 3000 | return NULL; |
| 3001 | } |
| 3002 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3003 | if (!p) |
| 3004 | return NULL; |
| 3005 | p->kind = Attribute_kind; |
| 3006 | p->v.Attribute.value = value; |
| 3007 | p->v.Attribute.attr = attr; |
| 3008 | p->v.Attribute.ctx = ctx; |
| 3009 | p->lineno = lineno; |
| 3010 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3011 | p->end_lineno = end_lineno; |
| 3012 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3013 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3017 | 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] | 3018 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3019 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3020 | expr_ty p; |
| 3021 | if (!value) { |
| 3022 | PyErr_SetString(PyExc_ValueError, |
| 3023 | "field value is required for Subscript"); |
| 3024 | return NULL; |
| 3025 | } |
| 3026 | if (!slice) { |
| 3027 | PyErr_SetString(PyExc_ValueError, |
| 3028 | "field slice is required for Subscript"); |
| 3029 | return NULL; |
| 3030 | } |
| 3031 | if (!ctx) { |
| 3032 | PyErr_SetString(PyExc_ValueError, |
| 3033 | "field ctx is required for Subscript"); |
| 3034 | return NULL; |
| 3035 | } |
| 3036 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3037 | if (!p) |
| 3038 | return NULL; |
| 3039 | p->kind = Subscript_kind; |
| 3040 | p->v.Subscript.value = value; |
| 3041 | p->v.Subscript.slice = slice; |
| 3042 | p->v.Subscript.ctx = ctx; |
| 3043 | p->lineno = lineno; |
| 3044 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3045 | p->end_lineno = end_lineno; |
| 3046 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3047 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3051 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3052 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3053 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3054 | expr_ty p; |
| 3055 | if (!value) { |
| 3056 | PyErr_SetString(PyExc_ValueError, |
| 3057 | "field value is required for Starred"); |
| 3058 | return NULL; |
| 3059 | } |
| 3060 | if (!ctx) { |
| 3061 | PyErr_SetString(PyExc_ValueError, |
| 3062 | "field ctx is required for Starred"); |
| 3063 | return NULL; |
| 3064 | } |
| 3065 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3066 | if (!p) |
| 3067 | return NULL; |
| 3068 | p->kind = Starred_kind; |
| 3069 | p->v.Starred.value = value; |
| 3070 | p->v.Starred.ctx = ctx; |
| 3071 | p->lineno = lineno; |
| 3072 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3073 | p->end_lineno = end_lineno; |
| 3074 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3075 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3079 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3080 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3081 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3082 | expr_ty p; |
| 3083 | if (!id) { |
| 3084 | PyErr_SetString(PyExc_ValueError, |
| 3085 | "field id is required for Name"); |
| 3086 | return NULL; |
| 3087 | } |
| 3088 | if (!ctx) { |
| 3089 | PyErr_SetString(PyExc_ValueError, |
| 3090 | "field ctx is required for Name"); |
| 3091 | return NULL; |
| 3092 | } |
| 3093 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3094 | if (!p) |
| 3095 | return NULL; |
| 3096 | p->kind = Name_kind; |
| 3097 | p->v.Name.id = id; |
| 3098 | p->v.Name.ctx = ctx; |
| 3099 | p->lineno = lineno; |
| 3100 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3101 | p->end_lineno = end_lineno; |
| 3102 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3103 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3107 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3108 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3109 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3110 | expr_ty p; |
| 3111 | if (!ctx) { |
| 3112 | PyErr_SetString(PyExc_ValueError, |
| 3113 | "field ctx is required for List"); |
| 3114 | return NULL; |
| 3115 | } |
| 3116 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3117 | if (!p) |
| 3118 | return NULL; |
| 3119 | p->kind = List_kind; |
| 3120 | p->v.List.elts = elts; |
| 3121 | p->v.List.ctx = ctx; |
| 3122 | p->lineno = lineno; |
| 3123 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3124 | p->end_lineno = end_lineno; |
| 3125 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3126 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3130 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3131 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3132 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3133 | expr_ty p; |
| 3134 | if (!ctx) { |
| 3135 | PyErr_SetString(PyExc_ValueError, |
| 3136 | "field ctx is required for Tuple"); |
| 3137 | return NULL; |
| 3138 | } |
| 3139 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3140 | if (!p) |
| 3141 | return NULL; |
| 3142 | p->kind = Tuple_kind; |
| 3143 | p->v.Tuple.elts = elts; |
| 3144 | p->v.Tuple.ctx = ctx; |
| 3145 | p->lineno = lineno; |
| 3146 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3147 | p->end_lineno = end_lineno; |
| 3148 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3149 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3153 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3154 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3155 | slice_ty p; |
| 3156 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3157 | if (!p) |
| 3158 | return NULL; |
| 3159 | p->kind = Slice_kind; |
| 3160 | p->v.Slice.lower = lower; |
| 3161 | p->v.Slice.upper = upper; |
| 3162 | p->v.Slice.step = step; |
| 3163 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3167 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3168 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3169 | slice_ty p; |
| 3170 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3171 | if (!p) |
| 3172 | return NULL; |
| 3173 | p->kind = ExtSlice_kind; |
| 3174 | p->v.ExtSlice.dims = dims; |
| 3175 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3179 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3180 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3181 | slice_ty p; |
| 3182 | if (!value) { |
| 3183 | PyErr_SetString(PyExc_ValueError, |
| 3184 | "field value is required for Index"); |
| 3185 | return NULL; |
| 3186 | } |
| 3187 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3188 | if (!p) |
| 3189 | return NULL; |
| 3190 | p->kind = Index_kind; |
| 3191 | p->v.Index.value = value; |
| 3192 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3196 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3197 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3198 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3199 | comprehension_ty p; |
| 3200 | if (!target) { |
| 3201 | PyErr_SetString(PyExc_ValueError, |
| 3202 | "field target is required for comprehension"); |
| 3203 | return NULL; |
| 3204 | } |
| 3205 | if (!iter) { |
| 3206 | PyErr_SetString(PyExc_ValueError, |
| 3207 | "field iter is required for comprehension"); |
| 3208 | return NULL; |
| 3209 | } |
| 3210 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3211 | if (!p) |
| 3212 | return NULL; |
| 3213 | p->target = target; |
| 3214 | p->iter = iter; |
| 3215 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3216 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3217 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3221 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3222 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3223 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3224 | excepthandler_ty p; |
| 3225 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3226 | if (!p) |
| 3227 | return NULL; |
| 3228 | p->kind = ExceptHandler_kind; |
| 3229 | p->v.ExceptHandler.type = type; |
| 3230 | p->v.ExceptHandler.name = name; |
| 3231 | p->v.ExceptHandler.body = body; |
| 3232 | p->lineno = lineno; |
| 3233 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3234 | p->end_lineno = end_lineno; |
| 3235 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3236 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3240 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3241 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3242 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3243 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3244 | arguments_ty p; |
| 3245 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3246 | if (!p) |
| 3247 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3248 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3249 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3250 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3251 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3252 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3253 | p->kwarg = kwarg; |
| 3254 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3255 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3256 | } |
| 3257 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3258 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3259 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3260 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3261 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3262 | arg_ty p; |
| 3263 | if (!arg) { |
| 3264 | PyErr_SetString(PyExc_ValueError, |
| 3265 | "field arg is required for arg"); |
| 3266 | return NULL; |
| 3267 | } |
| 3268 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3269 | if (!p) |
| 3270 | return NULL; |
| 3271 | p->arg = arg; |
| 3272 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3273 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3274 | p->lineno = lineno; |
| 3275 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3276 | p->end_lineno = end_lineno; |
| 3277 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3278 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3281 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3282 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3283 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3284 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3285 | if (!value) { |
| 3286 | PyErr_SetString(PyExc_ValueError, |
| 3287 | "field value is required for keyword"); |
| 3288 | return NULL; |
| 3289 | } |
| 3290 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3291 | if (!p) |
| 3292 | return NULL; |
| 3293 | p->arg = arg; |
| 3294 | p->value = value; |
| 3295 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3299 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3300 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3301 | alias_ty p; |
| 3302 | if (!name) { |
| 3303 | PyErr_SetString(PyExc_ValueError, |
| 3304 | "field name is required for alias"); |
| 3305 | return NULL; |
| 3306 | } |
| 3307 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3308 | if (!p) |
| 3309 | return NULL; |
| 3310 | p->name = name; |
| 3311 | p->asname = asname; |
| 3312 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3313 | } |
| 3314 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3315 | withitem_ty |
| 3316 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3317 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3318 | withitem_ty p; |
| 3319 | if (!context_expr) { |
| 3320 | PyErr_SetString(PyExc_ValueError, |
| 3321 | "field context_expr is required for withitem"); |
| 3322 | return NULL; |
| 3323 | } |
| 3324 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3325 | if (!p) |
| 3326 | return NULL; |
| 3327 | p->context_expr = context_expr; |
| 3328 | p->optional_vars = optional_vars; |
| 3329 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3330 | } |
| 3331 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3332 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3333 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3334 | { |
| 3335 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3336 | if (!tag) { |
| 3337 | PyErr_SetString(PyExc_ValueError, |
| 3338 | "field tag is required for TypeIgnore"); |
| 3339 | return NULL; |
| 3340 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3341 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3342 | if (!p) |
| 3343 | return NULL; |
| 3344 | p->kind = TypeIgnore_kind; |
| 3345 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3346 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3347 | return p; |
| 3348 | } |
| 3349 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3350 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3351 | PyObject* |
| 3352 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3353 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3354 | mod_ty o = (mod_ty)_o; |
| 3355 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3356 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3357 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3358 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3359 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3360 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3361 | switch (o->kind) { |
| 3362 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3363 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3364 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3365 | if (!result) goto failed; |
| 3366 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3367 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3368 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3369 | goto failed; |
| 3370 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3371 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3372 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3373 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3374 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3375 | goto failed; |
| 3376 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3377 | break; |
| 3378 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3379 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3380 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3381 | if (!result) goto failed; |
| 3382 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3383 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3384 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3385 | goto failed; |
| 3386 | Py_DECREF(value); |
| 3387 | break; |
| 3388 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3389 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3390 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3391 | if (!result) goto failed; |
| 3392 | value = ast2obj_expr(o->v.Expression.body); |
| 3393 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3394 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3395 | goto failed; |
| 3396 | Py_DECREF(value); |
| 3397 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3398 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3399 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3400 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3401 | if (!result) goto failed; |
| 3402 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3403 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3404 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3405 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3406 | goto failed; |
| 3407 | Py_DECREF(value); |
| 3408 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3409 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3410 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3411 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3412 | goto failed; |
| 3413 | Py_DECREF(value); |
| 3414 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3415 | case Suite_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3416 | tp = (PyTypeObject *)astmodulestate_global->Suite_type; |
| 3417 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3418 | if (!result) goto failed; |
| 3419 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 3420 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3421 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3422 | goto failed; |
| 3423 | Py_DECREF(value); |
| 3424 | break; |
| 3425 | } |
| 3426 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3427 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3428 | Py_XDECREF(value); |
| 3429 | Py_XDECREF(result); |
| 3430 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3433 | PyObject* |
| 3434 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3435 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3436 | stmt_ty o = (stmt_ty)_o; |
| 3437 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3438 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3439 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3440 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3441 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3442 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3443 | switch (o->kind) { |
| 3444 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3445 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3446 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3447 | if (!result) goto failed; |
| 3448 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3449 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3450 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3451 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3452 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3453 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3454 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3455 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3456 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3457 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3458 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3459 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3460 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3461 | goto failed; |
| 3462 | Py_DECREF(value); |
| 3463 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3464 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3465 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3466 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3467 | goto failed; |
| 3468 | Py_DECREF(value); |
| 3469 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3470 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3471 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3472 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3473 | goto failed; |
| 3474 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3475 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3476 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3477 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3478 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3479 | goto failed; |
| 3480 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3481 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3482 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3483 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3484 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3485 | if (!result) goto failed; |
| 3486 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3487 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3488 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3489 | goto failed; |
| 3490 | Py_DECREF(value); |
| 3491 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3492 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3493 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3494 | goto failed; |
| 3495 | Py_DECREF(value); |
| 3496 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3497 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3498 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3499 | goto failed; |
| 3500 | Py_DECREF(value); |
| 3501 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3502 | ast2obj_expr); |
| 3503 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3504 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3505 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3506 | goto failed; |
| 3507 | Py_DECREF(value); |
| 3508 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3509 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3510 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3511 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3512 | goto failed; |
| 3513 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3514 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3515 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3516 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3517 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3518 | goto failed; |
| 3519 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3520 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3521 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3522 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3523 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3524 | if (!result) goto failed; |
| 3525 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3526 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3527 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3528 | goto failed; |
| 3529 | Py_DECREF(value); |
| 3530 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3531 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3532 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3533 | goto failed; |
| 3534 | Py_DECREF(value); |
| 3535 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3536 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3537 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3538 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3539 | goto failed; |
| 3540 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3541 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3542 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3543 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3544 | goto failed; |
| 3545 | Py_DECREF(value); |
| 3546 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3547 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3548 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3549 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3550 | goto failed; |
| 3551 | Py_DECREF(value); |
| 3552 | break; |
| 3553 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3554 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3555 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3556 | if (!result) goto failed; |
| 3557 | value = ast2obj_expr(o->v.Return.value); |
| 3558 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3559 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3560 | goto failed; |
| 3561 | Py_DECREF(value); |
| 3562 | break; |
| 3563 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3564 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3565 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3566 | if (!result) goto failed; |
| 3567 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3568 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3569 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3570 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3571 | goto failed; |
| 3572 | Py_DECREF(value); |
| 3573 | break; |
| 3574 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3575 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3576 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3577 | if (!result) goto failed; |
| 3578 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3579 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3580 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3581 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3582 | goto failed; |
| 3583 | Py_DECREF(value); |
| 3584 | value = ast2obj_expr(o->v.Assign.value); |
| 3585 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3586 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3587 | goto failed; |
| 3588 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3589 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3590 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3591 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3592 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3593 | goto failed; |
| 3594 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3595 | break; |
| 3596 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3597 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3598 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3599 | if (!result) goto failed; |
| 3600 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3601 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3602 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3603 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3604 | goto failed; |
| 3605 | Py_DECREF(value); |
| 3606 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3607 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3608 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3609 | goto failed; |
| 3610 | Py_DECREF(value); |
| 3611 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3612 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3613 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3614 | goto failed; |
| 3615 | Py_DECREF(value); |
| 3616 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3617 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3618 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3619 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3620 | if (!result) goto failed; |
| 3621 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3622 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3623 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3624 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3625 | goto failed; |
| 3626 | Py_DECREF(value); |
| 3627 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3628 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3629 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3630 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3631 | goto failed; |
| 3632 | Py_DECREF(value); |
| 3633 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3634 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3635 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3636 | goto failed; |
| 3637 | Py_DECREF(value); |
| 3638 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3639 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3640 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3641 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3642 | goto failed; |
| 3643 | Py_DECREF(value); |
| 3644 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3645 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3646 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3647 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3648 | if (!result) goto failed; |
| 3649 | value = ast2obj_expr(o->v.For.target); |
| 3650 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3651 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3652 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3653 | goto failed; |
| 3654 | Py_DECREF(value); |
| 3655 | value = ast2obj_expr(o->v.For.iter); |
| 3656 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3657 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3658 | goto failed; |
| 3659 | Py_DECREF(value); |
| 3660 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3661 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3662 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3663 | goto failed; |
| 3664 | Py_DECREF(value); |
| 3665 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3666 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3667 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3668 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3669 | goto failed; |
| 3670 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3671 | value = ast2obj_string(o->v.For.type_comment); |
| 3672 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3673 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3674 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3675 | goto failed; |
| 3676 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3677 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3678 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3679 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3680 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3681 | if (!result) goto failed; |
| 3682 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3683 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3684 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3685 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3686 | goto failed; |
| 3687 | Py_DECREF(value); |
| 3688 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3689 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3690 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3691 | goto failed; |
| 3692 | Py_DECREF(value); |
| 3693 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3694 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3695 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3696 | goto failed; |
| 3697 | Py_DECREF(value); |
| 3698 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3699 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3700 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3701 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3702 | goto failed; |
| 3703 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3704 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3705 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3706 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3707 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3708 | goto failed; |
| 3709 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3710 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3711 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3712 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3713 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3714 | if (!result) goto failed; |
| 3715 | value = ast2obj_expr(o->v.While.test); |
| 3716 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3717 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3718 | goto failed; |
| 3719 | Py_DECREF(value); |
| 3720 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3721 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3722 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3723 | goto failed; |
| 3724 | Py_DECREF(value); |
| 3725 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3726 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3727 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3728 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3729 | goto failed; |
| 3730 | Py_DECREF(value); |
| 3731 | break; |
| 3732 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3733 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3734 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3735 | if (!result) goto failed; |
| 3736 | value = ast2obj_expr(o->v.If.test); |
| 3737 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3738 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3739 | goto failed; |
| 3740 | Py_DECREF(value); |
| 3741 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3742 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3743 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3744 | goto failed; |
| 3745 | Py_DECREF(value); |
| 3746 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3747 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3748 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3749 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3750 | goto failed; |
| 3751 | Py_DECREF(value); |
| 3752 | break; |
| 3753 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3754 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3755 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3756 | if (!result) goto failed; |
| 3757 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3758 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3759 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3760 | goto failed; |
| 3761 | Py_DECREF(value); |
| 3762 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3763 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3764 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3765 | goto failed; |
| 3766 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3767 | value = ast2obj_string(o->v.With.type_comment); |
| 3768 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3769 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3770 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3771 | goto failed; |
| 3772 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3773 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3774 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3775 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3776 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3777 | if (!result) goto failed; |
| 3778 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3779 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3780 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3781 | goto failed; |
| 3782 | Py_DECREF(value); |
| 3783 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3784 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3785 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3786 | goto failed; |
| 3787 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3788 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3789 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3790 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3791 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3792 | goto failed; |
| 3793 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3794 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3795 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3796 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3797 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3798 | if (!result) goto failed; |
| 3799 | value = ast2obj_expr(o->v.Raise.exc); |
| 3800 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3801 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3802 | goto failed; |
| 3803 | Py_DECREF(value); |
| 3804 | value = ast2obj_expr(o->v.Raise.cause); |
| 3805 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3806 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3807 | goto failed; |
| 3808 | Py_DECREF(value); |
| 3809 | break; |
| 3810 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3811 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3812 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3813 | if (!result) goto failed; |
| 3814 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3815 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3816 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3817 | goto failed; |
| 3818 | Py_DECREF(value); |
| 3819 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3820 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3821 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3822 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3823 | goto failed; |
| 3824 | Py_DECREF(value); |
| 3825 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3826 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3827 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3828 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3829 | goto failed; |
| 3830 | Py_DECREF(value); |
| 3831 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3832 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3833 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3834 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3835 | goto failed; |
| 3836 | Py_DECREF(value); |
| 3837 | break; |
| 3838 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3839 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3840 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3841 | if (!result) goto failed; |
| 3842 | value = ast2obj_expr(o->v.Assert.test); |
| 3843 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3844 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3845 | goto failed; |
| 3846 | Py_DECREF(value); |
| 3847 | value = ast2obj_expr(o->v.Assert.msg); |
| 3848 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3849 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3850 | goto failed; |
| 3851 | Py_DECREF(value); |
| 3852 | break; |
| 3853 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3854 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 3855 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3856 | if (!result) goto failed; |
| 3857 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3858 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3859 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3860 | goto failed; |
| 3861 | Py_DECREF(value); |
| 3862 | break; |
| 3863 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3864 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 3865 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3866 | if (!result) goto failed; |
| 3867 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3868 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3869 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 3870 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3871 | goto failed; |
| 3872 | Py_DECREF(value); |
| 3873 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3874 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3875 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3876 | goto failed; |
| 3877 | Py_DECREF(value); |
| 3878 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3879 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3880 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3881 | goto failed; |
| 3882 | Py_DECREF(value); |
| 3883 | break; |
| 3884 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3885 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 3886 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3887 | if (!result) goto failed; |
| 3888 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3889 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3890 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | goto failed; |
| 3892 | Py_DECREF(value); |
| 3893 | break; |
| 3894 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3895 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 3896 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3897 | if (!result) goto failed; |
| 3898 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3899 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3900 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3901 | goto failed; |
| 3902 | Py_DECREF(value); |
| 3903 | break; |
| 3904 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3905 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 3906 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | if (!result) goto failed; |
| 3908 | value = ast2obj_expr(o->v.Expr.value); |
| 3909 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3910 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3911 | goto failed; |
| 3912 | Py_DECREF(value); |
| 3913 | break; |
| 3914 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3915 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 3916 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3917 | if (!result) goto failed; |
| 3918 | break; |
| 3919 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3920 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 3921 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3922 | if (!result) goto failed; |
| 3923 | break; |
| 3924 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3925 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 3926 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3927 | if (!result) goto failed; |
| 3928 | break; |
| 3929 | } |
| 3930 | value = ast2obj_int(o->lineno); |
| 3931 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3932 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3933 | goto failed; |
| 3934 | Py_DECREF(value); |
| 3935 | value = ast2obj_int(o->col_offset); |
| 3936 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3937 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3938 | goto failed; |
| 3939 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3940 | value = ast2obj_int(o->end_lineno); |
| 3941 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3942 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3943 | goto failed; |
| 3944 | Py_DECREF(value); |
| 3945 | value = ast2obj_int(o->end_col_offset); |
| 3946 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3947 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 3948 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3949 | goto failed; |
| 3950 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3951 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3952 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3953 | Py_XDECREF(value); |
| 3954 | Py_XDECREF(result); |
| 3955 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3956 | } |
| 3957 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3958 | PyObject* |
| 3959 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3960 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3961 | expr_ty o = (expr_ty)_o; |
| 3962 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3963 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3964 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3965 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3966 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3967 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3968 | switch (o->kind) { |
| 3969 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3970 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 3971 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3972 | if (!result) goto failed; |
| 3973 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3974 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3975 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | goto failed; |
| 3977 | Py_DECREF(value); |
| 3978 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3979 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3980 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 3981 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3982 | goto failed; |
| 3983 | Py_DECREF(value); |
| 3984 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3985 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3986 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 3987 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3988 | if (!result) goto failed; |
| 3989 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3990 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3991 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3992 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3993 | goto failed; |
| 3994 | Py_DECREF(value); |
| 3995 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 3996 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3997 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3998 | goto failed; |
| 3999 | Py_DECREF(value); |
| 4000 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4001 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4002 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4003 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4004 | if (!result) goto failed; |
| 4005 | value = ast2obj_expr(o->v.BinOp.left); |
| 4006 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4007 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4008 | goto failed; |
| 4009 | Py_DECREF(value); |
| 4010 | value = ast2obj_operator(o->v.BinOp.op); |
| 4011 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4012 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4013 | goto failed; |
| 4014 | Py_DECREF(value); |
| 4015 | value = ast2obj_expr(o->v.BinOp.right); |
| 4016 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4017 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4018 | goto failed; |
| 4019 | Py_DECREF(value); |
| 4020 | break; |
| 4021 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4022 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4023 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4024 | if (!result) goto failed; |
| 4025 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4026 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4027 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4028 | goto failed; |
| 4029 | Py_DECREF(value); |
| 4030 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4031 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4032 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4033 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4034 | goto failed; |
| 4035 | Py_DECREF(value); |
| 4036 | break; |
| 4037 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4038 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4039 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4040 | if (!result) goto failed; |
| 4041 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4042 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4043 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | goto failed; |
| 4045 | Py_DECREF(value); |
| 4046 | value = ast2obj_expr(o->v.Lambda.body); |
| 4047 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4048 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4049 | goto failed; |
| 4050 | Py_DECREF(value); |
| 4051 | break; |
| 4052 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4053 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4054 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4055 | if (!result) goto failed; |
| 4056 | value = ast2obj_expr(o->v.IfExp.test); |
| 4057 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4058 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4059 | goto failed; |
| 4060 | Py_DECREF(value); |
| 4061 | value = ast2obj_expr(o->v.IfExp.body); |
| 4062 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4063 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4064 | goto failed; |
| 4065 | Py_DECREF(value); |
| 4066 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4067 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4068 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4069 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4070 | goto failed; |
| 4071 | Py_DECREF(value); |
| 4072 | break; |
| 4073 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4074 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4075 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4076 | if (!result) goto failed; |
| 4077 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4078 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4079 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4080 | goto failed; |
| 4081 | Py_DECREF(value); |
| 4082 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4083 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4084 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4085 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4086 | goto failed; |
| 4087 | Py_DECREF(value); |
| 4088 | break; |
| 4089 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4090 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4091 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4092 | if (!result) goto failed; |
| 4093 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4094 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4095 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4096 | goto failed; |
| 4097 | Py_DECREF(value); |
| 4098 | break; |
| 4099 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4100 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4101 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4102 | if (!result) goto failed; |
| 4103 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4104 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4105 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4106 | goto failed; |
| 4107 | Py_DECREF(value); |
| 4108 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4109 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4110 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4111 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4112 | goto failed; |
| 4113 | Py_DECREF(value); |
| 4114 | break; |
| 4115 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4116 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4117 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4118 | if (!result) goto failed; |
| 4119 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4120 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4121 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4122 | goto failed; |
| 4123 | Py_DECREF(value); |
| 4124 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4125 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4126 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4127 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4128 | goto failed; |
| 4129 | Py_DECREF(value); |
| 4130 | break; |
| 4131 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4132 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4133 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4134 | if (!result) goto failed; |
| 4135 | value = ast2obj_expr(o->v.DictComp.key); |
| 4136 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4137 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4138 | goto failed; |
| 4139 | Py_DECREF(value); |
| 4140 | value = ast2obj_expr(o->v.DictComp.value); |
| 4141 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4142 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4143 | goto failed; |
| 4144 | Py_DECREF(value); |
| 4145 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4146 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4147 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4148 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4149 | goto failed; |
| 4150 | Py_DECREF(value); |
| 4151 | break; |
| 4152 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4153 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4154 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4155 | if (!result) goto failed; |
| 4156 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4157 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4158 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4159 | goto failed; |
| 4160 | Py_DECREF(value); |
| 4161 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4162 | ast2obj_comprehension); |
| 4163 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4164 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4165 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4166 | goto failed; |
| 4167 | Py_DECREF(value); |
| 4168 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4169 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4170 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4171 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4172 | if (!result) goto failed; |
| 4173 | value = ast2obj_expr(o->v.Await.value); |
| 4174 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4175 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4176 | goto failed; |
| 4177 | Py_DECREF(value); |
| 4178 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4179 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4180 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4181 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4182 | if (!result) goto failed; |
| 4183 | value = ast2obj_expr(o->v.Yield.value); |
| 4184 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4185 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4186 | goto failed; |
| 4187 | Py_DECREF(value); |
| 4188 | break; |
| 4189 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4190 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4191 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4192 | if (!result) goto failed; |
| 4193 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4194 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4195 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4196 | goto failed; |
| 4197 | Py_DECREF(value); |
| 4198 | break; |
| 4199 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4200 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4201 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4202 | if (!result) goto failed; |
| 4203 | value = ast2obj_expr(o->v.Compare.left); |
| 4204 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4205 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4206 | goto failed; |
| 4207 | Py_DECREF(value); |
| 4208 | { |
| 4209 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4210 | value = PyList_New(n); |
| 4211 | if (!value) goto failed; |
| 4212 | for(i = 0; i < n; i++) |
| 4213 | 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] | 4214 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4215 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4216 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4217 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4218 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4219 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4220 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4221 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4222 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4223 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4224 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4225 | break; |
| 4226 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4227 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4228 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4229 | if (!result) goto failed; |
| 4230 | value = ast2obj_expr(o->v.Call.func); |
| 4231 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4232 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4233 | goto failed; |
| 4234 | Py_DECREF(value); |
| 4235 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4236 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4237 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4238 | goto failed; |
| 4239 | Py_DECREF(value); |
| 4240 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4241 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4242 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4243 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4244 | goto failed; |
| 4245 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4246 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4247 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4248 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4249 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4250 | if (!result) goto failed; |
| 4251 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4252 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4253 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4254 | goto failed; |
| 4255 | Py_DECREF(value); |
| 4256 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4257 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4258 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4259 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4260 | goto failed; |
| 4261 | Py_DECREF(value); |
| 4262 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4263 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4264 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4265 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4266 | goto failed; |
| 4267 | Py_DECREF(value); |
| 4268 | break; |
| 4269 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4270 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4271 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4272 | if (!result) goto failed; |
| 4273 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4274 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4275 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4276 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4277 | goto failed; |
| 4278 | Py_DECREF(value); |
| 4279 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4280 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4281 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4282 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4283 | if (!result) goto failed; |
| 4284 | value = ast2obj_constant(o->v.Constant.value); |
| 4285 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4286 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4287 | goto failed; |
| 4288 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4289 | value = ast2obj_string(o->v.Constant.kind); |
| 4290 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4291 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4292 | goto failed; |
| 4293 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4294 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4295 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4296 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4297 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4298 | if (!result) goto failed; |
| 4299 | value = ast2obj_expr(o->v.Attribute.value); |
| 4300 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4301 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4302 | goto failed; |
| 4303 | Py_DECREF(value); |
| 4304 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4305 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4306 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4307 | goto failed; |
| 4308 | Py_DECREF(value); |
| 4309 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4310 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4311 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4312 | goto failed; |
| 4313 | Py_DECREF(value); |
| 4314 | break; |
| 4315 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4316 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4317 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4318 | if (!result) goto failed; |
| 4319 | value = ast2obj_expr(o->v.Subscript.value); |
| 4320 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4321 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4322 | goto failed; |
| 4323 | Py_DECREF(value); |
| 4324 | value = ast2obj_slice(o->v.Subscript.slice); |
| 4325 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4326 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4327 | goto failed; |
| 4328 | Py_DECREF(value); |
| 4329 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4330 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4331 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4332 | goto failed; |
| 4333 | Py_DECREF(value); |
| 4334 | break; |
| 4335 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4336 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4337 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4338 | if (!result) goto failed; |
| 4339 | value = ast2obj_expr(o->v.Starred.value); |
| 4340 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4341 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4342 | goto failed; |
| 4343 | Py_DECREF(value); |
| 4344 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4345 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4346 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4347 | goto failed; |
| 4348 | Py_DECREF(value); |
| 4349 | break; |
| 4350 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4351 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4352 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4353 | if (!result) goto failed; |
| 4354 | value = ast2obj_identifier(o->v.Name.id); |
| 4355 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4356 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4357 | goto failed; |
| 4358 | Py_DECREF(value); |
| 4359 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4360 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4361 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4362 | goto failed; |
| 4363 | Py_DECREF(value); |
| 4364 | break; |
| 4365 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4366 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4367 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4368 | if (!result) goto failed; |
| 4369 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4370 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4371 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4372 | goto failed; |
| 4373 | Py_DECREF(value); |
| 4374 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4375 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4376 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4377 | goto failed; |
| 4378 | Py_DECREF(value); |
| 4379 | break; |
| 4380 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4381 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4382 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4383 | if (!result) goto failed; |
| 4384 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4385 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4386 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4387 | goto failed; |
| 4388 | Py_DECREF(value); |
| 4389 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4390 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4391 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4392 | goto failed; |
| 4393 | Py_DECREF(value); |
| 4394 | break; |
| 4395 | } |
| 4396 | value = ast2obj_int(o->lineno); |
| 4397 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4398 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4399 | goto failed; |
| 4400 | Py_DECREF(value); |
| 4401 | value = ast2obj_int(o->col_offset); |
| 4402 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4403 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4404 | goto failed; |
| 4405 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4406 | value = ast2obj_int(o->end_lineno); |
| 4407 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4408 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4409 | goto failed; |
| 4410 | Py_DECREF(value); |
| 4411 | value = ast2obj_int(o->end_col_offset); |
| 4412 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4413 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4414 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4415 | goto failed; |
| 4416 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4417 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4418 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4419 | Py_XDECREF(value); |
| 4420 | Py_XDECREF(result); |
| 4421 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4422 | } |
| 4423 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4424 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4425 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4426 | switch(o) { |
| 4427 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4428 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4429 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4430 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4431 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4432 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4433 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4434 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4435 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4436 | case AugLoad: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4437 | Py_INCREF(astmodulestate_global->AugLoad_singleton); |
| 4438 | return astmodulestate_global->AugLoad_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4439 | case AugStore: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4440 | Py_INCREF(astmodulestate_global->AugStore_singleton); |
| 4441 | return astmodulestate_global->AugStore_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4442 | case Param: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4443 | Py_INCREF(astmodulestate_global->Param_singleton); |
| 4444 | return astmodulestate_global->Param_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4445 | default: |
| 4446 | /* should never happen, but just in case ... */ |
| 4447 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 4448 | return NULL; |
| 4449 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4450 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4451 | PyObject* |
| 4452 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4453 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4454 | slice_ty o = (slice_ty)_o; |
| 4455 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4456 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4457 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4458 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4459 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4460 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4461 | switch (o->kind) { |
| 4462 | case Slice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4463 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4464 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | if (!result) goto failed; |
| 4466 | value = ast2obj_expr(o->v.Slice.lower); |
| 4467 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4468 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4469 | goto failed; |
| 4470 | Py_DECREF(value); |
| 4471 | value = ast2obj_expr(o->v.Slice.upper); |
| 4472 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4473 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4474 | goto failed; |
| 4475 | Py_DECREF(value); |
| 4476 | value = ast2obj_expr(o->v.Slice.step); |
| 4477 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4478 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4479 | goto failed; |
| 4480 | Py_DECREF(value); |
| 4481 | break; |
| 4482 | case ExtSlice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4483 | tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type; |
| 4484 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4485 | if (!result) goto failed; |
| 4486 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 4487 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4488 | if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4489 | goto failed; |
| 4490 | Py_DECREF(value); |
| 4491 | break; |
| 4492 | case Index_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4493 | tp = (PyTypeObject *)astmodulestate_global->Index_type; |
| 4494 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4495 | if (!result) goto failed; |
| 4496 | value = ast2obj_expr(o->v.Index.value); |
| 4497 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4498 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4499 | goto failed; |
| 4500 | Py_DECREF(value); |
| 4501 | break; |
| 4502 | } |
| 4503 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4504 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4505 | Py_XDECREF(value); |
| 4506 | Py_XDECREF(result); |
| 4507 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4510 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4511 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4512 | switch(o) { |
| 4513 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4514 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4515 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4516 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4517 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4518 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4519 | default: |
| 4520 | /* should never happen, but just in case ... */ |
| 4521 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 4522 | return NULL; |
| 4523 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4524 | } |
| 4525 | PyObject* ast2obj_operator(operator_ty o) |
| 4526 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4527 | switch(o) { |
| 4528 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4529 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4530 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4531 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4532 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4533 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4534 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4535 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4536 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4537 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4538 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4539 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4540 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4541 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4542 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4543 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4544 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4545 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4546 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4547 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4548 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4549 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4550 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4551 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4552 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4553 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4554 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4555 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4556 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4557 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4558 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4559 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4560 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4561 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4562 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4563 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4564 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4565 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4566 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4567 | default: |
| 4568 | /* should never happen, but just in case ... */ |
| 4569 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 4570 | return NULL; |
| 4571 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4572 | } |
| 4573 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4574 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4575 | switch(o) { |
| 4576 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4577 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4578 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4579 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4580 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4581 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4582 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4583 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4584 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4585 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4586 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4587 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4588 | default: |
| 4589 | /* should never happen, but just in case ... */ |
| 4590 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 4591 | return NULL; |
| 4592 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4593 | } |
| 4594 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4595 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4596 | switch(o) { |
| 4597 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4598 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4599 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4600 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4601 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4602 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4603 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4604 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4605 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4606 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4607 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4608 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4609 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4610 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4611 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4612 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4613 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4614 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4615 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4616 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4617 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4618 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4619 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4620 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4621 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4622 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4623 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4624 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4625 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4626 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4627 | default: |
| 4628 | /* should never happen, but just in case ... */ |
| 4629 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 4630 | return NULL; |
| 4631 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4632 | } |
| 4633 | PyObject* |
| 4634 | ast2obj_comprehension(void* _o) |
| 4635 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4636 | comprehension_ty o = (comprehension_ty)_o; |
| 4637 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4638 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4639 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4640 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4641 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4642 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4643 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4644 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4645 | if (!result) return NULL; |
| 4646 | value = ast2obj_expr(o->target); |
| 4647 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4648 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4649 | goto failed; |
| 4650 | Py_DECREF(value); |
| 4651 | value = ast2obj_expr(o->iter); |
| 4652 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4653 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4654 | goto failed; |
| 4655 | Py_DECREF(value); |
| 4656 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4657 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4658 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4659 | goto failed; |
| 4660 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4661 | value = ast2obj_int(o->is_async); |
| 4662 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4663 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4664 | goto failed; |
| 4665 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4666 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4667 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4668 | Py_XDECREF(value); |
| 4669 | Py_XDECREF(result); |
| 4670 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4671 | } |
| 4672 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4673 | PyObject* |
| 4674 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4675 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4676 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4677 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4678 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4679 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4680 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4681 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4682 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4683 | switch (o->kind) { |
| 4684 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4685 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4686 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4687 | if (!result) goto failed; |
| 4688 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4689 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4690 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4691 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4692 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4693 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4694 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4695 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4696 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4697 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4698 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4699 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4700 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4701 | goto failed; |
| 4702 | Py_DECREF(value); |
| 4703 | break; |
| 4704 | } |
| 4705 | value = ast2obj_int(o->lineno); |
| 4706 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4707 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4708 | goto failed; |
| 4709 | Py_DECREF(value); |
| 4710 | value = ast2obj_int(o->col_offset); |
| 4711 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4712 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4713 | goto failed; |
| 4714 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4715 | value = ast2obj_int(o->end_lineno); |
| 4716 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4717 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4718 | goto failed; |
| 4719 | Py_DECREF(value); |
| 4720 | value = ast2obj_int(o->end_col_offset); |
| 4721 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4722 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4723 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4724 | goto failed; |
| 4725 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4726 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4727 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4728 | Py_XDECREF(value); |
| 4729 | Py_XDECREF(result); |
| 4730 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4733 | PyObject* |
| 4734 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4735 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4736 | arguments_ty o = (arguments_ty)_o; |
| 4737 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4738 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4739 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4740 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4741 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4742 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4743 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4744 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4745 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4746 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4747 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4748 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4749 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4750 | goto failed; |
| 4751 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4752 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4753 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4754 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4755 | goto failed; |
| 4756 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4757 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4758 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4759 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4760 | goto failed; |
| 4761 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4762 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4763 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4764 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4765 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4766 | goto failed; |
| 4767 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4768 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4769 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4770 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4771 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4772 | goto failed; |
| 4773 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4774 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4775 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4776 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4777 | goto failed; |
| 4778 | Py_DECREF(value); |
| 4779 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4780 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4781 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4782 | goto failed; |
| 4783 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4784 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4785 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4786 | Py_XDECREF(value); |
| 4787 | Py_XDECREF(result); |
| 4788 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4789 | } |
| 4790 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4791 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4792 | ast2obj_arg(void* _o) |
| 4793 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4794 | arg_ty o = (arg_ty)_o; |
| 4795 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4796 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4797 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4798 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4799 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4800 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4801 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4802 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4803 | if (!result) return NULL; |
| 4804 | value = ast2obj_identifier(o->arg); |
| 4805 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4806 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4807 | goto failed; |
| 4808 | Py_DECREF(value); |
| 4809 | value = ast2obj_expr(o->annotation); |
| 4810 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4811 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4812 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4813 | goto failed; |
| 4814 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4815 | value = ast2obj_string(o->type_comment); |
| 4816 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4817 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4818 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4819 | goto failed; |
| 4820 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4821 | value = ast2obj_int(o->lineno); |
| 4822 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4823 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4824 | goto failed; |
| 4825 | Py_DECREF(value); |
| 4826 | value = ast2obj_int(o->col_offset); |
| 4827 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4828 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4829 | goto failed; |
| 4830 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4831 | value = ast2obj_int(o->end_lineno); |
| 4832 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4833 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4834 | goto failed; |
| 4835 | Py_DECREF(value); |
| 4836 | value = ast2obj_int(o->end_col_offset); |
| 4837 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4838 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4839 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4840 | goto failed; |
| 4841 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4842 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4843 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4844 | Py_XDECREF(value); |
| 4845 | Py_XDECREF(result); |
| 4846 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4850 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4851 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4852 | keyword_ty o = (keyword_ty)_o; |
| 4853 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4854 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4855 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4856 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4857 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4858 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4859 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4860 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4861 | if (!result) return NULL; |
| 4862 | value = ast2obj_identifier(o->arg); |
| 4863 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4864 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4865 | goto failed; |
| 4866 | Py_DECREF(value); |
| 4867 | value = ast2obj_expr(o->value); |
| 4868 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4869 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4870 | goto failed; |
| 4871 | Py_DECREF(value); |
| 4872 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4873 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4874 | Py_XDECREF(value); |
| 4875 | Py_XDECREF(result); |
| 4876 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4877 | } |
| 4878 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4879 | PyObject* |
| 4880 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4881 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4882 | alias_ty o = (alias_ty)_o; |
| 4883 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4884 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4885 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4886 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4887 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4888 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4889 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 4890 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4891 | if (!result) return NULL; |
| 4892 | value = ast2obj_identifier(o->name); |
| 4893 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4894 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4895 | goto failed; |
| 4896 | Py_DECREF(value); |
| 4897 | value = ast2obj_identifier(o->asname); |
| 4898 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4899 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4900 | goto failed; |
| 4901 | Py_DECREF(value); |
| 4902 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4903 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4904 | Py_XDECREF(value); |
| 4905 | Py_XDECREF(result); |
| 4906 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4907 | } |
| 4908 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4909 | PyObject* |
| 4910 | ast2obj_withitem(void* _o) |
| 4911 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4912 | withitem_ty o = (withitem_ty)_o; |
| 4913 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4914 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4915 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4916 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4917 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4918 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4919 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 4920 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4921 | if (!result) return NULL; |
| 4922 | value = ast2obj_expr(o->context_expr); |
| 4923 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4924 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 4925 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4926 | goto failed; |
| 4927 | Py_DECREF(value); |
| 4928 | value = ast2obj_expr(o->optional_vars); |
| 4929 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4930 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 4931 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4932 | goto failed; |
| 4933 | Py_DECREF(value); |
| 4934 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4935 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4936 | Py_XDECREF(value); |
| 4937 | Py_XDECREF(result); |
| 4938 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4939 | } |
| 4940 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4941 | PyObject* |
| 4942 | ast2obj_type_ignore(void* _o) |
| 4943 | { |
| 4944 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4945 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4946 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4947 | if (!o) { |
| 4948 | Py_RETURN_NONE; |
| 4949 | } |
| 4950 | |
| 4951 | switch (o->kind) { |
| 4952 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4953 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 4954 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4955 | if (!result) goto failed; |
| 4956 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4957 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4958 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 4959 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4960 | goto failed; |
| 4961 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4962 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 4963 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4964 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4965 | goto failed; |
| 4966 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4967 | break; |
| 4968 | } |
| 4969 | return result; |
| 4970 | failed: |
| 4971 | Py_XDECREF(value); |
| 4972 | Py_XDECREF(result); |
| 4973 | return NULL; |
| 4974 | } |
| 4975 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4976 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4977 | int |
| 4978 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4979 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4980 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4981 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4982 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4983 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4984 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4985 | if (obj == Py_None) { |
| 4986 | *out = NULL; |
| 4987 | return 0; |
| 4988 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4989 | tp = astmodulestate_global->Module_type; |
| 4990 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4991 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4992 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4993 | } |
| 4994 | if (isinstance) { |
| 4995 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4996 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4997 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4998 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4999 | return 1; |
| 5000 | } |
| 5001 | if (tmp == NULL) { |
| 5002 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 5003 | return 1; |
| 5004 | } |
| 5005 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5006 | int res; |
| 5007 | Py_ssize_t len; |
| 5008 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5009 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5010 | 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] | 5011 | goto failed; |
| 5012 | } |
| 5013 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5014 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5015 | if (body == NULL) goto failed; |
| 5016 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5017 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5018 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5019 | Py_INCREF(tmp2); |
| 5020 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5021 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5022 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5023 | if (len != PyList_GET_SIZE(tmp)) { |
| 5024 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5025 | goto failed; |
| 5026 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5027 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5028 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5029 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5030 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5031 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5032 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5033 | return 1; |
| 5034 | } |
| 5035 | if (tmp == NULL) { |
| 5036 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5037 | return 1; |
| 5038 | } |
| 5039 | else { |
| 5040 | int res; |
| 5041 | Py_ssize_t len; |
| 5042 | Py_ssize_t i; |
| 5043 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5044 | 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] | 5045 | goto failed; |
| 5046 | } |
| 5047 | len = PyList_GET_SIZE(tmp); |
| 5048 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5049 | if (type_ignores == NULL) goto failed; |
| 5050 | for (i = 0; i < len; i++) { |
| 5051 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5052 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5053 | Py_INCREF(tmp2); |
| 5054 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5055 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5056 | if (res != 0) goto failed; |
| 5057 | if (len != PyList_GET_SIZE(tmp)) { |
| 5058 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5059 | goto failed; |
| 5060 | } |
| 5061 | asdl_seq_SET(type_ignores, i, val); |
| 5062 | } |
| 5063 | Py_CLEAR(tmp); |
| 5064 | } |
| 5065 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5066 | if (*out == NULL) goto failed; |
| 5067 | return 0; |
| 5068 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5069 | tp = astmodulestate_global->Interactive_type; |
| 5070 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5071 | if (isinstance == -1) { |
| 5072 | return 1; |
| 5073 | } |
| 5074 | if (isinstance) { |
| 5075 | asdl_seq* body; |
| 5076 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5077 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5078 | return 1; |
| 5079 | } |
| 5080 | if (tmp == NULL) { |
| 5081 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5082 | return 1; |
| 5083 | } |
| 5084 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5085 | int res; |
| 5086 | Py_ssize_t len; |
| 5087 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5088 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5089 | 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] | 5090 | goto failed; |
| 5091 | } |
| 5092 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5093 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5094 | if (body == NULL) goto failed; |
| 5095 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5096 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5097 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5098 | Py_INCREF(tmp2); |
| 5099 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5100 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5101 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5102 | if (len != PyList_GET_SIZE(tmp)) { |
| 5103 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5104 | goto failed; |
| 5105 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5106 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5107 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5108 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5109 | } |
| 5110 | *out = Interactive(body, arena); |
| 5111 | if (*out == NULL) goto failed; |
| 5112 | return 0; |
| 5113 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5114 | tp = astmodulestate_global->Expression_type; |
| 5115 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5116 | if (isinstance == -1) { |
| 5117 | return 1; |
| 5118 | } |
| 5119 | if (isinstance) { |
| 5120 | expr_ty body; |
| 5121 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5122 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5123 | return 1; |
| 5124 | } |
| 5125 | if (tmp == NULL) { |
| 5126 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5127 | return 1; |
| 5128 | } |
| 5129 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5130 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5131 | res = obj2ast_expr(tmp, &body, arena); |
| 5132 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5133 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5134 | } |
| 5135 | *out = Expression(body, arena); |
| 5136 | if (*out == NULL) goto failed; |
| 5137 | return 0; |
| 5138 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5139 | tp = astmodulestate_global->FunctionType_type; |
| 5140 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5141 | if (isinstance == -1) { |
| 5142 | return 1; |
| 5143 | } |
| 5144 | if (isinstance) { |
| 5145 | asdl_seq* argtypes; |
| 5146 | expr_ty returns; |
| 5147 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5148 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5149 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5150 | return 1; |
| 5151 | } |
| 5152 | if (tmp == NULL) { |
| 5153 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5154 | return 1; |
| 5155 | } |
| 5156 | else { |
| 5157 | int res; |
| 5158 | Py_ssize_t len; |
| 5159 | Py_ssize_t i; |
| 5160 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5161 | 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] | 5162 | goto failed; |
| 5163 | } |
| 5164 | len = PyList_GET_SIZE(tmp); |
| 5165 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5166 | if (argtypes == NULL) goto failed; |
| 5167 | for (i = 0; i < len; i++) { |
| 5168 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5169 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5170 | Py_INCREF(tmp2); |
| 5171 | res = obj2ast_expr(tmp2, &val, arena); |
| 5172 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5173 | if (res != 0) goto failed; |
| 5174 | if (len != PyList_GET_SIZE(tmp)) { |
| 5175 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5176 | goto failed; |
| 5177 | } |
| 5178 | asdl_seq_SET(argtypes, i, val); |
| 5179 | } |
| 5180 | Py_CLEAR(tmp); |
| 5181 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5182 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5183 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5184 | return 1; |
| 5185 | } |
| 5186 | if (tmp == NULL) { |
| 5187 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5188 | return 1; |
| 5189 | } |
| 5190 | else { |
| 5191 | int res; |
| 5192 | res = obj2ast_expr(tmp, &returns, arena); |
| 5193 | if (res != 0) goto failed; |
| 5194 | Py_CLEAR(tmp); |
| 5195 | } |
| 5196 | *out = FunctionType(argtypes, returns, arena); |
| 5197 | if (*out == NULL) goto failed; |
| 5198 | return 0; |
| 5199 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5200 | tp = astmodulestate_global->Suite_type; |
| 5201 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5202 | if (isinstance == -1) { |
| 5203 | return 1; |
| 5204 | } |
| 5205 | if (isinstance) { |
| 5206 | asdl_seq* body; |
| 5207 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5208 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5209 | return 1; |
| 5210 | } |
| 5211 | if (tmp == NULL) { |
| 5212 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 5213 | return 1; |
| 5214 | } |
| 5215 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5216 | int res; |
| 5217 | Py_ssize_t len; |
| 5218 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5219 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5220 | 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] | 5221 | goto failed; |
| 5222 | } |
| 5223 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5224 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5225 | if (body == NULL) goto failed; |
| 5226 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5227 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5228 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5229 | Py_INCREF(tmp2); |
| 5230 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5231 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5232 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5233 | if (len != PyList_GET_SIZE(tmp)) { |
| 5234 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 5235 | goto failed; |
| 5236 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5237 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5238 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5239 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5240 | } |
| 5241 | *out = Suite(body, arena); |
| 5242 | if (*out == NULL) goto failed; |
| 5243 | return 0; |
| 5244 | } |
| 5245 | |
| 5246 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5247 | failed: |
| 5248 | Py_XDECREF(tmp); |
| 5249 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | int |
| 5253 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5254 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5255 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5256 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5257 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5258 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5259 | int lineno; |
| 5260 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5261 | int end_lineno; |
| 5262 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5263 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5264 | if (obj == Py_None) { |
| 5265 | *out = NULL; |
| 5266 | return 0; |
| 5267 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5268 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5269 | return 1; |
| 5270 | } |
| 5271 | if (tmp == NULL) { |
| 5272 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5273 | return 1; |
| 5274 | } |
| 5275 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5276 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5277 | res = obj2ast_int(tmp, &lineno, arena); |
| 5278 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5279 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5280 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5281 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5282 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5283 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5284 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5285 | if (tmp == NULL) { |
| 5286 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5287 | return 1; |
| 5288 | } |
| 5289 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5290 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5291 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5292 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5293 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5294 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5295 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5296 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5297 | return 1; |
| 5298 | } |
| 5299 | if (tmp == NULL || tmp == Py_None) { |
| 5300 | Py_CLEAR(tmp); |
| 5301 | end_lineno = 0; |
| 5302 | } |
| 5303 | else { |
| 5304 | int res; |
| 5305 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5306 | if (res != 0) goto failed; |
| 5307 | Py_CLEAR(tmp); |
| 5308 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5309 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5310 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5311 | return 1; |
| 5312 | } |
| 5313 | if (tmp == NULL || tmp == Py_None) { |
| 5314 | Py_CLEAR(tmp); |
| 5315 | end_col_offset = 0; |
| 5316 | } |
| 5317 | else { |
| 5318 | int res; |
| 5319 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5320 | if (res != 0) goto failed; |
| 5321 | Py_CLEAR(tmp); |
| 5322 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5323 | tp = astmodulestate_global->FunctionDef_type; |
| 5324 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5325 | if (isinstance == -1) { |
| 5326 | return 1; |
| 5327 | } |
| 5328 | if (isinstance) { |
| 5329 | identifier name; |
| 5330 | arguments_ty args; |
| 5331 | asdl_seq* body; |
| 5332 | asdl_seq* decorator_list; |
| 5333 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5334 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5335 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5336 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5337 | return 1; |
| 5338 | } |
| 5339 | if (tmp == NULL) { |
| 5340 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5341 | return 1; |
| 5342 | } |
| 5343 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5344 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5345 | res = obj2ast_identifier(tmp, &name, arena); |
| 5346 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5347 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5348 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5349 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5350 | return 1; |
| 5351 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5352 | if (tmp == NULL) { |
| 5353 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5354 | return 1; |
| 5355 | } |
| 5356 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5357 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5358 | res = obj2ast_arguments(tmp, &args, arena); |
| 5359 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5360 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5361 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5362 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5363 | return 1; |
| 5364 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5365 | if (tmp == NULL) { |
| 5366 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5367 | return 1; |
| 5368 | } |
| 5369 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5370 | int res; |
| 5371 | Py_ssize_t len; |
| 5372 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5373 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5374 | 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] | 5375 | goto failed; |
| 5376 | } |
| 5377 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5378 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5379 | if (body == NULL) goto failed; |
| 5380 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5381 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5382 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5383 | Py_INCREF(tmp2); |
| 5384 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5385 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5386 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5387 | if (len != PyList_GET_SIZE(tmp)) { |
| 5388 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5389 | goto failed; |
| 5390 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5391 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5392 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5393 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5394 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5395 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5396 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5397 | return 1; |
| 5398 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5399 | if (tmp == NULL) { |
| 5400 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5401 | return 1; |
| 5402 | } |
| 5403 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5404 | int res; |
| 5405 | Py_ssize_t len; |
| 5406 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5407 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5408 | 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] | 5409 | goto failed; |
| 5410 | } |
| 5411 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5412 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5413 | if (decorator_list == NULL) goto failed; |
| 5414 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5415 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5416 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5417 | Py_INCREF(tmp2); |
| 5418 | res = obj2ast_expr(tmp2, &val, arena); |
| 5419 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5420 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5421 | if (len != PyList_GET_SIZE(tmp)) { |
| 5422 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5423 | goto failed; |
| 5424 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5425 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5426 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5427 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5428 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5429 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5430 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5431 | return 1; |
| 5432 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5433 | if (tmp == NULL || tmp == Py_None) { |
| 5434 | Py_CLEAR(tmp); |
| 5435 | returns = NULL; |
| 5436 | } |
| 5437 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5438 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5439 | res = obj2ast_expr(tmp, &returns, arena); |
| 5440 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5441 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5442 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5443 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5444 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5445 | return 1; |
| 5446 | } |
| 5447 | if (tmp == NULL || tmp == Py_None) { |
| 5448 | Py_CLEAR(tmp); |
| 5449 | type_comment = NULL; |
| 5450 | } |
| 5451 | else { |
| 5452 | int res; |
| 5453 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5454 | if (res != 0) goto failed; |
| 5455 | Py_CLEAR(tmp); |
| 5456 | } |
| 5457 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5458 | type_comment, lineno, col_offset, end_lineno, |
| 5459 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5460 | if (*out == NULL) goto failed; |
| 5461 | return 0; |
| 5462 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5463 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5464 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5465 | if (isinstance == -1) { |
| 5466 | return 1; |
| 5467 | } |
| 5468 | if (isinstance) { |
| 5469 | identifier name; |
| 5470 | arguments_ty args; |
| 5471 | asdl_seq* body; |
| 5472 | asdl_seq* decorator_list; |
| 5473 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5474 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5475 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5476 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5477 | return 1; |
| 5478 | } |
| 5479 | if (tmp == NULL) { |
| 5480 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5481 | return 1; |
| 5482 | } |
| 5483 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5484 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5485 | res = obj2ast_identifier(tmp, &name, arena); |
| 5486 | if (res != 0) goto failed; |
| 5487 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5488 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5489 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5490 | return 1; |
| 5491 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5492 | if (tmp == NULL) { |
| 5493 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5494 | return 1; |
| 5495 | } |
| 5496 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5497 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5498 | res = obj2ast_arguments(tmp, &args, arena); |
| 5499 | if (res != 0) goto failed; |
| 5500 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5501 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5502 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5503 | return 1; |
| 5504 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5505 | if (tmp == NULL) { |
| 5506 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5507 | return 1; |
| 5508 | } |
| 5509 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5510 | int res; |
| 5511 | Py_ssize_t len; |
| 5512 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5513 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5514 | 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] | 5515 | goto failed; |
| 5516 | } |
| 5517 | len = PyList_GET_SIZE(tmp); |
| 5518 | body = _Py_asdl_seq_new(len, arena); |
| 5519 | if (body == NULL) goto failed; |
| 5520 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5521 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5522 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5523 | Py_INCREF(tmp2); |
| 5524 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5525 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5526 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5527 | if (len != PyList_GET_SIZE(tmp)) { |
| 5528 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5529 | goto failed; |
| 5530 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5531 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5532 | } |
| 5533 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5534 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5535 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5536 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5537 | return 1; |
| 5538 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5539 | if (tmp == NULL) { |
| 5540 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5541 | return 1; |
| 5542 | } |
| 5543 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5544 | int res; |
| 5545 | Py_ssize_t len; |
| 5546 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5547 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5548 | 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] | 5549 | goto failed; |
| 5550 | } |
| 5551 | len = PyList_GET_SIZE(tmp); |
| 5552 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5553 | if (decorator_list == NULL) goto failed; |
| 5554 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5555 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5556 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5557 | Py_INCREF(tmp2); |
| 5558 | res = obj2ast_expr(tmp2, &val, arena); |
| 5559 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5560 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5561 | if (len != PyList_GET_SIZE(tmp)) { |
| 5562 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5563 | goto failed; |
| 5564 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5565 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5566 | } |
| 5567 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5568 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5569 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5570 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5571 | return 1; |
| 5572 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5573 | if (tmp == NULL || tmp == Py_None) { |
| 5574 | Py_CLEAR(tmp); |
| 5575 | returns = NULL; |
| 5576 | } |
| 5577 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5578 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5579 | res = obj2ast_expr(tmp, &returns, arena); |
| 5580 | if (res != 0) goto failed; |
| 5581 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5582 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5583 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5584 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5585 | return 1; |
| 5586 | } |
| 5587 | if (tmp == NULL || tmp == Py_None) { |
| 5588 | Py_CLEAR(tmp); |
| 5589 | type_comment = NULL; |
| 5590 | } |
| 5591 | else { |
| 5592 | int res; |
| 5593 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5594 | if (res != 0) goto failed; |
| 5595 | Py_CLEAR(tmp); |
| 5596 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5597 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5598 | type_comment, lineno, col_offset, end_lineno, |
| 5599 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5600 | if (*out == NULL) goto failed; |
| 5601 | return 0; |
| 5602 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5603 | tp = astmodulestate_global->ClassDef_type; |
| 5604 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5605 | if (isinstance == -1) { |
| 5606 | return 1; |
| 5607 | } |
| 5608 | if (isinstance) { |
| 5609 | identifier name; |
| 5610 | asdl_seq* bases; |
| 5611 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5612 | asdl_seq* body; |
| 5613 | asdl_seq* decorator_list; |
| 5614 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5615 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5616 | return 1; |
| 5617 | } |
| 5618 | if (tmp == NULL) { |
| 5619 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5620 | return 1; |
| 5621 | } |
| 5622 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5623 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5624 | res = obj2ast_identifier(tmp, &name, arena); |
| 5625 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5626 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5627 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5628 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5629 | return 1; |
| 5630 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5631 | if (tmp == NULL) { |
| 5632 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5633 | return 1; |
| 5634 | } |
| 5635 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5636 | int res; |
| 5637 | Py_ssize_t len; |
| 5638 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5639 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5640 | 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] | 5641 | goto failed; |
| 5642 | } |
| 5643 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5644 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5645 | if (bases == NULL) goto failed; |
| 5646 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5647 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5648 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5649 | Py_INCREF(tmp2); |
| 5650 | res = obj2ast_expr(tmp2, &val, arena); |
| 5651 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5652 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5653 | if (len != PyList_GET_SIZE(tmp)) { |
| 5654 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5655 | goto failed; |
| 5656 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5657 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5658 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5659 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5660 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5661 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5662 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5663 | return 1; |
| 5664 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5665 | if (tmp == NULL) { |
| 5666 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5667 | return 1; |
| 5668 | } |
| 5669 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5670 | int res; |
| 5671 | Py_ssize_t len; |
| 5672 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5673 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5674 | 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] | 5675 | goto failed; |
| 5676 | } |
| 5677 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5678 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5679 | if (keywords == NULL) goto failed; |
| 5680 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5681 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5682 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5683 | Py_INCREF(tmp2); |
| 5684 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5685 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5686 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5687 | if (len != PyList_GET_SIZE(tmp)) { |
| 5688 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5689 | goto failed; |
| 5690 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5691 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5692 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5693 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5694 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5695 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5696 | return 1; |
| 5697 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5698 | if (tmp == NULL) { |
| 5699 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5700 | return 1; |
| 5701 | } |
| 5702 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5703 | int res; |
| 5704 | Py_ssize_t len; |
| 5705 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5706 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5707 | 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] | 5708 | goto failed; |
| 5709 | } |
| 5710 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5711 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5712 | if (body == NULL) goto failed; |
| 5713 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5714 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5715 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5716 | Py_INCREF(tmp2); |
| 5717 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5718 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5719 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5720 | if (len != PyList_GET_SIZE(tmp)) { |
| 5721 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5722 | goto failed; |
| 5723 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5724 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5725 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5726 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5727 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5728 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5729 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5730 | return 1; |
| 5731 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5732 | if (tmp == NULL) { |
| 5733 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5734 | return 1; |
| 5735 | } |
| 5736 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5737 | int res; |
| 5738 | Py_ssize_t len; |
| 5739 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5740 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5741 | 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] | 5742 | goto failed; |
| 5743 | } |
| 5744 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5745 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5746 | if (decorator_list == NULL) goto failed; |
| 5747 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5748 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5749 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5750 | Py_INCREF(tmp2); |
| 5751 | res = obj2ast_expr(tmp2, &val, arena); |
| 5752 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5753 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5754 | if (len != PyList_GET_SIZE(tmp)) { |
| 5755 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5756 | goto failed; |
| 5757 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5758 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5759 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5760 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5761 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5762 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5763 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5764 | if (*out == NULL) goto failed; |
| 5765 | return 0; |
| 5766 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5767 | tp = astmodulestate_global->Return_type; |
| 5768 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5769 | if (isinstance == -1) { |
| 5770 | return 1; |
| 5771 | } |
| 5772 | if (isinstance) { |
| 5773 | expr_ty value; |
| 5774 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5775 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5776 | return 1; |
| 5777 | } |
| 5778 | if (tmp == NULL || tmp == Py_None) { |
| 5779 | Py_CLEAR(tmp); |
| 5780 | value = NULL; |
| 5781 | } |
| 5782 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5783 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5784 | res = obj2ast_expr(tmp, &value, arena); |
| 5785 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5786 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5787 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5788 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5789 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5790 | if (*out == NULL) goto failed; |
| 5791 | return 0; |
| 5792 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5793 | tp = astmodulestate_global->Delete_type; |
| 5794 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5795 | if (isinstance == -1) { |
| 5796 | return 1; |
| 5797 | } |
| 5798 | if (isinstance) { |
| 5799 | asdl_seq* targets; |
| 5800 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5801 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5802 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5803 | return 1; |
| 5804 | } |
| 5805 | if (tmp == NULL) { |
| 5806 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5807 | return 1; |
| 5808 | } |
| 5809 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5810 | int res; |
| 5811 | Py_ssize_t len; |
| 5812 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5813 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5814 | 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] | 5815 | goto failed; |
| 5816 | } |
| 5817 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5818 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5819 | if (targets == NULL) goto failed; |
| 5820 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5821 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5822 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5823 | Py_INCREF(tmp2); |
| 5824 | res = obj2ast_expr(tmp2, &val, arena); |
| 5825 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5826 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5827 | if (len != PyList_GET_SIZE(tmp)) { |
| 5828 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5829 | goto failed; |
| 5830 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5831 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5832 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5833 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5834 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5835 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5836 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5837 | if (*out == NULL) goto failed; |
| 5838 | return 0; |
| 5839 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5840 | tp = astmodulestate_global->Assign_type; |
| 5841 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5842 | if (isinstance == -1) { |
| 5843 | return 1; |
| 5844 | } |
| 5845 | if (isinstance) { |
| 5846 | asdl_seq* targets; |
| 5847 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5848 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5849 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5850 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5851 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5852 | return 1; |
| 5853 | } |
| 5854 | if (tmp == NULL) { |
| 5855 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5856 | return 1; |
| 5857 | } |
| 5858 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5859 | int res; |
| 5860 | Py_ssize_t len; |
| 5861 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5862 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5863 | 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] | 5864 | goto failed; |
| 5865 | } |
| 5866 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5867 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5868 | if (targets == NULL) goto failed; |
| 5869 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5870 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5871 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5872 | Py_INCREF(tmp2); |
| 5873 | res = obj2ast_expr(tmp2, &val, arena); |
| 5874 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5875 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5876 | if (len != PyList_GET_SIZE(tmp)) { |
| 5877 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5878 | goto failed; |
| 5879 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5880 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5881 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5882 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5883 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5884 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5885 | return 1; |
| 5886 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5887 | if (tmp == NULL) { |
| 5888 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5889 | return 1; |
| 5890 | } |
| 5891 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5892 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5893 | res = obj2ast_expr(tmp, &value, arena); |
| 5894 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5895 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5896 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5897 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5898 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5899 | return 1; |
| 5900 | } |
| 5901 | if (tmp == NULL || tmp == Py_None) { |
| 5902 | Py_CLEAR(tmp); |
| 5903 | type_comment = NULL; |
| 5904 | } |
| 5905 | else { |
| 5906 | int res; |
| 5907 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5908 | if (res != 0) goto failed; |
| 5909 | Py_CLEAR(tmp); |
| 5910 | } |
| 5911 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5912 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5913 | if (*out == NULL) goto failed; |
| 5914 | return 0; |
| 5915 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5916 | tp = astmodulestate_global->AugAssign_type; |
| 5917 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5918 | if (isinstance == -1) { |
| 5919 | return 1; |
| 5920 | } |
| 5921 | if (isinstance) { |
| 5922 | expr_ty target; |
| 5923 | operator_ty op; |
| 5924 | expr_ty value; |
| 5925 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5926 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5927 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5928 | return 1; |
| 5929 | } |
| 5930 | if (tmp == NULL) { |
| 5931 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5932 | return 1; |
| 5933 | } |
| 5934 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5935 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5936 | res = obj2ast_expr(tmp, &target, arena); |
| 5937 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5938 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5939 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5940 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5941 | return 1; |
| 5942 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5943 | if (tmp == NULL) { |
| 5944 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5945 | return 1; |
| 5946 | } |
| 5947 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5948 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5949 | res = obj2ast_operator(tmp, &op, arena); |
| 5950 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5951 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5952 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5953 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5954 | return 1; |
| 5955 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5956 | if (tmp == NULL) { |
| 5957 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5958 | return 1; |
| 5959 | } |
| 5960 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5961 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5962 | res = obj2ast_expr(tmp, &value, arena); |
| 5963 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5964 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5965 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5966 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5967 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5968 | if (*out == NULL) goto failed; |
| 5969 | return 0; |
| 5970 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5971 | tp = astmodulestate_global->AnnAssign_type; |
| 5972 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5973 | if (isinstance == -1) { |
| 5974 | return 1; |
| 5975 | } |
| 5976 | if (isinstance) { |
| 5977 | expr_ty target; |
| 5978 | expr_ty annotation; |
| 5979 | expr_ty value; |
| 5980 | int simple; |
| 5981 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5982 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5983 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5984 | return 1; |
| 5985 | } |
| 5986 | if (tmp == NULL) { |
| 5987 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 5988 | return 1; |
| 5989 | } |
| 5990 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5991 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5992 | res = obj2ast_expr(tmp, &target, arena); |
| 5993 | if (res != 0) goto failed; |
| 5994 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5995 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5996 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 5997 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5998 | return 1; |
| 5999 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6000 | if (tmp == NULL) { |
| 6001 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 6002 | return 1; |
| 6003 | } |
| 6004 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6005 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6006 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6007 | if (res != 0) goto failed; |
| 6008 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6009 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6010 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6011 | return 1; |
| 6012 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6013 | if (tmp == NULL || tmp == Py_None) { |
| 6014 | Py_CLEAR(tmp); |
| 6015 | value = NULL; |
| 6016 | } |
| 6017 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6018 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6019 | res = obj2ast_expr(tmp, &value, arena); |
| 6020 | if (res != 0) goto failed; |
| 6021 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6022 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6023 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6024 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6025 | return 1; |
| 6026 | } |
| 6027 | if (tmp == NULL) { |
| 6028 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6029 | return 1; |
| 6030 | } |
| 6031 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6032 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6033 | res = obj2ast_int(tmp, &simple, arena); |
| 6034 | if (res != 0) goto failed; |
| 6035 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6036 | } |
| 6037 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6038 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6039 | if (*out == NULL) goto failed; |
| 6040 | return 0; |
| 6041 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6042 | tp = astmodulestate_global->For_type; |
| 6043 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6044 | if (isinstance == -1) { |
| 6045 | return 1; |
| 6046 | } |
| 6047 | if (isinstance) { |
| 6048 | expr_ty target; |
| 6049 | expr_ty iter; |
| 6050 | asdl_seq* body; |
| 6051 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6052 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6053 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6054 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6055 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6056 | return 1; |
| 6057 | } |
| 6058 | if (tmp == NULL) { |
| 6059 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6060 | return 1; |
| 6061 | } |
| 6062 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6063 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6064 | res = obj2ast_expr(tmp, &target, arena); |
| 6065 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6066 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6067 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6068 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6069 | return 1; |
| 6070 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6071 | if (tmp == NULL) { |
| 6072 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6073 | return 1; |
| 6074 | } |
| 6075 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6076 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6077 | res = obj2ast_expr(tmp, &iter, arena); |
| 6078 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6079 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6080 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6081 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6082 | return 1; |
| 6083 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6084 | if (tmp == NULL) { |
| 6085 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6086 | return 1; |
| 6087 | } |
| 6088 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6089 | int res; |
| 6090 | Py_ssize_t len; |
| 6091 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6092 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6093 | 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] | 6094 | goto failed; |
| 6095 | } |
| 6096 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6097 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6098 | if (body == NULL) goto failed; |
| 6099 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6100 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6101 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6102 | Py_INCREF(tmp2); |
| 6103 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6104 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6105 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6106 | if (len != PyList_GET_SIZE(tmp)) { |
| 6107 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6108 | goto failed; |
| 6109 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6110 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6111 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6112 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6113 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6114 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6115 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6116 | return 1; |
| 6117 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6118 | if (tmp == NULL) { |
| 6119 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6120 | return 1; |
| 6121 | } |
| 6122 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6123 | int res; |
| 6124 | Py_ssize_t len; |
| 6125 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6126 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6127 | 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] | 6128 | goto failed; |
| 6129 | } |
| 6130 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6131 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6132 | if (orelse == NULL) goto failed; |
| 6133 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6134 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6135 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6136 | Py_INCREF(tmp2); |
| 6137 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6138 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6139 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6140 | if (len != PyList_GET_SIZE(tmp)) { |
| 6141 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6142 | goto failed; |
| 6143 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6144 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6145 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6146 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6147 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6148 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6149 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6150 | return 1; |
| 6151 | } |
| 6152 | if (tmp == NULL || tmp == Py_None) { |
| 6153 | Py_CLEAR(tmp); |
| 6154 | type_comment = NULL; |
| 6155 | } |
| 6156 | else { |
| 6157 | int res; |
| 6158 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6159 | if (res != 0) goto failed; |
| 6160 | Py_CLEAR(tmp); |
| 6161 | } |
| 6162 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6163 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6164 | if (*out == NULL) goto failed; |
| 6165 | return 0; |
| 6166 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6167 | tp = astmodulestate_global->AsyncFor_type; |
| 6168 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6169 | if (isinstance == -1) { |
| 6170 | return 1; |
| 6171 | } |
| 6172 | if (isinstance) { |
| 6173 | expr_ty target; |
| 6174 | expr_ty iter; |
| 6175 | asdl_seq* body; |
| 6176 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6177 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6178 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6179 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6180 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6181 | return 1; |
| 6182 | } |
| 6183 | if (tmp == NULL) { |
| 6184 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6185 | return 1; |
| 6186 | } |
| 6187 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6188 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6189 | res = obj2ast_expr(tmp, &target, arena); |
| 6190 | if (res != 0) goto failed; |
| 6191 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6192 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6193 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6194 | return 1; |
| 6195 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6196 | if (tmp == NULL) { |
| 6197 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6198 | return 1; |
| 6199 | } |
| 6200 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6201 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6202 | res = obj2ast_expr(tmp, &iter, arena); |
| 6203 | if (res != 0) goto failed; |
| 6204 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6205 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6206 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6207 | return 1; |
| 6208 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6209 | if (tmp == NULL) { |
| 6210 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6211 | return 1; |
| 6212 | } |
| 6213 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6214 | int res; |
| 6215 | Py_ssize_t len; |
| 6216 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6217 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6218 | 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] | 6219 | goto failed; |
| 6220 | } |
| 6221 | len = PyList_GET_SIZE(tmp); |
| 6222 | body = _Py_asdl_seq_new(len, arena); |
| 6223 | if (body == NULL) goto failed; |
| 6224 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6225 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6226 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6227 | Py_INCREF(tmp2); |
| 6228 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6229 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6230 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6231 | if (len != PyList_GET_SIZE(tmp)) { |
| 6232 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6233 | goto failed; |
| 6234 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6235 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6236 | } |
| 6237 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6238 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6239 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6240 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6241 | return 1; |
| 6242 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6243 | if (tmp == NULL) { |
| 6244 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6245 | return 1; |
| 6246 | } |
| 6247 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6248 | int res; |
| 6249 | Py_ssize_t len; |
| 6250 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6251 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6252 | 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] | 6253 | goto failed; |
| 6254 | } |
| 6255 | len = PyList_GET_SIZE(tmp); |
| 6256 | orelse = _Py_asdl_seq_new(len, arena); |
| 6257 | if (orelse == NULL) goto failed; |
| 6258 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6259 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6260 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6261 | Py_INCREF(tmp2); |
| 6262 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6263 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6264 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6265 | if (len != PyList_GET_SIZE(tmp)) { |
| 6266 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6267 | goto failed; |
| 6268 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6269 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6270 | } |
| 6271 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6272 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6273 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6274 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6275 | return 1; |
| 6276 | } |
| 6277 | if (tmp == NULL || tmp == Py_None) { |
| 6278 | Py_CLEAR(tmp); |
| 6279 | type_comment = NULL; |
| 6280 | } |
| 6281 | else { |
| 6282 | int res; |
| 6283 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6284 | if (res != 0) goto failed; |
| 6285 | Py_CLEAR(tmp); |
| 6286 | } |
| 6287 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6288 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6289 | if (*out == NULL) goto failed; |
| 6290 | return 0; |
| 6291 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6292 | tp = astmodulestate_global->While_type; |
| 6293 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6294 | if (isinstance == -1) { |
| 6295 | return 1; |
| 6296 | } |
| 6297 | if (isinstance) { |
| 6298 | expr_ty test; |
| 6299 | asdl_seq* body; |
| 6300 | asdl_seq* orelse; |
| 6301 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6302 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6303 | return 1; |
| 6304 | } |
| 6305 | if (tmp == NULL) { |
| 6306 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6307 | return 1; |
| 6308 | } |
| 6309 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6310 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6311 | res = obj2ast_expr(tmp, &test, arena); |
| 6312 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6313 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6314 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6315 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6316 | return 1; |
| 6317 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6318 | if (tmp == NULL) { |
| 6319 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6320 | return 1; |
| 6321 | } |
| 6322 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6323 | int res; |
| 6324 | Py_ssize_t len; |
| 6325 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6326 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6327 | 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] | 6328 | goto failed; |
| 6329 | } |
| 6330 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6331 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6332 | if (body == NULL) goto failed; |
| 6333 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6334 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6335 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6336 | Py_INCREF(tmp2); |
| 6337 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6338 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6339 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6340 | if (len != PyList_GET_SIZE(tmp)) { |
| 6341 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6342 | goto failed; |
| 6343 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6344 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6345 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6346 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6347 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6348 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6349 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6350 | return 1; |
| 6351 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6352 | if (tmp == NULL) { |
| 6353 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6354 | return 1; |
| 6355 | } |
| 6356 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6357 | int res; |
| 6358 | Py_ssize_t len; |
| 6359 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6360 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6361 | 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] | 6362 | goto failed; |
| 6363 | } |
| 6364 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6365 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6366 | if (orelse == NULL) goto failed; |
| 6367 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6368 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6369 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6370 | Py_INCREF(tmp2); |
| 6371 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6372 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6373 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6374 | if (len != PyList_GET_SIZE(tmp)) { |
| 6375 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6376 | goto failed; |
| 6377 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6378 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6379 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6380 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6381 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6382 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6383 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6384 | if (*out == NULL) goto failed; |
| 6385 | return 0; |
| 6386 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6387 | tp = astmodulestate_global->If_type; |
| 6388 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6389 | if (isinstance == -1) { |
| 6390 | return 1; |
| 6391 | } |
| 6392 | if (isinstance) { |
| 6393 | expr_ty test; |
| 6394 | asdl_seq* body; |
| 6395 | asdl_seq* orelse; |
| 6396 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6397 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6398 | return 1; |
| 6399 | } |
| 6400 | if (tmp == NULL) { |
| 6401 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6402 | return 1; |
| 6403 | } |
| 6404 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6405 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6406 | res = obj2ast_expr(tmp, &test, arena); |
| 6407 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6408 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6409 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6410 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6411 | return 1; |
| 6412 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6413 | if (tmp == NULL) { |
| 6414 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6415 | return 1; |
| 6416 | } |
| 6417 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6418 | int res; |
| 6419 | Py_ssize_t len; |
| 6420 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6421 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6422 | 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] | 6423 | goto failed; |
| 6424 | } |
| 6425 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6426 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6427 | if (body == NULL) goto failed; |
| 6428 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6429 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6430 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6431 | Py_INCREF(tmp2); |
| 6432 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6433 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6434 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6435 | if (len != PyList_GET_SIZE(tmp)) { |
| 6436 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6437 | goto failed; |
| 6438 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6439 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6440 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6441 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6442 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6443 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6444 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6445 | return 1; |
| 6446 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6447 | if (tmp == NULL) { |
| 6448 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6449 | return 1; |
| 6450 | } |
| 6451 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6452 | int res; |
| 6453 | Py_ssize_t len; |
| 6454 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6455 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6456 | 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] | 6457 | goto failed; |
| 6458 | } |
| 6459 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6460 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6461 | if (orelse == NULL) goto failed; |
| 6462 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6463 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6464 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6465 | Py_INCREF(tmp2); |
| 6466 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6467 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6468 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6469 | if (len != PyList_GET_SIZE(tmp)) { |
| 6470 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6471 | goto failed; |
| 6472 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6473 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6474 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6475 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6476 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6477 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6478 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6479 | if (*out == NULL) goto failed; |
| 6480 | return 0; |
| 6481 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6482 | tp = astmodulestate_global->With_type; |
| 6483 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6484 | if (isinstance == -1) { |
| 6485 | return 1; |
| 6486 | } |
| 6487 | if (isinstance) { |
| 6488 | asdl_seq* items; |
| 6489 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6490 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6491 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6492 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6493 | return 1; |
| 6494 | } |
| 6495 | if (tmp == NULL) { |
| 6496 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6497 | return 1; |
| 6498 | } |
| 6499 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6500 | int res; |
| 6501 | Py_ssize_t len; |
| 6502 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6503 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6504 | PyErr_Format(PyExc_TypeError, "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] | 6505 | goto failed; |
| 6506 | } |
| 6507 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6508 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6509 | if (items == NULL) goto failed; |
| 6510 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6511 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6512 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6513 | Py_INCREF(tmp2); |
| 6514 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6515 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6516 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6517 | if (len != PyList_GET_SIZE(tmp)) { |
| 6518 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6519 | goto failed; |
| 6520 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6521 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6522 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6523 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6524 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6525 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6526 | return 1; |
| 6527 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6528 | if (tmp == NULL) { |
| 6529 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6530 | return 1; |
| 6531 | } |
| 6532 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6533 | int res; |
| 6534 | Py_ssize_t len; |
| 6535 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6536 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6537 | 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] | 6538 | goto failed; |
| 6539 | } |
| 6540 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6541 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6542 | if (body == NULL) goto failed; |
| 6543 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6544 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6545 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6546 | Py_INCREF(tmp2); |
| 6547 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6548 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6549 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6550 | if (len != PyList_GET_SIZE(tmp)) { |
| 6551 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6552 | goto failed; |
| 6553 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6554 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6555 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6556 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6557 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6558 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6559 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6560 | return 1; |
| 6561 | } |
| 6562 | if (tmp == NULL || tmp == Py_None) { |
| 6563 | Py_CLEAR(tmp); |
| 6564 | type_comment = NULL; |
| 6565 | } |
| 6566 | else { |
| 6567 | int res; |
| 6568 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6569 | if (res != 0) goto failed; |
| 6570 | Py_CLEAR(tmp); |
| 6571 | } |
| 6572 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6573 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6574 | if (*out == NULL) goto failed; |
| 6575 | return 0; |
| 6576 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6577 | tp = astmodulestate_global->AsyncWith_type; |
| 6578 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6579 | if (isinstance == -1) { |
| 6580 | return 1; |
| 6581 | } |
| 6582 | if (isinstance) { |
| 6583 | asdl_seq* items; |
| 6584 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6585 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6586 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6587 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6588 | return 1; |
| 6589 | } |
| 6590 | if (tmp == NULL) { |
| 6591 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6592 | return 1; |
| 6593 | } |
| 6594 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6595 | int res; |
| 6596 | Py_ssize_t len; |
| 6597 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6598 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6599 | 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] | 6600 | goto failed; |
| 6601 | } |
| 6602 | len = PyList_GET_SIZE(tmp); |
| 6603 | items = _Py_asdl_seq_new(len, arena); |
| 6604 | if (items == NULL) goto failed; |
| 6605 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6606 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6607 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6608 | Py_INCREF(tmp2); |
| 6609 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6610 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6611 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6612 | if (len != PyList_GET_SIZE(tmp)) { |
| 6613 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6614 | goto failed; |
| 6615 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6616 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6617 | } |
| 6618 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6619 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6620 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6621 | return 1; |
| 6622 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6623 | if (tmp == NULL) { |
| 6624 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6625 | return 1; |
| 6626 | } |
| 6627 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6628 | int res; |
| 6629 | Py_ssize_t len; |
| 6630 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6631 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6632 | 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] | 6633 | goto failed; |
| 6634 | } |
| 6635 | len = PyList_GET_SIZE(tmp); |
| 6636 | body = _Py_asdl_seq_new(len, arena); |
| 6637 | if (body == NULL) goto failed; |
| 6638 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6639 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6640 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6641 | Py_INCREF(tmp2); |
| 6642 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6643 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6644 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6645 | if (len != PyList_GET_SIZE(tmp)) { |
| 6646 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6647 | goto failed; |
| 6648 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6649 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6650 | } |
| 6651 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6652 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6653 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6654 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6655 | return 1; |
| 6656 | } |
| 6657 | if (tmp == NULL || tmp == Py_None) { |
| 6658 | Py_CLEAR(tmp); |
| 6659 | type_comment = NULL; |
| 6660 | } |
| 6661 | else { |
| 6662 | int res; |
| 6663 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6664 | if (res != 0) goto failed; |
| 6665 | Py_CLEAR(tmp); |
| 6666 | } |
| 6667 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6668 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6669 | if (*out == NULL) goto failed; |
| 6670 | return 0; |
| 6671 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6672 | tp = astmodulestate_global->Raise_type; |
| 6673 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6674 | if (isinstance == -1) { |
| 6675 | return 1; |
| 6676 | } |
| 6677 | if (isinstance) { |
| 6678 | expr_ty exc; |
| 6679 | expr_ty cause; |
| 6680 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6681 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6682 | return 1; |
| 6683 | } |
| 6684 | if (tmp == NULL || tmp == Py_None) { |
| 6685 | Py_CLEAR(tmp); |
| 6686 | exc = NULL; |
| 6687 | } |
| 6688 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6689 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6690 | res = obj2ast_expr(tmp, &exc, arena); |
| 6691 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6692 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6693 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6694 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6695 | return 1; |
| 6696 | } |
| 6697 | if (tmp == NULL || tmp == Py_None) { |
| 6698 | Py_CLEAR(tmp); |
| 6699 | cause = NULL; |
| 6700 | } |
| 6701 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6702 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6703 | res = obj2ast_expr(tmp, &cause, arena); |
| 6704 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6705 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6706 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6707 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6708 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6709 | if (*out == NULL) goto failed; |
| 6710 | return 0; |
| 6711 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6712 | tp = astmodulestate_global->Try_type; |
| 6713 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6714 | if (isinstance == -1) { |
| 6715 | return 1; |
| 6716 | } |
| 6717 | if (isinstance) { |
| 6718 | asdl_seq* body; |
| 6719 | asdl_seq* handlers; |
| 6720 | asdl_seq* orelse; |
| 6721 | asdl_seq* finalbody; |
| 6722 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6723 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6724 | return 1; |
| 6725 | } |
| 6726 | if (tmp == NULL) { |
| 6727 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6728 | return 1; |
| 6729 | } |
| 6730 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6731 | int res; |
| 6732 | Py_ssize_t len; |
| 6733 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6734 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6735 | 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] | 6736 | goto failed; |
| 6737 | } |
| 6738 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6739 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6740 | if (body == NULL) goto failed; |
| 6741 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6742 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6743 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6744 | Py_INCREF(tmp2); |
| 6745 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6746 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6747 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6748 | if (len != PyList_GET_SIZE(tmp)) { |
| 6749 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6750 | goto failed; |
| 6751 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6752 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6753 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6754 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6755 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6756 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6757 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6758 | return 1; |
| 6759 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6760 | if (tmp == NULL) { |
| 6761 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6762 | return 1; |
| 6763 | } |
| 6764 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6765 | int res; |
| 6766 | Py_ssize_t len; |
| 6767 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6768 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6769 | 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] | 6770 | goto failed; |
| 6771 | } |
| 6772 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6773 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6774 | if (handlers == NULL) goto failed; |
| 6775 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6776 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6777 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6778 | Py_INCREF(tmp2); |
| 6779 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6780 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6781 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6782 | if (len != PyList_GET_SIZE(tmp)) { |
| 6783 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6784 | goto failed; |
| 6785 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6786 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6787 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6788 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6789 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6790 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6791 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6792 | return 1; |
| 6793 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6794 | if (tmp == NULL) { |
| 6795 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6796 | return 1; |
| 6797 | } |
| 6798 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6799 | int res; |
| 6800 | Py_ssize_t len; |
| 6801 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6802 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6803 | 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] | 6804 | goto failed; |
| 6805 | } |
| 6806 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6807 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6808 | if (orelse == NULL) goto failed; |
| 6809 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6810 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6811 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6812 | Py_INCREF(tmp2); |
| 6813 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6814 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6815 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6816 | if (len != PyList_GET_SIZE(tmp)) { |
| 6817 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6818 | goto failed; |
| 6819 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6820 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6821 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6822 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6823 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6824 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6825 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6826 | return 1; |
| 6827 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6828 | if (tmp == NULL) { |
| 6829 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6830 | return 1; |
| 6831 | } |
| 6832 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6833 | int res; |
| 6834 | Py_ssize_t len; |
| 6835 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6836 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6837 | 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] | 6838 | goto failed; |
| 6839 | } |
| 6840 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6841 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6842 | if (finalbody == NULL) goto failed; |
| 6843 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6844 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6845 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6846 | Py_INCREF(tmp2); |
| 6847 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6848 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6849 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6850 | if (len != PyList_GET_SIZE(tmp)) { |
| 6851 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6852 | goto failed; |
| 6853 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6854 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6855 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6856 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6857 | } |
| 6858 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6859 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6860 | if (*out == NULL) goto failed; |
| 6861 | return 0; |
| 6862 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6863 | tp = astmodulestate_global->Assert_type; |
| 6864 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6865 | if (isinstance == -1) { |
| 6866 | return 1; |
| 6867 | } |
| 6868 | if (isinstance) { |
| 6869 | expr_ty test; |
| 6870 | expr_ty msg; |
| 6871 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6872 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6873 | return 1; |
| 6874 | } |
| 6875 | if (tmp == NULL) { |
| 6876 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6877 | return 1; |
| 6878 | } |
| 6879 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6880 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6881 | res = obj2ast_expr(tmp, &test, arena); |
| 6882 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6883 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6884 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6885 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6886 | return 1; |
| 6887 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6888 | if (tmp == NULL || tmp == Py_None) { |
| 6889 | Py_CLEAR(tmp); |
| 6890 | msg = NULL; |
| 6891 | } |
| 6892 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6893 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6894 | res = obj2ast_expr(tmp, &msg, arena); |
| 6895 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6896 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6897 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6898 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6899 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6900 | if (*out == NULL) goto failed; |
| 6901 | return 0; |
| 6902 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6903 | tp = astmodulestate_global->Import_type; |
| 6904 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6905 | if (isinstance == -1) { |
| 6906 | return 1; |
| 6907 | } |
| 6908 | if (isinstance) { |
| 6909 | asdl_seq* names; |
| 6910 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6911 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6912 | return 1; |
| 6913 | } |
| 6914 | if (tmp == NULL) { |
| 6915 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6916 | return 1; |
| 6917 | } |
| 6918 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6919 | int res; |
| 6920 | Py_ssize_t len; |
| 6921 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6922 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6923 | 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] | 6924 | goto failed; |
| 6925 | } |
| 6926 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6927 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6928 | if (names == NULL) goto failed; |
| 6929 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6930 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6931 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6932 | Py_INCREF(tmp2); |
| 6933 | res = obj2ast_alias(tmp2, &val, arena); |
| 6934 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6935 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6936 | if (len != PyList_GET_SIZE(tmp)) { |
| 6937 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 6938 | goto failed; |
| 6939 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6940 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6941 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6942 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6943 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6944 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6945 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6946 | if (*out == NULL) goto failed; |
| 6947 | return 0; |
| 6948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6949 | tp = astmodulestate_global->ImportFrom_type; |
| 6950 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6951 | if (isinstance == -1) { |
| 6952 | return 1; |
| 6953 | } |
| 6954 | if (isinstance) { |
| 6955 | identifier module; |
| 6956 | asdl_seq* names; |
| 6957 | int level; |
| 6958 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6959 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 6960 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6961 | return 1; |
| 6962 | } |
| 6963 | if (tmp == NULL || tmp == Py_None) { |
| 6964 | Py_CLEAR(tmp); |
| 6965 | module = NULL; |
| 6966 | } |
| 6967 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6968 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6969 | res = obj2ast_identifier(tmp, &module, arena); |
| 6970 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6971 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6972 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6973 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6974 | return 1; |
| 6975 | } |
| 6976 | if (tmp == NULL) { |
| 6977 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 6978 | return 1; |
| 6979 | } |
| 6980 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6981 | int res; |
| 6982 | Py_ssize_t len; |
| 6983 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6984 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6985 | 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] | 6986 | goto failed; |
| 6987 | } |
| 6988 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6989 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6990 | if (names == NULL) goto failed; |
| 6991 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6992 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6993 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6994 | Py_INCREF(tmp2); |
| 6995 | res = obj2ast_alias(tmp2, &val, arena); |
| 6996 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6997 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6998 | if (len != PyList_GET_SIZE(tmp)) { |
| 6999 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 7000 | goto failed; |
| 7001 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7002 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7003 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7004 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7005 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7006 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7007 | return 1; |
| 7008 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7009 | if (tmp == NULL || tmp == Py_None) { |
| 7010 | Py_CLEAR(tmp); |
| 7011 | level = 0; |
| 7012 | } |
| 7013 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7014 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7015 | res = obj2ast_int(tmp, &level, arena); |
| 7016 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7017 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7018 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7019 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7020 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7021 | if (*out == NULL) goto failed; |
| 7022 | return 0; |
| 7023 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7024 | tp = astmodulestate_global->Global_type; |
| 7025 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7026 | if (isinstance == -1) { |
| 7027 | return 1; |
| 7028 | } |
| 7029 | if (isinstance) { |
| 7030 | asdl_seq* names; |
| 7031 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7032 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7033 | return 1; |
| 7034 | } |
| 7035 | if (tmp == NULL) { |
| 7036 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7037 | return 1; |
| 7038 | } |
| 7039 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7040 | int res; |
| 7041 | Py_ssize_t len; |
| 7042 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7043 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7044 | 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] | 7045 | goto failed; |
| 7046 | } |
| 7047 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7048 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7049 | if (names == NULL) goto failed; |
| 7050 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7051 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7052 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7053 | Py_INCREF(tmp2); |
| 7054 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7055 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7056 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7057 | if (len != PyList_GET_SIZE(tmp)) { |
| 7058 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7059 | goto failed; |
| 7060 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7061 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7062 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7063 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7064 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7065 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7066 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7067 | if (*out == NULL) goto failed; |
| 7068 | return 0; |
| 7069 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7070 | tp = astmodulestate_global->Nonlocal_type; |
| 7071 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7072 | if (isinstance == -1) { |
| 7073 | return 1; |
| 7074 | } |
| 7075 | if (isinstance) { |
| 7076 | asdl_seq* names; |
| 7077 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7078 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7079 | return 1; |
| 7080 | } |
| 7081 | if (tmp == NULL) { |
| 7082 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7083 | return 1; |
| 7084 | } |
| 7085 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7086 | int res; |
| 7087 | Py_ssize_t len; |
| 7088 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7089 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7090 | 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] | 7091 | goto failed; |
| 7092 | } |
| 7093 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7094 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7095 | if (names == NULL) goto failed; |
| 7096 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7097 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7098 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7099 | Py_INCREF(tmp2); |
| 7100 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7101 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7102 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7103 | if (len != PyList_GET_SIZE(tmp)) { |
| 7104 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7105 | goto failed; |
| 7106 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7107 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7108 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7109 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7110 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7111 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7112 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7113 | if (*out == NULL) goto failed; |
| 7114 | return 0; |
| 7115 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7116 | tp = astmodulestate_global->Expr_type; |
| 7117 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7118 | if (isinstance == -1) { |
| 7119 | return 1; |
| 7120 | } |
| 7121 | if (isinstance) { |
| 7122 | expr_ty value; |
| 7123 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7124 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7125 | return 1; |
| 7126 | } |
| 7127 | if (tmp == NULL) { |
| 7128 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7129 | return 1; |
| 7130 | } |
| 7131 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7132 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7133 | res = obj2ast_expr(tmp, &value, arena); |
| 7134 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7135 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7136 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7137 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7138 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7139 | if (*out == NULL) goto failed; |
| 7140 | return 0; |
| 7141 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7142 | tp = astmodulestate_global->Pass_type; |
| 7143 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7144 | if (isinstance == -1) { |
| 7145 | return 1; |
| 7146 | } |
| 7147 | if (isinstance) { |
| 7148 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7149 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7150 | if (*out == NULL) goto failed; |
| 7151 | return 0; |
| 7152 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7153 | tp = astmodulestate_global->Break_type; |
| 7154 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7155 | if (isinstance == -1) { |
| 7156 | return 1; |
| 7157 | } |
| 7158 | if (isinstance) { |
| 7159 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7160 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7161 | if (*out == NULL) goto failed; |
| 7162 | return 0; |
| 7163 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7164 | tp = astmodulestate_global->Continue_type; |
| 7165 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7166 | if (isinstance == -1) { |
| 7167 | return 1; |
| 7168 | } |
| 7169 | if (isinstance) { |
| 7170 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7171 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7172 | if (*out == NULL) goto failed; |
| 7173 | return 0; |
| 7174 | } |
| 7175 | |
| 7176 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7177 | failed: |
| 7178 | Py_XDECREF(tmp); |
| 7179 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7180 | } |
| 7181 | |
| 7182 | int |
| 7183 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7184 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7185 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7186 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7187 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7188 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7189 | int lineno; |
| 7190 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7191 | int end_lineno; |
| 7192 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7193 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7194 | if (obj == Py_None) { |
| 7195 | *out = NULL; |
| 7196 | return 0; |
| 7197 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7198 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7199 | return 1; |
| 7200 | } |
| 7201 | if (tmp == NULL) { |
| 7202 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7203 | return 1; |
| 7204 | } |
| 7205 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7206 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7207 | res = obj2ast_int(tmp, &lineno, arena); |
| 7208 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7209 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7210 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7211 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7212 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7213 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7214 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7215 | if (tmp == NULL) { |
| 7216 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7217 | return 1; |
| 7218 | } |
| 7219 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7220 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7221 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7222 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7223 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7224 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7225 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7226 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7227 | return 1; |
| 7228 | } |
| 7229 | if (tmp == NULL || tmp == Py_None) { |
| 7230 | Py_CLEAR(tmp); |
| 7231 | end_lineno = 0; |
| 7232 | } |
| 7233 | else { |
| 7234 | int res; |
| 7235 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7236 | if (res != 0) goto failed; |
| 7237 | Py_CLEAR(tmp); |
| 7238 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7239 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7240 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7241 | return 1; |
| 7242 | } |
| 7243 | if (tmp == NULL || tmp == Py_None) { |
| 7244 | Py_CLEAR(tmp); |
| 7245 | end_col_offset = 0; |
| 7246 | } |
| 7247 | else { |
| 7248 | int res; |
| 7249 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7250 | if (res != 0) goto failed; |
| 7251 | Py_CLEAR(tmp); |
| 7252 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7253 | tp = astmodulestate_global->BoolOp_type; |
| 7254 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7255 | if (isinstance == -1) { |
| 7256 | return 1; |
| 7257 | } |
| 7258 | if (isinstance) { |
| 7259 | boolop_ty op; |
| 7260 | asdl_seq* values; |
| 7261 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7262 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7263 | return 1; |
| 7264 | } |
| 7265 | if (tmp == NULL) { |
| 7266 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7267 | return 1; |
| 7268 | } |
| 7269 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7270 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7271 | res = obj2ast_boolop(tmp, &op, arena); |
| 7272 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7273 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7274 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7275 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7276 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7277 | return 1; |
| 7278 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7279 | if (tmp == NULL) { |
| 7280 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7281 | return 1; |
| 7282 | } |
| 7283 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7284 | int res; |
| 7285 | Py_ssize_t len; |
| 7286 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7287 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7288 | 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] | 7289 | goto failed; |
| 7290 | } |
| 7291 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7292 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7293 | if (values == NULL) goto failed; |
| 7294 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7295 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7296 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7297 | Py_INCREF(tmp2); |
| 7298 | res = obj2ast_expr(tmp2, &val, arena); |
| 7299 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7300 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7301 | if (len != PyList_GET_SIZE(tmp)) { |
| 7302 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7303 | goto failed; |
| 7304 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7305 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7306 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7307 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7308 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7309 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7310 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7311 | if (*out == NULL) goto failed; |
| 7312 | return 0; |
| 7313 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7314 | tp = astmodulestate_global->NamedExpr_type; |
| 7315 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7316 | if (isinstance == -1) { |
| 7317 | return 1; |
| 7318 | } |
| 7319 | if (isinstance) { |
| 7320 | expr_ty target; |
| 7321 | expr_ty value; |
| 7322 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7323 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7324 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7325 | return 1; |
| 7326 | } |
| 7327 | if (tmp == NULL) { |
| 7328 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7329 | return 1; |
| 7330 | } |
| 7331 | else { |
| 7332 | int res; |
| 7333 | res = obj2ast_expr(tmp, &target, arena); |
| 7334 | if (res != 0) goto failed; |
| 7335 | Py_CLEAR(tmp); |
| 7336 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7337 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7338 | return 1; |
| 7339 | } |
| 7340 | if (tmp == NULL) { |
| 7341 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7342 | return 1; |
| 7343 | } |
| 7344 | else { |
| 7345 | int res; |
| 7346 | res = obj2ast_expr(tmp, &value, arena); |
| 7347 | if (res != 0) goto failed; |
| 7348 | Py_CLEAR(tmp); |
| 7349 | } |
| 7350 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7351 | end_col_offset, arena); |
| 7352 | if (*out == NULL) goto failed; |
| 7353 | return 0; |
| 7354 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7355 | tp = astmodulestate_global->BinOp_type; |
| 7356 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7357 | if (isinstance == -1) { |
| 7358 | return 1; |
| 7359 | } |
| 7360 | if (isinstance) { |
| 7361 | expr_ty left; |
| 7362 | operator_ty op; |
| 7363 | expr_ty right; |
| 7364 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7365 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7366 | return 1; |
| 7367 | } |
| 7368 | if (tmp == NULL) { |
| 7369 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7370 | return 1; |
| 7371 | } |
| 7372 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7373 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7374 | res = obj2ast_expr(tmp, &left, arena); |
| 7375 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7376 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7377 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7378 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7379 | return 1; |
| 7380 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7381 | if (tmp == NULL) { |
| 7382 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7383 | return 1; |
| 7384 | } |
| 7385 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7386 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7387 | res = obj2ast_operator(tmp, &op, arena); |
| 7388 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7389 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7390 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7391 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7392 | return 1; |
| 7393 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7394 | if (tmp == NULL) { |
| 7395 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7396 | return 1; |
| 7397 | } |
| 7398 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7399 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7400 | res = obj2ast_expr(tmp, &right, arena); |
| 7401 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7402 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7403 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7404 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7405 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7406 | if (*out == NULL) goto failed; |
| 7407 | return 0; |
| 7408 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7409 | tp = astmodulestate_global->UnaryOp_type; |
| 7410 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7411 | if (isinstance == -1) { |
| 7412 | return 1; |
| 7413 | } |
| 7414 | if (isinstance) { |
| 7415 | unaryop_ty op; |
| 7416 | expr_ty operand; |
| 7417 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7418 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7419 | return 1; |
| 7420 | } |
| 7421 | if (tmp == NULL) { |
| 7422 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7423 | return 1; |
| 7424 | } |
| 7425 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7426 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7427 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7428 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7429 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7430 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7431 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7432 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7433 | return 1; |
| 7434 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7435 | if (tmp == NULL) { |
| 7436 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7437 | return 1; |
| 7438 | } |
| 7439 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7440 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7441 | res = obj2ast_expr(tmp, &operand, arena); |
| 7442 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7443 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7444 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7445 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7446 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7447 | if (*out == NULL) goto failed; |
| 7448 | return 0; |
| 7449 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7450 | tp = astmodulestate_global->Lambda_type; |
| 7451 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7452 | if (isinstance == -1) { |
| 7453 | return 1; |
| 7454 | } |
| 7455 | if (isinstance) { |
| 7456 | arguments_ty args; |
| 7457 | expr_ty body; |
| 7458 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7459 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7460 | return 1; |
| 7461 | } |
| 7462 | if (tmp == NULL) { |
| 7463 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7464 | return 1; |
| 7465 | } |
| 7466 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7467 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7468 | res = obj2ast_arguments(tmp, &args, arena); |
| 7469 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7470 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7471 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7472 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7473 | return 1; |
| 7474 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7475 | if (tmp == NULL) { |
| 7476 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7477 | return 1; |
| 7478 | } |
| 7479 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7480 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7481 | res = obj2ast_expr(tmp, &body, arena); |
| 7482 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7483 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7484 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7485 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7486 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7487 | if (*out == NULL) goto failed; |
| 7488 | return 0; |
| 7489 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7490 | tp = astmodulestate_global->IfExp_type; |
| 7491 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7492 | if (isinstance == -1) { |
| 7493 | return 1; |
| 7494 | } |
| 7495 | if (isinstance) { |
| 7496 | expr_ty test; |
| 7497 | expr_ty body; |
| 7498 | expr_ty orelse; |
| 7499 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7500 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7501 | return 1; |
| 7502 | } |
| 7503 | if (tmp == NULL) { |
| 7504 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7505 | return 1; |
| 7506 | } |
| 7507 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7508 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7509 | res = obj2ast_expr(tmp, &test, arena); |
| 7510 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7511 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7512 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7513 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7514 | return 1; |
| 7515 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7516 | if (tmp == NULL) { |
| 7517 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7518 | return 1; |
| 7519 | } |
| 7520 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7521 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7522 | res = obj2ast_expr(tmp, &body, arena); |
| 7523 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7524 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7525 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7526 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7527 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7528 | return 1; |
| 7529 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7530 | if (tmp == NULL) { |
| 7531 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7532 | return 1; |
| 7533 | } |
| 7534 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7535 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7536 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7537 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7538 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7539 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7540 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7541 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7542 | if (*out == NULL) goto failed; |
| 7543 | return 0; |
| 7544 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7545 | tp = astmodulestate_global->Dict_type; |
| 7546 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7547 | if (isinstance == -1) { |
| 7548 | return 1; |
| 7549 | } |
| 7550 | if (isinstance) { |
| 7551 | asdl_seq* keys; |
| 7552 | asdl_seq* values; |
| 7553 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7554 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7555 | return 1; |
| 7556 | } |
| 7557 | if (tmp == NULL) { |
| 7558 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7559 | return 1; |
| 7560 | } |
| 7561 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7562 | int res; |
| 7563 | Py_ssize_t len; |
| 7564 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7565 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7566 | 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] | 7567 | goto failed; |
| 7568 | } |
| 7569 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7570 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7571 | if (keys == NULL) goto failed; |
| 7572 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7573 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7574 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7575 | Py_INCREF(tmp2); |
| 7576 | res = obj2ast_expr(tmp2, &val, arena); |
| 7577 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7578 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7579 | if (len != PyList_GET_SIZE(tmp)) { |
| 7580 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7581 | goto failed; |
| 7582 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7583 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7584 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7585 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7586 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7587 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7588 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7589 | return 1; |
| 7590 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7591 | if (tmp == NULL) { |
| 7592 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7593 | return 1; |
| 7594 | } |
| 7595 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7596 | int res; |
| 7597 | Py_ssize_t len; |
| 7598 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7599 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7600 | 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] | 7601 | goto failed; |
| 7602 | } |
| 7603 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7604 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7605 | if (values == NULL) goto failed; |
| 7606 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7607 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7608 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7609 | Py_INCREF(tmp2); |
| 7610 | res = obj2ast_expr(tmp2, &val, arena); |
| 7611 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7612 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7613 | if (len != PyList_GET_SIZE(tmp)) { |
| 7614 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7615 | goto failed; |
| 7616 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7617 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7618 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7619 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7620 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7621 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7622 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7623 | if (*out == NULL) goto failed; |
| 7624 | return 0; |
| 7625 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7626 | tp = astmodulestate_global->Set_type; |
| 7627 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7628 | if (isinstance == -1) { |
| 7629 | return 1; |
| 7630 | } |
| 7631 | if (isinstance) { |
| 7632 | asdl_seq* elts; |
| 7633 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7634 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7635 | return 1; |
| 7636 | } |
| 7637 | if (tmp == NULL) { |
| 7638 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7639 | return 1; |
| 7640 | } |
| 7641 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7642 | int res; |
| 7643 | Py_ssize_t len; |
| 7644 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7645 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7646 | 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] | 7647 | goto failed; |
| 7648 | } |
| 7649 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7650 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7651 | if (elts == NULL) goto failed; |
| 7652 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7653 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7654 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7655 | Py_INCREF(tmp2); |
| 7656 | res = obj2ast_expr(tmp2, &val, arena); |
| 7657 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7658 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7659 | if (len != PyList_GET_SIZE(tmp)) { |
| 7660 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7661 | goto failed; |
| 7662 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7663 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7664 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7665 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7666 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7667 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7668 | if (*out == NULL) goto failed; |
| 7669 | return 0; |
| 7670 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7671 | tp = astmodulestate_global->ListComp_type; |
| 7672 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7673 | if (isinstance == -1) { |
| 7674 | return 1; |
| 7675 | } |
| 7676 | if (isinstance) { |
| 7677 | expr_ty elt; |
| 7678 | asdl_seq* generators; |
| 7679 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7680 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7681 | return 1; |
| 7682 | } |
| 7683 | if (tmp == NULL) { |
| 7684 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7685 | return 1; |
| 7686 | } |
| 7687 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7688 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7689 | res = obj2ast_expr(tmp, &elt, arena); |
| 7690 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7691 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7692 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7693 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7694 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7695 | return 1; |
| 7696 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7697 | if (tmp == NULL) { |
| 7698 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7699 | return 1; |
| 7700 | } |
| 7701 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7702 | int res; |
| 7703 | Py_ssize_t len; |
| 7704 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7705 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7706 | 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] | 7707 | goto failed; |
| 7708 | } |
| 7709 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7710 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7711 | if (generators == NULL) goto failed; |
| 7712 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7713 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7714 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7715 | Py_INCREF(tmp2); |
| 7716 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7717 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7718 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7719 | if (len != PyList_GET_SIZE(tmp)) { |
| 7720 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7721 | goto failed; |
| 7722 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7723 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7724 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7725 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7726 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7727 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7728 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7729 | if (*out == NULL) goto failed; |
| 7730 | return 0; |
| 7731 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7732 | tp = astmodulestate_global->SetComp_type; |
| 7733 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7734 | if (isinstance == -1) { |
| 7735 | return 1; |
| 7736 | } |
| 7737 | if (isinstance) { |
| 7738 | expr_ty elt; |
| 7739 | asdl_seq* generators; |
| 7740 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7741 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7742 | return 1; |
| 7743 | } |
| 7744 | if (tmp == NULL) { |
| 7745 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7746 | return 1; |
| 7747 | } |
| 7748 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7749 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7750 | res = obj2ast_expr(tmp, &elt, arena); |
| 7751 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7752 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7753 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7754 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7755 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7756 | return 1; |
| 7757 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7758 | if (tmp == NULL) { |
| 7759 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7760 | return 1; |
| 7761 | } |
| 7762 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7763 | int res; |
| 7764 | Py_ssize_t len; |
| 7765 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7766 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7767 | 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] | 7768 | goto failed; |
| 7769 | } |
| 7770 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7771 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7772 | if (generators == NULL) goto failed; |
| 7773 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7774 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7775 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7776 | Py_INCREF(tmp2); |
| 7777 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7778 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7779 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7780 | if (len != PyList_GET_SIZE(tmp)) { |
| 7781 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7782 | goto failed; |
| 7783 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7784 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7785 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7786 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7787 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7788 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7789 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7790 | if (*out == NULL) goto failed; |
| 7791 | return 0; |
| 7792 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7793 | tp = astmodulestate_global->DictComp_type; |
| 7794 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7795 | if (isinstance == -1) { |
| 7796 | return 1; |
| 7797 | } |
| 7798 | if (isinstance) { |
| 7799 | expr_ty key; |
| 7800 | expr_ty value; |
| 7801 | asdl_seq* generators; |
| 7802 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7803 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7804 | return 1; |
| 7805 | } |
| 7806 | if (tmp == NULL) { |
| 7807 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7808 | return 1; |
| 7809 | } |
| 7810 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7811 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7812 | res = obj2ast_expr(tmp, &key, arena); |
| 7813 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7814 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7815 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7816 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7817 | return 1; |
| 7818 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7819 | if (tmp == NULL) { |
| 7820 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7821 | return 1; |
| 7822 | } |
| 7823 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7824 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7825 | res = obj2ast_expr(tmp, &value, arena); |
| 7826 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7827 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7828 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7829 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7830 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7831 | return 1; |
| 7832 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7833 | if (tmp == NULL) { |
| 7834 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7835 | return 1; |
| 7836 | } |
| 7837 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7838 | int res; |
| 7839 | Py_ssize_t len; |
| 7840 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7841 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7842 | 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] | 7843 | goto failed; |
| 7844 | } |
| 7845 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7846 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7847 | if (generators == NULL) goto failed; |
| 7848 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7849 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7850 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7851 | Py_INCREF(tmp2); |
| 7852 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7853 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7854 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7855 | if (len != PyList_GET_SIZE(tmp)) { |
| 7856 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7857 | goto failed; |
| 7858 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7859 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7860 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7861 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7862 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7863 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7864 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7865 | if (*out == NULL) goto failed; |
| 7866 | return 0; |
| 7867 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7868 | tp = astmodulestate_global->GeneratorExp_type; |
| 7869 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7870 | if (isinstance == -1) { |
| 7871 | return 1; |
| 7872 | } |
| 7873 | if (isinstance) { |
| 7874 | expr_ty elt; |
| 7875 | asdl_seq* generators; |
| 7876 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7877 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7878 | return 1; |
| 7879 | } |
| 7880 | if (tmp == NULL) { |
| 7881 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7882 | return 1; |
| 7883 | } |
| 7884 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7885 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7886 | res = obj2ast_expr(tmp, &elt, arena); |
| 7887 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7888 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7889 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7890 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7891 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7892 | return 1; |
| 7893 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7894 | if (tmp == NULL) { |
| 7895 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7896 | return 1; |
| 7897 | } |
| 7898 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7899 | int res; |
| 7900 | Py_ssize_t len; |
| 7901 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7902 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7903 | 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] | 7904 | goto failed; |
| 7905 | } |
| 7906 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7907 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7908 | if (generators == NULL) goto failed; |
| 7909 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7910 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7911 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7912 | Py_INCREF(tmp2); |
| 7913 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7914 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7915 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7916 | if (len != PyList_GET_SIZE(tmp)) { |
| 7917 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7918 | goto failed; |
| 7919 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7920 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7921 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7922 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7923 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7924 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7925 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7926 | if (*out == NULL) goto failed; |
| 7927 | return 0; |
| 7928 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7929 | tp = astmodulestate_global->Await_type; |
| 7930 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7931 | if (isinstance == -1) { |
| 7932 | return 1; |
| 7933 | } |
| 7934 | if (isinstance) { |
| 7935 | expr_ty value; |
| 7936 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7937 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7938 | return 1; |
| 7939 | } |
| 7940 | if (tmp == NULL) { |
| 7941 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 7942 | return 1; |
| 7943 | } |
| 7944 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7945 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7946 | res = obj2ast_expr(tmp, &value, arena); |
| 7947 | if (res != 0) goto failed; |
| 7948 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7949 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7950 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7951 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7952 | if (*out == NULL) goto failed; |
| 7953 | return 0; |
| 7954 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7955 | tp = astmodulestate_global->Yield_type; |
| 7956 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7957 | if (isinstance == -1) { |
| 7958 | return 1; |
| 7959 | } |
| 7960 | if (isinstance) { |
| 7961 | expr_ty value; |
| 7962 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7963 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7964 | return 1; |
| 7965 | } |
| 7966 | if (tmp == NULL || tmp == Py_None) { |
| 7967 | Py_CLEAR(tmp); |
| 7968 | value = NULL; |
| 7969 | } |
| 7970 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7971 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7972 | res = obj2ast_expr(tmp, &value, arena); |
| 7973 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7974 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7975 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7976 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7977 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7978 | if (*out == NULL) goto failed; |
| 7979 | return 0; |
| 7980 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7981 | tp = astmodulestate_global->YieldFrom_type; |
| 7982 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7983 | if (isinstance == -1) { |
| 7984 | return 1; |
| 7985 | } |
| 7986 | if (isinstance) { |
| 7987 | expr_ty value; |
| 7988 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7989 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7990 | return 1; |
| 7991 | } |
| 7992 | if (tmp == NULL) { |
| 7993 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 7994 | return 1; |
| 7995 | } |
| 7996 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7997 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7998 | res = obj2ast_expr(tmp, &value, arena); |
| 7999 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8000 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8001 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8002 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8003 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8004 | if (*out == NULL) goto failed; |
| 8005 | return 0; |
| 8006 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8007 | tp = astmodulestate_global->Compare_type; |
| 8008 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8009 | if (isinstance == -1) { |
| 8010 | return 1; |
| 8011 | } |
| 8012 | if (isinstance) { |
| 8013 | expr_ty left; |
| 8014 | asdl_int_seq* ops; |
| 8015 | asdl_seq* comparators; |
| 8016 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8017 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8018 | return 1; |
| 8019 | } |
| 8020 | if (tmp == NULL) { |
| 8021 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8022 | return 1; |
| 8023 | } |
| 8024 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8025 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8026 | res = obj2ast_expr(tmp, &left, arena); |
| 8027 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8028 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8030 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8031 | return 1; |
| 8032 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8033 | if (tmp == NULL) { |
| 8034 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8035 | return 1; |
| 8036 | } |
| 8037 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8038 | int res; |
| 8039 | Py_ssize_t len; |
| 8040 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8041 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8042 | 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] | 8043 | goto failed; |
| 8044 | } |
| 8045 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8046 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8047 | if (ops == NULL) goto failed; |
| 8048 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8049 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8050 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8051 | Py_INCREF(tmp2); |
| 8052 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8053 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8054 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8055 | if (len != PyList_GET_SIZE(tmp)) { |
| 8056 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8057 | goto failed; |
| 8058 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8059 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8060 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8061 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8062 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8063 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8064 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8065 | return 1; |
| 8066 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8067 | if (tmp == NULL) { |
| 8068 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8069 | return 1; |
| 8070 | } |
| 8071 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8072 | int res; |
| 8073 | Py_ssize_t len; |
| 8074 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8075 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8076 | 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] | 8077 | goto failed; |
| 8078 | } |
| 8079 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8080 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8081 | if (comparators == NULL) goto failed; |
| 8082 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8083 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8084 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8085 | Py_INCREF(tmp2); |
| 8086 | res = obj2ast_expr(tmp2, &val, arena); |
| 8087 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8088 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8089 | if (len != PyList_GET_SIZE(tmp)) { |
| 8090 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8091 | goto failed; |
| 8092 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8093 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8094 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8095 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8096 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8097 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8098 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8099 | if (*out == NULL) goto failed; |
| 8100 | return 0; |
| 8101 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8102 | tp = astmodulestate_global->Call_type; |
| 8103 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8104 | if (isinstance == -1) { |
| 8105 | return 1; |
| 8106 | } |
| 8107 | if (isinstance) { |
| 8108 | expr_ty func; |
| 8109 | asdl_seq* args; |
| 8110 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8111 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8112 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8113 | return 1; |
| 8114 | } |
| 8115 | if (tmp == NULL) { |
| 8116 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8117 | return 1; |
| 8118 | } |
| 8119 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8120 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8121 | res = obj2ast_expr(tmp, &func, arena); |
| 8122 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8123 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8124 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8125 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8126 | return 1; |
| 8127 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8128 | if (tmp == NULL) { |
| 8129 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8130 | return 1; |
| 8131 | } |
| 8132 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8133 | int res; |
| 8134 | Py_ssize_t len; |
| 8135 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8136 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8137 | 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] | 8138 | goto failed; |
| 8139 | } |
| 8140 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8141 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8142 | if (args == NULL) goto failed; |
| 8143 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8144 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8145 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8146 | Py_INCREF(tmp2); |
| 8147 | res = obj2ast_expr(tmp2, &val, arena); |
| 8148 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8149 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8150 | if (len != PyList_GET_SIZE(tmp)) { |
| 8151 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8152 | goto failed; |
| 8153 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8154 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8155 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8156 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8157 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8158 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8159 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8160 | return 1; |
| 8161 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8162 | if (tmp == NULL) { |
| 8163 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8164 | return 1; |
| 8165 | } |
| 8166 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8167 | int res; |
| 8168 | Py_ssize_t len; |
| 8169 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8170 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8171 | 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] | 8172 | goto failed; |
| 8173 | } |
| 8174 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8175 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8176 | if (keywords == NULL) goto failed; |
| 8177 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8178 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8179 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8180 | Py_INCREF(tmp2); |
| 8181 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8182 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8183 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8184 | if (len != PyList_GET_SIZE(tmp)) { |
| 8185 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8186 | goto failed; |
| 8187 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8188 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8189 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8190 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8191 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8192 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8193 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8194 | if (*out == NULL) goto failed; |
| 8195 | return 0; |
| 8196 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8197 | tp = astmodulestate_global->FormattedValue_type; |
| 8198 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8199 | if (isinstance == -1) { |
| 8200 | return 1; |
| 8201 | } |
| 8202 | if (isinstance) { |
| 8203 | expr_ty value; |
| 8204 | int conversion; |
| 8205 | expr_ty format_spec; |
| 8206 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8207 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8208 | return 1; |
| 8209 | } |
| 8210 | if (tmp == NULL) { |
| 8211 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8212 | return 1; |
| 8213 | } |
| 8214 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8215 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8216 | res = obj2ast_expr(tmp, &value, arena); |
| 8217 | if (res != 0) goto failed; |
| 8218 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8219 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8220 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8221 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8222 | return 1; |
| 8223 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8224 | if (tmp == NULL || tmp == Py_None) { |
| 8225 | Py_CLEAR(tmp); |
| 8226 | conversion = 0; |
| 8227 | } |
| 8228 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8229 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8230 | res = obj2ast_int(tmp, &conversion, arena); |
| 8231 | if (res != 0) goto failed; |
| 8232 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8233 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8234 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8235 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8236 | return 1; |
| 8237 | } |
| 8238 | if (tmp == NULL || tmp == Py_None) { |
| 8239 | Py_CLEAR(tmp); |
| 8240 | format_spec = NULL; |
| 8241 | } |
| 8242 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8243 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8244 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8245 | if (res != 0) goto failed; |
| 8246 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8247 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8248 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8249 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8250 | if (*out == NULL) goto failed; |
| 8251 | return 0; |
| 8252 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8253 | tp = astmodulestate_global->JoinedStr_type; |
| 8254 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8255 | if (isinstance == -1) { |
| 8256 | return 1; |
| 8257 | } |
| 8258 | if (isinstance) { |
| 8259 | asdl_seq* values; |
| 8260 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8261 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8262 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8263 | return 1; |
| 8264 | } |
| 8265 | if (tmp == NULL) { |
| 8266 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8267 | return 1; |
| 8268 | } |
| 8269 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8270 | int res; |
| 8271 | Py_ssize_t len; |
| 8272 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8273 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8274 | 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] | 8275 | goto failed; |
| 8276 | } |
| 8277 | len = PyList_GET_SIZE(tmp); |
| 8278 | values = _Py_asdl_seq_new(len, arena); |
| 8279 | if (values == NULL) goto failed; |
| 8280 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8281 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8282 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8283 | Py_INCREF(tmp2); |
| 8284 | res = obj2ast_expr(tmp2, &val, arena); |
| 8285 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8286 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8287 | if (len != PyList_GET_SIZE(tmp)) { |
| 8288 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8289 | goto failed; |
| 8290 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8291 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8292 | } |
| 8293 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8294 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8295 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8296 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8297 | if (*out == NULL) goto failed; |
| 8298 | return 0; |
| 8299 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8300 | tp = astmodulestate_global->Constant_type; |
| 8301 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8302 | if (isinstance == -1) { |
| 8303 | return 1; |
| 8304 | } |
| 8305 | if (isinstance) { |
| 8306 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8307 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8308 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8309 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8310 | return 1; |
| 8311 | } |
| 8312 | if (tmp == NULL) { |
| 8313 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8314 | return 1; |
| 8315 | } |
| 8316 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8317 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8318 | res = obj2ast_constant(tmp, &value, arena); |
| 8319 | if (res != 0) goto failed; |
| 8320 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8321 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8322 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8323 | return 1; |
| 8324 | } |
| 8325 | if (tmp == NULL || tmp == Py_None) { |
| 8326 | Py_CLEAR(tmp); |
| 8327 | kind = NULL; |
| 8328 | } |
| 8329 | else { |
| 8330 | int res; |
| 8331 | res = obj2ast_string(tmp, &kind, arena); |
| 8332 | if (res != 0) goto failed; |
| 8333 | Py_CLEAR(tmp); |
| 8334 | } |
| 8335 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8336 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8337 | if (*out == NULL) goto failed; |
| 8338 | return 0; |
| 8339 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8340 | tp = astmodulestate_global->Attribute_type; |
| 8341 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8342 | if (isinstance == -1) { |
| 8343 | return 1; |
| 8344 | } |
| 8345 | if (isinstance) { |
| 8346 | expr_ty value; |
| 8347 | identifier attr; |
| 8348 | expr_context_ty ctx; |
| 8349 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8350 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8351 | return 1; |
| 8352 | } |
| 8353 | if (tmp == NULL) { |
| 8354 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8355 | return 1; |
| 8356 | } |
| 8357 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8358 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8359 | res = obj2ast_expr(tmp, &value, arena); |
| 8360 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8361 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8362 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8363 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8364 | return 1; |
| 8365 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8366 | if (tmp == NULL) { |
| 8367 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8368 | return 1; |
| 8369 | } |
| 8370 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8371 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8372 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8373 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8374 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8375 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8376 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8377 | return 1; |
| 8378 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8379 | if (tmp == NULL) { |
| 8380 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8381 | return 1; |
| 8382 | } |
| 8383 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8384 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8385 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8386 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8387 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8388 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8389 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8390 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8391 | if (*out == NULL) goto failed; |
| 8392 | return 0; |
| 8393 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8394 | tp = astmodulestate_global->Subscript_type; |
| 8395 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8396 | if (isinstance == -1) { |
| 8397 | return 1; |
| 8398 | } |
| 8399 | if (isinstance) { |
| 8400 | expr_ty value; |
| 8401 | slice_ty slice; |
| 8402 | expr_context_ty ctx; |
| 8403 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8404 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8405 | return 1; |
| 8406 | } |
| 8407 | if (tmp == NULL) { |
| 8408 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8409 | return 1; |
| 8410 | } |
| 8411 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8412 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8413 | res = obj2ast_expr(tmp, &value, arena); |
| 8414 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8415 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8416 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8417 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8418 | return 1; |
| 8419 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8420 | if (tmp == NULL) { |
| 8421 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8422 | return 1; |
| 8423 | } |
| 8424 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8425 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8426 | res = obj2ast_slice(tmp, &slice, arena); |
| 8427 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8428 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8429 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8430 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8431 | return 1; |
| 8432 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8433 | if (tmp == NULL) { |
| 8434 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8435 | return 1; |
| 8436 | } |
| 8437 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8438 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8439 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8440 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8441 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8442 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8443 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8444 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8445 | if (*out == NULL) goto failed; |
| 8446 | return 0; |
| 8447 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8448 | tp = astmodulestate_global->Starred_type; |
| 8449 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8450 | if (isinstance == -1) { |
| 8451 | return 1; |
| 8452 | } |
| 8453 | if (isinstance) { |
| 8454 | expr_ty value; |
| 8455 | expr_context_ty ctx; |
| 8456 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8457 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8458 | return 1; |
| 8459 | } |
| 8460 | if (tmp == NULL) { |
| 8461 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8462 | return 1; |
| 8463 | } |
| 8464 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8465 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8466 | res = obj2ast_expr(tmp, &value, arena); |
| 8467 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8468 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8469 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8470 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8471 | return 1; |
| 8472 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8473 | if (tmp == NULL) { |
| 8474 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8475 | return 1; |
| 8476 | } |
| 8477 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8478 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8479 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8480 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8481 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8482 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8483 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8484 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8485 | if (*out == NULL) goto failed; |
| 8486 | return 0; |
| 8487 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8488 | tp = astmodulestate_global->Name_type; |
| 8489 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8490 | if (isinstance == -1) { |
| 8491 | return 1; |
| 8492 | } |
| 8493 | if (isinstance) { |
| 8494 | identifier id; |
| 8495 | expr_context_ty ctx; |
| 8496 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8497 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8498 | return 1; |
| 8499 | } |
| 8500 | if (tmp == NULL) { |
| 8501 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8502 | return 1; |
| 8503 | } |
| 8504 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8505 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8506 | res = obj2ast_identifier(tmp, &id, arena); |
| 8507 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8508 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8509 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8510 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8511 | return 1; |
| 8512 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8513 | if (tmp == NULL) { |
| 8514 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8515 | return 1; |
| 8516 | } |
| 8517 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8518 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8519 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8520 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8521 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8522 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8523 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8524 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8525 | if (*out == NULL) goto failed; |
| 8526 | return 0; |
| 8527 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8528 | tp = astmodulestate_global->List_type; |
| 8529 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8530 | if (isinstance == -1) { |
| 8531 | return 1; |
| 8532 | } |
| 8533 | if (isinstance) { |
| 8534 | asdl_seq* elts; |
| 8535 | expr_context_ty ctx; |
| 8536 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8537 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8538 | return 1; |
| 8539 | } |
| 8540 | if (tmp == NULL) { |
| 8541 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8542 | return 1; |
| 8543 | } |
| 8544 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8545 | int res; |
| 8546 | Py_ssize_t len; |
| 8547 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8548 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8549 | 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] | 8550 | goto failed; |
| 8551 | } |
| 8552 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8553 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8554 | if (elts == NULL) goto failed; |
| 8555 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8556 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8557 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8558 | Py_INCREF(tmp2); |
| 8559 | res = obj2ast_expr(tmp2, &val, arena); |
| 8560 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8561 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8562 | if (len != PyList_GET_SIZE(tmp)) { |
| 8563 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8564 | goto failed; |
| 8565 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8566 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8567 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8568 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8569 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8570 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8571 | return 1; |
| 8572 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8573 | if (tmp == NULL) { |
| 8574 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8575 | return 1; |
| 8576 | } |
| 8577 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8578 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8579 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8580 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8581 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8582 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8583 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8584 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8585 | if (*out == NULL) goto failed; |
| 8586 | return 0; |
| 8587 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8588 | tp = astmodulestate_global->Tuple_type; |
| 8589 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8590 | if (isinstance == -1) { |
| 8591 | return 1; |
| 8592 | } |
| 8593 | if (isinstance) { |
| 8594 | asdl_seq* elts; |
| 8595 | expr_context_ty ctx; |
| 8596 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8597 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8598 | return 1; |
| 8599 | } |
| 8600 | if (tmp == NULL) { |
| 8601 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8602 | return 1; |
| 8603 | } |
| 8604 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8605 | int res; |
| 8606 | Py_ssize_t len; |
| 8607 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8608 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8609 | 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] | 8610 | goto failed; |
| 8611 | } |
| 8612 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8613 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8614 | if (elts == NULL) goto failed; |
| 8615 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8616 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8617 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8618 | Py_INCREF(tmp2); |
| 8619 | res = obj2ast_expr(tmp2, &val, arena); |
| 8620 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8621 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8622 | if (len != PyList_GET_SIZE(tmp)) { |
| 8623 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8624 | goto failed; |
| 8625 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8626 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8627 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8628 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8629 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8630 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8631 | return 1; |
| 8632 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8633 | if (tmp == NULL) { |
| 8634 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8635 | return 1; |
| 8636 | } |
| 8637 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8638 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8639 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8640 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8641 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8642 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8643 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8644 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8645 | if (*out == NULL) goto failed; |
| 8646 | return 0; |
| 8647 | } |
| 8648 | |
| 8649 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8650 | failed: |
| 8651 | Py_XDECREF(tmp); |
| 8652 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8653 | } |
| 8654 | |
| 8655 | int |
| 8656 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8657 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8658 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8659 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8660 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8661 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8662 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8663 | } |
| 8664 | if (isinstance) { |
| 8665 | *out = Load; |
| 8666 | return 0; |
| 8667 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8668 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8669 | if (isinstance == -1) { |
| 8670 | return 1; |
| 8671 | } |
| 8672 | if (isinstance) { |
| 8673 | *out = Store; |
| 8674 | return 0; |
| 8675 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8676 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8677 | if (isinstance == -1) { |
| 8678 | return 1; |
| 8679 | } |
| 8680 | if (isinstance) { |
| 8681 | *out = Del; |
| 8682 | return 0; |
| 8683 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8684 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8685 | if (isinstance == -1) { |
| 8686 | return 1; |
| 8687 | } |
| 8688 | if (isinstance) { |
| 8689 | *out = AugLoad; |
| 8690 | return 0; |
| 8691 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8692 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8693 | if (isinstance == -1) { |
| 8694 | return 1; |
| 8695 | } |
| 8696 | if (isinstance) { |
| 8697 | *out = AugStore; |
| 8698 | return 0; |
| 8699 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8700 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8701 | if (isinstance == -1) { |
| 8702 | return 1; |
| 8703 | } |
| 8704 | if (isinstance) { |
| 8705 | *out = Param; |
| 8706 | return 0; |
| 8707 | } |
| 8708 | |
| 8709 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8710 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8711 | } |
| 8712 | |
| 8713 | int |
| 8714 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 8715 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8716 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8717 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8718 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8719 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8720 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8721 | if (obj == Py_None) { |
| 8722 | *out = NULL; |
| 8723 | return 0; |
| 8724 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8725 | tp = astmodulestate_global->Slice_type; |
| 8726 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8727 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8728 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8729 | } |
| 8730 | if (isinstance) { |
| 8731 | expr_ty lower; |
| 8732 | expr_ty upper; |
| 8733 | expr_ty step; |
| 8734 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8735 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8736 | return 1; |
| 8737 | } |
| 8738 | if (tmp == NULL || tmp == Py_None) { |
| 8739 | Py_CLEAR(tmp); |
| 8740 | lower = NULL; |
| 8741 | } |
| 8742 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8743 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8744 | res = obj2ast_expr(tmp, &lower, arena); |
| 8745 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8746 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8747 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8748 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8749 | return 1; |
| 8750 | } |
| 8751 | if (tmp == NULL || tmp == Py_None) { |
| 8752 | Py_CLEAR(tmp); |
| 8753 | upper = NULL; |
| 8754 | } |
| 8755 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8756 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8757 | res = obj2ast_expr(tmp, &upper, arena); |
| 8758 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8759 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8760 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8761 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8762 | return 1; |
| 8763 | } |
| 8764 | if (tmp == NULL || tmp == Py_None) { |
| 8765 | Py_CLEAR(tmp); |
| 8766 | step = NULL; |
| 8767 | } |
| 8768 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8769 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8770 | res = obj2ast_expr(tmp, &step, arena); |
| 8771 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8772 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8773 | } |
| 8774 | *out = Slice(lower, upper, step, arena); |
| 8775 | if (*out == NULL) goto failed; |
| 8776 | return 0; |
| 8777 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8778 | tp = astmodulestate_global->ExtSlice_type; |
| 8779 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8780 | if (isinstance == -1) { |
| 8781 | return 1; |
| 8782 | } |
| 8783 | if (isinstance) { |
| 8784 | asdl_seq* dims; |
| 8785 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8786 | if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8787 | return 1; |
| 8788 | } |
| 8789 | if (tmp == NULL) { |
| 8790 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 8791 | return 1; |
| 8792 | } |
| 8793 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8794 | int res; |
| 8795 | Py_ssize_t len; |
| 8796 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8797 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8798 | 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] | 8799 | goto failed; |
| 8800 | } |
| 8801 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8802 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8803 | if (dims == NULL) goto failed; |
| 8804 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8805 | slice_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8806 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8807 | Py_INCREF(tmp2); |
| 8808 | res = obj2ast_slice(tmp2, &val, arena); |
| 8809 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8810 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8811 | if (len != PyList_GET_SIZE(tmp)) { |
| 8812 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 8813 | goto failed; |
| 8814 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8815 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8816 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8817 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8818 | } |
| 8819 | *out = ExtSlice(dims, arena); |
| 8820 | if (*out == NULL) goto failed; |
| 8821 | return 0; |
| 8822 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8823 | tp = astmodulestate_global->Index_type; |
| 8824 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8825 | if (isinstance == -1) { |
| 8826 | return 1; |
| 8827 | } |
| 8828 | if (isinstance) { |
| 8829 | expr_ty value; |
| 8830 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8831 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8832 | return 1; |
| 8833 | } |
| 8834 | if (tmp == NULL) { |
| 8835 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 8836 | return 1; |
| 8837 | } |
| 8838 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8839 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8840 | res = obj2ast_expr(tmp, &value, arena); |
| 8841 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8842 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8843 | } |
| 8844 | *out = Index(value, arena); |
| 8845 | if (*out == NULL) goto failed; |
| 8846 | return 0; |
| 8847 | } |
| 8848 | |
| 8849 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 8850 | failed: |
| 8851 | Py_XDECREF(tmp); |
| 8852 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8853 | } |
| 8854 | |
| 8855 | int |
| 8856 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8857 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8858 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8859 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8860 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8861 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8862 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8863 | } |
| 8864 | if (isinstance) { |
| 8865 | *out = And; |
| 8866 | return 0; |
| 8867 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8868 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8869 | if (isinstance == -1) { |
| 8870 | return 1; |
| 8871 | } |
| 8872 | if (isinstance) { |
| 8873 | *out = Or; |
| 8874 | return 0; |
| 8875 | } |
| 8876 | |
| 8877 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8878 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8879 | } |
| 8880 | |
| 8881 | int |
| 8882 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8883 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8884 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8885 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8886 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8887 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8888 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8889 | } |
| 8890 | if (isinstance) { |
| 8891 | *out = Add; |
| 8892 | return 0; |
| 8893 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8894 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8895 | if (isinstance == -1) { |
| 8896 | return 1; |
| 8897 | } |
| 8898 | if (isinstance) { |
| 8899 | *out = Sub; |
| 8900 | return 0; |
| 8901 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8902 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8903 | if (isinstance == -1) { |
| 8904 | return 1; |
| 8905 | } |
| 8906 | if (isinstance) { |
| 8907 | *out = Mult; |
| 8908 | return 0; |
| 8909 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8910 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8911 | if (isinstance == -1) { |
| 8912 | return 1; |
| 8913 | } |
| 8914 | if (isinstance) { |
| 8915 | *out = MatMult; |
| 8916 | return 0; |
| 8917 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8918 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8919 | if (isinstance == -1) { |
| 8920 | return 1; |
| 8921 | } |
| 8922 | if (isinstance) { |
| 8923 | *out = Div; |
| 8924 | return 0; |
| 8925 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8926 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8927 | if (isinstance == -1) { |
| 8928 | return 1; |
| 8929 | } |
| 8930 | if (isinstance) { |
| 8931 | *out = Mod; |
| 8932 | return 0; |
| 8933 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8934 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8935 | if (isinstance == -1) { |
| 8936 | return 1; |
| 8937 | } |
| 8938 | if (isinstance) { |
| 8939 | *out = Pow; |
| 8940 | return 0; |
| 8941 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8942 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8943 | if (isinstance == -1) { |
| 8944 | return 1; |
| 8945 | } |
| 8946 | if (isinstance) { |
| 8947 | *out = LShift; |
| 8948 | return 0; |
| 8949 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8950 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8951 | if (isinstance == -1) { |
| 8952 | return 1; |
| 8953 | } |
| 8954 | if (isinstance) { |
| 8955 | *out = RShift; |
| 8956 | return 0; |
| 8957 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8958 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8959 | if (isinstance == -1) { |
| 8960 | return 1; |
| 8961 | } |
| 8962 | if (isinstance) { |
| 8963 | *out = BitOr; |
| 8964 | return 0; |
| 8965 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8966 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8967 | if (isinstance == -1) { |
| 8968 | return 1; |
| 8969 | } |
| 8970 | if (isinstance) { |
| 8971 | *out = BitXor; |
| 8972 | return 0; |
| 8973 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8974 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8975 | if (isinstance == -1) { |
| 8976 | return 1; |
| 8977 | } |
| 8978 | if (isinstance) { |
| 8979 | *out = BitAnd; |
| 8980 | return 0; |
| 8981 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8982 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8983 | if (isinstance == -1) { |
| 8984 | return 1; |
| 8985 | } |
| 8986 | if (isinstance) { |
| 8987 | *out = FloorDiv; |
| 8988 | return 0; |
| 8989 | } |
| 8990 | |
| 8991 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8992 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8993 | } |
| 8994 | |
| 8995 | int |
| 8996 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8997 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8998 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8999 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9000 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9001 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9002 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9003 | } |
| 9004 | if (isinstance) { |
| 9005 | *out = Invert; |
| 9006 | return 0; |
| 9007 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9008 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9009 | if (isinstance == -1) { |
| 9010 | return 1; |
| 9011 | } |
| 9012 | if (isinstance) { |
| 9013 | *out = Not; |
| 9014 | return 0; |
| 9015 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9016 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9017 | if (isinstance == -1) { |
| 9018 | return 1; |
| 9019 | } |
| 9020 | if (isinstance) { |
| 9021 | *out = UAdd; |
| 9022 | return 0; |
| 9023 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9024 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9025 | if (isinstance == -1) { |
| 9026 | return 1; |
| 9027 | } |
| 9028 | if (isinstance) { |
| 9029 | *out = USub; |
| 9030 | return 0; |
| 9031 | } |
| 9032 | |
| 9033 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 9034 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9035 | } |
| 9036 | |
| 9037 | int |
| 9038 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 9039 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9040 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9041 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9042 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9043 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9044 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9045 | } |
| 9046 | if (isinstance) { |
| 9047 | *out = Eq; |
| 9048 | return 0; |
| 9049 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9050 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9051 | if (isinstance == -1) { |
| 9052 | return 1; |
| 9053 | } |
| 9054 | if (isinstance) { |
| 9055 | *out = NotEq; |
| 9056 | return 0; |
| 9057 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9058 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9059 | if (isinstance == -1) { |
| 9060 | return 1; |
| 9061 | } |
| 9062 | if (isinstance) { |
| 9063 | *out = Lt; |
| 9064 | return 0; |
| 9065 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9066 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9067 | if (isinstance == -1) { |
| 9068 | return 1; |
| 9069 | } |
| 9070 | if (isinstance) { |
| 9071 | *out = LtE; |
| 9072 | return 0; |
| 9073 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9074 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9075 | if (isinstance == -1) { |
| 9076 | return 1; |
| 9077 | } |
| 9078 | if (isinstance) { |
| 9079 | *out = Gt; |
| 9080 | return 0; |
| 9081 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9082 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9083 | if (isinstance == -1) { |
| 9084 | return 1; |
| 9085 | } |
| 9086 | if (isinstance) { |
| 9087 | *out = GtE; |
| 9088 | return 0; |
| 9089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9090 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9091 | if (isinstance == -1) { |
| 9092 | return 1; |
| 9093 | } |
| 9094 | if (isinstance) { |
| 9095 | *out = Is; |
| 9096 | return 0; |
| 9097 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9098 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9099 | if (isinstance == -1) { |
| 9100 | return 1; |
| 9101 | } |
| 9102 | if (isinstance) { |
| 9103 | *out = IsNot; |
| 9104 | return 0; |
| 9105 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9106 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9107 | if (isinstance == -1) { |
| 9108 | return 1; |
| 9109 | } |
| 9110 | if (isinstance) { |
| 9111 | *out = In; |
| 9112 | return 0; |
| 9113 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9114 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9115 | if (isinstance == -1) { |
| 9116 | return 1; |
| 9117 | } |
| 9118 | if (isinstance) { |
| 9119 | *out = NotIn; |
| 9120 | return 0; |
| 9121 | } |
| 9122 | |
| 9123 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9124 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9125 | } |
| 9126 | |
| 9127 | int |
| 9128 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9129 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9130 | PyObject* tmp = NULL; |
| 9131 | expr_ty target; |
| 9132 | expr_ty iter; |
| 9133 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9134 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9135 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9136 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9137 | return 1; |
| 9138 | } |
| 9139 | if (tmp == NULL) { |
| 9140 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9141 | return 1; |
| 9142 | } |
| 9143 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9144 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9145 | res = obj2ast_expr(tmp, &target, arena); |
| 9146 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9147 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9148 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9149 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9150 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9151 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9152 | if (tmp == NULL) { |
| 9153 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9154 | return 1; |
| 9155 | } |
| 9156 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9157 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9158 | res = obj2ast_expr(tmp, &iter, arena); |
| 9159 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9160 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9162 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9163 | return 1; |
| 9164 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9165 | if (tmp == NULL) { |
| 9166 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9167 | return 1; |
| 9168 | } |
| 9169 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9170 | int res; |
| 9171 | Py_ssize_t len; |
| 9172 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9173 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9174 | 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] | 9175 | goto failed; |
| 9176 | } |
| 9177 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9178 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9179 | if (ifs == NULL) goto failed; |
| 9180 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9181 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9182 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9183 | Py_INCREF(tmp2); |
| 9184 | res = obj2ast_expr(tmp2, &val, arena); |
| 9185 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9186 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9187 | if (len != PyList_GET_SIZE(tmp)) { |
| 9188 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9189 | goto failed; |
| 9190 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9191 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9192 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9193 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9194 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9195 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9196 | return 1; |
| 9197 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9198 | if (tmp == NULL) { |
| 9199 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9200 | return 1; |
| 9201 | } |
| 9202 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9203 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9204 | res = obj2ast_int(tmp, &is_async, arena); |
| 9205 | if (res != 0) goto failed; |
| 9206 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9207 | } |
| 9208 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9209 | return 0; |
| 9210 | failed: |
| 9211 | Py_XDECREF(tmp); |
| 9212 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9213 | } |
| 9214 | |
| 9215 | int |
| 9216 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9217 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9218 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9219 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9220 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9221 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9222 | int lineno; |
| 9223 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9224 | int end_lineno; |
| 9225 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9226 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9227 | if (obj == Py_None) { |
| 9228 | *out = NULL; |
| 9229 | return 0; |
| 9230 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9231 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9232 | return 1; |
| 9233 | } |
| 9234 | if (tmp == NULL) { |
| 9235 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9236 | return 1; |
| 9237 | } |
| 9238 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9239 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9240 | res = obj2ast_int(tmp, &lineno, arena); |
| 9241 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9242 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9243 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9244 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9245 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9246 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9247 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9248 | if (tmp == NULL) { |
| 9249 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9250 | return 1; |
| 9251 | } |
| 9252 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9253 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9254 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9255 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9256 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9257 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9258 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9259 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9260 | return 1; |
| 9261 | } |
| 9262 | if (tmp == NULL || tmp == Py_None) { |
| 9263 | Py_CLEAR(tmp); |
| 9264 | end_lineno = 0; |
| 9265 | } |
| 9266 | else { |
| 9267 | int res; |
| 9268 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9269 | if (res != 0) goto failed; |
| 9270 | Py_CLEAR(tmp); |
| 9271 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9272 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9273 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9274 | return 1; |
| 9275 | } |
| 9276 | if (tmp == NULL || tmp == Py_None) { |
| 9277 | Py_CLEAR(tmp); |
| 9278 | end_col_offset = 0; |
| 9279 | } |
| 9280 | else { |
| 9281 | int res; |
| 9282 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9283 | if (res != 0) goto failed; |
| 9284 | Py_CLEAR(tmp); |
| 9285 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9286 | tp = astmodulestate_global->ExceptHandler_type; |
| 9287 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9288 | if (isinstance == -1) { |
| 9289 | return 1; |
| 9290 | } |
| 9291 | if (isinstance) { |
| 9292 | expr_ty type; |
| 9293 | identifier name; |
| 9294 | asdl_seq* body; |
| 9295 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9296 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9297 | return 1; |
| 9298 | } |
| 9299 | if (tmp == NULL || tmp == Py_None) { |
| 9300 | Py_CLEAR(tmp); |
| 9301 | type = NULL; |
| 9302 | } |
| 9303 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9304 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9305 | res = obj2ast_expr(tmp, &type, arena); |
| 9306 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9307 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9308 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9309 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9310 | return 1; |
| 9311 | } |
| 9312 | if (tmp == NULL || tmp == Py_None) { |
| 9313 | Py_CLEAR(tmp); |
| 9314 | name = NULL; |
| 9315 | } |
| 9316 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9317 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9318 | res = obj2ast_identifier(tmp, &name, arena); |
| 9319 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9320 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9321 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9322 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9323 | return 1; |
| 9324 | } |
| 9325 | if (tmp == NULL) { |
| 9326 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9327 | return 1; |
| 9328 | } |
| 9329 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9330 | int res; |
| 9331 | Py_ssize_t len; |
| 9332 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9333 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9334 | 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] | 9335 | goto failed; |
| 9336 | } |
| 9337 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9338 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9339 | if (body == NULL) goto failed; |
| 9340 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9341 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9342 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9343 | Py_INCREF(tmp2); |
| 9344 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9345 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9346 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9347 | if (len != PyList_GET_SIZE(tmp)) { |
| 9348 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9349 | goto failed; |
| 9350 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9351 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9352 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9353 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9354 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9355 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9356 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9357 | if (*out == NULL) goto failed; |
| 9358 | return 0; |
| 9359 | } |
| 9360 | |
| 9361 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9362 | failed: |
| 9363 | Py_XDECREF(tmp); |
| 9364 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9365 | } |
| 9366 | |
| 9367 | int |
| 9368 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9369 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9370 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9371 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9372 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9373 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9374 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9375 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9376 | arg_ty kwarg; |
| 9377 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9378 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9379 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9380 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9381 | return 1; |
| 9382 | } |
| 9383 | if (tmp == NULL) { |
| 9384 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9385 | return 1; |
| 9386 | } |
| 9387 | else { |
| 9388 | int res; |
| 9389 | Py_ssize_t len; |
| 9390 | Py_ssize_t i; |
| 9391 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9392 | 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] | 9393 | goto failed; |
| 9394 | } |
| 9395 | len = PyList_GET_SIZE(tmp); |
| 9396 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9397 | if (posonlyargs == NULL) goto failed; |
| 9398 | for (i = 0; i < len; i++) { |
| 9399 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9400 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9401 | Py_INCREF(tmp2); |
| 9402 | res = obj2ast_arg(tmp2, &val, arena); |
| 9403 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9404 | if (res != 0) goto failed; |
| 9405 | if (len != PyList_GET_SIZE(tmp)) { |
| 9406 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9407 | goto failed; |
| 9408 | } |
| 9409 | asdl_seq_SET(posonlyargs, i, val); |
| 9410 | } |
| 9411 | Py_CLEAR(tmp); |
| 9412 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9413 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9414 | return 1; |
| 9415 | } |
| 9416 | if (tmp == NULL) { |
| 9417 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9418 | return 1; |
| 9419 | } |
| 9420 | else { |
| 9421 | int res; |
| 9422 | Py_ssize_t len; |
| 9423 | Py_ssize_t i; |
| 9424 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9425 | 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] | 9426 | goto failed; |
| 9427 | } |
| 9428 | len = PyList_GET_SIZE(tmp); |
| 9429 | args = _Py_asdl_seq_new(len, arena); |
| 9430 | if (args == NULL) goto failed; |
| 9431 | for (i = 0; i < len; i++) { |
| 9432 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9433 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9434 | Py_INCREF(tmp2); |
| 9435 | res = obj2ast_arg(tmp2, &val, arena); |
| 9436 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9437 | if (res != 0) goto failed; |
| 9438 | if (len != PyList_GET_SIZE(tmp)) { |
| 9439 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9440 | goto failed; |
| 9441 | } |
| 9442 | asdl_seq_SET(args, i, val); |
| 9443 | } |
| 9444 | Py_CLEAR(tmp); |
| 9445 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9446 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9447 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9448 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9449 | if (tmp == NULL || tmp == Py_None) { |
| 9450 | Py_CLEAR(tmp); |
| 9451 | vararg = NULL; |
| 9452 | } |
| 9453 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9454 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9455 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9456 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9457 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9458 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9459 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9460 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9461 | return 1; |
| 9462 | } |
| 9463 | if (tmp == NULL) { |
| 9464 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9465 | return 1; |
| 9466 | } |
| 9467 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9468 | int res; |
| 9469 | Py_ssize_t len; |
| 9470 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9471 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9472 | 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] | 9473 | goto failed; |
| 9474 | } |
| 9475 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9476 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9477 | if (kwonlyargs == NULL) goto failed; |
| 9478 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9479 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9480 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9481 | Py_INCREF(tmp2); |
| 9482 | res = obj2ast_arg(tmp2, &val, arena); |
| 9483 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9484 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9485 | if (len != PyList_GET_SIZE(tmp)) { |
| 9486 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9487 | goto failed; |
| 9488 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9489 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9490 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9491 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9492 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9493 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9494 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9495 | return 1; |
| 9496 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9497 | if (tmp == NULL) { |
| 9498 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9499 | return 1; |
| 9500 | } |
| 9501 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9502 | int res; |
| 9503 | Py_ssize_t len; |
| 9504 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9505 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9506 | 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] | 9507 | goto failed; |
| 9508 | } |
| 9509 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9510 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9511 | if (kw_defaults == NULL) goto failed; |
| 9512 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9513 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9514 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9515 | Py_INCREF(tmp2); |
| 9516 | res = obj2ast_expr(tmp2, &val, arena); |
| 9517 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9518 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9519 | if (len != PyList_GET_SIZE(tmp)) { |
| 9520 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9521 | goto failed; |
| 9522 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9523 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9524 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9525 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9526 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9527 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9528 | return 1; |
| 9529 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9530 | if (tmp == NULL || tmp == Py_None) { |
| 9531 | Py_CLEAR(tmp); |
| 9532 | kwarg = NULL; |
| 9533 | } |
| 9534 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9535 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9536 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9537 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9538 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9539 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9540 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9541 | return 1; |
| 9542 | } |
| 9543 | if (tmp == NULL) { |
| 9544 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9545 | return 1; |
| 9546 | } |
| 9547 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9548 | int res; |
| 9549 | Py_ssize_t len; |
| 9550 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9551 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9552 | 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] | 9553 | goto failed; |
| 9554 | } |
| 9555 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9556 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9557 | if (defaults == NULL) goto failed; |
| 9558 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9559 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9560 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9561 | Py_INCREF(tmp2); |
| 9562 | res = obj2ast_expr(tmp2, &val, arena); |
| 9563 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9564 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9565 | if (len != PyList_GET_SIZE(tmp)) { |
| 9566 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9567 | goto failed; |
| 9568 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9569 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9570 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9571 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9572 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9573 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9574 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9575 | return 0; |
| 9576 | failed: |
| 9577 | Py_XDECREF(tmp); |
| 9578 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9579 | } |
| 9580 | |
| 9581 | int |
| 9582 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9583 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9584 | PyObject* tmp = NULL; |
| 9585 | identifier arg; |
| 9586 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9587 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9588 | int lineno; |
| 9589 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9590 | int end_lineno; |
| 9591 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9592 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9593 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9594 | return 1; |
| 9595 | } |
| 9596 | if (tmp == NULL) { |
| 9597 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9598 | return 1; |
| 9599 | } |
| 9600 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9601 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9602 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9603 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9604 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9605 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9606 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9607 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9608 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9609 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9610 | if (tmp == NULL || tmp == Py_None) { |
| 9611 | Py_CLEAR(tmp); |
| 9612 | annotation = NULL; |
| 9613 | } |
| 9614 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9615 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9616 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9617 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9618 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9619 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9620 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9621 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9622 | return 1; |
| 9623 | } |
| 9624 | if (tmp == NULL || tmp == Py_None) { |
| 9625 | Py_CLEAR(tmp); |
| 9626 | type_comment = NULL; |
| 9627 | } |
| 9628 | else { |
| 9629 | int res; |
| 9630 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9631 | if (res != 0) goto failed; |
| 9632 | Py_CLEAR(tmp); |
| 9633 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9634 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9635 | return 1; |
| 9636 | } |
| 9637 | if (tmp == NULL) { |
| 9638 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9639 | return 1; |
| 9640 | } |
| 9641 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9642 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9643 | res = obj2ast_int(tmp, &lineno, arena); |
| 9644 | if (res != 0) goto failed; |
| 9645 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9646 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9647 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9648 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9649 | return 1; |
| 9650 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9651 | if (tmp == NULL) { |
| 9652 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9653 | return 1; |
| 9654 | } |
| 9655 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9656 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9657 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9658 | if (res != 0) goto failed; |
| 9659 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9660 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9661 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9662 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9663 | return 1; |
| 9664 | } |
| 9665 | if (tmp == NULL || tmp == Py_None) { |
| 9666 | Py_CLEAR(tmp); |
| 9667 | end_lineno = 0; |
| 9668 | } |
| 9669 | else { |
| 9670 | int res; |
| 9671 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9672 | if (res != 0) goto failed; |
| 9673 | Py_CLEAR(tmp); |
| 9674 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9675 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9676 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9677 | return 1; |
| 9678 | } |
| 9679 | if (tmp == NULL || tmp == Py_None) { |
| 9680 | Py_CLEAR(tmp); |
| 9681 | end_col_offset = 0; |
| 9682 | } |
| 9683 | else { |
| 9684 | int res; |
| 9685 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9686 | if (res != 0) goto failed; |
| 9687 | Py_CLEAR(tmp); |
| 9688 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9689 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9690 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9691 | return 0; |
| 9692 | failed: |
| 9693 | Py_XDECREF(tmp); |
| 9694 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9695 | } |
| 9696 | |
| 9697 | int |
| 9698 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9699 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9700 | PyObject* tmp = NULL; |
| 9701 | identifier arg; |
| 9702 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9703 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9704 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9705 | return 1; |
| 9706 | } |
| 9707 | if (tmp == NULL || tmp == Py_None) { |
| 9708 | Py_CLEAR(tmp); |
| 9709 | arg = NULL; |
| 9710 | } |
| 9711 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9712 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9713 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9714 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9715 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9716 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9717 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9718 | return 1; |
| 9719 | } |
| 9720 | if (tmp == NULL) { |
| 9721 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9722 | return 1; |
| 9723 | } |
| 9724 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9725 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9726 | res = obj2ast_expr(tmp, &value, arena); |
| 9727 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9728 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9729 | } |
| 9730 | *out = keyword(arg, value, arena); |
| 9731 | return 0; |
| 9732 | failed: |
| 9733 | Py_XDECREF(tmp); |
| 9734 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9735 | } |
| 9736 | |
| 9737 | int |
| 9738 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9739 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9740 | PyObject* tmp = NULL; |
| 9741 | identifier name; |
| 9742 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9743 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9744 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9745 | return 1; |
| 9746 | } |
| 9747 | if (tmp == NULL) { |
| 9748 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9749 | return 1; |
| 9750 | } |
| 9751 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9752 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9753 | res = obj2ast_identifier(tmp, &name, arena); |
| 9754 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9755 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9756 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9757 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9758 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9759 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9760 | if (tmp == NULL || tmp == Py_None) { |
| 9761 | Py_CLEAR(tmp); |
| 9762 | asname = NULL; |
| 9763 | } |
| 9764 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9765 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9766 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9767 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9768 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9769 | } |
| 9770 | *out = alias(name, asname, arena); |
| 9771 | return 0; |
| 9772 | failed: |
| 9773 | Py_XDECREF(tmp); |
| 9774 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9775 | } |
| 9776 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9777 | int |
| 9778 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9779 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9780 | PyObject* tmp = NULL; |
| 9781 | expr_ty context_expr; |
| 9782 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9783 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9784 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9785 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9786 | return 1; |
| 9787 | } |
| 9788 | if (tmp == NULL) { |
| 9789 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9790 | return 1; |
| 9791 | } |
| 9792 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9793 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9794 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9795 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9796 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9797 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9798 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9799 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9800 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9801 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9802 | if (tmp == NULL || tmp == Py_None) { |
| 9803 | Py_CLEAR(tmp); |
| 9804 | optional_vars = NULL; |
| 9805 | } |
| 9806 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9807 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9808 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9809 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9810 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9811 | } |
| 9812 | *out = withitem(context_expr, optional_vars, arena); |
| 9813 | return 0; |
| 9814 | failed: |
| 9815 | Py_XDECREF(tmp); |
| 9816 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9817 | } |
| 9818 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9819 | int |
| 9820 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9821 | { |
| 9822 | int isinstance; |
| 9823 | |
| 9824 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9825 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9826 | |
| 9827 | if (obj == Py_None) { |
| 9828 | *out = NULL; |
| 9829 | return 0; |
| 9830 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9831 | tp = astmodulestate_global->TypeIgnore_type; |
| 9832 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9833 | if (isinstance == -1) { |
| 9834 | return 1; |
| 9835 | } |
| 9836 | if (isinstance) { |
| 9837 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9838 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9839 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9840 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9841 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9842 | return 1; |
| 9843 | } |
| 9844 | if (tmp == NULL) { |
| 9845 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9846 | return 1; |
| 9847 | } |
| 9848 | else { |
| 9849 | int res; |
| 9850 | res = obj2ast_int(tmp, &lineno, arena); |
| 9851 | if (res != 0) goto failed; |
| 9852 | Py_CLEAR(tmp); |
| 9853 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9854 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9855 | return 1; |
| 9856 | } |
| 9857 | if (tmp == NULL) { |
| 9858 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9859 | return 1; |
| 9860 | } |
| 9861 | else { |
| 9862 | int res; |
| 9863 | res = obj2ast_string(tmp, &tag, arena); |
| 9864 | if (res != 0) goto failed; |
| 9865 | Py_CLEAR(tmp); |
| 9866 | } |
| 9867 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9868 | if (*out == NULL) goto failed; |
| 9869 | return 0; |
| 9870 | } |
| 9871 | |
| 9872 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9873 | failed: |
| 9874 | Py_XDECREF(tmp); |
| 9875 | return 1; |
| 9876 | } |
| 9877 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9878 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9879 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9880 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9881 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9882 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9883 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9884 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9885 | if (!m) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9886 | Py_INCREF(astmodulestate(m)->AST_type); |
| 9887 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) |
| 9888 | return NULL; |
Matthias Bussonnier | 565b4f1 | 2019-05-21 13:12:03 -0700 | [diff] [blame] | 9889 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) |
| 9890 | return NULL; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9891 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9892 | return NULL; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9893 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) |
| 9894 | return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9895 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) |
| 9896 | return NULL; |
| 9897 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9898 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9899 | 0) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9900 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9901 | if (PyModule_AddObject(m, "Interactive", |
| 9902 | astmodulestate_global->Interactive_type) < 0) return NULL; |
| 9903 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9904 | if (PyModule_AddObject(m, "Expression", |
| 9905 | astmodulestate_global->Expression_type) < 0) return NULL; |
| 9906 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9907 | if (PyModule_AddObject(m, "FunctionType", |
| 9908 | astmodulestate_global->FunctionType_type) < 0) return NULL; |
| 9909 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
| 9910 | if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9911 | return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9912 | Py_INCREF(astmodulestate(m)->Suite_type); |
| 9913 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9914 | return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9915 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9916 | if (PyModule_AddObject(m, "FunctionDef", |
| 9917 | astmodulestate_global->FunctionDef_type) < 0) return NULL; |
| 9918 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9919 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
| 9920 | astmodulestate_global->AsyncFunctionDef_type) < 0) return NULL; |
| 9921 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9922 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9923 | < 0) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9924 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9925 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9926 | 0) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9927 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9928 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
| 9929 | 0) return NULL; |
| 9930 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9931 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
| 9932 | 0) return NULL; |
| 9933 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9934 | if (PyModule_AddObject(m, "AugAssign", |
| 9935 | astmodulestate_global->AugAssign_type) < 0) return NULL; |
| 9936 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9937 | if (PyModule_AddObject(m, "AnnAssign", |
| 9938 | astmodulestate_global->AnnAssign_type) < 0) return NULL; |
| 9939 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
| 9940 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9941 | return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9942 | Py_INCREF(astmodulestate(m)->For_type); |
| 9943 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
| 9944 | < 0) return NULL; |
| 9945 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
| 9946 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) |
| 9947 | return NULL; |
| 9948 | Py_INCREF(astmodulestate(m)->While_type); |
| 9949 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) return |
| 9950 | NULL; |
| 9951 | Py_INCREF(astmodulestate(m)->If_type); |
| 9952 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) |
| 9953 | return NULL; |
| 9954 | Py_INCREF(astmodulestate(m)->With_type); |
| 9955 | if (PyModule_AddObject(m, "AsyncWith", |
| 9956 | astmodulestate_global->AsyncWith_type) < 0) return NULL; |
| 9957 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
| 9958 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) |
| 9959 | return NULL; |
| 9960 | Py_INCREF(astmodulestate(m)->Raise_type); |
| 9961 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) |
| 9962 | return NULL; |
| 9963 | Py_INCREF(astmodulestate(m)->Try_type); |
| 9964 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
| 9965 | 0) return NULL; |
| 9966 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 9967 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
| 9968 | 0) return NULL; |
| 9969 | Py_INCREF(astmodulestate(m)->Import_type); |
| 9970 | if (PyModule_AddObject(m, "ImportFrom", |
| 9971 | astmodulestate_global->ImportFrom_type) < 0) return NULL; |
| 9972 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 9973 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
| 9974 | 0) return NULL; |
| 9975 | Py_INCREF(astmodulestate(m)->Global_type); |
| 9976 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
| 9977 | < 0) return NULL; |
| 9978 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
| 9979 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) |
| 9980 | return NULL; |
| 9981 | Py_INCREF(astmodulestate(m)->Expr_type); |
| 9982 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) |
| 9983 | return NULL; |
| 9984 | Py_INCREF(astmodulestate(m)->Pass_type); |
| 9985 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) |
| 9986 | return NULL; |
| 9987 | Py_INCREF(astmodulestate(m)->Break_type); |
| 9988 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
| 9989 | < 0) return NULL; |
| 9990 | Py_INCREF(astmodulestate(m)->Continue_type); |
| 9991 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) |
| 9992 | return NULL; |
| 9993 | Py_INCREF(astmodulestate(m)->expr_type); |
| 9994 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
| 9995 | 0) return NULL; |
| 9996 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 9997 | if (PyModule_AddObject(m, "NamedExpr", |
| 9998 | astmodulestate_global->NamedExpr_type) < 0) return NULL; |
| 9999 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
| 10000 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) |
| 10001 | return NULL; |
| 10002 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 10003 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
| 10004 | 0) return NULL; |
| 10005 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 10006 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
| 10007 | 0) return NULL; |
| 10008 | Py_INCREF(astmodulestate(m)->Lambda_type); |
| 10009 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) |
| 10010 | return NULL; |
| 10011 | Py_INCREF(astmodulestate(m)->IfExp_type); |
| 10012 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) |
| 10013 | return NULL; |
| 10014 | Py_INCREF(astmodulestate(m)->Dict_type); |
| 10015 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) |
| 10016 | return NULL; |
| 10017 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10018 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
| 10019 | < 0) return NULL; |
| 10020 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10021 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
| 10022 | 0) return NULL; |
| 10023 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10024 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
| 10025 | < 0) return NULL; |
| 10026 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10027 | if (PyModule_AddObject(m, "GeneratorExp", |
| 10028 | astmodulestate_global->GeneratorExp_type) < 0) return NULL; |
| 10029 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
| 10030 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) |
| 10031 | return NULL; |
| 10032 | Py_INCREF(astmodulestate(m)->Await_type); |
| 10033 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) |
| 10034 | return NULL; |
| 10035 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10036 | if (PyModule_AddObject(m, "YieldFrom", |
| 10037 | astmodulestate_global->YieldFrom_type) < 0) return NULL; |
| 10038 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10039 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
| 10040 | 0) return NULL; |
| 10041 | Py_INCREF(astmodulestate(m)->Compare_type); |
| 10042 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) |
| 10043 | return NULL; |
| 10044 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10045 | if (PyModule_AddObject(m, "FormattedValue", |
| 10046 | astmodulestate_global->FormattedValue_type) < 0) return NULL; |
| 10047 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10048 | if (PyModule_AddObject(m, "JoinedStr", |
| 10049 | astmodulestate_global->JoinedStr_type) < 0) return NULL; |
| 10050 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10051 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
| 10052 | < 0) return NULL; |
| 10053 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10054 | if (PyModule_AddObject(m, "Attribute", |
| 10055 | astmodulestate_global->Attribute_type) < 0) return NULL; |
| 10056 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10057 | if (PyModule_AddObject(m, "Subscript", |
| 10058 | astmodulestate_global->Subscript_type) < 0) return NULL; |
| 10059 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10060 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
| 10061 | 0) return NULL; |
| 10062 | Py_INCREF(astmodulestate(m)->Starred_type); |
| 10063 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) |
| 10064 | return NULL; |
| 10065 | Py_INCREF(astmodulestate(m)->Name_type); |
| 10066 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) |
| 10067 | return NULL; |
| 10068 | Py_INCREF(astmodulestate(m)->List_type); |
| 10069 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) |
| 10070 | return NULL; |
| 10071 | Py_INCREF(astmodulestate(m)->Tuple_type); |
| 10072 | if (PyModule_AddObject(m, "expr_context", |
| 10073 | astmodulestate_global->expr_context_type) < 0) return NULL; |
| 10074 | Py_INCREF(astmodulestate(m)->expr_context_type); |
| 10075 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) |
| 10076 | return NULL; |
| 10077 | Py_INCREF(astmodulestate(m)->Load_type); |
| 10078 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) |
| 10079 | return NULL; |
| 10080 | Py_INCREF(astmodulestate(m)->Store_type); |
| 10081 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) |
| 10082 | return NULL; |
| 10083 | Py_INCREF(astmodulestate(m)->Del_type); |
| 10084 | if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) < |
| 10085 | 0) return NULL; |
| 10086 | Py_INCREF(astmodulestate(m)->AugLoad_type); |
| 10087 | if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type) |
| 10088 | < 0) return NULL; |
| 10089 | Py_INCREF(astmodulestate(m)->AugStore_type); |
| 10090 | if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) |
| 10091 | return NULL; |
| 10092 | Py_INCREF(astmodulestate(m)->Param_type); |
| 10093 | if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0) |
| 10094 | return NULL; |
| 10095 | Py_INCREF(astmodulestate(m)->slice_type); |
| 10096 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) |
| 10097 | return NULL; |
| 10098 | Py_INCREF(astmodulestate(m)->Slice_type); |
| 10099 | if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type) |
| 10100 | < 0) return NULL; |
| 10101 | Py_INCREF(astmodulestate(m)->ExtSlice_type); |
| 10102 | if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0) |
| 10103 | return NULL; |
| 10104 | Py_INCREF(astmodulestate(m)->Index_type); |
| 10105 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
| 10106 | 0) return NULL; |
| 10107 | Py_INCREF(astmodulestate(m)->boolop_type); |
| 10108 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) |
| 10109 | return NULL; |
| 10110 | Py_INCREF(astmodulestate(m)->And_type); |
| 10111 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) return |
| 10112 | NULL; |
| 10113 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10114 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
| 10115 | < 0) return NULL; |
| 10116 | Py_INCREF(astmodulestate(m)->operator_type); |
| 10117 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) |
| 10118 | return NULL; |
| 10119 | Py_INCREF(astmodulestate(m)->Add_type); |
| 10120 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) |
| 10121 | return NULL; |
| 10122 | Py_INCREF(astmodulestate(m)->Sub_type); |
| 10123 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) |
| 10124 | return NULL; |
| 10125 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10126 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
| 10127 | 0) return NULL; |
| 10128 | Py_INCREF(astmodulestate(m)->MatMult_type); |
| 10129 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) |
| 10130 | return NULL; |
| 10131 | Py_INCREF(astmodulestate(m)->Div_type); |
| 10132 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) |
| 10133 | return NULL; |
| 10134 | Py_INCREF(astmodulestate(m)->Mod_type); |
| 10135 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) |
| 10136 | return NULL; |
| 10137 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10138 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
| 10139 | 0) return NULL; |
| 10140 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10141 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
| 10142 | 0) return NULL; |
| 10143 | Py_INCREF(astmodulestate(m)->RShift_type); |
| 10144 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) |
| 10145 | return NULL; |
| 10146 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10147 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
| 10148 | 0) return NULL; |
| 10149 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10150 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
| 10151 | 0) return NULL; |
| 10152 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10153 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
| 10154 | < 0) return NULL; |
| 10155 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10156 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
| 10157 | 0) return NULL; |
| 10158 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10159 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
| 10160 | 0) return NULL; |
| 10161 | Py_INCREF(astmodulestate(m)->Invert_type); |
| 10162 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) |
| 10163 | return NULL; |
| 10164 | Py_INCREF(astmodulestate(m)->Not_type); |
| 10165 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) |
| 10166 | return NULL; |
| 10167 | Py_INCREF(astmodulestate(m)->UAdd_type); |
| 10168 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) |
| 10169 | return NULL; |
| 10170 | Py_INCREF(astmodulestate(m)->USub_type); |
| 10171 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) |
| 10172 | return NULL; |
| 10173 | Py_INCREF(astmodulestate(m)->cmpop_type); |
| 10174 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) return |
| 10175 | NULL; |
| 10176 | Py_INCREF(astmodulestate(m)->Eq_type); |
| 10177 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) |
| 10178 | return NULL; |
| 10179 | Py_INCREF(astmodulestate(m)->NotEq_type); |
| 10180 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) return |
| 10181 | NULL; |
| 10182 | Py_INCREF(astmodulestate(m)->Lt_type); |
| 10183 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) |
| 10184 | return NULL; |
| 10185 | Py_INCREF(astmodulestate(m)->LtE_type); |
| 10186 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) return |
| 10187 | NULL; |
| 10188 | Py_INCREF(astmodulestate(m)->Gt_type); |
| 10189 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) |
| 10190 | return NULL; |
| 10191 | Py_INCREF(astmodulestate(m)->GtE_type); |
| 10192 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) return |
| 10193 | NULL; |
| 10194 | Py_INCREF(astmodulestate(m)->Is_type); |
| 10195 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) |
| 10196 | return NULL; |
| 10197 | Py_INCREF(astmodulestate(m)->IsNot_type); |
| 10198 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) return |
| 10199 | NULL; |
| 10200 | Py_INCREF(astmodulestate(m)->In_type); |
| 10201 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) |
| 10202 | return NULL; |
| 10203 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10204 | if (PyModule_AddObject(m, "comprehension", |
| 10205 | astmodulestate_global->comprehension_type) < 0) return NULL; |
| 10206 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10207 | if (PyModule_AddObject(m, "excepthandler", |
| 10208 | astmodulestate_global->excepthandler_type) < 0) return NULL; |
| 10209 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10210 | if (PyModule_AddObject(m, "ExceptHandler", |
| 10211 | astmodulestate_global->ExceptHandler_type) < 0) return NULL; |
| 10212 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10213 | if (PyModule_AddObject(m, "arguments", |
| 10214 | astmodulestate_global->arguments_type) < 0) return NULL; |
| 10215 | Py_INCREF(astmodulestate(m)->arguments_type); |
| 10216 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) |
| 10217 | return NULL; |
| 10218 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10219 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
| 10220 | 0) return NULL; |
| 10221 | Py_INCREF(astmodulestate(m)->keyword_type); |
| 10222 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) |
| 10223 | return NULL; |
| 10224 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10225 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
| 10226 | < 0) return NULL; |
| 10227 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10228 | if (PyModule_AddObject(m, "type_ignore", |
| 10229 | astmodulestate_global->type_ignore_type) < 0) return NULL; |
| 10230 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10231 | if (PyModule_AddObject(m, "TypeIgnore", |
| 10232 | astmodulestate_global->TypeIgnore_type) < 0) return NULL; |
| 10233 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10234 | return m; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10235 | } |
| 10236 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10237 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10238 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10239 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10240 | if (!init_types()) |
| 10241 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10242 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10243 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10244 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10245 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10246 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10247 | { |
| 10248 | mod_ty res; |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10249 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10250 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10251 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10252 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10253 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10254 | return NULL; |
| 10255 | } |
| 10256 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10257 | req_type[0] = astmodulestate_global->Module_type; |
| 10258 | req_type[1] = astmodulestate_global->Expression_type; |
| 10259 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10260 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10261 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10262 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10263 | if (!init_types()) |
| 10264 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10265 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10266 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10267 | if (isinstance == -1) |
| 10268 | return NULL; |
| 10269 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10270 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10271 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10272 | return NULL; |
| 10273 | } |
| 10274 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10275 | return NULL; |
| 10276 | else |
| 10277 | return res; |
| 10278 | } |
| 10279 | |
| 10280 | int PyAST_Check(PyObject* obj) |
| 10281 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10282 | if (!init_types()) |
| 10283 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10284 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10285 | } |
| 10286 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10287 | |