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" |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 7 | #include "structmember.h" |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9 | typedef struct { |
| 10 | int initialized; |
| 11 | PyObject *AST_type; |
| 12 | PyObject *Add_singleton; |
| 13 | PyObject *Add_type; |
| 14 | PyObject *And_singleton; |
| 15 | PyObject *And_type; |
| 16 | PyObject *AnnAssign_type; |
| 17 | PyObject *Assert_type; |
| 18 | PyObject *Assign_type; |
| 19 | PyObject *AsyncFor_type; |
| 20 | PyObject *AsyncFunctionDef_type; |
| 21 | PyObject *AsyncWith_type; |
| 22 | PyObject *Attribute_type; |
| 23 | PyObject *AugAssign_type; |
| 24 | PyObject *AugLoad_singleton; |
| 25 | PyObject *AugLoad_type; |
| 26 | PyObject *AugStore_singleton; |
| 27 | PyObject *AugStore_type; |
| 28 | PyObject *Await_type; |
| 29 | PyObject *BinOp_type; |
| 30 | PyObject *BitAnd_singleton; |
| 31 | PyObject *BitAnd_type; |
| 32 | PyObject *BitOr_singleton; |
| 33 | PyObject *BitOr_type; |
| 34 | PyObject *BitXor_singleton; |
| 35 | PyObject *BitXor_type; |
| 36 | PyObject *BoolOp_type; |
| 37 | PyObject *Break_type; |
| 38 | PyObject *Call_type; |
| 39 | PyObject *ClassDef_type; |
| 40 | PyObject *Compare_type; |
| 41 | PyObject *Constant_type; |
| 42 | PyObject *Continue_type; |
| 43 | PyObject *Del_singleton; |
| 44 | PyObject *Del_type; |
| 45 | PyObject *Delete_type; |
| 46 | PyObject *DictComp_type; |
| 47 | PyObject *Dict_type; |
| 48 | PyObject *Div_singleton; |
| 49 | PyObject *Div_type; |
| 50 | PyObject *Eq_singleton; |
| 51 | PyObject *Eq_type; |
| 52 | PyObject *ExceptHandler_type; |
| 53 | PyObject *Expr_type; |
| 54 | PyObject *Expression_type; |
| 55 | PyObject *ExtSlice_type; |
| 56 | PyObject *FloorDiv_singleton; |
| 57 | PyObject *FloorDiv_type; |
| 58 | PyObject *For_type; |
| 59 | PyObject *FormattedValue_type; |
| 60 | PyObject *FunctionDef_type; |
| 61 | PyObject *FunctionType_type; |
| 62 | PyObject *GeneratorExp_type; |
| 63 | PyObject *Global_type; |
| 64 | PyObject *GtE_singleton; |
| 65 | PyObject *GtE_type; |
| 66 | PyObject *Gt_singleton; |
| 67 | PyObject *Gt_type; |
| 68 | PyObject *IfExp_type; |
| 69 | PyObject *If_type; |
| 70 | PyObject *ImportFrom_type; |
| 71 | PyObject *Import_type; |
| 72 | PyObject *In_singleton; |
| 73 | PyObject *In_type; |
| 74 | PyObject *Index_type; |
| 75 | PyObject *Interactive_type; |
| 76 | PyObject *Invert_singleton; |
| 77 | PyObject *Invert_type; |
| 78 | PyObject *IsNot_singleton; |
| 79 | PyObject *IsNot_type; |
| 80 | PyObject *Is_singleton; |
| 81 | PyObject *Is_type; |
| 82 | PyObject *JoinedStr_type; |
| 83 | PyObject *LShift_singleton; |
| 84 | PyObject *LShift_type; |
| 85 | PyObject *Lambda_type; |
| 86 | PyObject *ListComp_type; |
| 87 | PyObject *List_type; |
| 88 | PyObject *Load_singleton; |
| 89 | PyObject *Load_type; |
| 90 | PyObject *LtE_singleton; |
| 91 | PyObject *LtE_type; |
| 92 | PyObject *Lt_singleton; |
| 93 | PyObject *Lt_type; |
| 94 | PyObject *MatMult_singleton; |
| 95 | PyObject *MatMult_type; |
| 96 | PyObject *Mod_singleton; |
| 97 | PyObject *Mod_type; |
| 98 | PyObject *Module_type; |
| 99 | PyObject *Mult_singleton; |
| 100 | PyObject *Mult_type; |
| 101 | PyObject *Name_type; |
| 102 | PyObject *NamedExpr_type; |
| 103 | PyObject *Nonlocal_type; |
| 104 | PyObject *NotEq_singleton; |
| 105 | PyObject *NotEq_type; |
| 106 | PyObject *NotIn_singleton; |
| 107 | PyObject *NotIn_type; |
| 108 | PyObject *Not_singleton; |
| 109 | PyObject *Not_type; |
| 110 | PyObject *Or_singleton; |
| 111 | PyObject *Or_type; |
| 112 | PyObject *Param_singleton; |
| 113 | PyObject *Param_type; |
| 114 | PyObject *Pass_type; |
| 115 | PyObject *Pow_singleton; |
| 116 | PyObject *Pow_type; |
| 117 | PyObject *RShift_singleton; |
| 118 | PyObject *RShift_type; |
| 119 | PyObject *Raise_type; |
| 120 | PyObject *Return_type; |
| 121 | PyObject *SetComp_type; |
| 122 | PyObject *Set_type; |
| 123 | PyObject *Slice_type; |
| 124 | PyObject *Starred_type; |
| 125 | PyObject *Store_singleton; |
| 126 | PyObject *Store_type; |
| 127 | PyObject *Sub_singleton; |
| 128 | PyObject *Sub_type; |
| 129 | PyObject *Subscript_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 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); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 359 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 360 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 361 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 362 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 363 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 364 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 365 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 366 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 367 | Py_CLEAR(astmodulestate(module)->While_type); |
| 368 | Py_CLEAR(astmodulestate(module)->With_type); |
| 369 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 370 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 371 | Py_CLEAR(astmodulestate(module)->__dict__); |
| 372 | Py_CLEAR(astmodulestate(module)->__module__); |
| 373 | Py_CLEAR(astmodulestate(module)->_ast); |
| 374 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 375 | Py_CLEAR(astmodulestate(module)->_fields); |
| 376 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 377 | Py_CLEAR(astmodulestate(module)->annotation); |
| 378 | Py_CLEAR(astmodulestate(module)->arg); |
| 379 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 380 | Py_CLEAR(astmodulestate(module)->args); |
| 381 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 382 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 383 | Py_CLEAR(astmodulestate(module)->asname); |
| 384 | Py_CLEAR(astmodulestate(module)->attr); |
| 385 | Py_CLEAR(astmodulestate(module)->bases); |
| 386 | Py_CLEAR(astmodulestate(module)->body); |
| 387 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 388 | Py_CLEAR(astmodulestate(module)->cause); |
| 389 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 390 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 391 | Py_CLEAR(astmodulestate(module)->comparators); |
| 392 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 393 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 394 | Py_CLEAR(astmodulestate(module)->conversion); |
| 395 | Py_CLEAR(astmodulestate(module)->ctx); |
| 396 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 397 | Py_CLEAR(astmodulestate(module)->defaults); |
| 398 | Py_CLEAR(astmodulestate(module)->dims); |
| 399 | Py_CLEAR(astmodulestate(module)->elt); |
| 400 | Py_CLEAR(astmodulestate(module)->elts); |
| 401 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 402 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 403 | Py_CLEAR(astmodulestate(module)->exc); |
| 404 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 405 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 406 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 407 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 408 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 409 | Py_CLEAR(astmodulestate(module)->func); |
| 410 | Py_CLEAR(astmodulestate(module)->generators); |
| 411 | Py_CLEAR(astmodulestate(module)->handlers); |
| 412 | Py_CLEAR(astmodulestate(module)->id); |
| 413 | Py_CLEAR(astmodulestate(module)->ifs); |
| 414 | Py_CLEAR(astmodulestate(module)->is_async); |
| 415 | Py_CLEAR(astmodulestate(module)->items); |
| 416 | Py_CLEAR(astmodulestate(module)->iter); |
| 417 | Py_CLEAR(astmodulestate(module)->key); |
| 418 | Py_CLEAR(astmodulestate(module)->keys); |
| 419 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 420 | Py_CLEAR(astmodulestate(module)->keywords); |
| 421 | Py_CLEAR(astmodulestate(module)->kind); |
| 422 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 423 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 424 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 425 | Py_CLEAR(astmodulestate(module)->left); |
| 426 | Py_CLEAR(astmodulestate(module)->level); |
| 427 | Py_CLEAR(astmodulestate(module)->lineno); |
| 428 | Py_CLEAR(astmodulestate(module)->lower); |
| 429 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 430 | Py_CLEAR(astmodulestate(module)->module); |
| 431 | Py_CLEAR(astmodulestate(module)->msg); |
| 432 | Py_CLEAR(astmodulestate(module)->name); |
| 433 | Py_CLEAR(astmodulestate(module)->names); |
| 434 | Py_CLEAR(astmodulestate(module)->op); |
| 435 | Py_CLEAR(astmodulestate(module)->operand); |
| 436 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 437 | Py_CLEAR(astmodulestate(module)->ops); |
| 438 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 439 | Py_CLEAR(astmodulestate(module)->orelse); |
| 440 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 441 | Py_CLEAR(astmodulestate(module)->returns); |
| 442 | Py_CLEAR(astmodulestate(module)->right); |
| 443 | Py_CLEAR(astmodulestate(module)->simple); |
| 444 | Py_CLEAR(astmodulestate(module)->slice); |
| 445 | Py_CLEAR(astmodulestate(module)->slice_type); |
| 446 | Py_CLEAR(astmodulestate(module)->step); |
| 447 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 448 | Py_CLEAR(astmodulestate(module)->tag); |
| 449 | Py_CLEAR(astmodulestate(module)->target); |
| 450 | Py_CLEAR(astmodulestate(module)->targets); |
| 451 | Py_CLEAR(astmodulestate(module)->test); |
| 452 | Py_CLEAR(astmodulestate(module)->type); |
| 453 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 454 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 455 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 456 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 457 | Py_CLEAR(astmodulestate(module)->upper); |
| 458 | Py_CLEAR(astmodulestate(module)->value); |
| 459 | Py_CLEAR(astmodulestate(module)->values); |
| 460 | Py_CLEAR(astmodulestate(module)->vararg); |
| 461 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 467 | { |
| 468 | Py_VISIT(astmodulestate(module)->AST_type); |
| 469 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 470 | Py_VISIT(astmodulestate(module)->Add_type); |
| 471 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 472 | Py_VISIT(astmodulestate(module)->And_type); |
| 473 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 474 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 475 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 476 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 477 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 478 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 479 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 480 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
| 481 | Py_VISIT(astmodulestate(module)->AugLoad_singleton); |
| 482 | Py_VISIT(astmodulestate(module)->AugLoad_type); |
| 483 | Py_VISIT(astmodulestate(module)->AugStore_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->AugStore_type); |
| 485 | Py_VISIT(astmodulestate(module)->Await_type); |
| 486 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 487 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 488 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 489 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 490 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 491 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 492 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 493 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 494 | Py_VISIT(astmodulestate(module)->Break_type); |
| 495 | Py_VISIT(astmodulestate(module)->Call_type); |
| 496 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 497 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 498 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 499 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 500 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 501 | Py_VISIT(astmodulestate(module)->Del_type); |
| 502 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 503 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 504 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 505 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 506 | Py_VISIT(astmodulestate(module)->Div_type); |
| 507 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 508 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 509 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 510 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 511 | Py_VISIT(astmodulestate(module)->Expression_type); |
| 512 | Py_VISIT(astmodulestate(module)->ExtSlice_type); |
| 513 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 514 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 515 | Py_VISIT(astmodulestate(module)->For_type); |
| 516 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 517 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 518 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 519 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 520 | Py_VISIT(astmodulestate(module)->Global_type); |
| 521 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 522 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 523 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 525 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 526 | Py_VISIT(astmodulestate(module)->If_type); |
| 527 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 528 | Py_VISIT(astmodulestate(module)->Import_type); |
| 529 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 530 | Py_VISIT(astmodulestate(module)->In_type); |
| 531 | Py_VISIT(astmodulestate(module)->Index_type); |
| 532 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 533 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 534 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 535 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 536 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 537 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->Is_type); |
| 539 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 540 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 541 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 542 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 543 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 544 | Py_VISIT(astmodulestate(module)->List_type); |
| 545 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 546 | Py_VISIT(astmodulestate(module)->Load_type); |
| 547 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 548 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 549 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 550 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 551 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 552 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 553 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 554 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 555 | Py_VISIT(astmodulestate(module)->Module_type); |
| 556 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 557 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 558 | Py_VISIT(astmodulestate(module)->Name_type); |
| 559 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 560 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 561 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 562 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 563 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 564 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 565 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 566 | Py_VISIT(astmodulestate(module)->Not_type); |
| 567 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 568 | Py_VISIT(astmodulestate(module)->Or_type); |
| 569 | Py_VISIT(astmodulestate(module)->Param_singleton); |
| 570 | Py_VISIT(astmodulestate(module)->Param_type); |
| 571 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 572 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 573 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 574 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 575 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 576 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 577 | Py_VISIT(astmodulestate(module)->Return_type); |
| 578 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 579 | Py_VISIT(astmodulestate(module)->Set_type); |
| 580 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 581 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 582 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 583 | Py_VISIT(astmodulestate(module)->Store_type); |
| 584 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 585 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 586 | Py_VISIT(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 587 | Py_VISIT(astmodulestate(module)->Try_type); |
| 588 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 589 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 590 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 591 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 592 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 593 | Py_VISIT(astmodulestate(module)->USub_type); |
| 594 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 595 | Py_VISIT(astmodulestate(module)->While_type); |
| 596 | Py_VISIT(astmodulestate(module)->With_type); |
| 597 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 598 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 599 | Py_VISIT(astmodulestate(module)->__dict__); |
| 600 | Py_VISIT(astmodulestate(module)->__module__); |
| 601 | Py_VISIT(astmodulestate(module)->_ast); |
| 602 | Py_VISIT(astmodulestate(module)->_attributes); |
| 603 | Py_VISIT(astmodulestate(module)->_fields); |
| 604 | Py_VISIT(astmodulestate(module)->alias_type); |
| 605 | Py_VISIT(astmodulestate(module)->annotation); |
| 606 | Py_VISIT(astmodulestate(module)->arg); |
| 607 | Py_VISIT(astmodulestate(module)->arg_type); |
| 608 | Py_VISIT(astmodulestate(module)->args); |
| 609 | Py_VISIT(astmodulestate(module)->argtypes); |
| 610 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 611 | Py_VISIT(astmodulestate(module)->asname); |
| 612 | Py_VISIT(astmodulestate(module)->attr); |
| 613 | Py_VISIT(astmodulestate(module)->bases); |
| 614 | Py_VISIT(astmodulestate(module)->body); |
| 615 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 616 | Py_VISIT(astmodulestate(module)->cause); |
| 617 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 618 | Py_VISIT(astmodulestate(module)->col_offset); |
| 619 | Py_VISIT(astmodulestate(module)->comparators); |
| 620 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 621 | Py_VISIT(astmodulestate(module)->context_expr); |
| 622 | Py_VISIT(astmodulestate(module)->conversion); |
| 623 | Py_VISIT(astmodulestate(module)->ctx); |
| 624 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 625 | Py_VISIT(astmodulestate(module)->defaults); |
| 626 | Py_VISIT(astmodulestate(module)->dims); |
| 627 | Py_VISIT(astmodulestate(module)->elt); |
| 628 | Py_VISIT(astmodulestate(module)->elts); |
| 629 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 630 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 631 | Py_VISIT(astmodulestate(module)->exc); |
| 632 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 633 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 634 | Py_VISIT(astmodulestate(module)->expr_type); |
| 635 | Py_VISIT(astmodulestate(module)->finalbody); |
| 636 | Py_VISIT(astmodulestate(module)->format_spec); |
| 637 | Py_VISIT(astmodulestate(module)->func); |
| 638 | Py_VISIT(astmodulestate(module)->generators); |
| 639 | Py_VISIT(astmodulestate(module)->handlers); |
| 640 | Py_VISIT(astmodulestate(module)->id); |
| 641 | Py_VISIT(astmodulestate(module)->ifs); |
| 642 | Py_VISIT(astmodulestate(module)->is_async); |
| 643 | Py_VISIT(astmodulestate(module)->items); |
| 644 | Py_VISIT(astmodulestate(module)->iter); |
| 645 | Py_VISIT(astmodulestate(module)->key); |
| 646 | Py_VISIT(astmodulestate(module)->keys); |
| 647 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 648 | Py_VISIT(astmodulestate(module)->keywords); |
| 649 | Py_VISIT(astmodulestate(module)->kind); |
| 650 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 651 | Py_VISIT(astmodulestate(module)->kwarg); |
| 652 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 653 | Py_VISIT(astmodulestate(module)->left); |
| 654 | Py_VISIT(astmodulestate(module)->level); |
| 655 | Py_VISIT(astmodulestate(module)->lineno); |
| 656 | Py_VISIT(astmodulestate(module)->lower); |
| 657 | Py_VISIT(astmodulestate(module)->mod_type); |
| 658 | Py_VISIT(astmodulestate(module)->module); |
| 659 | Py_VISIT(astmodulestate(module)->msg); |
| 660 | Py_VISIT(astmodulestate(module)->name); |
| 661 | Py_VISIT(astmodulestate(module)->names); |
| 662 | Py_VISIT(astmodulestate(module)->op); |
| 663 | Py_VISIT(astmodulestate(module)->operand); |
| 664 | Py_VISIT(astmodulestate(module)->operator_type); |
| 665 | Py_VISIT(astmodulestate(module)->ops); |
| 666 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 667 | Py_VISIT(astmodulestate(module)->orelse); |
| 668 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 669 | Py_VISIT(astmodulestate(module)->returns); |
| 670 | Py_VISIT(astmodulestate(module)->right); |
| 671 | Py_VISIT(astmodulestate(module)->simple); |
| 672 | Py_VISIT(astmodulestate(module)->slice); |
| 673 | Py_VISIT(astmodulestate(module)->slice_type); |
| 674 | Py_VISIT(astmodulestate(module)->step); |
| 675 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 676 | Py_VISIT(astmodulestate(module)->tag); |
| 677 | Py_VISIT(astmodulestate(module)->target); |
| 678 | Py_VISIT(astmodulestate(module)->targets); |
| 679 | Py_VISIT(astmodulestate(module)->test); |
| 680 | Py_VISIT(astmodulestate(module)->type); |
| 681 | Py_VISIT(astmodulestate(module)->type_comment); |
| 682 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 683 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 684 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 685 | Py_VISIT(astmodulestate(module)->upper); |
| 686 | Py_VISIT(astmodulestate(module)->value); |
| 687 | Py_VISIT(astmodulestate(module)->values); |
| 688 | Py_VISIT(astmodulestate(module)->vararg); |
| 689 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | static void astmodule_free(void* module) { |
| 695 | astmodule_clear((PyObject*)module); |
| 696 | } |
| 697 | |
| 698 | static struct PyModuleDef _astmodule = { |
| 699 | PyModuleDef_HEAD_INIT, |
| 700 | "_ast", |
| 701 | NULL, |
| 702 | sizeof(astmodulestate), |
| 703 | NULL, |
| 704 | NULL, |
| 705 | astmodule_traverse, |
| 706 | astmodule_clear, |
| 707 | astmodule_free, |
| 708 | }; |
| 709 | |
| 710 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 711 | |
| 712 | static int init_identifiers(void) |
| 713 | { |
| 714 | astmodulestate *state = astmodulestate_global; |
| 715 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
| 716 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
| 717 | if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0; |
| 718 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 719 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 720 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 721 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 722 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 723 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 724 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
| 725 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 726 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 727 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 728 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 729 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 730 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 731 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 732 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 733 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 734 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 735 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
| 736 | if ((state->dims = PyUnicode_InternFromString("dims")) == NULL) return 0; |
| 737 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 738 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 739 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 740 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 741 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 742 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 743 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 744 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 745 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 746 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 747 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 748 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 749 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 750 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 751 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 752 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 753 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 754 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 755 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 756 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 757 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 758 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 759 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 760 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 761 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 762 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 763 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 764 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 765 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 766 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 767 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 768 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 769 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 770 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 771 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 772 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 773 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 774 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 775 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 776 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 777 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 778 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 779 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 780 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 781 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 782 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 783 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 784 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 785 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 786 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 787 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 788 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 789 | return 1; |
| 790 | }; |
| 791 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 792 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 793 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 794 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 795 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 796 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 797 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 798 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 799 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 800 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 801 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 802 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 803 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 804 | "argtypes", |
| 805 | "returns", |
| 806 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 807 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 808 | "lineno", |
| 809 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 810 | "end_lineno", |
| 811 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 812 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 813 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 814 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 815 | "name", |
| 816 | "args", |
| 817 | "body", |
| 818 | "decorator_list", |
| 819 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 820 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 821 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 822 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 823 | "name", |
| 824 | "args", |
| 825 | "body", |
| 826 | "decorator_list", |
| 827 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 828 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 829 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 830 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 831 | "name", |
| 832 | "bases", |
| 833 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 834 | "body", |
| 835 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 836 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 837 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 838 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 839 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 840 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 841 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 842 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 843 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 844 | "targets", |
| 845 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 846 | "type_comment", |
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 AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 849 | "target", |
| 850 | "op", |
| 851 | "value", |
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 AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 854 | "target", |
| 855 | "annotation", |
| 856 | "value", |
| 857 | "simple", |
| 858 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 859 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 860 | "target", |
| 861 | "iter", |
| 862 | "body", |
| 863 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 864 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 865 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 866 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 867 | "target", |
| 868 | "iter", |
| 869 | "body", |
| 870 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 871 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 872 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 873 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 874 | "test", |
| 875 | "body", |
| 876 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 877 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 878 | static const char * const If_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 With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | "items", |
| 885 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 886 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 887 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 888 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 889 | "items", |
| 890 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 891 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 892 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 893 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 894 | "exc", |
| 895 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 896 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 897 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | "body", |
| 899 | "handlers", |
| 900 | "orelse", |
| 901 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 902 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 903 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 904 | "test", |
| 905 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 906 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 907 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 908 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 909 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 910 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 911 | "module", |
| 912 | "names", |
| 913 | "level", |
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 Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 916 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 917 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 918 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 919 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 920 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 921 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 923 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 924 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 925 | "lineno", |
| 926 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 927 | "end_lineno", |
| 928 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 929 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 930 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 931 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 932 | "op", |
| 933 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 934 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 935 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 936 | "target", |
| 937 | "value", |
| 938 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 939 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 940 | "left", |
| 941 | "op", |
| 942 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 943 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 944 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 945 | "op", |
| 946 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 947 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 948 | static const char * const Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 949 | "args", |
| 950 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 951 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 952 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 953 | "test", |
| 954 | "body", |
| 955 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 956 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 957 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 958 | "keys", |
| 959 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 960 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 961 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 962 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 963 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 964 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 965 | "elt", |
| 966 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 967 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 968 | static const char * const SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 969 | "elt", |
| 970 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 971 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 972 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 973 | "key", |
| 974 | "value", |
| 975 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 976 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 977 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 978 | "elt", |
| 979 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 980 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 981 | static const char * const Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 982 | "value", |
| 983 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 984 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 985 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 986 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 987 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 988 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 989 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 990 | static const char * const Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | "left", |
| 992 | "ops", |
| 993 | "comparators", |
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 Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 996 | "func", |
| 997 | "args", |
| 998 | "keywords", |
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 FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 1001 | "value", |
| 1002 | "conversion", |
| 1003 | "format_spec", |
| 1004 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1005 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 1006 | "values", |
| 1007 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1008 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1009 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 1010 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1011 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1012 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1013 | "value", |
| 1014 | "attr", |
| 1015 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1016 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1017 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1018 | "value", |
| 1019 | "slice", |
| 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 Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1023 | "value", |
| 1024 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1025 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1026 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1027 | "id", |
| 1028 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1029 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1030 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1031 | "elts", |
| 1032 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1033 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1034 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1035 | "elts", |
| 1036 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1037 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1038 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | static PyObject* ast2obj_slice(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1040 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1041 | "lower", |
| 1042 | "upper", |
| 1043 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1044 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1045 | static const char * const ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1046 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1047 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1048 | static const char * const Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1049 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1050 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1051 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1052 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1053 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1054 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1055 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1056 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1057 | "target", |
| 1058 | "iter", |
| 1059 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1060 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1061 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1062 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1063 | "lineno", |
| 1064 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1065 | "end_lineno", |
| 1066 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1067 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1068 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1069 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1070 | "type", |
| 1071 | "name", |
| 1072 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1073 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1074 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1075 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1076 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1077 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1078 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1079 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1080 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1081 | "kwarg", |
| 1082 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1083 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1084 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1085 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1086 | "lineno", |
| 1087 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1088 | "end_lineno", |
| 1089 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1090 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1091 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1092 | "arg", |
| 1093 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1094 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1095 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1096 | static PyObject* ast2obj_keyword(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1097 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1098 | "arg", |
| 1099 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1100 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1101 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1102 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1103 | "name", |
| 1104 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1105 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1106 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1107 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1108 | "context_expr", |
| 1109 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1110 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1111 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1112 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1113 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1114 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1115 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1116 | |
| 1117 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1118 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1119 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1120 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1121 | PyObject *dict; |
| 1122 | } AST_object; |
| 1123 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1124 | static void |
| 1125 | ast_dealloc(AST_object *self) |
| 1126 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1127 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1128 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1129 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1130 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1131 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1132 | assert(free_func != NULL); |
| 1133 | free_func(self); |
| 1134 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1135 | } |
| 1136 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1137 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1138 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1139 | { |
| 1140 | Py_VISIT(self->dict); |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1144 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1145 | ast_clear(AST_object *self) |
| 1146 | { |
| 1147 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1148 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1152 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1153 | { |
| 1154 | Py_ssize_t i, numfields = 0; |
| 1155 | int res = -1; |
| 1156 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1157 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1158 | goto cleanup; |
| 1159 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1160 | if (fields) { |
| 1161 | numfields = PySequence_Size(fields); |
| 1162 | if (numfields == -1) |
| 1163 | goto cleanup; |
| 1164 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1165 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1166 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1167 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1168 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1169 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1170 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1171 | numfields, numfields == 1 ? "" : "s"); |
| 1172 | res = -1; |
| 1173 | goto cleanup; |
| 1174 | } |
| 1175 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1176 | /* cannot be reached when fields is NULL */ |
| 1177 | PyObject *name = PySequence_GetItem(fields, i); |
| 1178 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1179 | res = -1; |
| 1180 | goto cleanup; |
| 1181 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1182 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1183 | Py_DECREF(name); |
| 1184 | if (res < 0) |
| 1185 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1186 | } |
| 1187 | if (kw) { |
| 1188 | i = 0; /* needed by PyDict_Next */ |
| 1189 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1190 | res = PyObject_SetAttr(self, key, value); |
| 1191 | if (res < 0) |
| 1192 | goto cleanup; |
| 1193 | } |
| 1194 | } |
| 1195 | cleanup: |
| 1196 | Py_XDECREF(fields); |
| 1197 | return res; |
| 1198 | } |
| 1199 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1200 | /* Pickling support */ |
| 1201 | static PyObject * |
| 1202 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1203 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1204 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1205 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1206 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1207 | } |
| 1208 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1209 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1210 | } |
| 1211 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1212 | } |
| 1213 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1214 | static PyMemberDef ast_type_members[] = { |
| 1215 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1216 | {NULL} /* Sentinel */ |
| 1217 | }; |
| 1218 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 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}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1235 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1236 | {Py_tp_methods, ast_type_methods}, |
| 1237 | {Py_tp_getset, ast_type_getsets}, |
| 1238 | {Py_tp_init, ast_type_init}, |
| 1239 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1240 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 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; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1424 | if (add_ast_fields() < 0) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1425 | state->mod_type = make_type("mod", state->AST_type, NULL, 0); |
| 1426 | if (!state->mod_type) return 0; |
| 1427 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
| 1428 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2); |
| 1429 | if (!state->Module_type) return 0; |
| 1430 | state->Interactive_type = make_type("Interactive", state->mod_type, |
| 1431 | Interactive_fields, 1); |
| 1432 | if (!state->Interactive_type) return 0; |
| 1433 | state->Expression_type = make_type("Expression", state->mod_type, |
| 1434 | Expression_fields, 1); |
| 1435 | if (!state->Expression_type) return 0; |
| 1436 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
| 1437 | FunctionType_fields, 2); |
| 1438 | if (!state->FunctionType_type) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1439 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0); |
| 1440 | if (!state->stmt_type) return 0; |
| 1441 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1442 | if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) |
| 1443 | return 0; |
| 1444 | if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == |
| 1445 | -1) |
| 1446 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1447 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
| 1448 | FunctionDef_fields, 6); |
| 1449 | if (!state->FunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1450 | if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == |
| 1451 | -1) |
| 1452 | return 0; |
| 1453 | if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) |
| 1454 | == -1) |
| 1455 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1456 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1457 | state->stmt_type, |
| 1458 | AsyncFunctionDef_fields, 6); |
| 1459 | if (!state->AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1460 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) |
| 1461 | == -1) |
| 1462 | return 0; |
| 1463 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, |
| 1464 | Py_None) == -1) |
| 1465 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1466 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
| 1467 | ClassDef_fields, 5); |
| 1468 | if (!state->ClassDef_type) return 0; |
| 1469 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, |
| 1470 | 1); |
| 1471 | if (!state->Return_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1472 | if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) |
| 1473 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1474 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, |
| 1475 | 1); |
| 1476 | if (!state->Delete_type) return 0; |
| 1477 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, |
| 1478 | 3); |
| 1479 | if (!state->Assign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1480 | if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == |
| 1481 | -1) |
| 1482 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1483 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
| 1484 | AugAssign_fields, 3); |
| 1485 | if (!state->AugAssign_type) return 0; |
| 1486 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
| 1487 | AnnAssign_fields, 4); |
| 1488 | if (!state->AnnAssign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1489 | if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) |
| 1490 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1491 | state->For_type = make_type("For", state->stmt_type, For_fields, 5); |
| 1492 | if (!state->For_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1493 | if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) |
| 1494 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1495 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
| 1496 | AsyncFor_fields, 5); |
| 1497 | if (!state->AsyncFor_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1498 | if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == |
| 1499 | -1) |
| 1500 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1501 | state->While_type = make_type("While", state->stmt_type, While_fields, 3); |
| 1502 | if (!state->While_type) return 0; |
| 1503 | state->If_type = make_type("If", state->stmt_type, If_fields, 3); |
| 1504 | if (!state->If_type) return 0; |
| 1505 | state->With_type = make_type("With", state->stmt_type, With_fields, 3); |
| 1506 | if (!state->With_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1507 | if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) |
| 1508 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1509 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
| 1510 | AsyncWith_fields, 3); |
| 1511 | if (!state->AsyncWith_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1512 | if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) |
| 1513 | == -1) |
| 1514 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1515 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2); |
| 1516 | if (!state->Raise_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1517 | if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) |
| 1518 | return 0; |
| 1519 | if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) |
| 1520 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1521 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4); |
| 1522 | if (!state->Try_type) return 0; |
| 1523 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, |
| 1524 | 2); |
| 1525 | if (!state->Assert_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1526 | if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) |
| 1527 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1528 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, |
| 1529 | 1); |
| 1530 | if (!state->Import_type) return 0; |
| 1531 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
| 1532 | ImportFrom_fields, 3); |
| 1533 | if (!state->ImportFrom_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1534 | if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) |
| 1535 | return 0; |
| 1536 | if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) |
| 1537 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1538 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, |
| 1539 | 1); |
| 1540 | if (!state->Global_type) return 0; |
| 1541 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
| 1542 | Nonlocal_fields, 1); |
| 1543 | if (!state->Nonlocal_type) return 0; |
| 1544 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1); |
| 1545 | if (!state->Expr_type) return 0; |
| 1546 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0); |
| 1547 | if (!state->Pass_type) return 0; |
| 1548 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0); |
| 1549 | if (!state->Break_type) return 0; |
| 1550 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0); |
| 1551 | if (!state->Continue_type) return 0; |
| 1552 | state->expr_type = make_type("expr", state->AST_type, NULL, 0); |
| 1553 | if (!state->expr_type) return 0; |
| 1554 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1555 | if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) |
| 1556 | return 0; |
| 1557 | if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == |
| 1558 | -1) |
| 1559 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1560 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, |
| 1561 | 2); |
| 1562 | if (!state->BoolOp_type) return 0; |
| 1563 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
| 1564 | NamedExpr_fields, 2); |
| 1565 | if (!state->NamedExpr_type) return 0; |
| 1566 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3); |
| 1567 | if (!state->BinOp_type) return 0; |
| 1568 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
| 1569 | UnaryOp_fields, 2); |
| 1570 | if (!state->UnaryOp_type) return 0; |
| 1571 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, |
| 1572 | 2); |
| 1573 | if (!state->Lambda_type) return 0; |
| 1574 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3); |
| 1575 | if (!state->IfExp_type) return 0; |
| 1576 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2); |
| 1577 | if (!state->Dict_type) return 0; |
| 1578 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1); |
| 1579 | if (!state->Set_type) return 0; |
| 1580 | state->ListComp_type = make_type("ListComp", state->expr_type, |
| 1581 | ListComp_fields, 2); |
| 1582 | if (!state->ListComp_type) return 0; |
| 1583 | state->SetComp_type = make_type("SetComp", state->expr_type, |
| 1584 | SetComp_fields, 2); |
| 1585 | if (!state->SetComp_type) return 0; |
| 1586 | state->DictComp_type = make_type("DictComp", state->expr_type, |
| 1587 | DictComp_fields, 3); |
| 1588 | if (!state->DictComp_type) return 0; |
| 1589 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
| 1590 | GeneratorExp_fields, 2); |
| 1591 | if (!state->GeneratorExp_type) return 0; |
| 1592 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1); |
| 1593 | if (!state->Await_type) return 0; |
| 1594 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1); |
| 1595 | if (!state->Yield_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1596 | if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) |
| 1597 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1598 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
| 1599 | YieldFrom_fields, 1); |
| 1600 | if (!state->YieldFrom_type) return 0; |
| 1601 | state->Compare_type = make_type("Compare", state->expr_type, |
| 1602 | Compare_fields, 3); |
| 1603 | if (!state->Compare_type) return 0; |
| 1604 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3); |
| 1605 | if (!state->Call_type) return 0; |
| 1606 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
| 1607 | FormattedValue_fields, 3); |
| 1608 | if (!state->FormattedValue_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1609 | if (PyObject_SetAttr(state->FormattedValue_type, state->conversion, |
| 1610 | Py_None) == -1) |
| 1611 | return 0; |
| 1612 | if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, |
| 1613 | Py_None) == -1) |
| 1614 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1615 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
| 1616 | JoinedStr_fields, 1); |
| 1617 | if (!state->JoinedStr_type) return 0; |
| 1618 | state->Constant_type = make_type("Constant", state->expr_type, |
| 1619 | Constant_fields, 2); |
| 1620 | if (!state->Constant_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1621 | if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) |
| 1622 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1623 | state->Attribute_type = make_type("Attribute", state->expr_type, |
| 1624 | Attribute_fields, 3); |
| 1625 | if (!state->Attribute_type) return 0; |
| 1626 | state->Subscript_type = make_type("Subscript", state->expr_type, |
| 1627 | Subscript_fields, 3); |
| 1628 | if (!state->Subscript_type) return 0; |
| 1629 | state->Starred_type = make_type("Starred", state->expr_type, |
| 1630 | Starred_fields, 2); |
| 1631 | if (!state->Starred_type) return 0; |
| 1632 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2); |
| 1633 | if (!state->Name_type) return 0; |
| 1634 | state->List_type = make_type("List", state->expr_type, List_fields, 2); |
| 1635 | if (!state->List_type) return 0; |
| 1636 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2); |
| 1637 | if (!state->Tuple_type) return 0; |
| 1638 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
| 1639 | 0); |
| 1640 | if (!state->expr_context_type) return 0; |
| 1641 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
| 1642 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0); |
| 1643 | if (!state->Load_type) return 0; |
| 1644 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1645 | NULL, NULL); |
| 1646 | if (!state->Load_singleton) return 0; |
| 1647 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0); |
| 1648 | if (!state->Store_type) return 0; |
| 1649 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1650 | *)state->Store_type, NULL, NULL); |
| 1651 | if (!state->Store_singleton) return 0; |
| 1652 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0); |
| 1653 | if (!state->Del_type) return 0; |
| 1654 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1655 | NULL, NULL); |
| 1656 | if (!state->Del_singleton) return 0; |
| 1657 | state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL, |
| 1658 | 0); |
| 1659 | if (!state->AugLoad_type) return 0; |
| 1660 | state->AugLoad_singleton = PyType_GenericNew((PyTypeObject |
| 1661 | *)state->AugLoad_type, NULL, |
| 1662 | NULL); |
| 1663 | if (!state->AugLoad_singleton) return 0; |
| 1664 | state->AugStore_type = make_type("AugStore", state->expr_context_type, |
| 1665 | NULL, 0); |
| 1666 | if (!state->AugStore_type) return 0; |
| 1667 | state->AugStore_singleton = PyType_GenericNew((PyTypeObject |
| 1668 | *)state->AugStore_type, NULL, |
| 1669 | NULL); |
| 1670 | if (!state->AugStore_singleton) return 0; |
| 1671 | state->Param_type = make_type("Param", state->expr_context_type, NULL, 0); |
| 1672 | if (!state->Param_type) return 0; |
| 1673 | state->Param_singleton = PyType_GenericNew((PyTypeObject |
| 1674 | *)state->Param_type, NULL, NULL); |
| 1675 | if (!state->Param_singleton) return 0; |
| 1676 | state->slice_type = make_type("slice", state->AST_type, NULL, 0); |
| 1677 | if (!state->slice_type) return 0; |
| 1678 | if (!add_attributes(state->slice_type, NULL, 0)) return 0; |
| 1679 | state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3); |
| 1680 | if (!state->Slice_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1681 | if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) |
| 1682 | return 0; |
| 1683 | if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1) |
| 1684 | return 0; |
| 1685 | if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) |
| 1686 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1687 | state->ExtSlice_type = make_type("ExtSlice", state->slice_type, |
| 1688 | ExtSlice_fields, 1); |
| 1689 | if (!state->ExtSlice_type) return 0; |
| 1690 | state->Index_type = make_type("Index", state->slice_type, Index_fields, 1); |
| 1691 | if (!state->Index_type) return 0; |
| 1692 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0); |
| 1693 | if (!state->boolop_type) return 0; |
| 1694 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
| 1695 | state->And_type = make_type("And", state->boolop_type, NULL, 0); |
| 1696 | if (!state->And_type) return 0; |
| 1697 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1698 | NULL, NULL); |
| 1699 | if (!state->And_singleton) return 0; |
| 1700 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0); |
| 1701 | if (!state->Or_type) return 0; |
| 1702 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1703 | NULL, NULL); |
| 1704 | if (!state->Or_singleton) return 0; |
| 1705 | state->operator_type = make_type("operator", state->AST_type, NULL, 0); |
| 1706 | if (!state->operator_type) return 0; |
| 1707 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
| 1708 | state->Add_type = make_type("Add", state->operator_type, NULL, 0); |
| 1709 | if (!state->Add_type) return 0; |
| 1710 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1711 | NULL, NULL); |
| 1712 | if (!state->Add_singleton) return 0; |
| 1713 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0); |
| 1714 | if (!state->Sub_type) return 0; |
| 1715 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1716 | NULL, NULL); |
| 1717 | if (!state->Sub_singleton) return 0; |
| 1718 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0); |
| 1719 | if (!state->Mult_type) return 0; |
| 1720 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1721 | NULL, NULL); |
| 1722 | if (!state->Mult_singleton) return 0; |
| 1723 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0); |
| 1724 | if (!state->MatMult_type) return 0; |
| 1725 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1726 | *)state->MatMult_type, NULL, |
| 1727 | NULL); |
| 1728 | if (!state->MatMult_singleton) return 0; |
| 1729 | state->Div_type = make_type("Div", state->operator_type, NULL, 0); |
| 1730 | if (!state->Div_type) return 0; |
| 1731 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1732 | NULL, NULL); |
| 1733 | if (!state->Div_singleton) return 0; |
| 1734 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0); |
| 1735 | if (!state->Mod_type) return 0; |
| 1736 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1737 | NULL, NULL); |
| 1738 | if (!state->Mod_singleton) return 0; |
| 1739 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0); |
| 1740 | if (!state->Pow_type) return 0; |
| 1741 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1742 | NULL, NULL); |
| 1743 | if (!state->Pow_singleton) return 0; |
| 1744 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0); |
| 1745 | if (!state->LShift_type) return 0; |
| 1746 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1747 | *)state->LShift_type, NULL, |
| 1748 | NULL); |
| 1749 | if (!state->LShift_singleton) return 0; |
| 1750 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0); |
| 1751 | if (!state->RShift_type) return 0; |
| 1752 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1753 | *)state->RShift_type, NULL, |
| 1754 | NULL); |
| 1755 | if (!state->RShift_singleton) return 0; |
| 1756 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0); |
| 1757 | if (!state->BitOr_type) return 0; |
| 1758 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1759 | *)state->BitOr_type, NULL, NULL); |
| 1760 | if (!state->BitOr_singleton) return 0; |
| 1761 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0); |
| 1762 | if (!state->BitXor_type) return 0; |
| 1763 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1764 | *)state->BitXor_type, NULL, |
| 1765 | NULL); |
| 1766 | if (!state->BitXor_singleton) return 0; |
| 1767 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0); |
| 1768 | if (!state->BitAnd_type) return 0; |
| 1769 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1770 | *)state->BitAnd_type, NULL, |
| 1771 | NULL); |
| 1772 | if (!state->BitAnd_singleton) return 0; |
| 1773 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0); |
| 1774 | if (!state->FloorDiv_type) return 0; |
| 1775 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1776 | *)state->FloorDiv_type, NULL, |
| 1777 | NULL); |
| 1778 | if (!state->FloorDiv_singleton) return 0; |
| 1779 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0); |
| 1780 | if (!state->unaryop_type) return 0; |
| 1781 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
| 1782 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0); |
| 1783 | if (!state->Invert_type) return 0; |
| 1784 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1785 | *)state->Invert_type, NULL, |
| 1786 | NULL); |
| 1787 | if (!state->Invert_singleton) return 0; |
| 1788 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0); |
| 1789 | if (!state->Not_type) return 0; |
| 1790 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1791 | NULL, NULL); |
| 1792 | if (!state->Not_singleton) return 0; |
| 1793 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0); |
| 1794 | if (!state->UAdd_type) return 0; |
| 1795 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1796 | NULL, NULL); |
| 1797 | if (!state->UAdd_singleton) return 0; |
| 1798 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0); |
| 1799 | if (!state->USub_type) return 0; |
| 1800 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1801 | NULL, NULL); |
| 1802 | if (!state->USub_singleton) return 0; |
| 1803 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0); |
| 1804 | if (!state->cmpop_type) return 0; |
| 1805 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
| 1806 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0); |
| 1807 | if (!state->Eq_type) return 0; |
| 1808 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1809 | NULL, NULL); |
| 1810 | if (!state->Eq_singleton) return 0; |
| 1811 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0); |
| 1812 | if (!state->NotEq_type) return 0; |
| 1813 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1814 | *)state->NotEq_type, NULL, NULL); |
| 1815 | if (!state->NotEq_singleton) return 0; |
| 1816 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0); |
| 1817 | if (!state->Lt_type) return 0; |
| 1818 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1819 | NULL, NULL); |
| 1820 | if (!state->Lt_singleton) return 0; |
| 1821 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0); |
| 1822 | if (!state->LtE_type) return 0; |
| 1823 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1824 | NULL, NULL); |
| 1825 | if (!state->LtE_singleton) return 0; |
| 1826 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0); |
| 1827 | if (!state->Gt_type) return 0; |
| 1828 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1829 | NULL, NULL); |
| 1830 | if (!state->Gt_singleton) return 0; |
| 1831 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0); |
| 1832 | if (!state->GtE_type) return 0; |
| 1833 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1834 | NULL, NULL); |
| 1835 | if (!state->GtE_singleton) return 0; |
| 1836 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0); |
| 1837 | if (!state->Is_type) return 0; |
| 1838 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1839 | NULL, NULL); |
| 1840 | if (!state->Is_singleton) return 0; |
| 1841 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0); |
| 1842 | if (!state->IsNot_type) return 0; |
| 1843 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1844 | *)state->IsNot_type, NULL, NULL); |
| 1845 | if (!state->IsNot_singleton) return 0; |
| 1846 | state->In_type = make_type("In", state->cmpop_type, NULL, 0); |
| 1847 | if (!state->In_type) return 0; |
| 1848 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1849 | NULL, NULL); |
| 1850 | if (!state->In_singleton) return 0; |
| 1851 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0); |
| 1852 | if (!state->NotIn_type) return 0; |
| 1853 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1854 | *)state->NotIn_type, NULL, NULL); |
| 1855 | if (!state->NotIn_singleton) return 0; |
| 1856 | state->comprehension_type = make_type("comprehension", state->AST_type, |
| 1857 | comprehension_fields, 4); |
| 1858 | if (!state->comprehension_type) return 0; |
| 1859 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1860 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
| 1861 | NULL, 0); |
| 1862 | if (!state->excepthandler_type) return 0; |
| 1863 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1864 | 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1865 | if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) |
| 1866 | == -1) |
| 1867 | return 0; |
| 1868 | if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, |
| 1869 | Py_None) == -1) |
| 1870 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1871 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1872 | state->excepthandler_type, |
| 1873 | ExceptHandler_fields, 3); |
| 1874 | if (!state->ExceptHandler_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1875 | if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1) |
| 1876 | return 0; |
| 1877 | if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) |
| 1878 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1879 | state->arguments_type = make_type("arguments", state->AST_type, |
| 1880 | arguments_fields, 7); |
| 1881 | if (!state->arguments_type) return 0; |
| 1882 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1883 | if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) |
| 1884 | return 0; |
| 1885 | if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) |
| 1886 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1887 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3); |
| 1888 | if (!state->arg_type) return 0; |
| 1889 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1890 | if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) |
| 1891 | return 0; |
| 1892 | if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) |
| 1893 | return 0; |
| 1894 | if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1) |
| 1895 | return 0; |
| 1896 | if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) |
| 1897 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1898 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
| 1899 | 2); |
| 1900 | if (!state->keyword_type) return 0; |
| 1901 | if (!add_attributes(state->keyword_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1902 | if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) |
| 1903 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1904 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2); |
| 1905 | if (!state->alias_type) return 0; |
| 1906 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1907 | if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) |
| 1908 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1909 | state->withitem_type = make_type("withitem", state->AST_type, |
| 1910 | withitem_fields, 2); |
| 1911 | if (!state->withitem_type) return 0; |
| 1912 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1913 | if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) |
| 1914 | == -1) |
| 1915 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1916 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, |
| 1917 | 0); |
| 1918 | if (!state->type_ignore_type) return 0; |
| 1919 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 1920 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
| 1921 | TypeIgnore_fields, 2); |
| 1922 | if (!state->TypeIgnore_type) return 0; |
| 1923 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1924 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1925 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1926 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1927 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1928 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1929 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1930 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1931 | arena); |
| 1932 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1933 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1934 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1935 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1936 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1937 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1938 | arena); |
| 1939 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1940 | arena); |
| 1941 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1942 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1943 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1944 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1945 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1946 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1947 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1948 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1949 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1950 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1951 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1952 | mod_ty p; |
| 1953 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1954 | if (!p) |
| 1955 | return NULL; |
| 1956 | p->kind = Module_kind; |
| 1957 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1958 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1959 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1963 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1964 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1965 | mod_ty p; |
| 1966 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1967 | if (!p) |
| 1968 | return NULL; |
| 1969 | p->kind = Interactive_kind; |
| 1970 | p->v.Interactive.body = body; |
| 1971 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1975 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1976 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1977 | mod_ty p; |
| 1978 | if (!body) { |
| 1979 | PyErr_SetString(PyExc_ValueError, |
| 1980 | "field body is required for Expression"); |
| 1981 | return NULL; |
| 1982 | } |
| 1983 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1984 | if (!p) |
| 1985 | return NULL; |
| 1986 | p->kind = Expression_kind; |
| 1987 | p->v.Expression.body = body; |
| 1988 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1992 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1993 | { |
| 1994 | mod_ty p; |
| 1995 | if (!returns) { |
| 1996 | PyErr_SetString(PyExc_ValueError, |
| 1997 | "field returns is required for FunctionType"); |
| 1998 | return NULL; |
| 1999 | } |
| 2000 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2001 | if (!p) |
| 2002 | return NULL; |
| 2003 | p->kind = FunctionType_kind; |
| 2004 | p->v.FunctionType.argtypes = argtypes; |
| 2005 | p->v.FunctionType.returns = returns; |
| 2006 | return p; |
| 2007 | } |
| 2008 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2009 | stmt_ty |
| 2010 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2011 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 2012 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2013 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2014 | stmt_ty p; |
| 2015 | if (!name) { |
| 2016 | PyErr_SetString(PyExc_ValueError, |
| 2017 | "field name is required for FunctionDef"); |
| 2018 | return NULL; |
| 2019 | } |
| 2020 | if (!args) { |
| 2021 | PyErr_SetString(PyExc_ValueError, |
| 2022 | "field args is required for FunctionDef"); |
| 2023 | return NULL; |
| 2024 | } |
| 2025 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2026 | if (!p) |
| 2027 | return NULL; |
| 2028 | p->kind = FunctionDef_kind; |
| 2029 | p->v.FunctionDef.name = name; |
| 2030 | p->v.FunctionDef.args = args; |
| 2031 | p->v.FunctionDef.body = body; |
| 2032 | p->v.FunctionDef.decorator_list = decorator_list; |
| 2033 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2034 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 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 |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2043 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2044 | * decorator_list, expr_ty returns, string type_comment, int |
| 2045 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2046 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2047 | { |
| 2048 | stmt_ty p; |
| 2049 | if (!name) { |
| 2050 | PyErr_SetString(PyExc_ValueError, |
| 2051 | "field name is required for AsyncFunctionDef"); |
| 2052 | return NULL; |
| 2053 | } |
| 2054 | if (!args) { |
| 2055 | PyErr_SetString(PyExc_ValueError, |
| 2056 | "field args is required for AsyncFunctionDef"); |
| 2057 | return NULL; |
| 2058 | } |
| 2059 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2060 | if (!p) |
| 2061 | return NULL; |
| 2062 | p->kind = AsyncFunctionDef_kind; |
| 2063 | p->v.AsyncFunctionDef.name = name; |
| 2064 | p->v.AsyncFunctionDef.args = args; |
| 2065 | p->v.AsyncFunctionDef.body = body; |
| 2066 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 2067 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2068 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2069 | p->lineno = lineno; |
| 2070 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2071 | p->end_lineno = end_lineno; |
| 2072 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2073 | return p; |
| 2074 | } |
| 2075 | |
| 2076 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2077 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2078 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2079 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2080 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2081 | stmt_ty p; |
| 2082 | if (!name) { |
| 2083 | PyErr_SetString(PyExc_ValueError, |
| 2084 | "field name is required for ClassDef"); |
| 2085 | return NULL; |
| 2086 | } |
| 2087 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2088 | if (!p) |
| 2089 | return NULL; |
| 2090 | p->kind = ClassDef_kind; |
| 2091 | p->v.ClassDef.name = name; |
| 2092 | p->v.ClassDef.bases = bases; |
| 2093 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2094 | p->v.ClassDef.body = body; |
| 2095 | p->v.ClassDef.decorator_list = decorator_list; |
| 2096 | p->lineno = lineno; |
| 2097 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2098 | p->end_lineno = end_lineno; |
| 2099 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2100 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2104 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2105 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2106 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2107 | stmt_ty p; |
| 2108 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2109 | if (!p) |
| 2110 | return NULL; |
| 2111 | p->kind = Return_kind; |
| 2112 | p->v.Return.value = value; |
| 2113 | p->lineno = lineno; |
| 2114 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2115 | p->end_lineno = end_lineno; |
| 2116 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2117 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2121 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2122 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2123 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2124 | stmt_ty p; |
| 2125 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2126 | if (!p) |
| 2127 | return NULL; |
| 2128 | p->kind = Delete_kind; |
| 2129 | p->v.Delete.targets = targets; |
| 2130 | p->lineno = lineno; |
| 2131 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2132 | p->end_lineno = end_lineno; |
| 2133 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2134 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2138 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2139 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2140 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2141 | stmt_ty p; |
| 2142 | if (!value) { |
| 2143 | PyErr_SetString(PyExc_ValueError, |
| 2144 | "field value is required for Assign"); |
| 2145 | return NULL; |
| 2146 | } |
| 2147 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2148 | if (!p) |
| 2149 | return NULL; |
| 2150 | p->kind = Assign_kind; |
| 2151 | p->v.Assign.targets = targets; |
| 2152 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2153 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2154 | p->lineno = lineno; |
| 2155 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2156 | p->end_lineno = end_lineno; |
| 2157 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2158 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2162 | 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] | 2163 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2164 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2165 | stmt_ty p; |
| 2166 | if (!target) { |
| 2167 | PyErr_SetString(PyExc_ValueError, |
| 2168 | "field target is required for AugAssign"); |
| 2169 | return NULL; |
| 2170 | } |
| 2171 | if (!op) { |
| 2172 | PyErr_SetString(PyExc_ValueError, |
| 2173 | "field op is required for AugAssign"); |
| 2174 | return NULL; |
| 2175 | } |
| 2176 | if (!value) { |
| 2177 | PyErr_SetString(PyExc_ValueError, |
| 2178 | "field value is required for AugAssign"); |
| 2179 | return NULL; |
| 2180 | } |
| 2181 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2182 | if (!p) |
| 2183 | return NULL; |
| 2184 | p->kind = AugAssign_kind; |
| 2185 | p->v.AugAssign.target = target; |
| 2186 | p->v.AugAssign.op = op; |
| 2187 | p->v.AugAssign.value = value; |
| 2188 | p->lineno = lineno; |
| 2189 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2190 | p->end_lineno = end_lineno; |
| 2191 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2192 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2196 | 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] | 2197 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2198 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2199 | { |
| 2200 | stmt_ty p; |
| 2201 | if (!target) { |
| 2202 | PyErr_SetString(PyExc_ValueError, |
| 2203 | "field target is required for AnnAssign"); |
| 2204 | return NULL; |
| 2205 | } |
| 2206 | if (!annotation) { |
| 2207 | PyErr_SetString(PyExc_ValueError, |
| 2208 | "field annotation is required for AnnAssign"); |
| 2209 | return NULL; |
| 2210 | } |
| 2211 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2212 | if (!p) |
| 2213 | return NULL; |
| 2214 | p->kind = AnnAssign_kind; |
| 2215 | p->v.AnnAssign.target = target; |
| 2216 | p->v.AnnAssign.annotation = annotation; |
| 2217 | p->v.AnnAssign.value = value; |
| 2218 | p->v.AnnAssign.simple = simple; |
| 2219 | p->lineno = lineno; |
| 2220 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2221 | p->end_lineno = end_lineno; |
| 2222 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2223 | return p; |
| 2224 | } |
| 2225 | |
| 2226 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2227 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2228 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2229 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2230 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2231 | stmt_ty p; |
| 2232 | if (!target) { |
| 2233 | PyErr_SetString(PyExc_ValueError, |
| 2234 | "field target is required for For"); |
| 2235 | return NULL; |
| 2236 | } |
| 2237 | if (!iter) { |
| 2238 | PyErr_SetString(PyExc_ValueError, |
| 2239 | "field iter is required for For"); |
| 2240 | return NULL; |
| 2241 | } |
| 2242 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2243 | if (!p) |
| 2244 | return NULL; |
| 2245 | p->kind = For_kind; |
| 2246 | p->v.For.target = target; |
| 2247 | p->v.For.iter = iter; |
| 2248 | p->v.For.body = body; |
| 2249 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2250 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2251 | p->lineno = lineno; |
| 2252 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2253 | p->end_lineno = end_lineno; |
| 2254 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2255 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2259 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2260 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2261 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2262 | { |
| 2263 | stmt_ty p; |
| 2264 | if (!target) { |
| 2265 | PyErr_SetString(PyExc_ValueError, |
| 2266 | "field target is required for AsyncFor"); |
| 2267 | return NULL; |
| 2268 | } |
| 2269 | if (!iter) { |
| 2270 | PyErr_SetString(PyExc_ValueError, |
| 2271 | "field iter is required for AsyncFor"); |
| 2272 | return NULL; |
| 2273 | } |
| 2274 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2275 | if (!p) |
| 2276 | return NULL; |
| 2277 | p->kind = AsyncFor_kind; |
| 2278 | p->v.AsyncFor.target = target; |
| 2279 | p->v.AsyncFor.iter = iter; |
| 2280 | p->v.AsyncFor.body = body; |
| 2281 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2282 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2283 | p->lineno = lineno; |
| 2284 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2285 | p->end_lineno = end_lineno; |
| 2286 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2287 | return p; |
| 2288 | } |
| 2289 | |
| 2290 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2291 | 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] | 2292 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2293 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2294 | stmt_ty p; |
| 2295 | if (!test) { |
| 2296 | PyErr_SetString(PyExc_ValueError, |
| 2297 | "field test is required for While"); |
| 2298 | return NULL; |
| 2299 | } |
| 2300 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2301 | if (!p) |
| 2302 | return NULL; |
| 2303 | p->kind = While_kind; |
| 2304 | p->v.While.test = test; |
| 2305 | p->v.While.body = body; |
| 2306 | p->v.While.orelse = orelse; |
| 2307 | p->lineno = lineno; |
| 2308 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2309 | p->end_lineno = end_lineno; |
| 2310 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2311 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2315 | 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] | 2316 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2317 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2318 | stmt_ty p; |
| 2319 | if (!test) { |
| 2320 | PyErr_SetString(PyExc_ValueError, |
| 2321 | "field test is required for If"); |
| 2322 | return NULL; |
| 2323 | } |
| 2324 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2325 | if (!p) |
| 2326 | return NULL; |
| 2327 | p->kind = If_kind; |
| 2328 | p->v.If.test = test; |
| 2329 | p->v.If.body = body; |
| 2330 | p->v.If.orelse = orelse; |
| 2331 | p->lineno = lineno; |
| 2332 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2333 | p->end_lineno = end_lineno; |
| 2334 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2335 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2339 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2340 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2341 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2342 | stmt_ty p; |
| 2343 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2344 | if (!p) |
| 2345 | return NULL; |
| 2346 | p->kind = With_kind; |
| 2347 | p->v.With.items = items; |
| 2348 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2349 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2350 | p->lineno = lineno; |
| 2351 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2352 | p->end_lineno = end_lineno; |
| 2353 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2354 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2358 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2359 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2360 | { |
| 2361 | stmt_ty p; |
| 2362 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2363 | if (!p) |
| 2364 | return NULL; |
| 2365 | p->kind = AsyncWith_kind; |
| 2366 | p->v.AsyncWith.items = items; |
| 2367 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2368 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2369 | p->lineno = lineno; |
| 2370 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2371 | p->end_lineno = end_lineno; |
| 2372 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2373 | return p; |
| 2374 | } |
| 2375 | |
| 2376 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2377 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2378 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2379 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2380 | stmt_ty p; |
| 2381 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2382 | if (!p) |
| 2383 | return NULL; |
| 2384 | p->kind = Raise_kind; |
| 2385 | p->v.Raise.exc = exc; |
| 2386 | p->v.Raise.cause = cause; |
| 2387 | p->lineno = lineno; |
| 2388 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2389 | p->end_lineno = end_lineno; |
| 2390 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2391 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2395 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2396 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2397 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2398 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2399 | stmt_ty p; |
| 2400 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2401 | if (!p) |
| 2402 | return NULL; |
| 2403 | p->kind = Try_kind; |
| 2404 | p->v.Try.body = body; |
| 2405 | p->v.Try.handlers = handlers; |
| 2406 | p->v.Try.orelse = orelse; |
| 2407 | p->v.Try.finalbody = finalbody; |
| 2408 | p->lineno = lineno; |
| 2409 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2410 | p->end_lineno = end_lineno; |
| 2411 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2412 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2416 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2417 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2418 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2419 | stmt_ty p; |
| 2420 | if (!test) { |
| 2421 | PyErr_SetString(PyExc_ValueError, |
| 2422 | "field test is required for Assert"); |
| 2423 | return NULL; |
| 2424 | } |
| 2425 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2426 | if (!p) |
| 2427 | return NULL; |
| 2428 | p->kind = Assert_kind; |
| 2429 | p->v.Assert.test = test; |
| 2430 | p->v.Assert.msg = msg; |
| 2431 | p->lineno = lineno; |
| 2432 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2433 | p->end_lineno = end_lineno; |
| 2434 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2435 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2439 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2440 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2441 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2442 | stmt_ty p; |
| 2443 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2444 | if (!p) |
| 2445 | return NULL; |
| 2446 | p->kind = Import_kind; |
| 2447 | p->v.Import.names = names; |
| 2448 | p->lineno = lineno; |
| 2449 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2450 | p->end_lineno = end_lineno; |
| 2451 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2452 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2456 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2457 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2458 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2459 | stmt_ty p; |
| 2460 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2461 | if (!p) |
| 2462 | return NULL; |
| 2463 | p->kind = ImportFrom_kind; |
| 2464 | p->v.ImportFrom.module = module; |
| 2465 | p->v.ImportFrom.names = names; |
| 2466 | p->v.ImportFrom.level = level; |
| 2467 | p->lineno = lineno; |
| 2468 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2469 | p->end_lineno = end_lineno; |
| 2470 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2471 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2475 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2476 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2477 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2478 | stmt_ty p; |
| 2479 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2480 | if (!p) |
| 2481 | return NULL; |
| 2482 | p->kind = Global_kind; |
| 2483 | p->v.Global.names = names; |
| 2484 | p->lineno = lineno; |
| 2485 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2486 | p->end_lineno = end_lineno; |
| 2487 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2488 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2492 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2493 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2494 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2495 | stmt_ty p; |
| 2496 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2497 | if (!p) |
| 2498 | return NULL; |
| 2499 | p->kind = Nonlocal_kind; |
| 2500 | p->v.Nonlocal.names = names; |
| 2501 | p->lineno = lineno; |
| 2502 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2503 | p->end_lineno = end_lineno; |
| 2504 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2505 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2509 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2510 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2511 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2512 | stmt_ty p; |
| 2513 | if (!value) { |
| 2514 | PyErr_SetString(PyExc_ValueError, |
| 2515 | "field value is required for Expr"); |
| 2516 | return NULL; |
| 2517 | } |
| 2518 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2519 | if (!p) |
| 2520 | return NULL; |
| 2521 | p->kind = Expr_kind; |
| 2522 | p->v.Expr.value = value; |
| 2523 | p->lineno = lineno; |
| 2524 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2525 | p->end_lineno = end_lineno; |
| 2526 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2527 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2531 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2532 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2533 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2534 | stmt_ty p; |
| 2535 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2536 | if (!p) |
| 2537 | return NULL; |
| 2538 | p->kind = Pass_kind; |
| 2539 | p->lineno = lineno; |
| 2540 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2541 | p->end_lineno = end_lineno; |
| 2542 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2543 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2547 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2548 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2549 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2550 | stmt_ty p; |
| 2551 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2552 | if (!p) |
| 2553 | return NULL; |
| 2554 | p->kind = Break_kind; |
| 2555 | p->lineno = lineno; |
| 2556 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2557 | p->end_lineno = end_lineno; |
| 2558 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2559 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2563 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2564 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2565 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2566 | stmt_ty p; |
| 2567 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2568 | if (!p) |
| 2569 | return NULL; |
| 2570 | p->kind = Continue_kind; |
| 2571 | p->lineno = lineno; |
| 2572 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2573 | p->end_lineno = end_lineno; |
| 2574 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2575 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2579 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2580 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2581 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2582 | expr_ty p; |
| 2583 | if (!op) { |
| 2584 | PyErr_SetString(PyExc_ValueError, |
| 2585 | "field op is required for BoolOp"); |
| 2586 | return NULL; |
| 2587 | } |
| 2588 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2589 | if (!p) |
| 2590 | return NULL; |
| 2591 | p->kind = BoolOp_kind; |
| 2592 | p->v.BoolOp.op = op; |
| 2593 | p->v.BoolOp.values = values; |
| 2594 | p->lineno = lineno; |
| 2595 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2596 | p->end_lineno = end_lineno; |
| 2597 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2598 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2602 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2603 | end_lineno, int end_col_offset, PyArena *arena) |
| 2604 | { |
| 2605 | expr_ty p; |
| 2606 | if (!target) { |
| 2607 | PyErr_SetString(PyExc_ValueError, |
| 2608 | "field target is required for NamedExpr"); |
| 2609 | return NULL; |
| 2610 | } |
| 2611 | if (!value) { |
| 2612 | PyErr_SetString(PyExc_ValueError, |
| 2613 | "field value is required for NamedExpr"); |
| 2614 | return NULL; |
| 2615 | } |
| 2616 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2617 | if (!p) |
| 2618 | return NULL; |
| 2619 | p->kind = NamedExpr_kind; |
| 2620 | p->v.NamedExpr.target = target; |
| 2621 | p->v.NamedExpr.value = value; |
| 2622 | p->lineno = lineno; |
| 2623 | p->col_offset = col_offset; |
| 2624 | p->end_lineno = end_lineno; |
| 2625 | p->end_col_offset = end_col_offset; |
| 2626 | return p; |
| 2627 | } |
| 2628 | |
| 2629 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2630 | 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] | 2631 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2632 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2633 | expr_ty p; |
| 2634 | if (!left) { |
| 2635 | PyErr_SetString(PyExc_ValueError, |
| 2636 | "field left is required for BinOp"); |
| 2637 | return NULL; |
| 2638 | } |
| 2639 | if (!op) { |
| 2640 | PyErr_SetString(PyExc_ValueError, |
| 2641 | "field op is required for BinOp"); |
| 2642 | return NULL; |
| 2643 | } |
| 2644 | if (!right) { |
| 2645 | PyErr_SetString(PyExc_ValueError, |
| 2646 | "field right is required for BinOp"); |
| 2647 | return NULL; |
| 2648 | } |
| 2649 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2650 | if (!p) |
| 2651 | return NULL; |
| 2652 | p->kind = BinOp_kind; |
| 2653 | p->v.BinOp.left = left; |
| 2654 | p->v.BinOp.op = op; |
| 2655 | p->v.BinOp.right = right; |
| 2656 | p->lineno = lineno; |
| 2657 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2658 | p->end_lineno = end_lineno; |
| 2659 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2660 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2664 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2665 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2666 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2667 | expr_ty p; |
| 2668 | if (!op) { |
| 2669 | PyErr_SetString(PyExc_ValueError, |
| 2670 | "field op is required for UnaryOp"); |
| 2671 | return NULL; |
| 2672 | } |
| 2673 | if (!operand) { |
| 2674 | PyErr_SetString(PyExc_ValueError, |
| 2675 | "field operand is required for UnaryOp"); |
| 2676 | return NULL; |
| 2677 | } |
| 2678 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2679 | if (!p) |
| 2680 | return NULL; |
| 2681 | p->kind = UnaryOp_kind; |
| 2682 | p->v.UnaryOp.op = op; |
| 2683 | p->v.UnaryOp.operand = operand; |
| 2684 | p->lineno = lineno; |
| 2685 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2686 | p->end_lineno = end_lineno; |
| 2687 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2688 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2692 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2693 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2694 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2695 | expr_ty p; |
| 2696 | if (!args) { |
| 2697 | PyErr_SetString(PyExc_ValueError, |
| 2698 | "field args is required for Lambda"); |
| 2699 | return NULL; |
| 2700 | } |
| 2701 | if (!body) { |
| 2702 | PyErr_SetString(PyExc_ValueError, |
| 2703 | "field body is required for Lambda"); |
| 2704 | return NULL; |
| 2705 | } |
| 2706 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2707 | if (!p) |
| 2708 | return NULL; |
| 2709 | p->kind = Lambda_kind; |
| 2710 | p->v.Lambda.args = args; |
| 2711 | p->v.Lambda.body = body; |
| 2712 | p->lineno = lineno; |
| 2713 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2714 | p->end_lineno = end_lineno; |
| 2715 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2716 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2720 | 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] | 2721 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2722 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2723 | expr_ty p; |
| 2724 | if (!test) { |
| 2725 | PyErr_SetString(PyExc_ValueError, |
| 2726 | "field test is required for IfExp"); |
| 2727 | return NULL; |
| 2728 | } |
| 2729 | if (!body) { |
| 2730 | PyErr_SetString(PyExc_ValueError, |
| 2731 | "field body is required for IfExp"); |
| 2732 | return NULL; |
| 2733 | } |
| 2734 | if (!orelse) { |
| 2735 | PyErr_SetString(PyExc_ValueError, |
| 2736 | "field orelse is required for IfExp"); |
| 2737 | return NULL; |
| 2738 | } |
| 2739 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2740 | if (!p) |
| 2741 | return NULL; |
| 2742 | p->kind = IfExp_kind; |
| 2743 | p->v.IfExp.test = test; |
| 2744 | p->v.IfExp.body = body; |
| 2745 | p->v.IfExp.orelse = orelse; |
| 2746 | p->lineno = lineno; |
| 2747 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2748 | p->end_lineno = end_lineno; |
| 2749 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2750 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2754 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2755 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2756 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2757 | expr_ty p; |
| 2758 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2759 | if (!p) |
| 2760 | return NULL; |
| 2761 | p->kind = Dict_kind; |
| 2762 | p->v.Dict.keys = keys; |
| 2763 | p->v.Dict.values = values; |
| 2764 | p->lineno = lineno; |
| 2765 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2766 | p->end_lineno = end_lineno; |
| 2767 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2768 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2772 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2773 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2774 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2775 | expr_ty p; |
| 2776 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2777 | if (!p) |
| 2778 | return NULL; |
| 2779 | p->kind = Set_kind; |
| 2780 | p->v.Set.elts = elts; |
| 2781 | p->lineno = lineno; |
| 2782 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2783 | p->end_lineno = end_lineno; |
| 2784 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2785 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2789 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2790 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2791 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2792 | expr_ty p; |
| 2793 | if (!elt) { |
| 2794 | PyErr_SetString(PyExc_ValueError, |
| 2795 | "field elt is required for ListComp"); |
| 2796 | return NULL; |
| 2797 | } |
| 2798 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2799 | if (!p) |
| 2800 | return NULL; |
| 2801 | p->kind = ListComp_kind; |
| 2802 | p->v.ListComp.elt = elt; |
| 2803 | p->v.ListComp.generators = generators; |
| 2804 | p->lineno = lineno; |
| 2805 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2806 | p->end_lineno = end_lineno; |
| 2807 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2808 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2812 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2813 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2814 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2815 | expr_ty p; |
| 2816 | if (!elt) { |
| 2817 | PyErr_SetString(PyExc_ValueError, |
| 2818 | "field elt is required for SetComp"); |
| 2819 | return NULL; |
| 2820 | } |
| 2821 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2822 | if (!p) |
| 2823 | return NULL; |
| 2824 | p->kind = SetComp_kind; |
| 2825 | p->v.SetComp.elt = elt; |
| 2826 | p->v.SetComp.generators = generators; |
| 2827 | p->lineno = lineno; |
| 2828 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2829 | p->end_lineno = end_lineno; |
| 2830 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2831 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2835 | 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] | 2836 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2837 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2838 | expr_ty p; |
| 2839 | if (!key) { |
| 2840 | PyErr_SetString(PyExc_ValueError, |
| 2841 | "field key is required for DictComp"); |
| 2842 | return NULL; |
| 2843 | } |
| 2844 | if (!value) { |
| 2845 | PyErr_SetString(PyExc_ValueError, |
| 2846 | "field value is required for DictComp"); |
| 2847 | return NULL; |
| 2848 | } |
| 2849 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2850 | if (!p) |
| 2851 | return NULL; |
| 2852 | p->kind = DictComp_kind; |
| 2853 | p->v.DictComp.key = key; |
| 2854 | p->v.DictComp.value = value; |
| 2855 | p->v.DictComp.generators = generators; |
| 2856 | p->lineno = lineno; |
| 2857 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2858 | p->end_lineno = end_lineno; |
| 2859 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2860 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2864 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2865 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2866 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2867 | expr_ty p; |
| 2868 | if (!elt) { |
| 2869 | PyErr_SetString(PyExc_ValueError, |
| 2870 | "field elt is required for GeneratorExp"); |
| 2871 | return NULL; |
| 2872 | } |
| 2873 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2874 | if (!p) |
| 2875 | return NULL; |
| 2876 | p->kind = GeneratorExp_kind; |
| 2877 | p->v.GeneratorExp.elt = elt; |
| 2878 | p->v.GeneratorExp.generators = generators; |
| 2879 | p->lineno = lineno; |
| 2880 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2881 | p->end_lineno = end_lineno; |
| 2882 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2883 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2887 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2888 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2889 | { |
| 2890 | expr_ty p; |
| 2891 | if (!value) { |
| 2892 | PyErr_SetString(PyExc_ValueError, |
| 2893 | "field value is required for Await"); |
| 2894 | return NULL; |
| 2895 | } |
| 2896 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2897 | if (!p) |
| 2898 | return NULL; |
| 2899 | p->kind = Await_kind; |
| 2900 | p->v.Await.value = value; |
| 2901 | p->lineno = lineno; |
| 2902 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2903 | p->end_lineno = end_lineno; |
| 2904 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2905 | return p; |
| 2906 | } |
| 2907 | |
| 2908 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2909 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2910 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2911 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2912 | expr_ty p; |
| 2913 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2914 | if (!p) |
| 2915 | return NULL; |
| 2916 | p->kind = Yield_kind; |
| 2917 | p->v.Yield.value = value; |
| 2918 | p->lineno = lineno; |
| 2919 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2920 | p->end_lineno = end_lineno; |
| 2921 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2922 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2926 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2927 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2928 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2929 | expr_ty p; |
| 2930 | if (!value) { |
| 2931 | PyErr_SetString(PyExc_ValueError, |
| 2932 | "field value is required for YieldFrom"); |
| 2933 | return NULL; |
| 2934 | } |
| 2935 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2936 | if (!p) |
| 2937 | return NULL; |
| 2938 | p->kind = YieldFrom_kind; |
| 2939 | p->v.YieldFrom.value = value; |
| 2940 | p->lineno = lineno; |
| 2941 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2942 | p->end_lineno = end_lineno; |
| 2943 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2944 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2948 | 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] | 2949 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2950 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2951 | expr_ty p; |
| 2952 | if (!left) { |
| 2953 | PyErr_SetString(PyExc_ValueError, |
| 2954 | "field left is required for Compare"); |
| 2955 | return NULL; |
| 2956 | } |
| 2957 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2958 | if (!p) |
| 2959 | return NULL; |
| 2960 | p->kind = Compare_kind; |
| 2961 | p->v.Compare.left = left; |
| 2962 | p->v.Compare.ops = ops; |
| 2963 | p->v.Compare.comparators = comparators; |
| 2964 | p->lineno = lineno; |
| 2965 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2966 | p->end_lineno = end_lineno; |
| 2967 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2968 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2972 | 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] | 2973 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2974 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2975 | expr_ty p; |
| 2976 | if (!func) { |
| 2977 | PyErr_SetString(PyExc_ValueError, |
| 2978 | "field func is required for Call"); |
| 2979 | return NULL; |
| 2980 | } |
| 2981 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2982 | if (!p) |
| 2983 | return NULL; |
| 2984 | p->kind = Call_kind; |
| 2985 | p->v.Call.func = func; |
| 2986 | p->v.Call.args = args; |
| 2987 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2988 | p->lineno = lineno; |
| 2989 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2990 | p->end_lineno = end_lineno; |
| 2991 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2992 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 2996 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2997 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2998 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2999 | { |
| 3000 | expr_ty p; |
| 3001 | if (!value) { |
| 3002 | PyErr_SetString(PyExc_ValueError, |
| 3003 | "field value is required for FormattedValue"); |
| 3004 | return NULL; |
| 3005 | } |
| 3006 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3007 | if (!p) |
| 3008 | return NULL; |
| 3009 | p->kind = FormattedValue_kind; |
| 3010 | p->v.FormattedValue.value = value; |
| 3011 | p->v.FormattedValue.conversion = conversion; |
| 3012 | p->v.FormattedValue.format_spec = format_spec; |
| 3013 | p->lineno = lineno; |
| 3014 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3015 | p->end_lineno = end_lineno; |
| 3016 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3017 | return p; |
| 3018 | } |
| 3019 | |
| 3020 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3021 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 3022 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3023 | { |
| 3024 | expr_ty p; |
| 3025 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3026 | if (!p) |
| 3027 | return NULL; |
| 3028 | p->kind = JoinedStr_kind; |
| 3029 | p->v.JoinedStr.values = values; |
| 3030 | p->lineno = lineno; |
| 3031 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3032 | p->end_lineno = end_lineno; |
| 3033 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3034 | return p; |
| 3035 | } |
| 3036 | |
| 3037 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3038 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 3039 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3040 | { |
| 3041 | expr_ty p; |
| 3042 | if (!value) { |
| 3043 | PyErr_SetString(PyExc_ValueError, |
| 3044 | "field value is required for Constant"); |
| 3045 | return NULL; |
| 3046 | } |
| 3047 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3048 | if (!p) |
| 3049 | return NULL; |
| 3050 | p->kind = Constant_kind; |
| 3051 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3052 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3053 | p->lineno = lineno; |
| 3054 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3055 | p->end_lineno = end_lineno; |
| 3056 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3057 | return p; |
| 3058 | } |
| 3059 | |
| 3060 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3061 | 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] | 3062 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3063 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3064 | expr_ty p; |
| 3065 | if (!value) { |
| 3066 | PyErr_SetString(PyExc_ValueError, |
| 3067 | "field value is required for Attribute"); |
| 3068 | return NULL; |
| 3069 | } |
| 3070 | if (!attr) { |
| 3071 | PyErr_SetString(PyExc_ValueError, |
| 3072 | "field attr is required for Attribute"); |
| 3073 | return NULL; |
| 3074 | } |
| 3075 | if (!ctx) { |
| 3076 | PyErr_SetString(PyExc_ValueError, |
| 3077 | "field ctx is required for Attribute"); |
| 3078 | return NULL; |
| 3079 | } |
| 3080 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3081 | if (!p) |
| 3082 | return NULL; |
| 3083 | p->kind = Attribute_kind; |
| 3084 | p->v.Attribute.value = value; |
| 3085 | p->v.Attribute.attr = attr; |
| 3086 | p->v.Attribute.ctx = ctx; |
| 3087 | p->lineno = lineno; |
| 3088 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3089 | p->end_lineno = end_lineno; |
| 3090 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3091 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3095 | 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] | 3096 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3097 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3098 | expr_ty p; |
| 3099 | if (!value) { |
| 3100 | PyErr_SetString(PyExc_ValueError, |
| 3101 | "field value is required for Subscript"); |
| 3102 | return NULL; |
| 3103 | } |
| 3104 | if (!slice) { |
| 3105 | PyErr_SetString(PyExc_ValueError, |
| 3106 | "field slice is required for Subscript"); |
| 3107 | return NULL; |
| 3108 | } |
| 3109 | if (!ctx) { |
| 3110 | PyErr_SetString(PyExc_ValueError, |
| 3111 | "field ctx is required for Subscript"); |
| 3112 | return NULL; |
| 3113 | } |
| 3114 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3115 | if (!p) |
| 3116 | return NULL; |
| 3117 | p->kind = Subscript_kind; |
| 3118 | p->v.Subscript.value = value; |
| 3119 | p->v.Subscript.slice = slice; |
| 3120 | p->v.Subscript.ctx = ctx; |
| 3121 | p->lineno = lineno; |
| 3122 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3123 | p->end_lineno = end_lineno; |
| 3124 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3125 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3129 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3130 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3131 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3132 | expr_ty p; |
| 3133 | if (!value) { |
| 3134 | PyErr_SetString(PyExc_ValueError, |
| 3135 | "field value is required for Starred"); |
| 3136 | return NULL; |
| 3137 | } |
| 3138 | if (!ctx) { |
| 3139 | PyErr_SetString(PyExc_ValueError, |
| 3140 | "field ctx is required for Starred"); |
| 3141 | return NULL; |
| 3142 | } |
| 3143 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3144 | if (!p) |
| 3145 | return NULL; |
| 3146 | p->kind = Starred_kind; |
| 3147 | p->v.Starred.value = value; |
| 3148 | p->v.Starred.ctx = ctx; |
| 3149 | p->lineno = lineno; |
| 3150 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3151 | p->end_lineno = end_lineno; |
| 3152 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3153 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3157 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3158 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3159 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3160 | expr_ty p; |
| 3161 | if (!id) { |
| 3162 | PyErr_SetString(PyExc_ValueError, |
| 3163 | "field id is required for Name"); |
| 3164 | return NULL; |
| 3165 | } |
| 3166 | if (!ctx) { |
| 3167 | PyErr_SetString(PyExc_ValueError, |
| 3168 | "field ctx is required for Name"); |
| 3169 | return NULL; |
| 3170 | } |
| 3171 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3172 | if (!p) |
| 3173 | return NULL; |
| 3174 | p->kind = Name_kind; |
| 3175 | p->v.Name.id = id; |
| 3176 | p->v.Name.ctx = ctx; |
| 3177 | p->lineno = lineno; |
| 3178 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3179 | p->end_lineno = end_lineno; |
| 3180 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3181 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3185 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3186 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3187 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3188 | expr_ty p; |
| 3189 | if (!ctx) { |
| 3190 | PyErr_SetString(PyExc_ValueError, |
| 3191 | "field ctx is required for List"); |
| 3192 | return NULL; |
| 3193 | } |
| 3194 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3195 | if (!p) |
| 3196 | return NULL; |
| 3197 | p->kind = List_kind; |
| 3198 | p->v.List.elts = elts; |
| 3199 | p->v.List.ctx = ctx; |
| 3200 | p->lineno = lineno; |
| 3201 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3202 | p->end_lineno = end_lineno; |
| 3203 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3204 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3208 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3209 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3210 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3211 | expr_ty p; |
| 3212 | if (!ctx) { |
| 3213 | PyErr_SetString(PyExc_ValueError, |
| 3214 | "field ctx is required for Tuple"); |
| 3215 | return NULL; |
| 3216 | } |
| 3217 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3218 | if (!p) |
| 3219 | return NULL; |
| 3220 | p->kind = Tuple_kind; |
| 3221 | p->v.Tuple.elts = elts; |
| 3222 | p->v.Tuple.ctx = ctx; |
| 3223 | p->lineno = lineno; |
| 3224 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3225 | p->end_lineno = end_lineno; |
| 3226 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3227 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3228 | } |
| 3229 | |
| 3230 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3231 | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3232 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3233 | slice_ty p; |
| 3234 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3235 | if (!p) |
| 3236 | return NULL; |
| 3237 | p->kind = Slice_kind; |
| 3238 | p->v.Slice.lower = lower; |
| 3239 | p->v.Slice.upper = upper; |
| 3240 | p->v.Slice.step = step; |
| 3241 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3245 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3246 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3247 | slice_ty p; |
| 3248 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3249 | if (!p) |
| 3250 | return NULL; |
| 3251 | p->kind = ExtSlice_kind; |
| 3252 | p->v.ExtSlice.dims = dims; |
| 3253 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3257 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3258 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3259 | slice_ty p; |
| 3260 | if (!value) { |
| 3261 | PyErr_SetString(PyExc_ValueError, |
| 3262 | "field value is required for Index"); |
| 3263 | return NULL; |
| 3264 | } |
| 3265 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3266 | if (!p) |
| 3267 | return NULL; |
| 3268 | p->kind = Index_kind; |
| 3269 | p->v.Index.value = value; |
| 3270 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3274 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3275 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3276 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3277 | comprehension_ty p; |
| 3278 | if (!target) { |
| 3279 | PyErr_SetString(PyExc_ValueError, |
| 3280 | "field target is required for comprehension"); |
| 3281 | return NULL; |
| 3282 | } |
| 3283 | if (!iter) { |
| 3284 | PyErr_SetString(PyExc_ValueError, |
| 3285 | "field iter is required for comprehension"); |
| 3286 | return NULL; |
| 3287 | } |
| 3288 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3289 | if (!p) |
| 3290 | return NULL; |
| 3291 | p->target = target; |
| 3292 | p->iter = iter; |
| 3293 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3294 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3295 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3299 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3300 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3301 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3302 | excepthandler_ty p; |
| 3303 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3304 | if (!p) |
| 3305 | return NULL; |
| 3306 | p->kind = ExceptHandler_kind; |
| 3307 | p->v.ExceptHandler.type = type; |
| 3308 | p->v.ExceptHandler.name = name; |
| 3309 | p->v.ExceptHandler.body = body; |
| 3310 | p->lineno = lineno; |
| 3311 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3312 | p->end_lineno = end_lineno; |
| 3313 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3314 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3318 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3319 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3320 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3321 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3322 | arguments_ty p; |
| 3323 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3324 | if (!p) |
| 3325 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3326 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3327 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3328 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3329 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3330 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3331 | p->kwarg = kwarg; |
| 3332 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3333 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3334 | } |
| 3335 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3336 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3337 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3338 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3339 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3340 | arg_ty p; |
| 3341 | if (!arg) { |
| 3342 | PyErr_SetString(PyExc_ValueError, |
| 3343 | "field arg is required for arg"); |
| 3344 | return NULL; |
| 3345 | } |
| 3346 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3347 | if (!p) |
| 3348 | return NULL; |
| 3349 | p->arg = arg; |
| 3350 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3351 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3352 | p->lineno = lineno; |
| 3353 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3354 | p->end_lineno = end_lineno; |
| 3355 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3356 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3359 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3360 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3361 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3362 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3363 | if (!value) { |
| 3364 | PyErr_SetString(PyExc_ValueError, |
| 3365 | "field value is required for keyword"); |
| 3366 | return NULL; |
| 3367 | } |
| 3368 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3369 | if (!p) |
| 3370 | return NULL; |
| 3371 | p->arg = arg; |
| 3372 | p->value = value; |
| 3373 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3377 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3378 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3379 | alias_ty p; |
| 3380 | if (!name) { |
| 3381 | PyErr_SetString(PyExc_ValueError, |
| 3382 | "field name is required for alias"); |
| 3383 | return NULL; |
| 3384 | } |
| 3385 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3386 | if (!p) |
| 3387 | return NULL; |
| 3388 | p->name = name; |
| 3389 | p->asname = asname; |
| 3390 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3393 | withitem_ty |
| 3394 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3395 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3396 | withitem_ty p; |
| 3397 | if (!context_expr) { |
| 3398 | PyErr_SetString(PyExc_ValueError, |
| 3399 | "field context_expr is required for withitem"); |
| 3400 | return NULL; |
| 3401 | } |
| 3402 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3403 | if (!p) |
| 3404 | return NULL; |
| 3405 | p->context_expr = context_expr; |
| 3406 | p->optional_vars = optional_vars; |
| 3407 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3408 | } |
| 3409 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3410 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3411 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3412 | { |
| 3413 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3414 | if (!tag) { |
| 3415 | PyErr_SetString(PyExc_ValueError, |
| 3416 | "field tag is required for TypeIgnore"); |
| 3417 | return NULL; |
| 3418 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3419 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3420 | if (!p) |
| 3421 | return NULL; |
| 3422 | p->kind = TypeIgnore_kind; |
| 3423 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3424 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3425 | return p; |
| 3426 | } |
| 3427 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3428 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3429 | PyObject* |
| 3430 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3431 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3432 | mod_ty o = (mod_ty)_o; |
| 3433 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3434 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3435 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3436 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3437 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3438 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3439 | switch (o->kind) { |
| 3440 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3441 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3442 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3443 | if (!result) goto failed; |
| 3444 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3445 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3446 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3447 | goto failed; |
| 3448 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3449 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3450 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3451 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3452 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3453 | goto failed; |
| 3454 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3455 | break; |
| 3456 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3457 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3458 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3459 | if (!result) goto failed; |
| 3460 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3461 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3462 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3463 | goto failed; |
| 3464 | Py_DECREF(value); |
| 3465 | break; |
| 3466 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3467 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3468 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3469 | if (!result) goto failed; |
| 3470 | value = ast2obj_expr(o->v.Expression.body); |
| 3471 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3472 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3473 | goto failed; |
| 3474 | Py_DECREF(value); |
| 3475 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3476 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3477 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3478 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3479 | if (!result) goto failed; |
| 3480 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3481 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3482 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3483 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3484 | goto failed; |
| 3485 | Py_DECREF(value); |
| 3486 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3487 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3488 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3489 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3490 | goto failed; |
| 3491 | Py_DECREF(value); |
| 3492 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3493 | } |
| 3494 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3495 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3496 | Py_XDECREF(value); |
| 3497 | Py_XDECREF(result); |
| 3498 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3501 | PyObject* |
| 3502 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3503 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3504 | stmt_ty o = (stmt_ty)_o; |
| 3505 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3506 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3507 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3508 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3509 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3510 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3511 | switch (o->kind) { |
| 3512 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3513 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3514 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3515 | if (!result) goto failed; |
| 3516 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3517 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3518 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3519 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3520 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3521 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3522 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3523 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3524 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3525 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3526 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3527 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3528 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3529 | goto failed; |
| 3530 | Py_DECREF(value); |
| 3531 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3532 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3533 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3534 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3535 | goto failed; |
| 3536 | Py_DECREF(value); |
| 3537 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3538 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3539 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3540 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3541 | goto failed; |
| 3542 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3543 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3544 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3545 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3546 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3547 | goto failed; |
| 3548 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3549 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3550 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3551 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3552 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3553 | if (!result) goto failed; |
| 3554 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3555 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3556 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3557 | goto failed; |
| 3558 | Py_DECREF(value); |
| 3559 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3560 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3561 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3562 | goto failed; |
| 3563 | Py_DECREF(value); |
| 3564 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3565 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3566 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3567 | goto failed; |
| 3568 | Py_DECREF(value); |
| 3569 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3570 | ast2obj_expr); |
| 3571 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3572 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3573 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3574 | goto failed; |
| 3575 | Py_DECREF(value); |
| 3576 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3577 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3578 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3579 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3580 | goto failed; |
| 3581 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3582 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3583 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3584 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3585 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3586 | goto failed; |
| 3587 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3588 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3589 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3590 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3591 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3592 | if (!result) goto failed; |
| 3593 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3594 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3595 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3596 | goto failed; |
| 3597 | Py_DECREF(value); |
| 3598 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3599 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3600 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3601 | goto failed; |
| 3602 | Py_DECREF(value); |
| 3603 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3604 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3605 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3606 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3607 | goto failed; |
| 3608 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3609 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3610 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3611 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3612 | goto failed; |
| 3613 | Py_DECREF(value); |
| 3614 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3615 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3616 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3617 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3618 | goto failed; |
| 3619 | Py_DECREF(value); |
| 3620 | break; |
| 3621 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3622 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3623 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3624 | if (!result) goto failed; |
| 3625 | value = ast2obj_expr(o->v.Return.value); |
| 3626 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3627 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3628 | goto failed; |
| 3629 | Py_DECREF(value); |
| 3630 | break; |
| 3631 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3632 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3633 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3634 | if (!result) goto failed; |
| 3635 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3636 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3637 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3638 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3639 | goto failed; |
| 3640 | Py_DECREF(value); |
| 3641 | break; |
| 3642 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3643 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3644 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3645 | if (!result) goto failed; |
| 3646 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3647 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3648 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3649 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3650 | goto failed; |
| 3651 | Py_DECREF(value); |
| 3652 | value = ast2obj_expr(o->v.Assign.value); |
| 3653 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3654 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3655 | goto failed; |
| 3656 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3657 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3658 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3659 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3660 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3661 | goto failed; |
| 3662 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3663 | break; |
| 3664 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3665 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3666 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3667 | if (!result) goto failed; |
| 3668 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3669 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3670 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3671 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3672 | goto failed; |
| 3673 | Py_DECREF(value); |
| 3674 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3675 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3676 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3677 | goto failed; |
| 3678 | Py_DECREF(value); |
| 3679 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3680 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3681 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3682 | goto failed; |
| 3683 | Py_DECREF(value); |
| 3684 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3685 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3686 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3687 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3688 | if (!result) goto failed; |
| 3689 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3690 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3691 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3692 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3693 | goto failed; |
| 3694 | Py_DECREF(value); |
| 3695 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3696 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3697 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3698 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3699 | goto failed; |
| 3700 | Py_DECREF(value); |
| 3701 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3702 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3703 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3704 | goto failed; |
| 3705 | Py_DECREF(value); |
| 3706 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3707 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3708 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3709 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3710 | goto failed; |
| 3711 | Py_DECREF(value); |
| 3712 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3713 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3714 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3715 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3716 | if (!result) goto failed; |
| 3717 | value = ast2obj_expr(o->v.For.target); |
| 3718 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3719 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3720 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3721 | goto failed; |
| 3722 | Py_DECREF(value); |
| 3723 | value = ast2obj_expr(o->v.For.iter); |
| 3724 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3725 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3726 | goto failed; |
| 3727 | Py_DECREF(value); |
| 3728 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3729 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3730 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3731 | goto failed; |
| 3732 | Py_DECREF(value); |
| 3733 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3734 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3735 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3736 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3737 | goto failed; |
| 3738 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3739 | value = ast2obj_string(o->v.For.type_comment); |
| 3740 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3741 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3742 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3743 | goto failed; |
| 3744 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3745 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3746 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3747 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3748 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3749 | if (!result) goto failed; |
| 3750 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3751 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3752 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3753 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3754 | goto failed; |
| 3755 | Py_DECREF(value); |
| 3756 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3757 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3758 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3759 | goto failed; |
| 3760 | Py_DECREF(value); |
| 3761 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3762 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3763 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3764 | goto failed; |
| 3765 | Py_DECREF(value); |
| 3766 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3767 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3768 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3769 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3770 | goto failed; |
| 3771 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3772 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3773 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3774 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3775 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3776 | goto failed; |
| 3777 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3778 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3779 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3780 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3781 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3782 | if (!result) goto failed; |
| 3783 | value = ast2obj_expr(o->v.While.test); |
| 3784 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3785 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3786 | goto failed; |
| 3787 | Py_DECREF(value); |
| 3788 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3789 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3790 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3791 | goto failed; |
| 3792 | Py_DECREF(value); |
| 3793 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3794 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3795 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3796 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3797 | goto failed; |
| 3798 | Py_DECREF(value); |
| 3799 | break; |
| 3800 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3801 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3802 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3803 | if (!result) goto failed; |
| 3804 | value = ast2obj_expr(o->v.If.test); |
| 3805 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3806 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3807 | goto failed; |
| 3808 | Py_DECREF(value); |
| 3809 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3810 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3811 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3812 | goto failed; |
| 3813 | Py_DECREF(value); |
| 3814 | value = ast2obj_list(o->v.If.orelse, 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->orelse, value) == |
| 3817 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3818 | goto failed; |
| 3819 | Py_DECREF(value); |
| 3820 | break; |
| 3821 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3822 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3823 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3824 | if (!result) goto failed; |
| 3825 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3826 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3827 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3828 | goto failed; |
| 3829 | Py_DECREF(value); |
| 3830 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3831 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3832 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3833 | goto failed; |
| 3834 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3835 | value = ast2obj_string(o->v.With.type_comment); |
| 3836 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3837 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3838 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3839 | goto failed; |
| 3840 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3841 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3842 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3843 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3844 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3845 | if (!result) goto failed; |
| 3846 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3847 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3848 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3849 | goto failed; |
| 3850 | Py_DECREF(value); |
| 3851 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3852 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3853 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3854 | goto failed; |
| 3855 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3856 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3857 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3858 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3859 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3860 | goto failed; |
| 3861 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3862 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3863 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3864 | tp = (PyTypeObject *)astmodulestate_global->Raise_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_expr(o->v.Raise.exc); |
| 3868 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3869 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3870 | goto failed; |
| 3871 | Py_DECREF(value); |
| 3872 | value = ast2obj_expr(o->v.Raise.cause); |
| 3873 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3874 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3875 | goto failed; |
| 3876 | Py_DECREF(value); |
| 3877 | break; |
| 3878 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3879 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3880 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3881 | if (!result) goto failed; |
| 3882 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3883 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3884 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3885 | goto failed; |
| 3886 | Py_DECREF(value); |
| 3887 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3888 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3889 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3890 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | goto failed; |
| 3892 | Py_DECREF(value); |
| 3893 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3894 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3895 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3896 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3897 | goto failed; |
| 3898 | Py_DECREF(value); |
| 3899 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3900 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3901 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3902 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3903 | goto failed; |
| 3904 | Py_DECREF(value); |
| 3905 | break; |
| 3906 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3907 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3908 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3909 | if (!result) goto failed; |
| 3910 | value = ast2obj_expr(o->v.Assert.test); |
| 3911 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3912 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3913 | goto failed; |
| 3914 | Py_DECREF(value); |
| 3915 | value = ast2obj_expr(o->v.Assert.msg); |
| 3916 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3917 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3918 | goto failed; |
| 3919 | Py_DECREF(value); |
| 3920 | break; |
| 3921 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3922 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 3923 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3924 | if (!result) goto failed; |
| 3925 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3926 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3927 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3928 | goto failed; |
| 3929 | Py_DECREF(value); |
| 3930 | break; |
| 3931 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3932 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 3933 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3934 | if (!result) goto failed; |
| 3935 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3936 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3937 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 3938 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3939 | goto failed; |
| 3940 | Py_DECREF(value); |
| 3941 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3942 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3943 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3944 | goto failed; |
| 3945 | Py_DECREF(value); |
| 3946 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3947 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3948 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3949 | goto failed; |
| 3950 | Py_DECREF(value); |
| 3951 | break; |
| 3952 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3953 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 3954 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3955 | if (!result) goto failed; |
| 3956 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3957 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3958 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3959 | goto failed; |
| 3960 | Py_DECREF(value); |
| 3961 | break; |
| 3962 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3963 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 3964 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3965 | if (!result) goto failed; |
| 3966 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3967 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3968 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3969 | goto failed; |
| 3970 | Py_DECREF(value); |
| 3971 | break; |
| 3972 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3973 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 3974 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3975 | if (!result) goto failed; |
| 3976 | value = ast2obj_expr(o->v.Expr.value); |
| 3977 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3978 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3979 | goto failed; |
| 3980 | Py_DECREF(value); |
| 3981 | break; |
| 3982 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3983 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 3984 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3985 | if (!result) goto failed; |
| 3986 | break; |
| 3987 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3988 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 3989 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3990 | if (!result) goto failed; |
| 3991 | break; |
| 3992 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3993 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 3994 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3995 | if (!result) goto failed; |
| 3996 | break; |
| 3997 | } |
| 3998 | value = ast2obj_int(o->lineno); |
| 3999 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4000 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4001 | goto failed; |
| 4002 | Py_DECREF(value); |
| 4003 | value = ast2obj_int(o->col_offset); |
| 4004 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4005 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4006 | goto failed; |
| 4007 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4008 | value = ast2obj_int(o->end_lineno); |
| 4009 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4010 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4011 | goto failed; |
| 4012 | Py_DECREF(value); |
| 4013 | value = ast2obj_int(o->end_col_offset); |
| 4014 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4015 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4016 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4017 | goto failed; |
| 4018 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4019 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4020 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4021 | Py_XDECREF(value); |
| 4022 | Py_XDECREF(result); |
| 4023 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4024 | } |
| 4025 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4026 | PyObject* |
| 4027 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4028 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4029 | expr_ty o = (expr_ty)_o; |
| 4030 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4031 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4032 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4033 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4034 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4035 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4036 | switch (o->kind) { |
| 4037 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4038 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_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_boolop(o->v.BoolOp.op); |
| 4042 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4043 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | goto failed; |
| 4045 | Py_DECREF(value); |
| 4046 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 4047 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4048 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4049 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4050 | goto failed; |
| 4051 | Py_DECREF(value); |
| 4052 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4053 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4054 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 4055 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4056 | if (!result) goto failed; |
| 4057 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 4058 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4059 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 4060 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4061 | goto failed; |
| 4062 | Py_DECREF(value); |
| 4063 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 4064 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4065 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4066 | goto failed; |
| 4067 | Py_DECREF(value); |
| 4068 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4069 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4070 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4071 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4072 | if (!result) goto failed; |
| 4073 | value = ast2obj_expr(o->v.BinOp.left); |
| 4074 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4075 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4076 | goto failed; |
| 4077 | Py_DECREF(value); |
| 4078 | value = ast2obj_operator(o->v.BinOp.op); |
| 4079 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4080 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4081 | goto failed; |
| 4082 | Py_DECREF(value); |
| 4083 | value = ast2obj_expr(o->v.BinOp.right); |
| 4084 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4085 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4086 | goto failed; |
| 4087 | Py_DECREF(value); |
| 4088 | break; |
| 4089 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4090 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_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_unaryop(o->v.UnaryOp.op); |
| 4094 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4095 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4096 | goto failed; |
| 4097 | Py_DECREF(value); |
| 4098 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4099 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4100 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4101 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4102 | goto failed; |
| 4103 | Py_DECREF(value); |
| 4104 | break; |
| 4105 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4106 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4107 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4108 | if (!result) goto failed; |
| 4109 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4110 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4111 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4112 | goto failed; |
| 4113 | Py_DECREF(value); |
| 4114 | value = ast2obj_expr(o->v.Lambda.body); |
| 4115 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4116 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4117 | goto failed; |
| 4118 | Py_DECREF(value); |
| 4119 | break; |
| 4120 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4121 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4122 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4123 | if (!result) goto failed; |
| 4124 | value = ast2obj_expr(o->v.IfExp.test); |
| 4125 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4126 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4127 | goto failed; |
| 4128 | Py_DECREF(value); |
| 4129 | value = ast2obj_expr(o->v.IfExp.body); |
| 4130 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4131 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4132 | goto failed; |
| 4133 | Py_DECREF(value); |
| 4134 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4135 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4136 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4137 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4138 | goto failed; |
| 4139 | Py_DECREF(value); |
| 4140 | break; |
| 4141 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4142 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4143 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4144 | if (!result) goto failed; |
| 4145 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4146 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4147 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4148 | goto failed; |
| 4149 | Py_DECREF(value); |
| 4150 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4151 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4152 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4153 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4154 | goto failed; |
| 4155 | Py_DECREF(value); |
| 4156 | break; |
| 4157 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4158 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4159 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4160 | if (!result) goto failed; |
| 4161 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4162 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4163 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4164 | goto failed; |
| 4165 | Py_DECREF(value); |
| 4166 | break; |
| 4167 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4168 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4169 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4170 | if (!result) goto failed; |
| 4171 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4172 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4173 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4174 | goto failed; |
| 4175 | Py_DECREF(value); |
| 4176 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4177 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4178 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4179 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4180 | goto failed; |
| 4181 | Py_DECREF(value); |
| 4182 | break; |
| 4183 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4184 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4185 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4186 | if (!result) goto failed; |
| 4187 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4188 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4189 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4190 | goto failed; |
| 4191 | Py_DECREF(value); |
| 4192 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4193 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4194 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4195 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4196 | goto failed; |
| 4197 | Py_DECREF(value); |
| 4198 | break; |
| 4199 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4200 | tp = (PyTypeObject *)astmodulestate_global->DictComp_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.DictComp.key); |
| 4204 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4205 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4206 | goto failed; |
| 4207 | Py_DECREF(value); |
| 4208 | value = ast2obj_expr(o->v.DictComp.value); |
| 4209 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4210 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4211 | goto failed; |
| 4212 | Py_DECREF(value); |
| 4213 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4214 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4215 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4216 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4217 | goto failed; |
| 4218 | Py_DECREF(value); |
| 4219 | break; |
| 4220 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4221 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4222 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4223 | if (!result) goto failed; |
| 4224 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4225 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4226 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4227 | goto failed; |
| 4228 | Py_DECREF(value); |
| 4229 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4230 | ast2obj_comprehension); |
| 4231 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4232 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4233 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4234 | goto failed; |
| 4235 | Py_DECREF(value); |
| 4236 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4237 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4238 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4239 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4240 | if (!result) goto failed; |
| 4241 | value = ast2obj_expr(o->v.Await.value); |
| 4242 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4243 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4244 | goto failed; |
| 4245 | Py_DECREF(value); |
| 4246 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4247 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4248 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4249 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4250 | if (!result) goto failed; |
| 4251 | value = ast2obj_expr(o->v.Yield.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) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4254 | goto failed; |
| 4255 | Py_DECREF(value); |
| 4256 | break; |
| 4257 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4258 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4259 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4260 | if (!result) goto failed; |
| 4261 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4262 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4263 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4264 | goto failed; |
| 4265 | Py_DECREF(value); |
| 4266 | break; |
| 4267 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4268 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4269 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4270 | if (!result) goto failed; |
| 4271 | value = ast2obj_expr(o->v.Compare.left); |
| 4272 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4273 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4274 | goto failed; |
| 4275 | Py_DECREF(value); |
| 4276 | { |
| 4277 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4278 | value = PyList_New(n); |
| 4279 | if (!value) goto failed; |
| 4280 | for(i = 0; i < n; i++) |
| 4281 | 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] | 4282 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4283 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4284 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4285 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4286 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4287 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4288 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4289 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4290 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4291 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4292 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4293 | break; |
| 4294 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4295 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4296 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4297 | if (!result) goto failed; |
| 4298 | value = ast2obj_expr(o->v.Call.func); |
| 4299 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4300 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4301 | goto failed; |
| 4302 | Py_DECREF(value); |
| 4303 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4304 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4305 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4306 | goto failed; |
| 4307 | Py_DECREF(value); |
| 4308 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4309 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4310 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4311 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4312 | goto failed; |
| 4313 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4314 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4315 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4316 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4317 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4318 | if (!result) goto failed; |
| 4319 | value = ast2obj_expr(o->v.FormattedValue.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) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4322 | goto failed; |
| 4323 | Py_DECREF(value); |
| 4324 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4325 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4326 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4327 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4328 | goto failed; |
| 4329 | Py_DECREF(value); |
| 4330 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4331 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4332 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4333 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4334 | goto failed; |
| 4335 | Py_DECREF(value); |
| 4336 | break; |
| 4337 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4338 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4339 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4340 | if (!result) goto failed; |
| 4341 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4342 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4343 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4344 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4345 | goto failed; |
| 4346 | Py_DECREF(value); |
| 4347 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4348 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4349 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4350 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4351 | if (!result) goto failed; |
| 4352 | value = ast2obj_constant(o->v.Constant.value); |
| 4353 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4354 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4355 | goto failed; |
| 4356 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4357 | value = ast2obj_string(o->v.Constant.kind); |
| 4358 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4359 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4360 | goto failed; |
| 4361 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4362 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4363 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4364 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4365 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4366 | if (!result) goto failed; |
| 4367 | value = ast2obj_expr(o->v.Attribute.value); |
| 4368 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4369 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4370 | goto failed; |
| 4371 | Py_DECREF(value); |
| 4372 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4373 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4374 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4375 | goto failed; |
| 4376 | Py_DECREF(value); |
| 4377 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4378 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4379 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4380 | goto failed; |
| 4381 | Py_DECREF(value); |
| 4382 | break; |
| 4383 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4384 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4385 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4386 | if (!result) goto failed; |
| 4387 | value = ast2obj_expr(o->v.Subscript.value); |
| 4388 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4389 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4390 | goto failed; |
| 4391 | Py_DECREF(value); |
| 4392 | value = ast2obj_slice(o->v.Subscript.slice); |
| 4393 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4394 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4395 | goto failed; |
| 4396 | Py_DECREF(value); |
| 4397 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4398 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4399 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4400 | goto failed; |
| 4401 | Py_DECREF(value); |
| 4402 | break; |
| 4403 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4404 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4405 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4406 | if (!result) goto failed; |
| 4407 | value = ast2obj_expr(o->v.Starred.value); |
| 4408 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4409 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4410 | goto failed; |
| 4411 | Py_DECREF(value); |
| 4412 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4413 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4414 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4415 | goto failed; |
| 4416 | Py_DECREF(value); |
| 4417 | break; |
| 4418 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4419 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4420 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4421 | if (!result) goto failed; |
| 4422 | value = ast2obj_identifier(o->v.Name.id); |
| 4423 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4424 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4425 | goto failed; |
| 4426 | Py_DECREF(value); |
| 4427 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4428 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4429 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4430 | goto failed; |
| 4431 | Py_DECREF(value); |
| 4432 | break; |
| 4433 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4434 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4435 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4436 | if (!result) goto failed; |
| 4437 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4438 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4439 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4440 | goto failed; |
| 4441 | Py_DECREF(value); |
| 4442 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4443 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4444 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4445 | goto failed; |
| 4446 | Py_DECREF(value); |
| 4447 | break; |
| 4448 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4449 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4450 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4451 | if (!result) goto failed; |
| 4452 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4453 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4454 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4455 | goto failed; |
| 4456 | Py_DECREF(value); |
| 4457 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4458 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4459 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4460 | goto failed; |
| 4461 | Py_DECREF(value); |
| 4462 | break; |
| 4463 | } |
| 4464 | value = ast2obj_int(o->lineno); |
| 4465 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4466 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4467 | goto failed; |
| 4468 | Py_DECREF(value); |
| 4469 | value = ast2obj_int(o->col_offset); |
| 4470 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4471 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4472 | goto failed; |
| 4473 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4474 | value = ast2obj_int(o->end_lineno); |
| 4475 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4476 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4477 | goto failed; |
| 4478 | Py_DECREF(value); |
| 4479 | value = ast2obj_int(o->end_col_offset); |
| 4480 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4481 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4482 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4483 | goto failed; |
| 4484 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4485 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4486 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4487 | Py_XDECREF(value); |
| 4488 | Py_XDECREF(result); |
| 4489 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4492 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4493 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4494 | switch(o) { |
| 4495 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4496 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4497 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4498 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4499 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4500 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4501 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4502 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4503 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4504 | case AugLoad: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4505 | Py_INCREF(astmodulestate_global->AugLoad_singleton); |
| 4506 | return astmodulestate_global->AugLoad_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4507 | case AugStore: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4508 | Py_INCREF(astmodulestate_global->AugStore_singleton); |
| 4509 | return astmodulestate_global->AugStore_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4510 | case Param: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4511 | Py_INCREF(astmodulestate_global->Param_singleton); |
| 4512 | return astmodulestate_global->Param_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4513 | default: |
| 4514 | /* should never happen, but just in case ... */ |
| 4515 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 4516 | return NULL; |
| 4517 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4518 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4519 | PyObject* |
| 4520 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4521 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4522 | slice_ty o = (slice_ty)_o; |
| 4523 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4524 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4525 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4526 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4527 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4528 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4529 | switch (o->kind) { |
| 4530 | case Slice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4531 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4532 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4533 | if (!result) goto failed; |
| 4534 | value = ast2obj_expr(o->v.Slice.lower); |
| 4535 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4536 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4537 | goto failed; |
| 4538 | Py_DECREF(value); |
| 4539 | value = ast2obj_expr(o->v.Slice.upper); |
| 4540 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4541 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4542 | goto failed; |
| 4543 | Py_DECREF(value); |
| 4544 | value = ast2obj_expr(o->v.Slice.step); |
| 4545 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4546 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4547 | goto failed; |
| 4548 | Py_DECREF(value); |
| 4549 | break; |
| 4550 | case ExtSlice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4551 | tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type; |
| 4552 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4553 | if (!result) goto failed; |
| 4554 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 4555 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4556 | if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4557 | goto failed; |
| 4558 | Py_DECREF(value); |
| 4559 | break; |
| 4560 | case Index_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4561 | tp = (PyTypeObject *)astmodulestate_global->Index_type; |
| 4562 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4563 | if (!result) goto failed; |
| 4564 | value = ast2obj_expr(o->v.Index.value); |
| 4565 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4566 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4567 | goto failed; |
| 4568 | Py_DECREF(value); |
| 4569 | break; |
| 4570 | } |
| 4571 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4572 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4573 | Py_XDECREF(value); |
| 4574 | Py_XDECREF(result); |
| 4575 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4576 | } |
| 4577 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4578 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4579 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4580 | switch(o) { |
| 4581 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4582 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4583 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4584 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4585 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4586 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4587 | default: |
| 4588 | /* should never happen, but just in case ... */ |
| 4589 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 4590 | return NULL; |
| 4591 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4592 | } |
| 4593 | PyObject* ast2obj_operator(operator_ty o) |
| 4594 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4595 | switch(o) { |
| 4596 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4597 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4598 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4599 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4600 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4601 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4602 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4603 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4604 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4605 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4606 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4607 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4608 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4609 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4610 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4611 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4612 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4613 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4614 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4615 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4616 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4617 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4618 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4619 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4620 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4621 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4622 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4623 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4624 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4625 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4626 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4627 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4628 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4629 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4630 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4631 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4632 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4633 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4634 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4635 | default: |
| 4636 | /* should never happen, but just in case ... */ |
| 4637 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 4638 | return NULL; |
| 4639 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4640 | } |
| 4641 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4642 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4643 | switch(o) { |
| 4644 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4645 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4646 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4647 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4648 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4649 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4650 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4651 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4652 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4653 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4654 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4655 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4656 | default: |
| 4657 | /* should never happen, but just in case ... */ |
| 4658 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 4659 | return NULL; |
| 4660 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4661 | } |
| 4662 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4663 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4664 | switch(o) { |
| 4665 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4666 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4667 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4668 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4669 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4670 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4671 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4672 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4673 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4674 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4675 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4676 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4677 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4678 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4679 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4680 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4681 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4682 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4683 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4684 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4685 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4686 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4687 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4688 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4689 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4690 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4691 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4692 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4693 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4694 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4695 | default: |
| 4696 | /* should never happen, but just in case ... */ |
| 4697 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 4698 | return NULL; |
| 4699 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4700 | } |
| 4701 | PyObject* |
| 4702 | ast2obj_comprehension(void* _o) |
| 4703 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4704 | comprehension_ty o = (comprehension_ty)_o; |
| 4705 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4706 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4707 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4708 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4709 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4710 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4711 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4712 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4713 | if (!result) return NULL; |
| 4714 | value = ast2obj_expr(o->target); |
| 4715 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4716 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4717 | goto failed; |
| 4718 | Py_DECREF(value); |
| 4719 | value = ast2obj_expr(o->iter); |
| 4720 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4721 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4722 | goto failed; |
| 4723 | Py_DECREF(value); |
| 4724 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4725 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4726 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4727 | goto failed; |
| 4728 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4729 | value = ast2obj_int(o->is_async); |
| 4730 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4731 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4732 | goto failed; |
| 4733 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4734 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4735 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4736 | Py_XDECREF(value); |
| 4737 | Py_XDECREF(result); |
| 4738 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4739 | } |
| 4740 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4741 | PyObject* |
| 4742 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4743 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4744 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4745 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4746 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4747 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4748 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4749 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4750 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4751 | switch (o->kind) { |
| 4752 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4753 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4754 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4755 | if (!result) goto failed; |
| 4756 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4757 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4758 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4759 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4760 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4761 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4762 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4763 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4764 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4765 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4766 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4767 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4768 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4769 | goto failed; |
| 4770 | Py_DECREF(value); |
| 4771 | break; |
| 4772 | } |
| 4773 | value = ast2obj_int(o->lineno); |
| 4774 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4775 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4776 | goto failed; |
| 4777 | Py_DECREF(value); |
| 4778 | value = ast2obj_int(o->col_offset); |
| 4779 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4780 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4781 | goto failed; |
| 4782 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4783 | value = ast2obj_int(o->end_lineno); |
| 4784 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4785 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4786 | goto failed; |
| 4787 | Py_DECREF(value); |
| 4788 | value = ast2obj_int(o->end_col_offset); |
| 4789 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4790 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4791 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4792 | goto failed; |
| 4793 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4794 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4795 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4796 | Py_XDECREF(value); |
| 4797 | Py_XDECREF(result); |
| 4798 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4799 | } |
| 4800 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4801 | PyObject* |
| 4802 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4803 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4804 | arguments_ty o = (arguments_ty)_o; |
| 4805 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4806 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4807 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4808 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4809 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4810 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4811 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4812 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4813 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4814 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4815 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4816 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4817 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4818 | goto failed; |
| 4819 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4820 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4821 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4822 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4823 | goto failed; |
| 4824 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4825 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4826 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4827 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4828 | goto failed; |
| 4829 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4830 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4831 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4832 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4833 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4834 | goto failed; |
| 4835 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4836 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4837 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4838 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4839 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4840 | goto failed; |
| 4841 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4842 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4843 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4844 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4845 | goto failed; |
| 4846 | Py_DECREF(value); |
| 4847 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4848 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4849 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4850 | goto failed; |
| 4851 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4852 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4853 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4854 | Py_XDECREF(value); |
| 4855 | Py_XDECREF(result); |
| 4856 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4857 | } |
| 4858 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4859 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4860 | ast2obj_arg(void* _o) |
| 4861 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4862 | arg_ty o = (arg_ty)_o; |
| 4863 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4864 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4865 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4866 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4867 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4868 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4869 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4870 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4871 | if (!result) return NULL; |
| 4872 | value = ast2obj_identifier(o->arg); |
| 4873 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4874 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4875 | goto failed; |
| 4876 | Py_DECREF(value); |
| 4877 | value = ast2obj_expr(o->annotation); |
| 4878 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4879 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4880 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4881 | goto failed; |
| 4882 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4883 | value = ast2obj_string(o->type_comment); |
| 4884 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4885 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4886 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4887 | goto failed; |
| 4888 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4889 | value = ast2obj_int(o->lineno); |
| 4890 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4891 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4892 | goto failed; |
| 4893 | Py_DECREF(value); |
| 4894 | value = ast2obj_int(o->col_offset); |
| 4895 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4896 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4897 | goto failed; |
| 4898 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4899 | value = ast2obj_int(o->end_lineno); |
| 4900 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4901 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4902 | goto failed; |
| 4903 | Py_DECREF(value); |
| 4904 | value = ast2obj_int(o->end_col_offset); |
| 4905 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4906 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4907 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4908 | goto failed; |
| 4909 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4910 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4911 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4912 | Py_XDECREF(value); |
| 4913 | Py_XDECREF(result); |
| 4914 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4918 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4919 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4920 | keyword_ty o = (keyword_ty)_o; |
| 4921 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4922 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4923 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4924 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4925 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4926 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4927 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4928 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4929 | if (!result) return NULL; |
| 4930 | value = ast2obj_identifier(o->arg); |
| 4931 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4932 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4933 | goto failed; |
| 4934 | Py_DECREF(value); |
| 4935 | value = ast2obj_expr(o->value); |
| 4936 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4937 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4938 | goto failed; |
| 4939 | Py_DECREF(value); |
| 4940 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4941 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4942 | Py_XDECREF(value); |
| 4943 | Py_XDECREF(result); |
| 4944 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4947 | PyObject* |
| 4948 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4949 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4950 | alias_ty o = (alias_ty)_o; |
| 4951 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4952 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4953 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4954 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4955 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4956 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4957 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 4958 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4959 | if (!result) return NULL; |
| 4960 | value = ast2obj_identifier(o->name); |
| 4961 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4962 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4963 | goto failed; |
| 4964 | Py_DECREF(value); |
| 4965 | value = ast2obj_identifier(o->asname); |
| 4966 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4967 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4968 | goto failed; |
| 4969 | Py_DECREF(value); |
| 4970 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4971 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4972 | Py_XDECREF(value); |
| 4973 | Py_XDECREF(result); |
| 4974 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4975 | } |
| 4976 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4977 | PyObject* |
| 4978 | ast2obj_withitem(void* _o) |
| 4979 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4980 | withitem_ty o = (withitem_ty)_o; |
| 4981 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4982 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4983 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4984 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4985 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4986 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4987 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 4988 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4989 | if (!result) return NULL; |
| 4990 | value = ast2obj_expr(o->context_expr); |
| 4991 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4992 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 4993 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4994 | goto failed; |
| 4995 | Py_DECREF(value); |
| 4996 | value = ast2obj_expr(o->optional_vars); |
| 4997 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4998 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 4999 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5000 | goto failed; |
| 5001 | Py_DECREF(value); |
| 5002 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5003 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5004 | Py_XDECREF(value); |
| 5005 | Py_XDECREF(result); |
| 5006 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5007 | } |
| 5008 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5009 | PyObject* |
| 5010 | ast2obj_type_ignore(void* _o) |
| 5011 | { |
| 5012 | type_ignore_ty o = (type_ignore_ty)_o; |
| 5013 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5014 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5015 | if (!o) { |
| 5016 | Py_RETURN_NONE; |
| 5017 | } |
| 5018 | |
| 5019 | switch (o->kind) { |
| 5020 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5021 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 5022 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5023 | if (!result) goto failed; |
| 5024 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 5025 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5026 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 5027 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5028 | goto failed; |
| 5029 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5030 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 5031 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5032 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5033 | goto failed; |
| 5034 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5035 | break; |
| 5036 | } |
| 5037 | return result; |
| 5038 | failed: |
| 5039 | Py_XDECREF(value); |
| 5040 | Py_XDECREF(result); |
| 5041 | return NULL; |
| 5042 | } |
| 5043 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5044 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5045 | int |
| 5046 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 5047 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5048 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5049 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5050 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5051 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5052 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5053 | if (obj == Py_None) { |
| 5054 | *out = NULL; |
| 5055 | return 0; |
| 5056 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5057 | tp = astmodulestate_global->Module_type; |
| 5058 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5059 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5060 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5061 | } |
| 5062 | if (isinstance) { |
| 5063 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5064 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5065 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5066 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5067 | return 1; |
| 5068 | } |
| 5069 | if (tmp == NULL) { |
| 5070 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 5071 | return 1; |
| 5072 | } |
| 5073 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5074 | int res; |
| 5075 | Py_ssize_t len; |
| 5076 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5077 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5078 | 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] | 5079 | goto failed; |
| 5080 | } |
| 5081 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5082 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5083 | if (body == NULL) goto failed; |
| 5084 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5085 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5086 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5087 | Py_INCREF(tmp2); |
| 5088 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5089 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5090 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5091 | if (len != PyList_GET_SIZE(tmp)) { |
| 5092 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5093 | goto failed; |
| 5094 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5095 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5096 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5097 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5098 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5099 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5100 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5101 | return 1; |
| 5102 | } |
| 5103 | if (tmp == NULL) { |
| 5104 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5105 | return 1; |
| 5106 | } |
| 5107 | else { |
| 5108 | int res; |
| 5109 | Py_ssize_t len; |
| 5110 | Py_ssize_t i; |
| 5111 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5112 | 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] | 5113 | goto failed; |
| 5114 | } |
| 5115 | len = PyList_GET_SIZE(tmp); |
| 5116 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5117 | if (type_ignores == NULL) goto failed; |
| 5118 | for (i = 0; i < len; i++) { |
| 5119 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5120 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5121 | Py_INCREF(tmp2); |
| 5122 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5123 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5124 | if (res != 0) goto failed; |
| 5125 | if (len != PyList_GET_SIZE(tmp)) { |
| 5126 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5127 | goto failed; |
| 5128 | } |
| 5129 | asdl_seq_SET(type_ignores, i, val); |
| 5130 | } |
| 5131 | Py_CLEAR(tmp); |
| 5132 | } |
| 5133 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5134 | if (*out == NULL) goto failed; |
| 5135 | return 0; |
| 5136 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5137 | tp = astmodulestate_global->Interactive_type; |
| 5138 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5139 | if (isinstance == -1) { |
| 5140 | return 1; |
| 5141 | } |
| 5142 | if (isinstance) { |
| 5143 | asdl_seq* body; |
| 5144 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5145 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5146 | return 1; |
| 5147 | } |
| 5148 | if (tmp == NULL) { |
| 5149 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5150 | return 1; |
| 5151 | } |
| 5152 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5153 | int res; |
| 5154 | Py_ssize_t len; |
| 5155 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5156 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5157 | 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] | 5158 | goto failed; |
| 5159 | } |
| 5160 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5161 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5162 | if (body == NULL) goto failed; |
| 5163 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5164 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5165 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5166 | Py_INCREF(tmp2); |
| 5167 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5168 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5169 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5170 | if (len != PyList_GET_SIZE(tmp)) { |
| 5171 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5172 | goto failed; |
| 5173 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5174 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5175 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5176 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5177 | } |
| 5178 | *out = Interactive(body, arena); |
| 5179 | if (*out == NULL) goto failed; |
| 5180 | return 0; |
| 5181 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5182 | tp = astmodulestate_global->Expression_type; |
| 5183 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5184 | if (isinstance == -1) { |
| 5185 | return 1; |
| 5186 | } |
| 5187 | if (isinstance) { |
| 5188 | expr_ty body; |
| 5189 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5190 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5191 | return 1; |
| 5192 | } |
| 5193 | if (tmp == NULL) { |
| 5194 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5195 | return 1; |
| 5196 | } |
| 5197 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5198 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5199 | res = obj2ast_expr(tmp, &body, arena); |
| 5200 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5201 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5202 | } |
| 5203 | *out = Expression(body, arena); |
| 5204 | if (*out == NULL) goto failed; |
| 5205 | return 0; |
| 5206 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5207 | tp = astmodulestate_global->FunctionType_type; |
| 5208 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5209 | if (isinstance == -1) { |
| 5210 | return 1; |
| 5211 | } |
| 5212 | if (isinstance) { |
| 5213 | asdl_seq* argtypes; |
| 5214 | expr_ty returns; |
| 5215 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5216 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5217 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5218 | return 1; |
| 5219 | } |
| 5220 | if (tmp == NULL) { |
| 5221 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5222 | return 1; |
| 5223 | } |
| 5224 | else { |
| 5225 | int res; |
| 5226 | Py_ssize_t len; |
| 5227 | Py_ssize_t i; |
| 5228 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5229 | 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] | 5230 | goto failed; |
| 5231 | } |
| 5232 | len = PyList_GET_SIZE(tmp); |
| 5233 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5234 | if (argtypes == NULL) goto failed; |
| 5235 | for (i = 0; i < len; i++) { |
| 5236 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5237 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5238 | Py_INCREF(tmp2); |
| 5239 | res = obj2ast_expr(tmp2, &val, arena); |
| 5240 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5241 | if (res != 0) goto failed; |
| 5242 | if (len != PyList_GET_SIZE(tmp)) { |
| 5243 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5244 | goto failed; |
| 5245 | } |
| 5246 | asdl_seq_SET(argtypes, i, val); |
| 5247 | } |
| 5248 | Py_CLEAR(tmp); |
| 5249 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5250 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5251 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5252 | return 1; |
| 5253 | } |
| 5254 | if (tmp == NULL) { |
| 5255 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5256 | return 1; |
| 5257 | } |
| 5258 | else { |
| 5259 | int res; |
| 5260 | res = obj2ast_expr(tmp, &returns, arena); |
| 5261 | if (res != 0) goto failed; |
| 5262 | Py_CLEAR(tmp); |
| 5263 | } |
| 5264 | *out = FunctionType(argtypes, returns, arena); |
| 5265 | if (*out == NULL) goto failed; |
| 5266 | return 0; |
| 5267 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5268 | |
| 5269 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5270 | failed: |
| 5271 | Py_XDECREF(tmp); |
| 5272 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | int |
| 5276 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5277 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5278 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5279 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5280 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5281 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5282 | int lineno; |
| 5283 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5284 | int end_lineno; |
| 5285 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5286 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5287 | if (obj == Py_None) { |
| 5288 | *out = NULL; |
| 5289 | return 0; |
| 5290 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5291 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5292 | return 1; |
| 5293 | } |
| 5294 | if (tmp == NULL) { |
| 5295 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5296 | return 1; |
| 5297 | } |
| 5298 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5299 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5300 | res = obj2ast_int(tmp, &lineno, arena); |
| 5301 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5302 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5303 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5304 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5305 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5306 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5307 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5308 | if (tmp == NULL) { |
| 5309 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5310 | return 1; |
| 5311 | } |
| 5312 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5313 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5314 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5315 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5316 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5318 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5319 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5320 | return 1; |
| 5321 | } |
| 5322 | if (tmp == NULL || tmp == Py_None) { |
| 5323 | Py_CLEAR(tmp); |
| 5324 | end_lineno = 0; |
| 5325 | } |
| 5326 | else { |
| 5327 | int res; |
| 5328 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5329 | if (res != 0) goto failed; |
| 5330 | Py_CLEAR(tmp); |
| 5331 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5332 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5333 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5334 | return 1; |
| 5335 | } |
| 5336 | if (tmp == NULL || tmp == Py_None) { |
| 5337 | Py_CLEAR(tmp); |
| 5338 | end_col_offset = 0; |
| 5339 | } |
| 5340 | else { |
| 5341 | int res; |
| 5342 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5343 | if (res != 0) goto failed; |
| 5344 | Py_CLEAR(tmp); |
| 5345 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5346 | tp = astmodulestate_global->FunctionDef_type; |
| 5347 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5348 | if (isinstance == -1) { |
| 5349 | return 1; |
| 5350 | } |
| 5351 | if (isinstance) { |
| 5352 | identifier name; |
| 5353 | arguments_ty args; |
| 5354 | asdl_seq* body; |
| 5355 | asdl_seq* decorator_list; |
| 5356 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5357 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5358 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5359 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5360 | return 1; |
| 5361 | } |
| 5362 | if (tmp == NULL) { |
| 5363 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5364 | return 1; |
| 5365 | } |
| 5366 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5367 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5368 | res = obj2ast_identifier(tmp, &name, arena); |
| 5369 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5370 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5371 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5372 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5373 | return 1; |
| 5374 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5375 | if (tmp == NULL) { |
| 5376 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5377 | return 1; |
| 5378 | } |
| 5379 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5380 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5381 | res = obj2ast_arguments(tmp, &args, arena); |
| 5382 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5383 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5384 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5385 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5386 | return 1; |
| 5387 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5388 | if (tmp == NULL) { |
| 5389 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5390 | return 1; |
| 5391 | } |
| 5392 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5393 | int res; |
| 5394 | Py_ssize_t len; |
| 5395 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5396 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5397 | 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] | 5398 | goto failed; |
| 5399 | } |
| 5400 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5401 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5402 | if (body == NULL) goto failed; |
| 5403 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5404 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5405 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5406 | Py_INCREF(tmp2); |
| 5407 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5408 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5409 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5410 | if (len != PyList_GET_SIZE(tmp)) { |
| 5411 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5412 | goto failed; |
| 5413 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5414 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5415 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5416 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5417 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5418 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5419 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5420 | return 1; |
| 5421 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5422 | if (tmp == NULL) { |
| 5423 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5424 | return 1; |
| 5425 | } |
| 5426 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5427 | int res; |
| 5428 | Py_ssize_t len; |
| 5429 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5430 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5431 | 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] | 5432 | goto failed; |
| 5433 | } |
| 5434 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5435 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5436 | if (decorator_list == NULL) goto failed; |
| 5437 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5438 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5439 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5440 | Py_INCREF(tmp2); |
| 5441 | res = obj2ast_expr(tmp2, &val, arena); |
| 5442 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5443 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5444 | if (len != PyList_GET_SIZE(tmp)) { |
| 5445 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5446 | goto failed; |
| 5447 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5448 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5449 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5450 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5451 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5452 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5453 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5454 | return 1; |
| 5455 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5456 | if (tmp == NULL || tmp == Py_None) { |
| 5457 | Py_CLEAR(tmp); |
| 5458 | returns = NULL; |
| 5459 | } |
| 5460 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5461 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5462 | res = obj2ast_expr(tmp, &returns, arena); |
| 5463 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5464 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5465 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5466 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5467 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5468 | return 1; |
| 5469 | } |
| 5470 | if (tmp == NULL || tmp == Py_None) { |
| 5471 | Py_CLEAR(tmp); |
| 5472 | type_comment = NULL; |
| 5473 | } |
| 5474 | else { |
| 5475 | int res; |
| 5476 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5477 | if (res != 0) goto failed; |
| 5478 | Py_CLEAR(tmp); |
| 5479 | } |
| 5480 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5481 | type_comment, lineno, col_offset, end_lineno, |
| 5482 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5483 | if (*out == NULL) goto failed; |
| 5484 | return 0; |
| 5485 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5486 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5487 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5488 | if (isinstance == -1) { |
| 5489 | return 1; |
| 5490 | } |
| 5491 | if (isinstance) { |
| 5492 | identifier name; |
| 5493 | arguments_ty args; |
| 5494 | asdl_seq* body; |
| 5495 | asdl_seq* decorator_list; |
| 5496 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5497 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5498 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5499 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5500 | return 1; |
| 5501 | } |
| 5502 | if (tmp == NULL) { |
| 5503 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5504 | return 1; |
| 5505 | } |
| 5506 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5507 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5508 | res = obj2ast_identifier(tmp, &name, arena); |
| 5509 | if (res != 0) goto failed; |
| 5510 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5511 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5512 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5513 | return 1; |
| 5514 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5515 | if (tmp == NULL) { |
| 5516 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5517 | return 1; |
| 5518 | } |
| 5519 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5520 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5521 | res = obj2ast_arguments(tmp, &args, arena); |
| 5522 | if (res != 0) goto failed; |
| 5523 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5524 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5525 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5526 | return 1; |
| 5527 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5528 | if (tmp == NULL) { |
| 5529 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5530 | return 1; |
| 5531 | } |
| 5532 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5533 | int res; |
| 5534 | Py_ssize_t len; |
| 5535 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5536 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5537 | 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] | 5538 | goto failed; |
| 5539 | } |
| 5540 | len = PyList_GET_SIZE(tmp); |
| 5541 | body = _Py_asdl_seq_new(len, arena); |
| 5542 | if (body == NULL) goto failed; |
| 5543 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5544 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5545 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5546 | Py_INCREF(tmp2); |
| 5547 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5548 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5549 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5550 | if (len != PyList_GET_SIZE(tmp)) { |
| 5551 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5552 | goto failed; |
| 5553 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5554 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5555 | } |
| 5556 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5557 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5558 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5559 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5560 | return 1; |
| 5561 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5562 | if (tmp == NULL) { |
| 5563 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5564 | return 1; |
| 5565 | } |
| 5566 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5567 | int res; |
| 5568 | Py_ssize_t len; |
| 5569 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5570 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5571 | 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] | 5572 | goto failed; |
| 5573 | } |
| 5574 | len = PyList_GET_SIZE(tmp); |
| 5575 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5576 | if (decorator_list == NULL) goto failed; |
| 5577 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5578 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5579 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5580 | Py_INCREF(tmp2); |
| 5581 | res = obj2ast_expr(tmp2, &val, arena); |
| 5582 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5583 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5584 | if (len != PyList_GET_SIZE(tmp)) { |
| 5585 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5586 | goto failed; |
| 5587 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5588 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5589 | } |
| 5590 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5591 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5592 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5593 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5594 | return 1; |
| 5595 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5596 | if (tmp == NULL || tmp == Py_None) { |
| 5597 | Py_CLEAR(tmp); |
| 5598 | returns = NULL; |
| 5599 | } |
| 5600 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5601 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5602 | res = obj2ast_expr(tmp, &returns, arena); |
| 5603 | if (res != 0) goto failed; |
| 5604 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5605 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5606 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5607 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5608 | return 1; |
| 5609 | } |
| 5610 | if (tmp == NULL || tmp == Py_None) { |
| 5611 | Py_CLEAR(tmp); |
| 5612 | type_comment = NULL; |
| 5613 | } |
| 5614 | else { |
| 5615 | int res; |
| 5616 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5617 | if (res != 0) goto failed; |
| 5618 | Py_CLEAR(tmp); |
| 5619 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5620 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5621 | type_comment, lineno, col_offset, end_lineno, |
| 5622 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5623 | if (*out == NULL) goto failed; |
| 5624 | return 0; |
| 5625 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5626 | tp = astmodulestate_global->ClassDef_type; |
| 5627 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5628 | if (isinstance == -1) { |
| 5629 | return 1; |
| 5630 | } |
| 5631 | if (isinstance) { |
| 5632 | identifier name; |
| 5633 | asdl_seq* bases; |
| 5634 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5635 | asdl_seq* body; |
| 5636 | asdl_seq* decorator_list; |
| 5637 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5638 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5639 | return 1; |
| 5640 | } |
| 5641 | if (tmp == NULL) { |
| 5642 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5643 | return 1; |
| 5644 | } |
| 5645 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5646 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5647 | res = obj2ast_identifier(tmp, &name, arena); |
| 5648 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5649 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5650 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5651 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5652 | return 1; |
| 5653 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5654 | if (tmp == NULL) { |
| 5655 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5656 | return 1; |
| 5657 | } |
| 5658 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5659 | int res; |
| 5660 | Py_ssize_t len; |
| 5661 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5662 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5663 | 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] | 5664 | goto failed; |
| 5665 | } |
| 5666 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5667 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5668 | if (bases == NULL) goto failed; |
| 5669 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5670 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5671 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5672 | Py_INCREF(tmp2); |
| 5673 | res = obj2ast_expr(tmp2, &val, arena); |
| 5674 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5675 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5676 | if (len != PyList_GET_SIZE(tmp)) { |
| 5677 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5678 | goto failed; |
| 5679 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5680 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5681 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5682 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5683 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5684 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5685 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5686 | return 1; |
| 5687 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5688 | if (tmp == NULL) { |
| 5689 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5690 | return 1; |
| 5691 | } |
| 5692 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5693 | int res; |
| 5694 | Py_ssize_t len; |
| 5695 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5696 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5697 | 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] | 5698 | goto failed; |
| 5699 | } |
| 5700 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5701 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5702 | if (keywords == NULL) goto failed; |
| 5703 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5704 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5705 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5706 | Py_INCREF(tmp2); |
| 5707 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5708 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5709 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5710 | if (len != PyList_GET_SIZE(tmp)) { |
| 5711 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5712 | goto failed; |
| 5713 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5714 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5715 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5716 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5717 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5718 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5719 | return 1; |
| 5720 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5721 | if (tmp == NULL) { |
| 5722 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5723 | return 1; |
| 5724 | } |
| 5725 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5726 | int res; |
| 5727 | Py_ssize_t len; |
| 5728 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5729 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5730 | 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] | 5731 | goto failed; |
| 5732 | } |
| 5733 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5734 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5735 | if (body == NULL) goto failed; |
| 5736 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5737 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5738 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5739 | Py_INCREF(tmp2); |
| 5740 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5741 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5742 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5743 | if (len != PyList_GET_SIZE(tmp)) { |
| 5744 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5745 | goto failed; |
| 5746 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5747 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5748 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5749 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5750 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5751 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5752 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5753 | return 1; |
| 5754 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5755 | if (tmp == NULL) { |
| 5756 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5757 | return 1; |
| 5758 | } |
| 5759 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5760 | int res; |
| 5761 | Py_ssize_t len; |
| 5762 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5763 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5764 | 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] | 5765 | goto failed; |
| 5766 | } |
| 5767 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5768 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5769 | if (decorator_list == NULL) goto failed; |
| 5770 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5771 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5772 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5773 | Py_INCREF(tmp2); |
| 5774 | res = obj2ast_expr(tmp2, &val, arena); |
| 5775 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5776 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5777 | if (len != PyList_GET_SIZE(tmp)) { |
| 5778 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5779 | goto failed; |
| 5780 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5781 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5782 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5783 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5784 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5785 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5786 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5787 | if (*out == NULL) goto failed; |
| 5788 | return 0; |
| 5789 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5790 | tp = astmodulestate_global->Return_type; |
| 5791 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5792 | if (isinstance == -1) { |
| 5793 | return 1; |
| 5794 | } |
| 5795 | if (isinstance) { |
| 5796 | expr_ty value; |
| 5797 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5798 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5799 | return 1; |
| 5800 | } |
| 5801 | if (tmp == NULL || tmp == Py_None) { |
| 5802 | Py_CLEAR(tmp); |
| 5803 | value = NULL; |
| 5804 | } |
| 5805 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5806 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5807 | res = obj2ast_expr(tmp, &value, arena); |
| 5808 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5809 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5810 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5811 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5812 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5813 | if (*out == NULL) goto failed; |
| 5814 | return 0; |
| 5815 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5816 | tp = astmodulestate_global->Delete_type; |
| 5817 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5818 | if (isinstance == -1) { |
| 5819 | return 1; |
| 5820 | } |
| 5821 | if (isinstance) { |
| 5822 | asdl_seq* targets; |
| 5823 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5824 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5825 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5826 | return 1; |
| 5827 | } |
| 5828 | if (tmp == NULL) { |
| 5829 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5830 | return 1; |
| 5831 | } |
| 5832 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5833 | int res; |
| 5834 | Py_ssize_t len; |
| 5835 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5836 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5837 | 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] | 5838 | goto failed; |
| 5839 | } |
| 5840 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5841 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5842 | if (targets == NULL) goto failed; |
| 5843 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5844 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5845 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5846 | Py_INCREF(tmp2); |
| 5847 | res = obj2ast_expr(tmp2, &val, arena); |
| 5848 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5849 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5850 | if (len != PyList_GET_SIZE(tmp)) { |
| 5851 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5852 | goto failed; |
| 5853 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5854 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5855 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5856 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5857 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5858 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5859 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5860 | if (*out == NULL) goto failed; |
| 5861 | return 0; |
| 5862 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5863 | tp = astmodulestate_global->Assign_type; |
| 5864 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5865 | if (isinstance == -1) { |
| 5866 | return 1; |
| 5867 | } |
| 5868 | if (isinstance) { |
| 5869 | asdl_seq* targets; |
| 5870 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5871 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5872 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5873 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5874 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5875 | return 1; |
| 5876 | } |
| 5877 | if (tmp == NULL) { |
| 5878 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5879 | return 1; |
| 5880 | } |
| 5881 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5882 | int res; |
| 5883 | Py_ssize_t len; |
| 5884 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5885 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5886 | 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] | 5887 | goto failed; |
| 5888 | } |
| 5889 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5890 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5891 | if (targets == NULL) goto failed; |
| 5892 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5893 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5894 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5895 | Py_INCREF(tmp2); |
| 5896 | res = obj2ast_expr(tmp2, &val, arena); |
| 5897 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5898 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5899 | if (len != PyList_GET_SIZE(tmp)) { |
| 5900 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5901 | goto failed; |
| 5902 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5903 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5904 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5905 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5906 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5907 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5908 | return 1; |
| 5909 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5910 | if (tmp == NULL) { |
| 5911 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5912 | return 1; |
| 5913 | } |
| 5914 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5915 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5916 | res = obj2ast_expr(tmp, &value, arena); |
| 5917 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5918 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5919 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5920 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5921 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5922 | return 1; |
| 5923 | } |
| 5924 | if (tmp == NULL || tmp == Py_None) { |
| 5925 | Py_CLEAR(tmp); |
| 5926 | type_comment = NULL; |
| 5927 | } |
| 5928 | else { |
| 5929 | int res; |
| 5930 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5931 | if (res != 0) goto failed; |
| 5932 | Py_CLEAR(tmp); |
| 5933 | } |
| 5934 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5935 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5936 | if (*out == NULL) goto failed; |
| 5937 | return 0; |
| 5938 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5939 | tp = astmodulestate_global->AugAssign_type; |
| 5940 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5941 | if (isinstance == -1) { |
| 5942 | return 1; |
| 5943 | } |
| 5944 | if (isinstance) { |
| 5945 | expr_ty target; |
| 5946 | operator_ty op; |
| 5947 | expr_ty value; |
| 5948 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5949 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5950 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5951 | return 1; |
| 5952 | } |
| 5953 | if (tmp == NULL) { |
| 5954 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5955 | return 1; |
| 5956 | } |
| 5957 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5959 | res = obj2ast_expr(tmp, &target, arena); |
| 5960 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5961 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5962 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5963 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5964 | return 1; |
| 5965 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5966 | if (tmp == NULL) { |
| 5967 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5968 | return 1; |
| 5969 | } |
| 5970 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5971 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5972 | res = obj2ast_operator(tmp, &op, arena); |
| 5973 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5974 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5975 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5976 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5977 | return 1; |
| 5978 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5979 | if (tmp == NULL) { |
| 5980 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5981 | return 1; |
| 5982 | } |
| 5983 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5984 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5985 | res = obj2ast_expr(tmp, &value, arena); |
| 5986 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5987 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5988 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5989 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5990 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5991 | if (*out == NULL) goto failed; |
| 5992 | return 0; |
| 5993 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5994 | tp = astmodulestate_global->AnnAssign_type; |
| 5995 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5996 | if (isinstance == -1) { |
| 5997 | return 1; |
| 5998 | } |
| 5999 | if (isinstance) { |
| 6000 | expr_ty target; |
| 6001 | expr_ty annotation; |
| 6002 | expr_ty value; |
| 6003 | int simple; |
| 6004 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6005 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6006 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6007 | return 1; |
| 6008 | } |
| 6009 | if (tmp == NULL) { |
| 6010 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 6011 | return 1; |
| 6012 | } |
| 6013 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6014 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6015 | res = obj2ast_expr(tmp, &target, arena); |
| 6016 | if (res != 0) goto failed; |
| 6017 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6018 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6019 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 6020 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6021 | return 1; |
| 6022 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6023 | if (tmp == NULL) { |
| 6024 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 6025 | return 1; |
| 6026 | } |
| 6027 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6028 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6029 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6030 | if (res != 0) goto failed; |
| 6031 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6032 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6033 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6034 | return 1; |
| 6035 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6036 | if (tmp == NULL || tmp == Py_None) { |
| 6037 | Py_CLEAR(tmp); |
| 6038 | value = NULL; |
| 6039 | } |
| 6040 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6041 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6042 | res = obj2ast_expr(tmp, &value, arena); |
| 6043 | if (res != 0) goto failed; |
| 6044 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6045 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6046 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6047 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6048 | return 1; |
| 6049 | } |
| 6050 | if (tmp == NULL) { |
| 6051 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6052 | return 1; |
| 6053 | } |
| 6054 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6055 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6056 | res = obj2ast_int(tmp, &simple, arena); |
| 6057 | if (res != 0) goto failed; |
| 6058 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6059 | } |
| 6060 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6061 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6062 | if (*out == NULL) goto failed; |
| 6063 | return 0; |
| 6064 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6065 | tp = astmodulestate_global->For_type; |
| 6066 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6067 | if (isinstance == -1) { |
| 6068 | return 1; |
| 6069 | } |
| 6070 | if (isinstance) { |
| 6071 | expr_ty target; |
| 6072 | expr_ty iter; |
| 6073 | asdl_seq* body; |
| 6074 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6075 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6076 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6077 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6078 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6079 | return 1; |
| 6080 | } |
| 6081 | if (tmp == NULL) { |
| 6082 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6083 | return 1; |
| 6084 | } |
| 6085 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6086 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6087 | res = obj2ast_expr(tmp, &target, arena); |
| 6088 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6089 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6090 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6091 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6092 | return 1; |
| 6093 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6094 | if (tmp == NULL) { |
| 6095 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6096 | return 1; |
| 6097 | } |
| 6098 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6099 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6100 | res = obj2ast_expr(tmp, &iter, arena); |
| 6101 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6102 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6103 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6104 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6105 | return 1; |
| 6106 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6107 | if (tmp == NULL) { |
| 6108 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6109 | return 1; |
| 6110 | } |
| 6111 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6112 | int res; |
| 6113 | Py_ssize_t len; |
| 6114 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6115 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6116 | 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] | 6117 | goto failed; |
| 6118 | } |
| 6119 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6120 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6121 | if (body == NULL) goto failed; |
| 6122 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6123 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6124 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6125 | Py_INCREF(tmp2); |
| 6126 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6127 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6128 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6129 | if (len != PyList_GET_SIZE(tmp)) { |
| 6130 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6131 | goto failed; |
| 6132 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6133 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6134 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6135 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6136 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6137 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6138 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6139 | return 1; |
| 6140 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6141 | if (tmp == NULL) { |
| 6142 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6143 | return 1; |
| 6144 | } |
| 6145 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6146 | int res; |
| 6147 | Py_ssize_t len; |
| 6148 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6149 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6150 | 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] | 6151 | goto failed; |
| 6152 | } |
| 6153 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6154 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6155 | if (orelse == NULL) goto failed; |
| 6156 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6157 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6158 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6159 | Py_INCREF(tmp2); |
| 6160 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6161 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6162 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6163 | if (len != PyList_GET_SIZE(tmp)) { |
| 6164 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6165 | goto failed; |
| 6166 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6167 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6168 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6169 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6170 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6171 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6172 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6173 | return 1; |
| 6174 | } |
| 6175 | if (tmp == NULL || tmp == Py_None) { |
| 6176 | Py_CLEAR(tmp); |
| 6177 | type_comment = NULL; |
| 6178 | } |
| 6179 | else { |
| 6180 | int res; |
| 6181 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6182 | if (res != 0) goto failed; |
| 6183 | Py_CLEAR(tmp); |
| 6184 | } |
| 6185 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6186 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6187 | if (*out == NULL) goto failed; |
| 6188 | return 0; |
| 6189 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6190 | tp = astmodulestate_global->AsyncFor_type; |
| 6191 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6192 | if (isinstance == -1) { |
| 6193 | return 1; |
| 6194 | } |
| 6195 | if (isinstance) { |
| 6196 | expr_ty target; |
| 6197 | expr_ty iter; |
| 6198 | asdl_seq* body; |
| 6199 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6200 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6201 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6202 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6203 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6204 | return 1; |
| 6205 | } |
| 6206 | if (tmp == NULL) { |
| 6207 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6208 | return 1; |
| 6209 | } |
| 6210 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6211 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6212 | res = obj2ast_expr(tmp, &target, arena); |
| 6213 | if (res != 0) goto failed; |
| 6214 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6215 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6216 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6217 | return 1; |
| 6218 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6219 | if (tmp == NULL) { |
| 6220 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6221 | return 1; |
| 6222 | } |
| 6223 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6224 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6225 | res = obj2ast_expr(tmp, &iter, arena); |
| 6226 | if (res != 0) goto failed; |
| 6227 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6228 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6229 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6230 | return 1; |
| 6231 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6232 | if (tmp == NULL) { |
| 6233 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6234 | return 1; |
| 6235 | } |
| 6236 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6237 | int res; |
| 6238 | Py_ssize_t len; |
| 6239 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6240 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6241 | 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] | 6242 | goto failed; |
| 6243 | } |
| 6244 | len = PyList_GET_SIZE(tmp); |
| 6245 | body = _Py_asdl_seq_new(len, arena); |
| 6246 | if (body == NULL) goto failed; |
| 6247 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6248 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6249 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6250 | Py_INCREF(tmp2); |
| 6251 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6252 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6253 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6254 | if (len != PyList_GET_SIZE(tmp)) { |
| 6255 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6256 | goto failed; |
| 6257 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6258 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6259 | } |
| 6260 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6261 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6262 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6263 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6264 | return 1; |
| 6265 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6266 | if (tmp == NULL) { |
| 6267 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6268 | return 1; |
| 6269 | } |
| 6270 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6271 | int res; |
| 6272 | Py_ssize_t len; |
| 6273 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6274 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6275 | 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] | 6276 | goto failed; |
| 6277 | } |
| 6278 | len = PyList_GET_SIZE(tmp); |
| 6279 | orelse = _Py_asdl_seq_new(len, arena); |
| 6280 | if (orelse == NULL) goto failed; |
| 6281 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6282 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6283 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6284 | Py_INCREF(tmp2); |
| 6285 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6286 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6287 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6288 | if (len != PyList_GET_SIZE(tmp)) { |
| 6289 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6290 | goto failed; |
| 6291 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6292 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6293 | } |
| 6294 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6295 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6296 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6297 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6298 | return 1; |
| 6299 | } |
| 6300 | if (tmp == NULL || tmp == Py_None) { |
| 6301 | Py_CLEAR(tmp); |
| 6302 | type_comment = NULL; |
| 6303 | } |
| 6304 | else { |
| 6305 | int res; |
| 6306 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6307 | if (res != 0) goto failed; |
| 6308 | Py_CLEAR(tmp); |
| 6309 | } |
| 6310 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6311 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6312 | if (*out == NULL) goto failed; |
| 6313 | return 0; |
| 6314 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6315 | tp = astmodulestate_global->While_type; |
| 6316 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6317 | if (isinstance == -1) { |
| 6318 | return 1; |
| 6319 | } |
| 6320 | if (isinstance) { |
| 6321 | expr_ty test; |
| 6322 | asdl_seq* body; |
| 6323 | asdl_seq* orelse; |
| 6324 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6325 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6326 | return 1; |
| 6327 | } |
| 6328 | if (tmp == NULL) { |
| 6329 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6330 | return 1; |
| 6331 | } |
| 6332 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6333 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6334 | res = obj2ast_expr(tmp, &test, arena); |
| 6335 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6336 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6337 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6338 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6339 | return 1; |
| 6340 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6341 | if (tmp == NULL) { |
| 6342 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6343 | return 1; |
| 6344 | } |
| 6345 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6346 | int res; |
| 6347 | Py_ssize_t len; |
| 6348 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6349 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6350 | 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] | 6351 | goto failed; |
| 6352 | } |
| 6353 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6354 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6355 | if (body == NULL) goto failed; |
| 6356 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6357 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6358 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6359 | Py_INCREF(tmp2); |
| 6360 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6361 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6362 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6363 | if (len != PyList_GET_SIZE(tmp)) { |
| 6364 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6365 | goto failed; |
| 6366 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6367 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6368 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6369 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6370 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6371 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6372 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6373 | return 1; |
| 6374 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6375 | if (tmp == NULL) { |
| 6376 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6377 | return 1; |
| 6378 | } |
| 6379 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6380 | int res; |
| 6381 | Py_ssize_t len; |
| 6382 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6383 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6384 | 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] | 6385 | goto failed; |
| 6386 | } |
| 6387 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6388 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6389 | if (orelse == NULL) goto failed; |
| 6390 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6391 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6392 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6393 | Py_INCREF(tmp2); |
| 6394 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6395 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6396 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6397 | if (len != PyList_GET_SIZE(tmp)) { |
| 6398 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6399 | goto failed; |
| 6400 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6401 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6402 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6403 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6404 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6405 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6406 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6407 | if (*out == NULL) goto failed; |
| 6408 | return 0; |
| 6409 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6410 | tp = astmodulestate_global->If_type; |
| 6411 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6412 | if (isinstance == -1) { |
| 6413 | return 1; |
| 6414 | } |
| 6415 | if (isinstance) { |
| 6416 | expr_ty test; |
| 6417 | asdl_seq* body; |
| 6418 | asdl_seq* orelse; |
| 6419 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6420 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6421 | return 1; |
| 6422 | } |
| 6423 | if (tmp == NULL) { |
| 6424 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6425 | return 1; |
| 6426 | } |
| 6427 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6428 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6429 | res = obj2ast_expr(tmp, &test, arena); |
| 6430 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6431 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6432 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6433 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6434 | return 1; |
| 6435 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6436 | if (tmp == NULL) { |
| 6437 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6438 | return 1; |
| 6439 | } |
| 6440 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6441 | int res; |
| 6442 | Py_ssize_t len; |
| 6443 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6444 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6445 | 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] | 6446 | goto failed; |
| 6447 | } |
| 6448 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6449 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6450 | if (body == NULL) goto failed; |
| 6451 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6452 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6453 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6454 | Py_INCREF(tmp2); |
| 6455 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6456 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6457 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6458 | if (len != PyList_GET_SIZE(tmp)) { |
| 6459 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6460 | goto failed; |
| 6461 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6462 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6463 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6464 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6465 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6466 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6467 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6468 | return 1; |
| 6469 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6470 | if (tmp == NULL) { |
| 6471 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6472 | return 1; |
| 6473 | } |
| 6474 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6475 | int res; |
| 6476 | Py_ssize_t len; |
| 6477 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6478 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6479 | 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] | 6480 | goto failed; |
| 6481 | } |
| 6482 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6483 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6484 | if (orelse == NULL) goto failed; |
| 6485 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6486 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6487 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6488 | Py_INCREF(tmp2); |
| 6489 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6490 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6491 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6492 | if (len != PyList_GET_SIZE(tmp)) { |
| 6493 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6494 | goto failed; |
| 6495 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6496 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6497 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6498 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6499 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6500 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6501 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6502 | if (*out == NULL) goto failed; |
| 6503 | return 0; |
| 6504 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6505 | tp = astmodulestate_global->With_type; |
| 6506 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6507 | if (isinstance == -1) { |
| 6508 | return 1; |
| 6509 | } |
| 6510 | if (isinstance) { |
| 6511 | asdl_seq* items; |
| 6512 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6513 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6514 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6515 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6516 | return 1; |
| 6517 | } |
| 6518 | if (tmp == NULL) { |
| 6519 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6520 | return 1; |
| 6521 | } |
| 6522 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6523 | int res; |
| 6524 | Py_ssize_t len; |
| 6525 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6526 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6527 | 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] | 6528 | goto failed; |
| 6529 | } |
| 6530 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6531 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6532 | if (items == NULL) goto failed; |
| 6533 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6534 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6535 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6536 | Py_INCREF(tmp2); |
| 6537 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6538 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6539 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6540 | if (len != PyList_GET_SIZE(tmp)) { |
| 6541 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6542 | goto failed; |
| 6543 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6544 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6545 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6546 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6547 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6548 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6549 | return 1; |
| 6550 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6551 | if (tmp == NULL) { |
| 6552 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6553 | return 1; |
| 6554 | } |
| 6555 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6556 | int res; |
| 6557 | Py_ssize_t len; |
| 6558 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6559 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6560 | 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] | 6561 | goto failed; |
| 6562 | } |
| 6563 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6564 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6565 | if (body == NULL) goto failed; |
| 6566 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6567 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6568 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6569 | Py_INCREF(tmp2); |
| 6570 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6571 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6572 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6573 | if (len != PyList_GET_SIZE(tmp)) { |
| 6574 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6575 | goto failed; |
| 6576 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6577 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6578 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6579 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6580 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6581 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6582 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6583 | return 1; |
| 6584 | } |
| 6585 | if (tmp == NULL || tmp == Py_None) { |
| 6586 | Py_CLEAR(tmp); |
| 6587 | type_comment = NULL; |
| 6588 | } |
| 6589 | else { |
| 6590 | int res; |
| 6591 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6592 | if (res != 0) goto failed; |
| 6593 | Py_CLEAR(tmp); |
| 6594 | } |
| 6595 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6596 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6597 | if (*out == NULL) goto failed; |
| 6598 | return 0; |
| 6599 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6600 | tp = astmodulestate_global->AsyncWith_type; |
| 6601 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6602 | if (isinstance == -1) { |
| 6603 | return 1; |
| 6604 | } |
| 6605 | if (isinstance) { |
| 6606 | asdl_seq* items; |
| 6607 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6608 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6609 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6610 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6611 | return 1; |
| 6612 | } |
| 6613 | if (tmp == NULL) { |
| 6614 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6615 | return 1; |
| 6616 | } |
| 6617 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6618 | int res; |
| 6619 | Py_ssize_t len; |
| 6620 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6621 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6622 | 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] | 6623 | goto failed; |
| 6624 | } |
| 6625 | len = PyList_GET_SIZE(tmp); |
| 6626 | items = _Py_asdl_seq_new(len, arena); |
| 6627 | if (items == NULL) goto failed; |
| 6628 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6629 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6630 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6631 | Py_INCREF(tmp2); |
| 6632 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6633 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6634 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6635 | if (len != PyList_GET_SIZE(tmp)) { |
| 6636 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6637 | goto failed; |
| 6638 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6639 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6640 | } |
| 6641 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6642 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6643 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6644 | return 1; |
| 6645 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6646 | if (tmp == NULL) { |
| 6647 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6648 | return 1; |
| 6649 | } |
| 6650 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6651 | int res; |
| 6652 | Py_ssize_t len; |
| 6653 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6654 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6655 | 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] | 6656 | goto failed; |
| 6657 | } |
| 6658 | len = PyList_GET_SIZE(tmp); |
| 6659 | body = _Py_asdl_seq_new(len, arena); |
| 6660 | if (body == NULL) goto failed; |
| 6661 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6662 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6663 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6664 | Py_INCREF(tmp2); |
| 6665 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6666 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6667 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6668 | if (len != PyList_GET_SIZE(tmp)) { |
| 6669 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6670 | goto failed; |
| 6671 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6672 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6673 | } |
| 6674 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6675 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6676 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6677 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6678 | return 1; |
| 6679 | } |
| 6680 | if (tmp == NULL || tmp == Py_None) { |
| 6681 | Py_CLEAR(tmp); |
| 6682 | type_comment = NULL; |
| 6683 | } |
| 6684 | else { |
| 6685 | int res; |
| 6686 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6687 | if (res != 0) goto failed; |
| 6688 | Py_CLEAR(tmp); |
| 6689 | } |
| 6690 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6691 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6692 | if (*out == NULL) goto failed; |
| 6693 | return 0; |
| 6694 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6695 | tp = astmodulestate_global->Raise_type; |
| 6696 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6697 | if (isinstance == -1) { |
| 6698 | return 1; |
| 6699 | } |
| 6700 | if (isinstance) { |
| 6701 | expr_ty exc; |
| 6702 | expr_ty cause; |
| 6703 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6704 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6705 | return 1; |
| 6706 | } |
| 6707 | if (tmp == NULL || tmp == Py_None) { |
| 6708 | Py_CLEAR(tmp); |
| 6709 | exc = NULL; |
| 6710 | } |
| 6711 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6712 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6713 | res = obj2ast_expr(tmp, &exc, arena); |
| 6714 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6715 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6716 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6717 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6718 | return 1; |
| 6719 | } |
| 6720 | if (tmp == NULL || tmp == Py_None) { |
| 6721 | Py_CLEAR(tmp); |
| 6722 | cause = NULL; |
| 6723 | } |
| 6724 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6725 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6726 | res = obj2ast_expr(tmp, &cause, arena); |
| 6727 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6728 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6729 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6730 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6731 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6732 | if (*out == NULL) goto failed; |
| 6733 | return 0; |
| 6734 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6735 | tp = astmodulestate_global->Try_type; |
| 6736 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6737 | if (isinstance == -1) { |
| 6738 | return 1; |
| 6739 | } |
| 6740 | if (isinstance) { |
| 6741 | asdl_seq* body; |
| 6742 | asdl_seq* handlers; |
| 6743 | asdl_seq* orelse; |
| 6744 | asdl_seq* finalbody; |
| 6745 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6746 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6747 | return 1; |
| 6748 | } |
| 6749 | if (tmp == NULL) { |
| 6750 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6751 | return 1; |
| 6752 | } |
| 6753 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6754 | int res; |
| 6755 | Py_ssize_t len; |
| 6756 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6757 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6758 | 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] | 6759 | goto failed; |
| 6760 | } |
| 6761 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6762 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6763 | if (body == NULL) goto failed; |
| 6764 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6765 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6766 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6767 | Py_INCREF(tmp2); |
| 6768 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6769 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6770 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6771 | if (len != PyList_GET_SIZE(tmp)) { |
| 6772 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6773 | goto failed; |
| 6774 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6775 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6776 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6777 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6778 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6779 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6780 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6781 | return 1; |
| 6782 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6783 | if (tmp == NULL) { |
| 6784 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6785 | return 1; |
| 6786 | } |
| 6787 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6788 | int res; |
| 6789 | Py_ssize_t len; |
| 6790 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6791 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6792 | 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] | 6793 | goto failed; |
| 6794 | } |
| 6795 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6796 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6797 | if (handlers == NULL) goto failed; |
| 6798 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6799 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6800 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6801 | Py_INCREF(tmp2); |
| 6802 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6803 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6804 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6805 | if (len != PyList_GET_SIZE(tmp)) { |
| 6806 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6807 | goto failed; |
| 6808 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6809 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6810 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6811 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6812 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6813 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6814 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6815 | return 1; |
| 6816 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6817 | if (tmp == NULL) { |
| 6818 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6819 | return 1; |
| 6820 | } |
| 6821 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6822 | int res; |
| 6823 | Py_ssize_t len; |
| 6824 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6825 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6826 | 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] | 6827 | goto failed; |
| 6828 | } |
| 6829 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6830 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6831 | if (orelse == NULL) goto failed; |
| 6832 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6833 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6834 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6835 | Py_INCREF(tmp2); |
| 6836 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6837 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6838 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6839 | if (len != PyList_GET_SIZE(tmp)) { |
| 6840 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6841 | goto failed; |
| 6842 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6843 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6844 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6845 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6846 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6847 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6848 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6849 | return 1; |
| 6850 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6851 | if (tmp == NULL) { |
| 6852 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6853 | return 1; |
| 6854 | } |
| 6855 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6856 | int res; |
| 6857 | Py_ssize_t len; |
| 6858 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6859 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6860 | 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] | 6861 | goto failed; |
| 6862 | } |
| 6863 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6864 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6865 | if (finalbody == NULL) goto failed; |
| 6866 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6867 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6868 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6869 | Py_INCREF(tmp2); |
| 6870 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6871 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6872 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6873 | if (len != PyList_GET_SIZE(tmp)) { |
| 6874 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6875 | goto failed; |
| 6876 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6877 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6878 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6879 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6880 | } |
| 6881 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6882 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6883 | if (*out == NULL) goto failed; |
| 6884 | return 0; |
| 6885 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6886 | tp = astmodulestate_global->Assert_type; |
| 6887 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6888 | if (isinstance == -1) { |
| 6889 | return 1; |
| 6890 | } |
| 6891 | if (isinstance) { |
| 6892 | expr_ty test; |
| 6893 | expr_ty msg; |
| 6894 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6895 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6896 | return 1; |
| 6897 | } |
| 6898 | if (tmp == NULL) { |
| 6899 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6900 | return 1; |
| 6901 | } |
| 6902 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6903 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6904 | res = obj2ast_expr(tmp, &test, arena); |
| 6905 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6906 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6907 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6908 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6909 | return 1; |
| 6910 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6911 | if (tmp == NULL || tmp == Py_None) { |
| 6912 | Py_CLEAR(tmp); |
| 6913 | msg = NULL; |
| 6914 | } |
| 6915 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6916 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6917 | res = obj2ast_expr(tmp, &msg, arena); |
| 6918 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6919 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6920 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6921 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6922 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6923 | if (*out == NULL) goto failed; |
| 6924 | return 0; |
| 6925 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6926 | tp = astmodulestate_global->Import_type; |
| 6927 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6928 | if (isinstance == -1) { |
| 6929 | return 1; |
| 6930 | } |
| 6931 | if (isinstance) { |
| 6932 | asdl_seq* names; |
| 6933 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6934 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6935 | return 1; |
| 6936 | } |
| 6937 | if (tmp == NULL) { |
| 6938 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6939 | return 1; |
| 6940 | } |
| 6941 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6942 | int res; |
| 6943 | Py_ssize_t len; |
| 6944 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6945 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6946 | 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] | 6947 | goto failed; |
| 6948 | } |
| 6949 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6950 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6951 | if (names == NULL) goto failed; |
| 6952 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6953 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6954 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6955 | Py_INCREF(tmp2); |
| 6956 | res = obj2ast_alias(tmp2, &val, arena); |
| 6957 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6958 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6959 | if (len != PyList_GET_SIZE(tmp)) { |
| 6960 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 6961 | goto failed; |
| 6962 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6963 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6964 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6965 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6966 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6967 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6968 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6969 | if (*out == NULL) goto failed; |
| 6970 | return 0; |
| 6971 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6972 | tp = astmodulestate_global->ImportFrom_type; |
| 6973 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6974 | if (isinstance == -1) { |
| 6975 | return 1; |
| 6976 | } |
| 6977 | if (isinstance) { |
| 6978 | identifier module; |
| 6979 | asdl_seq* names; |
| 6980 | int level; |
| 6981 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6982 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 6983 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6984 | return 1; |
| 6985 | } |
| 6986 | if (tmp == NULL || tmp == Py_None) { |
| 6987 | Py_CLEAR(tmp); |
| 6988 | module = NULL; |
| 6989 | } |
| 6990 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6991 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6992 | res = obj2ast_identifier(tmp, &module, arena); |
| 6993 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6994 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6995 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6996 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6997 | return 1; |
| 6998 | } |
| 6999 | if (tmp == NULL) { |
| 7000 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 7001 | return 1; |
| 7002 | } |
| 7003 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7004 | int res; |
| 7005 | Py_ssize_t len; |
| 7006 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7007 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7008 | 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] | 7009 | goto failed; |
| 7010 | } |
| 7011 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7012 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7013 | if (names == NULL) goto failed; |
| 7014 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7015 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7016 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7017 | Py_INCREF(tmp2); |
| 7018 | res = obj2ast_alias(tmp2, &val, arena); |
| 7019 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7020 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7021 | if (len != PyList_GET_SIZE(tmp)) { |
| 7022 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 7023 | goto failed; |
| 7024 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7025 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7026 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7027 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7028 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7029 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7030 | return 1; |
| 7031 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7032 | if (tmp == NULL || tmp == Py_None) { |
| 7033 | Py_CLEAR(tmp); |
| 7034 | level = 0; |
| 7035 | } |
| 7036 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7037 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7038 | res = obj2ast_int(tmp, &level, arena); |
| 7039 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7040 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7041 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7042 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7043 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7044 | if (*out == NULL) goto failed; |
| 7045 | return 0; |
| 7046 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7047 | tp = astmodulestate_global->Global_type; |
| 7048 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7049 | if (isinstance == -1) { |
| 7050 | return 1; |
| 7051 | } |
| 7052 | if (isinstance) { |
| 7053 | asdl_seq* names; |
| 7054 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7055 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7056 | return 1; |
| 7057 | } |
| 7058 | if (tmp == NULL) { |
| 7059 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7060 | return 1; |
| 7061 | } |
| 7062 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7063 | int res; |
| 7064 | Py_ssize_t len; |
| 7065 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7066 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7067 | PyErr_Format(PyExc_TypeError, "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] | 7068 | goto failed; |
| 7069 | } |
| 7070 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7071 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7072 | if (names == NULL) goto failed; |
| 7073 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7074 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7075 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7076 | Py_INCREF(tmp2); |
| 7077 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7078 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7079 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7080 | if (len != PyList_GET_SIZE(tmp)) { |
| 7081 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7082 | goto failed; |
| 7083 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7084 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7085 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7086 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7087 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7088 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7089 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7090 | if (*out == NULL) goto failed; |
| 7091 | return 0; |
| 7092 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7093 | tp = astmodulestate_global->Nonlocal_type; |
| 7094 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7095 | if (isinstance == -1) { |
| 7096 | return 1; |
| 7097 | } |
| 7098 | if (isinstance) { |
| 7099 | asdl_seq* names; |
| 7100 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7101 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7102 | return 1; |
| 7103 | } |
| 7104 | if (tmp == NULL) { |
| 7105 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7106 | return 1; |
| 7107 | } |
| 7108 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7109 | int res; |
| 7110 | Py_ssize_t len; |
| 7111 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7112 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7113 | 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] | 7114 | goto failed; |
| 7115 | } |
| 7116 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7117 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7118 | if (names == NULL) goto failed; |
| 7119 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7120 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7121 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7122 | Py_INCREF(tmp2); |
| 7123 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7124 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7125 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7126 | if (len != PyList_GET_SIZE(tmp)) { |
| 7127 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7128 | goto failed; |
| 7129 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7130 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7131 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7132 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7133 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7134 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7135 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7136 | if (*out == NULL) goto failed; |
| 7137 | return 0; |
| 7138 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7139 | tp = astmodulestate_global->Expr_type; |
| 7140 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7141 | if (isinstance == -1) { |
| 7142 | return 1; |
| 7143 | } |
| 7144 | if (isinstance) { |
| 7145 | expr_ty value; |
| 7146 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7147 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7148 | return 1; |
| 7149 | } |
| 7150 | if (tmp == NULL) { |
| 7151 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7152 | return 1; |
| 7153 | } |
| 7154 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7155 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7156 | res = obj2ast_expr(tmp, &value, arena); |
| 7157 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7158 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7159 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7160 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7161 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7162 | if (*out == NULL) goto failed; |
| 7163 | return 0; |
| 7164 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7165 | tp = astmodulestate_global->Pass_type; |
| 7166 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7167 | if (isinstance == -1) { |
| 7168 | return 1; |
| 7169 | } |
| 7170 | if (isinstance) { |
| 7171 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7172 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7173 | if (*out == NULL) goto failed; |
| 7174 | return 0; |
| 7175 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7176 | tp = astmodulestate_global->Break_type; |
| 7177 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7178 | if (isinstance == -1) { |
| 7179 | return 1; |
| 7180 | } |
| 7181 | if (isinstance) { |
| 7182 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7183 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7184 | if (*out == NULL) goto failed; |
| 7185 | return 0; |
| 7186 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7187 | tp = astmodulestate_global->Continue_type; |
| 7188 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7189 | if (isinstance == -1) { |
| 7190 | return 1; |
| 7191 | } |
| 7192 | if (isinstance) { |
| 7193 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7194 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7195 | if (*out == NULL) goto failed; |
| 7196 | return 0; |
| 7197 | } |
| 7198 | |
| 7199 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7200 | failed: |
| 7201 | Py_XDECREF(tmp); |
| 7202 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7203 | } |
| 7204 | |
| 7205 | int |
| 7206 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7207 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7208 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7209 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7210 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7211 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7212 | int lineno; |
| 7213 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7214 | int end_lineno; |
| 7215 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7216 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7217 | if (obj == Py_None) { |
| 7218 | *out = NULL; |
| 7219 | return 0; |
| 7220 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7221 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7222 | return 1; |
| 7223 | } |
| 7224 | if (tmp == NULL) { |
| 7225 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7226 | return 1; |
| 7227 | } |
| 7228 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7229 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7230 | res = obj2ast_int(tmp, &lineno, arena); |
| 7231 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7232 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7233 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7234 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7235 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7236 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7237 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7238 | if (tmp == NULL) { |
| 7239 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7240 | return 1; |
| 7241 | } |
| 7242 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7243 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7244 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7245 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7246 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7247 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7248 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7249 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7250 | return 1; |
| 7251 | } |
| 7252 | if (tmp == NULL || tmp == Py_None) { |
| 7253 | Py_CLEAR(tmp); |
| 7254 | end_lineno = 0; |
| 7255 | } |
| 7256 | else { |
| 7257 | int res; |
| 7258 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7259 | if (res != 0) goto failed; |
| 7260 | Py_CLEAR(tmp); |
| 7261 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7262 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7263 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7264 | return 1; |
| 7265 | } |
| 7266 | if (tmp == NULL || tmp == Py_None) { |
| 7267 | Py_CLEAR(tmp); |
| 7268 | end_col_offset = 0; |
| 7269 | } |
| 7270 | else { |
| 7271 | int res; |
| 7272 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7273 | if (res != 0) goto failed; |
| 7274 | Py_CLEAR(tmp); |
| 7275 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7276 | tp = astmodulestate_global->BoolOp_type; |
| 7277 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7278 | if (isinstance == -1) { |
| 7279 | return 1; |
| 7280 | } |
| 7281 | if (isinstance) { |
| 7282 | boolop_ty op; |
| 7283 | asdl_seq* values; |
| 7284 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7285 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7286 | return 1; |
| 7287 | } |
| 7288 | if (tmp == NULL) { |
| 7289 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7290 | return 1; |
| 7291 | } |
| 7292 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7293 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7294 | res = obj2ast_boolop(tmp, &op, arena); |
| 7295 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7296 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7297 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7298 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7299 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7300 | return 1; |
| 7301 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7302 | if (tmp == NULL) { |
| 7303 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7304 | return 1; |
| 7305 | } |
| 7306 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7307 | int res; |
| 7308 | Py_ssize_t len; |
| 7309 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7310 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7311 | 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] | 7312 | goto failed; |
| 7313 | } |
| 7314 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7315 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7316 | if (values == NULL) goto failed; |
| 7317 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7318 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7319 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7320 | Py_INCREF(tmp2); |
| 7321 | res = obj2ast_expr(tmp2, &val, arena); |
| 7322 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7323 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7324 | if (len != PyList_GET_SIZE(tmp)) { |
| 7325 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7326 | goto failed; |
| 7327 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7328 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7329 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7330 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7331 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7332 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7333 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7334 | if (*out == NULL) goto failed; |
| 7335 | return 0; |
| 7336 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7337 | tp = astmodulestate_global->NamedExpr_type; |
| 7338 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7339 | if (isinstance == -1) { |
| 7340 | return 1; |
| 7341 | } |
| 7342 | if (isinstance) { |
| 7343 | expr_ty target; |
| 7344 | expr_ty value; |
| 7345 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7346 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7347 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7348 | return 1; |
| 7349 | } |
| 7350 | if (tmp == NULL) { |
| 7351 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7352 | return 1; |
| 7353 | } |
| 7354 | else { |
| 7355 | int res; |
| 7356 | res = obj2ast_expr(tmp, &target, arena); |
| 7357 | if (res != 0) goto failed; |
| 7358 | Py_CLEAR(tmp); |
| 7359 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7360 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7361 | return 1; |
| 7362 | } |
| 7363 | if (tmp == NULL) { |
| 7364 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7365 | return 1; |
| 7366 | } |
| 7367 | else { |
| 7368 | int res; |
| 7369 | res = obj2ast_expr(tmp, &value, arena); |
| 7370 | if (res != 0) goto failed; |
| 7371 | Py_CLEAR(tmp); |
| 7372 | } |
| 7373 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7374 | end_col_offset, arena); |
| 7375 | if (*out == NULL) goto failed; |
| 7376 | return 0; |
| 7377 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7378 | tp = astmodulestate_global->BinOp_type; |
| 7379 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7380 | if (isinstance == -1) { |
| 7381 | return 1; |
| 7382 | } |
| 7383 | if (isinstance) { |
| 7384 | expr_ty left; |
| 7385 | operator_ty op; |
| 7386 | expr_ty right; |
| 7387 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7388 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7389 | return 1; |
| 7390 | } |
| 7391 | if (tmp == NULL) { |
| 7392 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7393 | return 1; |
| 7394 | } |
| 7395 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7396 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7397 | res = obj2ast_expr(tmp, &left, arena); |
| 7398 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7399 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7400 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7401 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7402 | return 1; |
| 7403 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7404 | if (tmp == NULL) { |
| 7405 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7406 | return 1; |
| 7407 | } |
| 7408 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7409 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7410 | res = obj2ast_operator(tmp, &op, arena); |
| 7411 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7412 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7413 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7414 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7415 | return 1; |
| 7416 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7417 | if (tmp == NULL) { |
| 7418 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7419 | return 1; |
| 7420 | } |
| 7421 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7422 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7423 | res = obj2ast_expr(tmp, &right, arena); |
| 7424 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7425 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7426 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7427 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7428 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7429 | if (*out == NULL) goto failed; |
| 7430 | return 0; |
| 7431 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7432 | tp = astmodulestate_global->UnaryOp_type; |
| 7433 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7434 | if (isinstance == -1) { |
| 7435 | return 1; |
| 7436 | } |
| 7437 | if (isinstance) { |
| 7438 | unaryop_ty op; |
| 7439 | expr_ty operand; |
| 7440 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7441 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7442 | return 1; |
| 7443 | } |
| 7444 | if (tmp == NULL) { |
| 7445 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7446 | return 1; |
| 7447 | } |
| 7448 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7449 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7450 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7451 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7452 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7453 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7454 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7455 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7456 | return 1; |
| 7457 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7458 | if (tmp == NULL) { |
| 7459 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7460 | return 1; |
| 7461 | } |
| 7462 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7463 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7464 | res = obj2ast_expr(tmp, &operand, arena); |
| 7465 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7466 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7467 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7468 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7469 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7470 | if (*out == NULL) goto failed; |
| 7471 | return 0; |
| 7472 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7473 | tp = astmodulestate_global->Lambda_type; |
| 7474 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7475 | if (isinstance == -1) { |
| 7476 | return 1; |
| 7477 | } |
| 7478 | if (isinstance) { |
| 7479 | arguments_ty args; |
| 7480 | expr_ty body; |
| 7481 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7482 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7483 | return 1; |
| 7484 | } |
| 7485 | if (tmp == NULL) { |
| 7486 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7487 | return 1; |
| 7488 | } |
| 7489 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7490 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7491 | res = obj2ast_arguments(tmp, &args, arena); |
| 7492 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7493 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7494 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7495 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7496 | return 1; |
| 7497 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7498 | if (tmp == NULL) { |
| 7499 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7500 | return 1; |
| 7501 | } |
| 7502 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7503 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7504 | res = obj2ast_expr(tmp, &body, arena); |
| 7505 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7506 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7507 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7508 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7509 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7510 | if (*out == NULL) goto failed; |
| 7511 | return 0; |
| 7512 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7513 | tp = astmodulestate_global->IfExp_type; |
| 7514 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7515 | if (isinstance == -1) { |
| 7516 | return 1; |
| 7517 | } |
| 7518 | if (isinstance) { |
| 7519 | expr_ty test; |
| 7520 | expr_ty body; |
| 7521 | expr_ty orelse; |
| 7522 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7523 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7524 | return 1; |
| 7525 | } |
| 7526 | if (tmp == NULL) { |
| 7527 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7528 | return 1; |
| 7529 | } |
| 7530 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7531 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7532 | res = obj2ast_expr(tmp, &test, arena); |
| 7533 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7534 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7535 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7536 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7537 | return 1; |
| 7538 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7539 | if (tmp == NULL) { |
| 7540 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7541 | return 1; |
| 7542 | } |
| 7543 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7544 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7545 | res = obj2ast_expr(tmp, &body, arena); |
| 7546 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7547 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7548 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7549 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7550 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7551 | return 1; |
| 7552 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7553 | if (tmp == NULL) { |
| 7554 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7555 | return 1; |
| 7556 | } |
| 7557 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7558 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7559 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7560 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7561 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7562 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7563 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7564 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7565 | if (*out == NULL) goto failed; |
| 7566 | return 0; |
| 7567 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7568 | tp = astmodulestate_global->Dict_type; |
| 7569 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7570 | if (isinstance == -1) { |
| 7571 | return 1; |
| 7572 | } |
| 7573 | if (isinstance) { |
| 7574 | asdl_seq* keys; |
| 7575 | asdl_seq* values; |
| 7576 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7577 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7578 | return 1; |
| 7579 | } |
| 7580 | if (tmp == NULL) { |
| 7581 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7582 | return 1; |
| 7583 | } |
| 7584 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7585 | int res; |
| 7586 | Py_ssize_t len; |
| 7587 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7588 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7589 | 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] | 7590 | goto failed; |
| 7591 | } |
| 7592 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7593 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7594 | if (keys == NULL) goto failed; |
| 7595 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7596 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7597 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7598 | Py_INCREF(tmp2); |
| 7599 | res = obj2ast_expr(tmp2, &val, arena); |
| 7600 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7601 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7602 | if (len != PyList_GET_SIZE(tmp)) { |
| 7603 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7604 | goto failed; |
| 7605 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7606 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7607 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7608 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7609 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7610 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7611 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7612 | return 1; |
| 7613 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7614 | if (tmp == NULL) { |
| 7615 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7616 | return 1; |
| 7617 | } |
| 7618 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7619 | int res; |
| 7620 | Py_ssize_t len; |
| 7621 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7622 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7623 | 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] | 7624 | goto failed; |
| 7625 | } |
| 7626 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7627 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7628 | if (values == NULL) goto failed; |
| 7629 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7630 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7631 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7632 | Py_INCREF(tmp2); |
| 7633 | res = obj2ast_expr(tmp2, &val, arena); |
| 7634 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7635 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7636 | if (len != PyList_GET_SIZE(tmp)) { |
| 7637 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7638 | goto failed; |
| 7639 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7640 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7641 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7642 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7643 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7644 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7645 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7646 | if (*out == NULL) goto failed; |
| 7647 | return 0; |
| 7648 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7649 | tp = astmodulestate_global->Set_type; |
| 7650 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7651 | if (isinstance == -1) { |
| 7652 | return 1; |
| 7653 | } |
| 7654 | if (isinstance) { |
| 7655 | asdl_seq* elts; |
| 7656 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7657 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7658 | return 1; |
| 7659 | } |
| 7660 | if (tmp == NULL) { |
| 7661 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7662 | return 1; |
| 7663 | } |
| 7664 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7665 | int res; |
| 7666 | Py_ssize_t len; |
| 7667 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7668 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7669 | 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] | 7670 | goto failed; |
| 7671 | } |
| 7672 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7673 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7674 | if (elts == NULL) goto failed; |
| 7675 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7676 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7677 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7678 | Py_INCREF(tmp2); |
| 7679 | res = obj2ast_expr(tmp2, &val, arena); |
| 7680 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7681 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7682 | if (len != PyList_GET_SIZE(tmp)) { |
| 7683 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7684 | goto failed; |
| 7685 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7686 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7687 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7688 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7689 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7690 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7691 | if (*out == NULL) goto failed; |
| 7692 | return 0; |
| 7693 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7694 | tp = astmodulestate_global->ListComp_type; |
| 7695 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7696 | if (isinstance == -1) { |
| 7697 | return 1; |
| 7698 | } |
| 7699 | if (isinstance) { |
| 7700 | expr_ty elt; |
| 7701 | asdl_seq* generators; |
| 7702 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7703 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7704 | return 1; |
| 7705 | } |
| 7706 | if (tmp == NULL) { |
| 7707 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7708 | return 1; |
| 7709 | } |
| 7710 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7711 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7712 | res = obj2ast_expr(tmp, &elt, arena); |
| 7713 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7714 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7715 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7716 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7717 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7718 | return 1; |
| 7719 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7720 | if (tmp == NULL) { |
| 7721 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7722 | return 1; |
| 7723 | } |
| 7724 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7725 | int res; |
| 7726 | Py_ssize_t len; |
| 7727 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7728 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7729 | 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] | 7730 | goto failed; |
| 7731 | } |
| 7732 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7733 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7734 | if (generators == NULL) goto failed; |
| 7735 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7736 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7737 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7738 | Py_INCREF(tmp2); |
| 7739 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7740 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7741 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7742 | if (len != PyList_GET_SIZE(tmp)) { |
| 7743 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7744 | goto failed; |
| 7745 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7746 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7747 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7748 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7749 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7750 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7751 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7752 | if (*out == NULL) goto failed; |
| 7753 | return 0; |
| 7754 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7755 | tp = astmodulestate_global->SetComp_type; |
| 7756 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7757 | if (isinstance == -1) { |
| 7758 | return 1; |
| 7759 | } |
| 7760 | if (isinstance) { |
| 7761 | expr_ty elt; |
| 7762 | asdl_seq* generators; |
| 7763 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7764 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7765 | return 1; |
| 7766 | } |
| 7767 | if (tmp == NULL) { |
| 7768 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7769 | return 1; |
| 7770 | } |
| 7771 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7772 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7773 | res = obj2ast_expr(tmp, &elt, arena); |
| 7774 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7775 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7776 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7777 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7778 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7779 | return 1; |
| 7780 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7781 | if (tmp == NULL) { |
| 7782 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7783 | return 1; |
| 7784 | } |
| 7785 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7786 | int res; |
| 7787 | Py_ssize_t len; |
| 7788 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7789 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7790 | 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] | 7791 | goto failed; |
| 7792 | } |
| 7793 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7794 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7795 | if (generators == NULL) goto failed; |
| 7796 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7797 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7798 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7799 | Py_INCREF(tmp2); |
| 7800 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7801 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7802 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7803 | if (len != PyList_GET_SIZE(tmp)) { |
| 7804 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7805 | goto failed; |
| 7806 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7807 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7808 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7809 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7810 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7811 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7812 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7813 | if (*out == NULL) goto failed; |
| 7814 | return 0; |
| 7815 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7816 | tp = astmodulestate_global->DictComp_type; |
| 7817 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7818 | if (isinstance == -1) { |
| 7819 | return 1; |
| 7820 | } |
| 7821 | if (isinstance) { |
| 7822 | expr_ty key; |
| 7823 | expr_ty value; |
| 7824 | asdl_seq* generators; |
| 7825 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7826 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7827 | return 1; |
| 7828 | } |
| 7829 | if (tmp == NULL) { |
| 7830 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7831 | return 1; |
| 7832 | } |
| 7833 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7834 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7835 | res = obj2ast_expr(tmp, &key, arena); |
| 7836 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7837 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7838 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7839 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7840 | return 1; |
| 7841 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7842 | if (tmp == NULL) { |
| 7843 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7844 | return 1; |
| 7845 | } |
| 7846 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7847 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7848 | res = obj2ast_expr(tmp, &value, arena); |
| 7849 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7850 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7851 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7852 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7853 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7854 | return 1; |
| 7855 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7856 | if (tmp == NULL) { |
| 7857 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7858 | return 1; |
| 7859 | } |
| 7860 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7861 | int res; |
| 7862 | Py_ssize_t len; |
| 7863 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7864 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7865 | 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] | 7866 | goto failed; |
| 7867 | } |
| 7868 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7869 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7870 | if (generators == NULL) goto failed; |
| 7871 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7872 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7873 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7874 | Py_INCREF(tmp2); |
| 7875 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7876 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7877 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7878 | if (len != PyList_GET_SIZE(tmp)) { |
| 7879 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7880 | goto failed; |
| 7881 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7882 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7883 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7884 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7885 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7886 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7887 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7888 | if (*out == NULL) goto failed; |
| 7889 | return 0; |
| 7890 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7891 | tp = astmodulestate_global->GeneratorExp_type; |
| 7892 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7893 | if (isinstance == -1) { |
| 7894 | return 1; |
| 7895 | } |
| 7896 | if (isinstance) { |
| 7897 | expr_ty elt; |
| 7898 | asdl_seq* generators; |
| 7899 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7900 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7901 | return 1; |
| 7902 | } |
| 7903 | if (tmp == NULL) { |
| 7904 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7905 | return 1; |
| 7906 | } |
| 7907 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7908 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7909 | res = obj2ast_expr(tmp, &elt, arena); |
| 7910 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7911 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7912 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7913 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7914 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7915 | return 1; |
| 7916 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7917 | if (tmp == NULL) { |
| 7918 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7919 | return 1; |
| 7920 | } |
| 7921 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7922 | int res; |
| 7923 | Py_ssize_t len; |
| 7924 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7925 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7926 | 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] | 7927 | goto failed; |
| 7928 | } |
| 7929 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7930 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7931 | if (generators == NULL) goto failed; |
| 7932 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7933 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7934 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7935 | Py_INCREF(tmp2); |
| 7936 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7937 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7938 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7939 | if (len != PyList_GET_SIZE(tmp)) { |
| 7940 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7941 | goto failed; |
| 7942 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7943 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7944 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7945 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7946 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7947 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7948 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7949 | if (*out == NULL) goto failed; |
| 7950 | return 0; |
| 7951 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7952 | tp = astmodulestate_global->Await_type; |
| 7953 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7954 | if (isinstance == -1) { |
| 7955 | return 1; |
| 7956 | } |
| 7957 | if (isinstance) { |
| 7958 | expr_ty value; |
| 7959 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7960 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7961 | return 1; |
| 7962 | } |
| 7963 | if (tmp == NULL) { |
| 7964 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 7965 | return 1; |
| 7966 | } |
| 7967 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7968 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7969 | res = obj2ast_expr(tmp, &value, arena); |
| 7970 | if (res != 0) goto failed; |
| 7971 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7972 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7973 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7974 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7975 | if (*out == NULL) goto failed; |
| 7976 | return 0; |
| 7977 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7978 | tp = astmodulestate_global->Yield_type; |
| 7979 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7980 | if (isinstance == -1) { |
| 7981 | return 1; |
| 7982 | } |
| 7983 | if (isinstance) { |
| 7984 | expr_ty value; |
| 7985 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7986 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7987 | return 1; |
| 7988 | } |
| 7989 | if (tmp == NULL || tmp == Py_None) { |
| 7990 | Py_CLEAR(tmp); |
| 7991 | value = NULL; |
| 7992 | } |
| 7993 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7994 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7995 | res = obj2ast_expr(tmp, &value, arena); |
| 7996 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7997 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7998 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7999 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8000 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8001 | if (*out == NULL) goto failed; |
| 8002 | return 0; |
| 8003 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8004 | tp = astmodulestate_global->YieldFrom_type; |
| 8005 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8006 | if (isinstance == -1) { |
| 8007 | return 1; |
| 8008 | } |
| 8009 | if (isinstance) { |
| 8010 | expr_ty value; |
| 8011 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8012 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8013 | return 1; |
| 8014 | } |
| 8015 | if (tmp == NULL) { |
| 8016 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 8017 | return 1; |
| 8018 | } |
| 8019 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8020 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8021 | res = obj2ast_expr(tmp, &value, arena); |
| 8022 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8023 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8024 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8025 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8026 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8027 | if (*out == NULL) goto failed; |
| 8028 | return 0; |
| 8029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8030 | tp = astmodulestate_global->Compare_type; |
| 8031 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8032 | if (isinstance == -1) { |
| 8033 | return 1; |
| 8034 | } |
| 8035 | if (isinstance) { |
| 8036 | expr_ty left; |
| 8037 | asdl_int_seq* ops; |
| 8038 | asdl_seq* comparators; |
| 8039 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8040 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8041 | return 1; |
| 8042 | } |
| 8043 | if (tmp == NULL) { |
| 8044 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8045 | return 1; |
| 8046 | } |
| 8047 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8048 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8049 | res = obj2ast_expr(tmp, &left, arena); |
| 8050 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8051 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8052 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8053 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8054 | return 1; |
| 8055 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8056 | if (tmp == NULL) { |
| 8057 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8058 | return 1; |
| 8059 | } |
| 8060 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8061 | int res; |
| 8062 | Py_ssize_t len; |
| 8063 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8064 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8065 | 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] | 8066 | goto failed; |
| 8067 | } |
| 8068 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8069 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8070 | if (ops == NULL) goto failed; |
| 8071 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8072 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8073 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8074 | Py_INCREF(tmp2); |
| 8075 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8076 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8077 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8078 | if (len != PyList_GET_SIZE(tmp)) { |
| 8079 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8080 | goto failed; |
| 8081 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8082 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8083 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8084 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8085 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8086 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8087 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8088 | return 1; |
| 8089 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8090 | if (tmp == NULL) { |
| 8091 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8092 | return 1; |
| 8093 | } |
| 8094 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8095 | int res; |
| 8096 | Py_ssize_t len; |
| 8097 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8098 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8099 | 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] | 8100 | goto failed; |
| 8101 | } |
| 8102 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8103 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8104 | if (comparators == NULL) goto failed; |
| 8105 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8106 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8107 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8108 | Py_INCREF(tmp2); |
| 8109 | res = obj2ast_expr(tmp2, &val, arena); |
| 8110 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8111 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8112 | if (len != PyList_GET_SIZE(tmp)) { |
| 8113 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8114 | goto failed; |
| 8115 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8116 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8117 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8118 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8119 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8120 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8121 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8122 | if (*out == NULL) goto failed; |
| 8123 | return 0; |
| 8124 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8125 | tp = astmodulestate_global->Call_type; |
| 8126 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8127 | if (isinstance == -1) { |
| 8128 | return 1; |
| 8129 | } |
| 8130 | if (isinstance) { |
| 8131 | expr_ty func; |
| 8132 | asdl_seq* args; |
| 8133 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8134 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8135 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8136 | return 1; |
| 8137 | } |
| 8138 | if (tmp == NULL) { |
| 8139 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8140 | return 1; |
| 8141 | } |
| 8142 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8143 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8144 | res = obj2ast_expr(tmp, &func, arena); |
| 8145 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8146 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8147 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8148 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8149 | return 1; |
| 8150 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8151 | if (tmp == NULL) { |
| 8152 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8153 | return 1; |
| 8154 | } |
| 8155 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8156 | int res; |
| 8157 | Py_ssize_t len; |
| 8158 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8159 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8160 | 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] | 8161 | goto failed; |
| 8162 | } |
| 8163 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8164 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8165 | if (args == NULL) goto failed; |
| 8166 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8167 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8168 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8169 | Py_INCREF(tmp2); |
| 8170 | res = obj2ast_expr(tmp2, &val, arena); |
| 8171 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8172 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8173 | if (len != PyList_GET_SIZE(tmp)) { |
| 8174 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8175 | goto failed; |
| 8176 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8177 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8178 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8179 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8180 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8181 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8182 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8183 | return 1; |
| 8184 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8185 | if (tmp == NULL) { |
| 8186 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8187 | return 1; |
| 8188 | } |
| 8189 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8190 | int res; |
| 8191 | Py_ssize_t len; |
| 8192 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8193 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8194 | 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] | 8195 | goto failed; |
| 8196 | } |
| 8197 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8198 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8199 | if (keywords == NULL) goto failed; |
| 8200 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8201 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8202 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8203 | Py_INCREF(tmp2); |
| 8204 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8205 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8206 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8207 | if (len != PyList_GET_SIZE(tmp)) { |
| 8208 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8209 | goto failed; |
| 8210 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8211 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8212 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8213 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8214 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8215 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8216 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8217 | if (*out == NULL) goto failed; |
| 8218 | return 0; |
| 8219 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8220 | tp = astmodulestate_global->FormattedValue_type; |
| 8221 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8222 | if (isinstance == -1) { |
| 8223 | return 1; |
| 8224 | } |
| 8225 | if (isinstance) { |
| 8226 | expr_ty value; |
| 8227 | int conversion; |
| 8228 | expr_ty format_spec; |
| 8229 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8230 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8231 | return 1; |
| 8232 | } |
| 8233 | if (tmp == NULL) { |
| 8234 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8235 | return 1; |
| 8236 | } |
| 8237 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8238 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8239 | res = obj2ast_expr(tmp, &value, arena); |
| 8240 | if (res != 0) goto failed; |
| 8241 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8242 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8243 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8244 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8245 | return 1; |
| 8246 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8247 | if (tmp == NULL || tmp == Py_None) { |
| 8248 | Py_CLEAR(tmp); |
| 8249 | conversion = 0; |
| 8250 | } |
| 8251 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8252 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8253 | res = obj2ast_int(tmp, &conversion, arena); |
| 8254 | if (res != 0) goto failed; |
| 8255 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8256 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8257 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8258 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8259 | return 1; |
| 8260 | } |
| 8261 | if (tmp == NULL || tmp == Py_None) { |
| 8262 | Py_CLEAR(tmp); |
| 8263 | format_spec = NULL; |
| 8264 | } |
| 8265 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8266 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8267 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8268 | if (res != 0) goto failed; |
| 8269 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8270 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8271 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8272 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8273 | if (*out == NULL) goto failed; |
| 8274 | return 0; |
| 8275 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8276 | tp = astmodulestate_global->JoinedStr_type; |
| 8277 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8278 | if (isinstance == -1) { |
| 8279 | return 1; |
| 8280 | } |
| 8281 | if (isinstance) { |
| 8282 | asdl_seq* values; |
| 8283 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8284 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8285 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8286 | return 1; |
| 8287 | } |
| 8288 | if (tmp == NULL) { |
| 8289 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8290 | return 1; |
| 8291 | } |
| 8292 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8293 | int res; |
| 8294 | Py_ssize_t len; |
| 8295 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8296 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8297 | 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] | 8298 | goto failed; |
| 8299 | } |
| 8300 | len = PyList_GET_SIZE(tmp); |
| 8301 | values = _Py_asdl_seq_new(len, arena); |
| 8302 | if (values == NULL) goto failed; |
| 8303 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8304 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8305 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8306 | Py_INCREF(tmp2); |
| 8307 | res = obj2ast_expr(tmp2, &val, arena); |
| 8308 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8309 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8310 | if (len != PyList_GET_SIZE(tmp)) { |
| 8311 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8312 | goto failed; |
| 8313 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8314 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8315 | } |
| 8316 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8317 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8318 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8319 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8320 | if (*out == NULL) goto failed; |
| 8321 | return 0; |
| 8322 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8323 | tp = astmodulestate_global->Constant_type; |
| 8324 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8325 | if (isinstance == -1) { |
| 8326 | return 1; |
| 8327 | } |
| 8328 | if (isinstance) { |
| 8329 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8330 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8331 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8332 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8333 | return 1; |
| 8334 | } |
| 8335 | if (tmp == NULL) { |
| 8336 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8337 | return 1; |
| 8338 | } |
| 8339 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8340 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8341 | res = obj2ast_constant(tmp, &value, arena); |
| 8342 | if (res != 0) goto failed; |
| 8343 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8344 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8345 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8346 | return 1; |
| 8347 | } |
| 8348 | if (tmp == NULL || tmp == Py_None) { |
| 8349 | Py_CLEAR(tmp); |
| 8350 | kind = NULL; |
| 8351 | } |
| 8352 | else { |
| 8353 | int res; |
| 8354 | res = obj2ast_string(tmp, &kind, arena); |
| 8355 | if (res != 0) goto failed; |
| 8356 | Py_CLEAR(tmp); |
| 8357 | } |
| 8358 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8359 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8360 | if (*out == NULL) goto failed; |
| 8361 | return 0; |
| 8362 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8363 | tp = astmodulestate_global->Attribute_type; |
| 8364 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8365 | if (isinstance == -1) { |
| 8366 | return 1; |
| 8367 | } |
| 8368 | if (isinstance) { |
| 8369 | expr_ty value; |
| 8370 | identifier attr; |
| 8371 | expr_context_ty ctx; |
| 8372 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8373 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8374 | return 1; |
| 8375 | } |
| 8376 | if (tmp == NULL) { |
| 8377 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8378 | return 1; |
| 8379 | } |
| 8380 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8381 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8382 | res = obj2ast_expr(tmp, &value, arena); |
| 8383 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8384 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8385 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8386 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8387 | return 1; |
| 8388 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8389 | if (tmp == NULL) { |
| 8390 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8391 | return 1; |
| 8392 | } |
| 8393 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8394 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8395 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8396 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8397 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8398 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8399 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8400 | return 1; |
| 8401 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8402 | if (tmp == NULL) { |
| 8403 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8404 | return 1; |
| 8405 | } |
| 8406 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8407 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8408 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8409 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8410 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8411 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8412 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8413 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8414 | if (*out == NULL) goto failed; |
| 8415 | return 0; |
| 8416 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8417 | tp = astmodulestate_global->Subscript_type; |
| 8418 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8419 | if (isinstance == -1) { |
| 8420 | return 1; |
| 8421 | } |
| 8422 | if (isinstance) { |
| 8423 | expr_ty value; |
| 8424 | slice_ty slice; |
| 8425 | expr_context_ty ctx; |
| 8426 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8427 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8428 | return 1; |
| 8429 | } |
| 8430 | if (tmp == NULL) { |
| 8431 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8432 | return 1; |
| 8433 | } |
| 8434 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8435 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8436 | res = obj2ast_expr(tmp, &value, arena); |
| 8437 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8438 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8439 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8440 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8441 | return 1; |
| 8442 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8443 | if (tmp == NULL) { |
| 8444 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8445 | return 1; |
| 8446 | } |
| 8447 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8448 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8449 | res = obj2ast_slice(tmp, &slice, arena); |
| 8450 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8451 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8452 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8453 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8454 | return 1; |
| 8455 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8456 | if (tmp == NULL) { |
| 8457 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8458 | return 1; |
| 8459 | } |
| 8460 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8461 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8462 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8463 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8464 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8465 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8466 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8467 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8468 | if (*out == NULL) goto failed; |
| 8469 | return 0; |
| 8470 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8471 | tp = astmodulestate_global->Starred_type; |
| 8472 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8473 | if (isinstance == -1) { |
| 8474 | return 1; |
| 8475 | } |
| 8476 | if (isinstance) { |
| 8477 | expr_ty value; |
| 8478 | expr_context_ty ctx; |
| 8479 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8480 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8481 | return 1; |
| 8482 | } |
| 8483 | if (tmp == NULL) { |
| 8484 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8485 | return 1; |
| 8486 | } |
| 8487 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8488 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8489 | res = obj2ast_expr(tmp, &value, arena); |
| 8490 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8491 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8492 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8493 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8494 | return 1; |
| 8495 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8496 | if (tmp == NULL) { |
| 8497 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8498 | return 1; |
| 8499 | } |
| 8500 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8501 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8502 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8503 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8504 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8505 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8506 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8507 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8508 | if (*out == NULL) goto failed; |
| 8509 | return 0; |
| 8510 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8511 | tp = astmodulestate_global->Name_type; |
| 8512 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8513 | if (isinstance == -1) { |
| 8514 | return 1; |
| 8515 | } |
| 8516 | if (isinstance) { |
| 8517 | identifier id; |
| 8518 | expr_context_ty ctx; |
| 8519 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8520 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8521 | return 1; |
| 8522 | } |
| 8523 | if (tmp == NULL) { |
| 8524 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8525 | return 1; |
| 8526 | } |
| 8527 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8528 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8529 | res = obj2ast_identifier(tmp, &id, arena); |
| 8530 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8531 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8532 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8533 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8534 | return 1; |
| 8535 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8536 | if (tmp == NULL) { |
| 8537 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8538 | return 1; |
| 8539 | } |
| 8540 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8541 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8542 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8543 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8544 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8545 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8546 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8547 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8548 | if (*out == NULL) goto failed; |
| 8549 | return 0; |
| 8550 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8551 | tp = astmodulestate_global->List_type; |
| 8552 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8553 | if (isinstance == -1) { |
| 8554 | return 1; |
| 8555 | } |
| 8556 | if (isinstance) { |
| 8557 | asdl_seq* elts; |
| 8558 | expr_context_ty ctx; |
| 8559 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8560 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8561 | return 1; |
| 8562 | } |
| 8563 | if (tmp == NULL) { |
| 8564 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8565 | return 1; |
| 8566 | } |
| 8567 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8568 | int res; |
| 8569 | Py_ssize_t len; |
| 8570 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8571 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8572 | 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] | 8573 | goto failed; |
| 8574 | } |
| 8575 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8576 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8577 | if (elts == NULL) goto failed; |
| 8578 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8579 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8580 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8581 | Py_INCREF(tmp2); |
| 8582 | res = obj2ast_expr(tmp2, &val, arena); |
| 8583 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8584 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8585 | if (len != PyList_GET_SIZE(tmp)) { |
| 8586 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8587 | goto failed; |
| 8588 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8589 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8590 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8591 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8592 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8593 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8594 | return 1; |
| 8595 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8596 | if (tmp == NULL) { |
| 8597 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8598 | return 1; |
| 8599 | } |
| 8600 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8601 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8602 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8603 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8604 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8605 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8606 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8607 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8608 | if (*out == NULL) goto failed; |
| 8609 | return 0; |
| 8610 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8611 | tp = astmodulestate_global->Tuple_type; |
| 8612 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8613 | if (isinstance == -1) { |
| 8614 | return 1; |
| 8615 | } |
| 8616 | if (isinstance) { |
| 8617 | asdl_seq* elts; |
| 8618 | expr_context_ty ctx; |
| 8619 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8620 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8621 | return 1; |
| 8622 | } |
| 8623 | if (tmp == NULL) { |
| 8624 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8625 | return 1; |
| 8626 | } |
| 8627 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8628 | int res; |
| 8629 | Py_ssize_t len; |
| 8630 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8631 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8632 | 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] | 8633 | goto failed; |
| 8634 | } |
| 8635 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8636 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8637 | if (elts == NULL) goto failed; |
| 8638 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8639 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8640 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8641 | Py_INCREF(tmp2); |
| 8642 | res = obj2ast_expr(tmp2, &val, arena); |
| 8643 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8644 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8645 | if (len != PyList_GET_SIZE(tmp)) { |
| 8646 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8647 | goto failed; |
| 8648 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8649 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8650 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8651 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8652 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8653 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8654 | return 1; |
| 8655 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8656 | if (tmp == NULL) { |
| 8657 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8658 | return 1; |
| 8659 | } |
| 8660 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8661 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8662 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8663 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8664 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8665 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8666 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8667 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8668 | if (*out == NULL) goto failed; |
| 8669 | return 0; |
| 8670 | } |
| 8671 | |
| 8672 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8673 | failed: |
| 8674 | Py_XDECREF(tmp); |
| 8675 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8676 | } |
| 8677 | |
| 8678 | int |
| 8679 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8680 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8681 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8682 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8683 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8684 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8685 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8686 | } |
| 8687 | if (isinstance) { |
| 8688 | *out = Load; |
| 8689 | return 0; |
| 8690 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8691 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8692 | if (isinstance == -1) { |
| 8693 | return 1; |
| 8694 | } |
| 8695 | if (isinstance) { |
| 8696 | *out = Store; |
| 8697 | return 0; |
| 8698 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8699 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8700 | if (isinstance == -1) { |
| 8701 | return 1; |
| 8702 | } |
| 8703 | if (isinstance) { |
| 8704 | *out = Del; |
| 8705 | return 0; |
| 8706 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8707 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8708 | if (isinstance == -1) { |
| 8709 | return 1; |
| 8710 | } |
| 8711 | if (isinstance) { |
| 8712 | *out = AugLoad; |
| 8713 | return 0; |
| 8714 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8715 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8716 | if (isinstance == -1) { |
| 8717 | return 1; |
| 8718 | } |
| 8719 | if (isinstance) { |
| 8720 | *out = AugStore; |
| 8721 | return 0; |
| 8722 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8723 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8724 | if (isinstance == -1) { |
| 8725 | return 1; |
| 8726 | } |
| 8727 | if (isinstance) { |
| 8728 | *out = Param; |
| 8729 | return 0; |
| 8730 | } |
| 8731 | |
| 8732 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8733 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8734 | } |
| 8735 | |
| 8736 | int |
| 8737 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 8738 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8739 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8740 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8741 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8742 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8743 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8744 | if (obj == Py_None) { |
| 8745 | *out = NULL; |
| 8746 | return 0; |
| 8747 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8748 | tp = astmodulestate_global->Slice_type; |
| 8749 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8750 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8751 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8752 | } |
| 8753 | if (isinstance) { |
| 8754 | expr_ty lower; |
| 8755 | expr_ty upper; |
| 8756 | expr_ty step; |
| 8757 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8758 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8759 | return 1; |
| 8760 | } |
| 8761 | if (tmp == NULL || tmp == Py_None) { |
| 8762 | Py_CLEAR(tmp); |
| 8763 | lower = NULL; |
| 8764 | } |
| 8765 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8766 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8767 | res = obj2ast_expr(tmp, &lower, arena); |
| 8768 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8769 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8770 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8771 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8772 | return 1; |
| 8773 | } |
| 8774 | if (tmp == NULL || tmp == Py_None) { |
| 8775 | Py_CLEAR(tmp); |
| 8776 | upper = NULL; |
| 8777 | } |
| 8778 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8779 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8780 | res = obj2ast_expr(tmp, &upper, arena); |
| 8781 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8782 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8783 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8784 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8785 | return 1; |
| 8786 | } |
| 8787 | if (tmp == NULL || tmp == Py_None) { |
| 8788 | Py_CLEAR(tmp); |
| 8789 | step = NULL; |
| 8790 | } |
| 8791 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8792 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8793 | res = obj2ast_expr(tmp, &step, arena); |
| 8794 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8795 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8796 | } |
| 8797 | *out = Slice(lower, upper, step, arena); |
| 8798 | if (*out == NULL) goto failed; |
| 8799 | return 0; |
| 8800 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8801 | tp = astmodulestate_global->ExtSlice_type; |
| 8802 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8803 | if (isinstance == -1) { |
| 8804 | return 1; |
| 8805 | } |
| 8806 | if (isinstance) { |
| 8807 | asdl_seq* dims; |
| 8808 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8809 | if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8810 | return 1; |
| 8811 | } |
| 8812 | if (tmp == NULL) { |
| 8813 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 8814 | return 1; |
| 8815 | } |
| 8816 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8817 | int res; |
| 8818 | Py_ssize_t len; |
| 8819 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8820 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8821 | 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] | 8822 | goto failed; |
| 8823 | } |
| 8824 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8825 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8826 | if (dims == NULL) goto failed; |
| 8827 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8828 | slice_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8829 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8830 | Py_INCREF(tmp2); |
| 8831 | res = obj2ast_slice(tmp2, &val, arena); |
| 8832 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8833 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8834 | if (len != PyList_GET_SIZE(tmp)) { |
| 8835 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 8836 | goto failed; |
| 8837 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8838 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8839 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8840 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8841 | } |
| 8842 | *out = ExtSlice(dims, arena); |
| 8843 | if (*out == NULL) goto failed; |
| 8844 | return 0; |
| 8845 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8846 | tp = astmodulestate_global->Index_type; |
| 8847 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8848 | if (isinstance == -1) { |
| 8849 | return 1; |
| 8850 | } |
| 8851 | if (isinstance) { |
| 8852 | expr_ty value; |
| 8853 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8854 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8855 | return 1; |
| 8856 | } |
| 8857 | if (tmp == NULL) { |
| 8858 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 8859 | return 1; |
| 8860 | } |
| 8861 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8862 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8863 | res = obj2ast_expr(tmp, &value, arena); |
| 8864 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8865 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8866 | } |
| 8867 | *out = Index(value, arena); |
| 8868 | if (*out == NULL) goto failed; |
| 8869 | return 0; |
| 8870 | } |
| 8871 | |
| 8872 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 8873 | failed: |
| 8874 | Py_XDECREF(tmp); |
| 8875 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8876 | } |
| 8877 | |
| 8878 | int |
| 8879 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8880 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8881 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8882 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8883 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8884 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8885 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8886 | } |
| 8887 | if (isinstance) { |
| 8888 | *out = And; |
| 8889 | return 0; |
| 8890 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8891 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8892 | if (isinstance == -1) { |
| 8893 | return 1; |
| 8894 | } |
| 8895 | if (isinstance) { |
| 8896 | *out = Or; |
| 8897 | return 0; |
| 8898 | } |
| 8899 | |
| 8900 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8901 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8902 | } |
| 8903 | |
| 8904 | int |
| 8905 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8906 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8907 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8908 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8909 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8910 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8911 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8912 | } |
| 8913 | if (isinstance) { |
| 8914 | *out = Add; |
| 8915 | return 0; |
| 8916 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8917 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8918 | if (isinstance == -1) { |
| 8919 | return 1; |
| 8920 | } |
| 8921 | if (isinstance) { |
| 8922 | *out = Sub; |
| 8923 | return 0; |
| 8924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8925 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8926 | if (isinstance == -1) { |
| 8927 | return 1; |
| 8928 | } |
| 8929 | if (isinstance) { |
| 8930 | *out = Mult; |
| 8931 | return 0; |
| 8932 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8933 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8934 | if (isinstance == -1) { |
| 8935 | return 1; |
| 8936 | } |
| 8937 | if (isinstance) { |
| 8938 | *out = MatMult; |
| 8939 | return 0; |
| 8940 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8941 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8942 | if (isinstance == -1) { |
| 8943 | return 1; |
| 8944 | } |
| 8945 | if (isinstance) { |
| 8946 | *out = Div; |
| 8947 | return 0; |
| 8948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8949 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8950 | if (isinstance == -1) { |
| 8951 | return 1; |
| 8952 | } |
| 8953 | if (isinstance) { |
| 8954 | *out = Mod; |
| 8955 | return 0; |
| 8956 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8957 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8958 | if (isinstance == -1) { |
| 8959 | return 1; |
| 8960 | } |
| 8961 | if (isinstance) { |
| 8962 | *out = Pow; |
| 8963 | return 0; |
| 8964 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8965 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8966 | if (isinstance == -1) { |
| 8967 | return 1; |
| 8968 | } |
| 8969 | if (isinstance) { |
| 8970 | *out = LShift; |
| 8971 | return 0; |
| 8972 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8973 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8974 | if (isinstance == -1) { |
| 8975 | return 1; |
| 8976 | } |
| 8977 | if (isinstance) { |
| 8978 | *out = RShift; |
| 8979 | return 0; |
| 8980 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8981 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8982 | if (isinstance == -1) { |
| 8983 | return 1; |
| 8984 | } |
| 8985 | if (isinstance) { |
| 8986 | *out = BitOr; |
| 8987 | return 0; |
| 8988 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8989 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8990 | if (isinstance == -1) { |
| 8991 | return 1; |
| 8992 | } |
| 8993 | if (isinstance) { |
| 8994 | *out = BitXor; |
| 8995 | return 0; |
| 8996 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8997 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8998 | if (isinstance == -1) { |
| 8999 | return 1; |
| 9000 | } |
| 9001 | if (isinstance) { |
| 9002 | *out = BitAnd; |
| 9003 | return 0; |
| 9004 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9005 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9006 | if (isinstance == -1) { |
| 9007 | return 1; |
| 9008 | } |
| 9009 | if (isinstance) { |
| 9010 | *out = FloorDiv; |
| 9011 | return 0; |
| 9012 | } |
| 9013 | |
| 9014 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 9015 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9016 | } |
| 9017 | |
| 9018 | int |
| 9019 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 9020 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9021 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9022 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9023 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9024 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9025 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9026 | } |
| 9027 | if (isinstance) { |
| 9028 | *out = Invert; |
| 9029 | return 0; |
| 9030 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9031 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9032 | if (isinstance == -1) { |
| 9033 | return 1; |
| 9034 | } |
| 9035 | if (isinstance) { |
| 9036 | *out = Not; |
| 9037 | return 0; |
| 9038 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9039 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9040 | if (isinstance == -1) { |
| 9041 | return 1; |
| 9042 | } |
| 9043 | if (isinstance) { |
| 9044 | *out = UAdd; |
| 9045 | return 0; |
| 9046 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9047 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9048 | if (isinstance == -1) { |
| 9049 | return 1; |
| 9050 | } |
| 9051 | if (isinstance) { |
| 9052 | *out = USub; |
| 9053 | return 0; |
| 9054 | } |
| 9055 | |
| 9056 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 9057 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9058 | } |
| 9059 | |
| 9060 | int |
| 9061 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 9062 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9063 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9064 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9065 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9066 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9067 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9068 | } |
| 9069 | if (isinstance) { |
| 9070 | *out = Eq; |
| 9071 | return 0; |
| 9072 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9073 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9074 | if (isinstance == -1) { |
| 9075 | return 1; |
| 9076 | } |
| 9077 | if (isinstance) { |
| 9078 | *out = NotEq; |
| 9079 | return 0; |
| 9080 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9081 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9082 | if (isinstance == -1) { |
| 9083 | return 1; |
| 9084 | } |
| 9085 | if (isinstance) { |
| 9086 | *out = Lt; |
| 9087 | return 0; |
| 9088 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9089 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9090 | if (isinstance == -1) { |
| 9091 | return 1; |
| 9092 | } |
| 9093 | if (isinstance) { |
| 9094 | *out = LtE; |
| 9095 | return 0; |
| 9096 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9097 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9098 | if (isinstance == -1) { |
| 9099 | return 1; |
| 9100 | } |
| 9101 | if (isinstance) { |
| 9102 | *out = Gt; |
| 9103 | return 0; |
| 9104 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9105 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9106 | if (isinstance == -1) { |
| 9107 | return 1; |
| 9108 | } |
| 9109 | if (isinstance) { |
| 9110 | *out = GtE; |
| 9111 | return 0; |
| 9112 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9113 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9114 | if (isinstance == -1) { |
| 9115 | return 1; |
| 9116 | } |
| 9117 | if (isinstance) { |
| 9118 | *out = Is; |
| 9119 | return 0; |
| 9120 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9121 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9122 | if (isinstance == -1) { |
| 9123 | return 1; |
| 9124 | } |
| 9125 | if (isinstance) { |
| 9126 | *out = IsNot; |
| 9127 | return 0; |
| 9128 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9129 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9130 | if (isinstance == -1) { |
| 9131 | return 1; |
| 9132 | } |
| 9133 | if (isinstance) { |
| 9134 | *out = In; |
| 9135 | return 0; |
| 9136 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9137 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9138 | if (isinstance == -1) { |
| 9139 | return 1; |
| 9140 | } |
| 9141 | if (isinstance) { |
| 9142 | *out = NotIn; |
| 9143 | return 0; |
| 9144 | } |
| 9145 | |
| 9146 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9147 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9148 | } |
| 9149 | |
| 9150 | int |
| 9151 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9152 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9153 | PyObject* tmp = NULL; |
| 9154 | expr_ty target; |
| 9155 | expr_ty iter; |
| 9156 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9157 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9158 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9159 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9160 | return 1; |
| 9161 | } |
| 9162 | if (tmp == NULL) { |
| 9163 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9164 | return 1; |
| 9165 | } |
| 9166 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9167 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9168 | res = obj2ast_expr(tmp, &target, arena); |
| 9169 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9170 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9171 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9172 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9173 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9174 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9175 | if (tmp == NULL) { |
| 9176 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9177 | return 1; |
| 9178 | } |
| 9179 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9180 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9181 | res = obj2ast_expr(tmp, &iter, arena); |
| 9182 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9183 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9184 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9185 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9186 | return 1; |
| 9187 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9188 | if (tmp == NULL) { |
| 9189 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9190 | return 1; |
| 9191 | } |
| 9192 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9193 | int res; |
| 9194 | Py_ssize_t len; |
| 9195 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9196 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9197 | 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] | 9198 | goto failed; |
| 9199 | } |
| 9200 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9201 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9202 | if (ifs == NULL) goto failed; |
| 9203 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9204 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9205 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9206 | Py_INCREF(tmp2); |
| 9207 | res = obj2ast_expr(tmp2, &val, arena); |
| 9208 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9209 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9210 | if (len != PyList_GET_SIZE(tmp)) { |
| 9211 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9212 | goto failed; |
| 9213 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9214 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9215 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9216 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9217 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9218 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9219 | return 1; |
| 9220 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9221 | if (tmp == NULL) { |
| 9222 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9223 | return 1; |
| 9224 | } |
| 9225 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9226 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9227 | res = obj2ast_int(tmp, &is_async, arena); |
| 9228 | if (res != 0) goto failed; |
| 9229 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9230 | } |
| 9231 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9232 | return 0; |
| 9233 | failed: |
| 9234 | Py_XDECREF(tmp); |
| 9235 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9236 | } |
| 9237 | |
| 9238 | int |
| 9239 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9240 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9241 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9242 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9243 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9244 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9245 | int lineno; |
| 9246 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9247 | int end_lineno; |
| 9248 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9249 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9250 | if (obj == Py_None) { |
| 9251 | *out = NULL; |
| 9252 | return 0; |
| 9253 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9254 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9255 | return 1; |
| 9256 | } |
| 9257 | if (tmp == NULL) { |
| 9258 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9259 | return 1; |
| 9260 | } |
| 9261 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9262 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9263 | res = obj2ast_int(tmp, &lineno, arena); |
| 9264 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9265 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9266 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9267 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9268 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9269 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9270 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9271 | if (tmp == NULL) { |
| 9272 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9273 | return 1; |
| 9274 | } |
| 9275 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9276 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9277 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9278 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9279 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9280 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9281 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9282 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9283 | return 1; |
| 9284 | } |
| 9285 | if (tmp == NULL || tmp == Py_None) { |
| 9286 | Py_CLEAR(tmp); |
| 9287 | end_lineno = 0; |
| 9288 | } |
| 9289 | else { |
| 9290 | int res; |
| 9291 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9292 | if (res != 0) goto failed; |
| 9293 | Py_CLEAR(tmp); |
| 9294 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9295 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9296 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9297 | return 1; |
| 9298 | } |
| 9299 | if (tmp == NULL || tmp == Py_None) { |
| 9300 | Py_CLEAR(tmp); |
| 9301 | end_col_offset = 0; |
| 9302 | } |
| 9303 | else { |
| 9304 | int res; |
| 9305 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9306 | if (res != 0) goto failed; |
| 9307 | Py_CLEAR(tmp); |
| 9308 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9309 | tp = astmodulestate_global->ExceptHandler_type; |
| 9310 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9311 | if (isinstance == -1) { |
| 9312 | return 1; |
| 9313 | } |
| 9314 | if (isinstance) { |
| 9315 | expr_ty type; |
| 9316 | identifier name; |
| 9317 | asdl_seq* body; |
| 9318 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9319 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9320 | return 1; |
| 9321 | } |
| 9322 | if (tmp == NULL || tmp == Py_None) { |
| 9323 | Py_CLEAR(tmp); |
| 9324 | type = NULL; |
| 9325 | } |
| 9326 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9327 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9328 | res = obj2ast_expr(tmp, &type, arena); |
| 9329 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9330 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9331 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9332 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9333 | return 1; |
| 9334 | } |
| 9335 | if (tmp == NULL || tmp == Py_None) { |
| 9336 | Py_CLEAR(tmp); |
| 9337 | name = NULL; |
| 9338 | } |
| 9339 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9340 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9341 | res = obj2ast_identifier(tmp, &name, arena); |
| 9342 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9343 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9344 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9345 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9346 | return 1; |
| 9347 | } |
| 9348 | if (tmp == NULL) { |
| 9349 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9350 | return 1; |
| 9351 | } |
| 9352 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9353 | int res; |
| 9354 | Py_ssize_t len; |
| 9355 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9356 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9357 | 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] | 9358 | goto failed; |
| 9359 | } |
| 9360 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9361 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9362 | if (body == NULL) goto failed; |
| 9363 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9364 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9365 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9366 | Py_INCREF(tmp2); |
| 9367 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9368 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9369 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9370 | if (len != PyList_GET_SIZE(tmp)) { |
| 9371 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9372 | goto failed; |
| 9373 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9374 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9375 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9376 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9377 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9378 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9379 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9380 | if (*out == NULL) goto failed; |
| 9381 | return 0; |
| 9382 | } |
| 9383 | |
| 9384 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9385 | failed: |
| 9386 | Py_XDECREF(tmp); |
| 9387 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9388 | } |
| 9389 | |
| 9390 | int |
| 9391 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9392 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9393 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9394 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9395 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9396 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9397 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9398 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9399 | arg_ty kwarg; |
| 9400 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9401 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9402 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9403 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9404 | return 1; |
| 9405 | } |
| 9406 | if (tmp == NULL) { |
| 9407 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9408 | return 1; |
| 9409 | } |
| 9410 | else { |
| 9411 | int res; |
| 9412 | Py_ssize_t len; |
| 9413 | Py_ssize_t i; |
| 9414 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9415 | 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] | 9416 | goto failed; |
| 9417 | } |
| 9418 | len = PyList_GET_SIZE(tmp); |
| 9419 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9420 | if (posonlyargs == NULL) goto failed; |
| 9421 | for (i = 0; i < len; i++) { |
| 9422 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9423 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9424 | Py_INCREF(tmp2); |
| 9425 | res = obj2ast_arg(tmp2, &val, arena); |
| 9426 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9427 | if (res != 0) goto failed; |
| 9428 | if (len != PyList_GET_SIZE(tmp)) { |
| 9429 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9430 | goto failed; |
| 9431 | } |
| 9432 | asdl_seq_SET(posonlyargs, i, val); |
| 9433 | } |
| 9434 | Py_CLEAR(tmp); |
| 9435 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9436 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9437 | return 1; |
| 9438 | } |
| 9439 | if (tmp == NULL) { |
| 9440 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9441 | return 1; |
| 9442 | } |
| 9443 | else { |
| 9444 | int res; |
| 9445 | Py_ssize_t len; |
| 9446 | Py_ssize_t i; |
| 9447 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9448 | 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] | 9449 | goto failed; |
| 9450 | } |
| 9451 | len = PyList_GET_SIZE(tmp); |
| 9452 | args = _Py_asdl_seq_new(len, arena); |
| 9453 | if (args == NULL) goto failed; |
| 9454 | for (i = 0; i < len; i++) { |
| 9455 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9456 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9457 | Py_INCREF(tmp2); |
| 9458 | res = obj2ast_arg(tmp2, &val, arena); |
| 9459 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9460 | if (res != 0) goto failed; |
| 9461 | if (len != PyList_GET_SIZE(tmp)) { |
| 9462 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9463 | goto failed; |
| 9464 | } |
| 9465 | asdl_seq_SET(args, i, val); |
| 9466 | } |
| 9467 | Py_CLEAR(tmp); |
| 9468 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9469 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9470 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9471 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9472 | if (tmp == NULL || tmp == Py_None) { |
| 9473 | Py_CLEAR(tmp); |
| 9474 | vararg = NULL; |
| 9475 | } |
| 9476 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9477 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9478 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9479 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9480 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9481 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9482 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9483 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9484 | return 1; |
| 9485 | } |
| 9486 | if (tmp == NULL) { |
| 9487 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9488 | return 1; |
| 9489 | } |
| 9490 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9491 | int res; |
| 9492 | Py_ssize_t len; |
| 9493 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9494 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9495 | 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] | 9496 | goto failed; |
| 9497 | } |
| 9498 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9499 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9500 | if (kwonlyargs == NULL) goto failed; |
| 9501 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9502 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9503 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9504 | Py_INCREF(tmp2); |
| 9505 | res = obj2ast_arg(tmp2, &val, arena); |
| 9506 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9507 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9508 | if (len != PyList_GET_SIZE(tmp)) { |
| 9509 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9510 | goto failed; |
| 9511 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9512 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9513 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9514 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9515 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9516 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9517 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9518 | return 1; |
| 9519 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9520 | if (tmp == NULL) { |
| 9521 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9522 | return 1; |
| 9523 | } |
| 9524 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9525 | int res; |
| 9526 | Py_ssize_t len; |
| 9527 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9528 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9529 | 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] | 9530 | goto failed; |
| 9531 | } |
| 9532 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9533 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9534 | if (kw_defaults == NULL) goto failed; |
| 9535 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9536 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9537 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9538 | Py_INCREF(tmp2); |
| 9539 | res = obj2ast_expr(tmp2, &val, arena); |
| 9540 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9541 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9542 | if (len != PyList_GET_SIZE(tmp)) { |
| 9543 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9544 | goto failed; |
| 9545 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9546 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9547 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9548 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9549 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9550 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9551 | return 1; |
| 9552 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9553 | if (tmp == NULL || tmp == Py_None) { |
| 9554 | Py_CLEAR(tmp); |
| 9555 | kwarg = NULL; |
| 9556 | } |
| 9557 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9558 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9559 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9560 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9561 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9562 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9563 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9564 | return 1; |
| 9565 | } |
| 9566 | if (tmp == NULL) { |
| 9567 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9568 | return 1; |
| 9569 | } |
| 9570 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9571 | int res; |
| 9572 | Py_ssize_t len; |
| 9573 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9574 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9575 | 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] | 9576 | goto failed; |
| 9577 | } |
| 9578 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9579 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9580 | if (defaults == NULL) goto failed; |
| 9581 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9582 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9583 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9584 | Py_INCREF(tmp2); |
| 9585 | res = obj2ast_expr(tmp2, &val, arena); |
| 9586 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9587 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9588 | if (len != PyList_GET_SIZE(tmp)) { |
| 9589 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9590 | goto failed; |
| 9591 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9592 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9593 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9594 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9595 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9596 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9597 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9598 | return 0; |
| 9599 | failed: |
| 9600 | Py_XDECREF(tmp); |
| 9601 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9602 | } |
| 9603 | |
| 9604 | int |
| 9605 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9606 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9607 | PyObject* tmp = NULL; |
| 9608 | identifier arg; |
| 9609 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9610 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9611 | int lineno; |
| 9612 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9613 | int end_lineno; |
| 9614 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9615 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9616 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9617 | return 1; |
| 9618 | } |
| 9619 | if (tmp == NULL) { |
| 9620 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9621 | return 1; |
| 9622 | } |
| 9623 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9624 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9625 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9626 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9627 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9628 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9629 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9630 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9631 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9632 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9633 | if (tmp == NULL || tmp == Py_None) { |
| 9634 | Py_CLEAR(tmp); |
| 9635 | annotation = NULL; |
| 9636 | } |
| 9637 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9638 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9639 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9640 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9641 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9642 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9643 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9644 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9645 | return 1; |
| 9646 | } |
| 9647 | if (tmp == NULL || tmp == Py_None) { |
| 9648 | Py_CLEAR(tmp); |
| 9649 | type_comment = NULL; |
| 9650 | } |
| 9651 | else { |
| 9652 | int res; |
| 9653 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9654 | if (res != 0) goto failed; |
| 9655 | Py_CLEAR(tmp); |
| 9656 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9657 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9658 | return 1; |
| 9659 | } |
| 9660 | if (tmp == NULL) { |
| 9661 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9662 | return 1; |
| 9663 | } |
| 9664 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9665 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9666 | res = obj2ast_int(tmp, &lineno, arena); |
| 9667 | if (res != 0) goto failed; |
| 9668 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9669 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9670 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9671 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9672 | return 1; |
| 9673 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9674 | if (tmp == NULL) { |
| 9675 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9676 | return 1; |
| 9677 | } |
| 9678 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9679 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9680 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9681 | if (res != 0) goto failed; |
| 9682 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9683 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9684 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9685 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9686 | return 1; |
| 9687 | } |
| 9688 | if (tmp == NULL || tmp == Py_None) { |
| 9689 | Py_CLEAR(tmp); |
| 9690 | end_lineno = 0; |
| 9691 | } |
| 9692 | else { |
| 9693 | int res; |
| 9694 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9695 | if (res != 0) goto failed; |
| 9696 | Py_CLEAR(tmp); |
| 9697 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9698 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9699 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9700 | return 1; |
| 9701 | } |
| 9702 | if (tmp == NULL || tmp == Py_None) { |
| 9703 | Py_CLEAR(tmp); |
| 9704 | end_col_offset = 0; |
| 9705 | } |
| 9706 | else { |
| 9707 | int res; |
| 9708 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9709 | if (res != 0) goto failed; |
| 9710 | Py_CLEAR(tmp); |
| 9711 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9712 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9713 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9714 | return 0; |
| 9715 | failed: |
| 9716 | Py_XDECREF(tmp); |
| 9717 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9718 | } |
| 9719 | |
| 9720 | int |
| 9721 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9722 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9723 | PyObject* tmp = NULL; |
| 9724 | identifier arg; |
| 9725 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9726 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9727 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9728 | return 1; |
| 9729 | } |
| 9730 | if (tmp == NULL || tmp == Py_None) { |
| 9731 | Py_CLEAR(tmp); |
| 9732 | arg = NULL; |
| 9733 | } |
| 9734 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9735 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9736 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9737 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9738 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9739 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9740 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9741 | return 1; |
| 9742 | } |
| 9743 | if (tmp == NULL) { |
| 9744 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9745 | return 1; |
| 9746 | } |
| 9747 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9748 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9749 | res = obj2ast_expr(tmp, &value, arena); |
| 9750 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9751 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9752 | } |
| 9753 | *out = keyword(arg, value, arena); |
| 9754 | return 0; |
| 9755 | failed: |
| 9756 | Py_XDECREF(tmp); |
| 9757 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9758 | } |
| 9759 | |
| 9760 | int |
| 9761 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9762 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9763 | PyObject* tmp = NULL; |
| 9764 | identifier name; |
| 9765 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9766 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9767 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9768 | return 1; |
| 9769 | } |
| 9770 | if (tmp == NULL) { |
| 9771 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9772 | return 1; |
| 9773 | } |
| 9774 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9775 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9776 | res = obj2ast_identifier(tmp, &name, arena); |
| 9777 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9778 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9779 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9780 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9781 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9782 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9783 | if (tmp == NULL || tmp == Py_None) { |
| 9784 | Py_CLEAR(tmp); |
| 9785 | asname = NULL; |
| 9786 | } |
| 9787 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9788 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9789 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9790 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9791 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9792 | } |
| 9793 | *out = alias(name, asname, arena); |
| 9794 | return 0; |
| 9795 | failed: |
| 9796 | Py_XDECREF(tmp); |
| 9797 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9798 | } |
| 9799 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9800 | int |
| 9801 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9802 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9803 | PyObject* tmp = NULL; |
| 9804 | expr_ty context_expr; |
| 9805 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9806 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9807 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9808 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9809 | return 1; |
| 9810 | } |
| 9811 | if (tmp == NULL) { |
| 9812 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9813 | return 1; |
| 9814 | } |
| 9815 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9816 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9817 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9818 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9819 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9820 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9821 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9822 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9823 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9824 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9825 | if (tmp == NULL || tmp == Py_None) { |
| 9826 | Py_CLEAR(tmp); |
| 9827 | optional_vars = NULL; |
| 9828 | } |
| 9829 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9830 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9831 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9832 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9833 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9834 | } |
| 9835 | *out = withitem(context_expr, optional_vars, arena); |
| 9836 | return 0; |
| 9837 | failed: |
| 9838 | Py_XDECREF(tmp); |
| 9839 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9840 | } |
| 9841 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9842 | int |
| 9843 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9844 | { |
| 9845 | int isinstance; |
| 9846 | |
| 9847 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9848 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9849 | |
| 9850 | if (obj == Py_None) { |
| 9851 | *out = NULL; |
| 9852 | return 0; |
| 9853 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9854 | tp = astmodulestate_global->TypeIgnore_type; |
| 9855 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9856 | if (isinstance == -1) { |
| 9857 | return 1; |
| 9858 | } |
| 9859 | if (isinstance) { |
| 9860 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9861 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9862 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9863 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9864 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9865 | return 1; |
| 9866 | } |
| 9867 | if (tmp == NULL) { |
| 9868 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9869 | return 1; |
| 9870 | } |
| 9871 | else { |
| 9872 | int res; |
| 9873 | res = obj2ast_int(tmp, &lineno, arena); |
| 9874 | if (res != 0) goto failed; |
| 9875 | Py_CLEAR(tmp); |
| 9876 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9877 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9878 | return 1; |
| 9879 | } |
| 9880 | if (tmp == NULL) { |
| 9881 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9882 | return 1; |
| 9883 | } |
| 9884 | else { |
| 9885 | int res; |
| 9886 | res = obj2ast_string(tmp, &tag, arena); |
| 9887 | if (res != 0) goto failed; |
| 9888 | Py_CLEAR(tmp); |
| 9889 | } |
| 9890 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9891 | if (*out == NULL) goto failed; |
| 9892 | return 0; |
| 9893 | } |
| 9894 | |
| 9895 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9896 | failed: |
| 9897 | Py_XDECREF(tmp); |
| 9898 | return 1; |
| 9899 | } |
| 9900 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9901 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9902 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9903 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9904 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9905 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9906 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9907 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9908 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9909 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9910 | goto error; |
| 9911 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9912 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9913 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9914 | goto error; |
| 9915 | } |
| 9916 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9917 | goto error; |
| 9918 | } |
| 9919 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9920 | goto error; |
| 9921 | } |
| 9922 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9923 | goto error; |
| 9924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9925 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9926 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9927 | 0) { |
| 9928 | goto error; |
| 9929 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9930 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9931 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9932 | astmodulestate_global->Interactive_type) < 0) { |
| 9933 | goto error; |
| 9934 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9935 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9936 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9937 | astmodulestate_global->Expression_type) < 0) { |
| 9938 | goto error; |
| 9939 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9940 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9941 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9942 | astmodulestate_global->FunctionType_type) < 0) { |
| 9943 | goto error; |
| 9944 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9945 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9946 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9947 | goto error; |
| 9948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9949 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9950 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9951 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9952 | goto error; |
| 9953 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9954 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9955 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9956 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9957 | goto error; |
| 9958 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9959 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9960 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9961 | < 0) { |
| 9962 | goto error; |
| 9963 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9964 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9965 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9966 | 0) { |
| 9967 | goto error; |
| 9968 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9969 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9970 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9971 | 0) { |
| 9972 | goto error; |
| 9973 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9974 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9975 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9976 | 0) { |
| 9977 | goto error; |
| 9978 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9979 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9980 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9981 | astmodulestate_global->AugAssign_type) < 0) { |
| 9982 | goto error; |
| 9983 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9984 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9985 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9986 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9987 | goto error; |
| 9988 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9989 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9990 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9991 | goto error; |
| 9992 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9993 | Py_INCREF(astmodulestate(m)->For_type); |
| 9994 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9995 | < 0) { |
| 9996 | goto error; |
| 9997 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9998 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9999 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 10000 | goto error; |
| 10001 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10002 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10003 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 10004 | goto error; |
| 10005 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10006 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10007 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 10008 | goto error; |
| 10009 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10010 | Py_INCREF(astmodulestate(m)->With_type); |
| 10011 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10012 | astmodulestate_global->AsyncWith_type) < 0) { |
| 10013 | goto error; |
| 10014 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10015 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10016 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 10017 | goto error; |
| 10018 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10019 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10020 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 10021 | goto error; |
| 10022 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10023 | Py_INCREF(astmodulestate(m)->Try_type); |
| 10024 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10025 | 0) { |
| 10026 | goto error; |
| 10027 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10028 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 10029 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10030 | 0) { |
| 10031 | goto error; |
| 10032 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10033 | Py_INCREF(astmodulestate(m)->Import_type); |
| 10034 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10035 | astmodulestate_global->ImportFrom_type) < 0) { |
| 10036 | goto error; |
| 10037 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10038 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 10039 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10040 | 0) { |
| 10041 | goto error; |
| 10042 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10043 | Py_INCREF(astmodulestate(m)->Global_type); |
| 10044 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10045 | < 0) { |
| 10046 | goto error; |
| 10047 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10048 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10049 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { |
| 10050 | goto error; |
| 10051 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10052 | Py_INCREF(astmodulestate(m)->Expr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10053 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 10054 | goto error; |
| 10055 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10056 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10057 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 10058 | goto error; |
| 10059 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10060 | Py_INCREF(astmodulestate(m)->Break_type); |
| 10061 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10062 | < 0) { |
| 10063 | goto error; |
| 10064 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10065 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10066 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 10067 | goto error; |
| 10068 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10069 | Py_INCREF(astmodulestate(m)->expr_type); |
| 10070 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10071 | 0) { |
| 10072 | goto error; |
| 10073 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10074 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 10075 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10076 | astmodulestate_global->NamedExpr_type) < 0) { |
| 10077 | goto error; |
| 10078 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10079 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10080 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 10081 | goto error; |
| 10082 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10083 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 10084 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10085 | 0) { |
| 10086 | goto error; |
| 10087 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10088 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 10089 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10090 | 0) { |
| 10091 | goto error; |
| 10092 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10093 | Py_INCREF(astmodulestate(m)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10094 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 10095 | goto error; |
| 10096 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10097 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10098 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 10099 | goto error; |
| 10100 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10101 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10102 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 10103 | goto error; |
| 10104 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10105 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10106 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10107 | < 0) { |
| 10108 | goto error; |
| 10109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10110 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10111 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10112 | 0) { |
| 10113 | goto error; |
| 10114 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10115 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10116 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10117 | < 0) { |
| 10118 | goto error; |
| 10119 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10120 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10121 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10122 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 10123 | goto error; |
| 10124 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10125 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10126 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 10127 | goto error; |
| 10128 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10129 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10130 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 10131 | goto error; |
| 10132 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10133 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10134 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10135 | astmodulestate_global->YieldFrom_type) < 0) { |
| 10136 | goto error; |
| 10137 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10138 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10139 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10140 | 0) { |
| 10141 | goto error; |
| 10142 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10143 | Py_INCREF(astmodulestate(m)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10144 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 10145 | goto error; |
| 10146 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10147 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10148 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10149 | astmodulestate_global->FormattedValue_type) < 0) { |
| 10150 | goto error; |
| 10151 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10152 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10153 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10154 | astmodulestate_global->JoinedStr_type) < 0) { |
| 10155 | goto error; |
| 10156 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10157 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10158 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10159 | < 0) { |
| 10160 | goto error; |
| 10161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10162 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10163 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10164 | astmodulestate_global->Attribute_type) < 0) { |
| 10165 | goto error; |
| 10166 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10167 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10168 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10169 | astmodulestate_global->Subscript_type) < 0) { |
| 10170 | goto error; |
| 10171 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10172 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10173 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10174 | 0) { |
| 10175 | goto error; |
| 10176 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10177 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10178 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 10179 | goto error; |
| 10180 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10181 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10182 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10183 | goto error; |
| 10184 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10185 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10186 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10187 | goto error; |
| 10188 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10189 | Py_INCREF(astmodulestate(m)->Tuple_type); |
| 10190 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10191 | astmodulestate_global->expr_context_type) < 0) { |
| 10192 | goto error; |
| 10193 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10194 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10195 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10196 | goto error; |
| 10197 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10198 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10199 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10200 | goto error; |
| 10201 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10202 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10203 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10204 | goto error; |
| 10205 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10206 | Py_INCREF(astmodulestate(m)->Del_type); |
| 10207 | if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10208 | 0) { |
| 10209 | goto error; |
| 10210 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10211 | Py_INCREF(astmodulestate(m)->AugLoad_type); |
| 10212 | if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10213 | < 0) { |
| 10214 | goto error; |
| 10215 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10216 | Py_INCREF(astmodulestate(m)->AugStore_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10217 | if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) { |
| 10218 | goto error; |
| 10219 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10220 | Py_INCREF(astmodulestate(m)->Param_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10221 | if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0) { |
| 10222 | goto error; |
| 10223 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10224 | Py_INCREF(astmodulestate(m)->slice_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10225 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10226 | goto error; |
| 10227 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10228 | Py_INCREF(astmodulestate(m)->Slice_type); |
| 10229 | if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10230 | < 0) { |
| 10231 | goto error; |
| 10232 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10233 | Py_INCREF(astmodulestate(m)->ExtSlice_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10234 | if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0) { |
| 10235 | goto error; |
| 10236 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10237 | Py_INCREF(astmodulestate(m)->Index_type); |
| 10238 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10239 | 0) { |
| 10240 | goto error; |
| 10241 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10242 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10243 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10244 | goto error; |
| 10245 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10246 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10247 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10248 | goto error; |
| 10249 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10250 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10251 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10252 | < 0) { |
| 10253 | goto error; |
| 10254 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10255 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10256 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10257 | goto error; |
| 10258 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10259 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10260 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10261 | goto error; |
| 10262 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10263 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10264 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10265 | goto error; |
| 10266 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10267 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10268 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10269 | 0) { |
| 10270 | goto error; |
| 10271 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10272 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10273 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10274 | goto error; |
| 10275 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10276 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10277 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10278 | goto error; |
| 10279 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10280 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10281 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10282 | goto error; |
| 10283 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10284 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10285 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10286 | 0) { |
| 10287 | goto error; |
| 10288 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10289 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10290 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10291 | 0) { |
| 10292 | goto error; |
| 10293 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10294 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10295 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10296 | goto error; |
| 10297 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10298 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10299 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10300 | 0) { |
| 10301 | goto error; |
| 10302 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10303 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10304 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10305 | 0) { |
| 10306 | goto error; |
| 10307 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10308 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10309 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10310 | < 0) { |
| 10311 | goto error; |
| 10312 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10313 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10314 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10315 | 0) { |
| 10316 | goto error; |
| 10317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10318 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10319 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10320 | 0) { |
| 10321 | goto error; |
| 10322 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10323 | Py_INCREF(astmodulestate(m)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10324 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10325 | goto error; |
| 10326 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10327 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10328 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10329 | goto error; |
| 10330 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10331 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10332 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10333 | goto error; |
| 10334 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10335 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10336 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10337 | goto error; |
| 10338 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10339 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10340 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10341 | goto error; |
| 10342 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10343 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10344 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10345 | goto error; |
| 10346 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10347 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10348 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10349 | goto error; |
| 10350 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10351 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10352 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10353 | goto error; |
| 10354 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10355 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10356 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10357 | goto error; |
| 10358 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10359 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10360 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10361 | goto error; |
| 10362 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10363 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10364 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10365 | goto error; |
| 10366 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10367 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10368 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10369 | goto error; |
| 10370 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10371 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10372 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10373 | goto error; |
| 10374 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10375 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10376 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10377 | goto error; |
| 10378 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10379 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10380 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10381 | astmodulestate_global->comprehension_type) < 0) { |
| 10382 | goto error; |
| 10383 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10384 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10385 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10386 | astmodulestate_global->excepthandler_type) < 0) { |
| 10387 | goto error; |
| 10388 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10389 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10390 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10391 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10392 | goto error; |
| 10393 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10394 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10395 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10396 | astmodulestate_global->arguments_type) < 0) { |
| 10397 | goto error; |
| 10398 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10399 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10400 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10401 | goto error; |
| 10402 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10403 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10404 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10405 | 0) { |
| 10406 | goto error; |
| 10407 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10408 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10409 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10410 | goto error; |
| 10411 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10412 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10413 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10414 | < 0) { |
| 10415 | goto error; |
| 10416 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10417 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10418 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10419 | astmodulestate_global->type_ignore_type) < 0) { |
| 10420 | goto error; |
| 10421 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10422 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10423 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10424 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10425 | goto error; |
| 10426 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10427 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10428 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10429 | error: |
| 10430 | Py_DECREF(m); |
| 10431 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10432 | } |
| 10433 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10434 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10435 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10436 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10437 | if (!init_types()) |
| 10438 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10439 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10440 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10441 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10442 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10443 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10444 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10445 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10446 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10447 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10448 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10449 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10450 | return NULL; |
| 10451 | } |
| 10452 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10453 | req_type[0] = astmodulestate_global->Module_type; |
| 10454 | req_type[1] = astmodulestate_global->Expression_type; |
| 10455 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10456 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10457 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10458 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10459 | if (!init_types()) |
| 10460 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10461 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10462 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10463 | if (isinstance == -1) |
| 10464 | return NULL; |
| 10465 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10466 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10467 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10468 | return NULL; |
| 10469 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10470 | |
| 10471 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10472 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10473 | return NULL; |
| 10474 | else |
| 10475 | return res; |
| 10476 | } |
| 10477 | |
| 10478 | int PyAST_Check(PyObject* obj) |
| 10479 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10480 | if (!init_types()) |
| 10481 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10482 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10483 | } |
| 10484 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10485 | |