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; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 55 | PyObject *FloorDiv_singleton; |
| 56 | PyObject *FloorDiv_type; |
| 57 | PyObject *For_type; |
| 58 | PyObject *FormattedValue_type; |
| 59 | PyObject *FunctionDef_type; |
| 60 | PyObject *FunctionType_type; |
| 61 | PyObject *GeneratorExp_type; |
| 62 | PyObject *Global_type; |
| 63 | PyObject *GtE_singleton; |
| 64 | PyObject *GtE_type; |
| 65 | PyObject *Gt_singleton; |
| 66 | PyObject *Gt_type; |
| 67 | PyObject *IfExp_type; |
| 68 | PyObject *If_type; |
| 69 | PyObject *ImportFrom_type; |
| 70 | PyObject *Import_type; |
| 71 | PyObject *In_singleton; |
| 72 | PyObject *In_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 73 | PyObject *Interactive_type; |
| 74 | PyObject *Invert_singleton; |
| 75 | PyObject *Invert_type; |
| 76 | PyObject *IsNot_singleton; |
| 77 | PyObject *IsNot_type; |
| 78 | PyObject *Is_singleton; |
| 79 | PyObject *Is_type; |
| 80 | PyObject *JoinedStr_type; |
| 81 | PyObject *LShift_singleton; |
| 82 | PyObject *LShift_type; |
| 83 | PyObject *Lambda_type; |
| 84 | PyObject *ListComp_type; |
| 85 | PyObject *List_type; |
| 86 | PyObject *Load_singleton; |
| 87 | PyObject *Load_type; |
| 88 | PyObject *LtE_singleton; |
| 89 | PyObject *LtE_type; |
| 90 | PyObject *Lt_singleton; |
| 91 | PyObject *Lt_type; |
| 92 | PyObject *MatMult_singleton; |
| 93 | PyObject *MatMult_type; |
| 94 | PyObject *Mod_singleton; |
| 95 | PyObject *Mod_type; |
| 96 | PyObject *Module_type; |
| 97 | PyObject *Mult_singleton; |
| 98 | PyObject *Mult_type; |
| 99 | PyObject *Name_type; |
| 100 | PyObject *NamedExpr_type; |
| 101 | PyObject *Nonlocal_type; |
| 102 | PyObject *NotEq_singleton; |
| 103 | PyObject *NotEq_type; |
| 104 | PyObject *NotIn_singleton; |
| 105 | PyObject *NotIn_type; |
| 106 | PyObject *Not_singleton; |
| 107 | PyObject *Not_type; |
| 108 | PyObject *Or_singleton; |
| 109 | PyObject *Or_type; |
| 110 | PyObject *Param_singleton; |
| 111 | PyObject *Param_type; |
| 112 | PyObject *Pass_type; |
| 113 | PyObject *Pow_singleton; |
| 114 | PyObject *Pow_type; |
| 115 | PyObject *RShift_singleton; |
| 116 | PyObject *RShift_type; |
| 117 | PyObject *Raise_type; |
| 118 | PyObject *Return_type; |
| 119 | PyObject *SetComp_type; |
| 120 | PyObject *Set_type; |
| 121 | PyObject *Slice_type; |
| 122 | PyObject *Starred_type; |
| 123 | PyObject *Store_singleton; |
| 124 | PyObject *Store_type; |
| 125 | PyObject *Sub_singleton; |
| 126 | PyObject *Sub_type; |
| 127 | PyObject *Subscript_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 128 | PyObject *Try_type; |
| 129 | PyObject *Tuple_type; |
| 130 | PyObject *TypeIgnore_type; |
| 131 | PyObject *UAdd_singleton; |
| 132 | PyObject *UAdd_type; |
| 133 | PyObject *USub_singleton; |
| 134 | PyObject *USub_type; |
| 135 | PyObject *UnaryOp_type; |
| 136 | PyObject *While_type; |
| 137 | PyObject *With_type; |
| 138 | PyObject *YieldFrom_type; |
| 139 | PyObject *Yield_type; |
| 140 | PyObject *__dict__; |
| 141 | PyObject *__module__; |
| 142 | PyObject *_ast; |
| 143 | PyObject *_attributes; |
| 144 | PyObject *_fields; |
| 145 | PyObject *alias_type; |
| 146 | PyObject *annotation; |
| 147 | PyObject *arg; |
| 148 | PyObject *arg_type; |
| 149 | PyObject *args; |
| 150 | PyObject *argtypes; |
| 151 | PyObject *arguments_type; |
| 152 | PyObject *asname; |
| 153 | PyObject *attr; |
| 154 | PyObject *bases; |
| 155 | PyObject *body; |
| 156 | PyObject *boolop_type; |
| 157 | PyObject *cause; |
| 158 | PyObject *cmpop_type; |
| 159 | PyObject *col_offset; |
| 160 | PyObject *comparators; |
| 161 | PyObject *comprehension_type; |
| 162 | PyObject *context_expr; |
| 163 | PyObject *conversion; |
| 164 | PyObject *ctx; |
| 165 | PyObject *decorator_list; |
| 166 | PyObject *defaults; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 167 | PyObject *elt; |
| 168 | PyObject *elts; |
| 169 | PyObject *end_col_offset; |
| 170 | PyObject *end_lineno; |
| 171 | PyObject *exc; |
| 172 | PyObject *excepthandler_type; |
| 173 | PyObject *expr_context_type; |
| 174 | PyObject *expr_type; |
| 175 | PyObject *finalbody; |
| 176 | PyObject *format_spec; |
| 177 | PyObject *func; |
| 178 | PyObject *generators; |
| 179 | PyObject *handlers; |
| 180 | PyObject *id; |
| 181 | PyObject *ifs; |
| 182 | PyObject *is_async; |
| 183 | PyObject *items; |
| 184 | PyObject *iter; |
| 185 | PyObject *key; |
| 186 | PyObject *keys; |
| 187 | PyObject *keyword_type; |
| 188 | PyObject *keywords; |
| 189 | PyObject *kind; |
| 190 | PyObject *kw_defaults; |
| 191 | PyObject *kwarg; |
| 192 | PyObject *kwonlyargs; |
| 193 | PyObject *left; |
| 194 | PyObject *level; |
| 195 | PyObject *lineno; |
| 196 | PyObject *lower; |
| 197 | PyObject *mod_type; |
| 198 | PyObject *module; |
| 199 | PyObject *msg; |
| 200 | PyObject *name; |
| 201 | PyObject *names; |
| 202 | PyObject *op; |
| 203 | PyObject *operand; |
| 204 | PyObject *operator_type; |
| 205 | PyObject *ops; |
| 206 | PyObject *optional_vars; |
| 207 | PyObject *orelse; |
| 208 | PyObject *posonlyargs; |
| 209 | PyObject *returns; |
| 210 | PyObject *right; |
| 211 | PyObject *simple; |
| 212 | PyObject *slice; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 213 | PyObject *step; |
| 214 | PyObject *stmt_type; |
| 215 | PyObject *tag; |
| 216 | PyObject *target; |
| 217 | PyObject *targets; |
| 218 | PyObject *test; |
| 219 | PyObject *type; |
| 220 | PyObject *type_comment; |
| 221 | PyObject *type_ignore_type; |
| 222 | PyObject *type_ignores; |
| 223 | PyObject *unaryop_type; |
| 224 | PyObject *upper; |
| 225 | PyObject *value; |
| 226 | PyObject *values; |
| 227 | PyObject *vararg; |
| 228 | PyObject *withitem_type; |
| 229 | } astmodulestate; |
| 230 | |
| 231 | |
| 232 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 233 | |
| 234 | static int astmodule_clear(PyObject *module) |
| 235 | { |
| 236 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 237 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 238 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 239 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 240 | Py_CLEAR(astmodulestate(module)->And_type); |
| 241 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 242 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 243 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 244 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 245 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 246 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 247 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 248 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
| 249 | Py_CLEAR(astmodulestate(module)->AugLoad_singleton); |
| 250 | Py_CLEAR(astmodulestate(module)->AugLoad_type); |
| 251 | Py_CLEAR(astmodulestate(module)->AugStore_singleton); |
| 252 | Py_CLEAR(astmodulestate(module)->AugStore_type); |
| 253 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 254 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 255 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 256 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 257 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 258 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 259 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 260 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 261 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 262 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 263 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 264 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 265 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 266 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 267 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 268 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 269 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 271 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 272 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 273 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 274 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 275 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 276 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 277 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 278 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 279 | Py_CLEAR(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 280 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 281 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 282 | Py_CLEAR(astmodulestate(module)->For_type); |
| 283 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 284 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 285 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 286 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 287 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 288 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 289 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 290 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 291 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 292 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 293 | Py_CLEAR(astmodulestate(module)->If_type); |
| 294 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 295 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 296 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 297 | Py_CLEAR(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 298 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 299 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 300 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 301 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 302 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 303 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 304 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 305 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 306 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 307 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 308 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 309 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 310 | Py_CLEAR(astmodulestate(module)->List_type); |
| 311 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 312 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 313 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 314 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 315 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 316 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 317 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 318 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 319 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 320 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 321 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 322 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 323 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 324 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 325 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 326 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 327 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 328 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 329 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 330 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 331 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 332 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 333 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 334 | Py_CLEAR(astmodulestate(module)->Or_type); |
| 335 | Py_CLEAR(astmodulestate(module)->Param_singleton); |
| 336 | Py_CLEAR(astmodulestate(module)->Param_type); |
| 337 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 338 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 339 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 340 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 341 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 342 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 343 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 344 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 345 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 346 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 347 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 348 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 349 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 350 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 351 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 352 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 353 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 354 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 355 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 356 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 357 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 358 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 359 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 360 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 361 | Py_CLEAR(astmodulestate(module)->While_type); |
| 362 | Py_CLEAR(astmodulestate(module)->With_type); |
| 363 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 364 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 365 | Py_CLEAR(astmodulestate(module)->__dict__); |
| 366 | Py_CLEAR(astmodulestate(module)->__module__); |
| 367 | Py_CLEAR(astmodulestate(module)->_ast); |
| 368 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 369 | Py_CLEAR(astmodulestate(module)->_fields); |
| 370 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 371 | Py_CLEAR(astmodulestate(module)->annotation); |
| 372 | Py_CLEAR(astmodulestate(module)->arg); |
| 373 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 374 | Py_CLEAR(astmodulestate(module)->args); |
| 375 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 376 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 377 | Py_CLEAR(astmodulestate(module)->asname); |
| 378 | Py_CLEAR(astmodulestate(module)->attr); |
| 379 | Py_CLEAR(astmodulestate(module)->bases); |
| 380 | Py_CLEAR(astmodulestate(module)->body); |
| 381 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 382 | Py_CLEAR(astmodulestate(module)->cause); |
| 383 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 384 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 385 | Py_CLEAR(astmodulestate(module)->comparators); |
| 386 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 387 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 388 | Py_CLEAR(astmodulestate(module)->conversion); |
| 389 | Py_CLEAR(astmodulestate(module)->ctx); |
| 390 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 391 | Py_CLEAR(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 392 | Py_CLEAR(astmodulestate(module)->elt); |
| 393 | Py_CLEAR(astmodulestate(module)->elts); |
| 394 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 395 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 396 | Py_CLEAR(astmodulestate(module)->exc); |
| 397 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 398 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 399 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 400 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 401 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 402 | Py_CLEAR(astmodulestate(module)->func); |
| 403 | Py_CLEAR(astmodulestate(module)->generators); |
| 404 | Py_CLEAR(astmodulestate(module)->handlers); |
| 405 | Py_CLEAR(astmodulestate(module)->id); |
| 406 | Py_CLEAR(astmodulestate(module)->ifs); |
| 407 | Py_CLEAR(astmodulestate(module)->is_async); |
| 408 | Py_CLEAR(astmodulestate(module)->items); |
| 409 | Py_CLEAR(astmodulestate(module)->iter); |
| 410 | Py_CLEAR(astmodulestate(module)->key); |
| 411 | Py_CLEAR(astmodulestate(module)->keys); |
| 412 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 413 | Py_CLEAR(astmodulestate(module)->keywords); |
| 414 | Py_CLEAR(astmodulestate(module)->kind); |
| 415 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 416 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 417 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 418 | Py_CLEAR(astmodulestate(module)->left); |
| 419 | Py_CLEAR(astmodulestate(module)->level); |
| 420 | Py_CLEAR(astmodulestate(module)->lineno); |
| 421 | Py_CLEAR(astmodulestate(module)->lower); |
| 422 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 423 | Py_CLEAR(astmodulestate(module)->module); |
| 424 | Py_CLEAR(astmodulestate(module)->msg); |
| 425 | Py_CLEAR(astmodulestate(module)->name); |
| 426 | Py_CLEAR(astmodulestate(module)->names); |
| 427 | Py_CLEAR(astmodulestate(module)->op); |
| 428 | Py_CLEAR(astmodulestate(module)->operand); |
| 429 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 430 | Py_CLEAR(astmodulestate(module)->ops); |
| 431 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 432 | Py_CLEAR(astmodulestate(module)->orelse); |
| 433 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 434 | Py_CLEAR(astmodulestate(module)->returns); |
| 435 | Py_CLEAR(astmodulestate(module)->right); |
| 436 | Py_CLEAR(astmodulestate(module)->simple); |
| 437 | Py_CLEAR(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 438 | Py_CLEAR(astmodulestate(module)->step); |
| 439 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 440 | Py_CLEAR(astmodulestate(module)->tag); |
| 441 | Py_CLEAR(astmodulestate(module)->target); |
| 442 | Py_CLEAR(astmodulestate(module)->targets); |
| 443 | Py_CLEAR(astmodulestate(module)->test); |
| 444 | Py_CLEAR(astmodulestate(module)->type); |
| 445 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 446 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 447 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 448 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 449 | Py_CLEAR(astmodulestate(module)->upper); |
| 450 | Py_CLEAR(astmodulestate(module)->value); |
| 451 | Py_CLEAR(astmodulestate(module)->values); |
| 452 | Py_CLEAR(astmodulestate(module)->vararg); |
| 453 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 459 | { |
| 460 | Py_VISIT(astmodulestate(module)->AST_type); |
| 461 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 462 | Py_VISIT(astmodulestate(module)->Add_type); |
| 463 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 464 | Py_VISIT(astmodulestate(module)->And_type); |
| 465 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 466 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 467 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 468 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 469 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 470 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 471 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 472 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
| 473 | Py_VISIT(astmodulestate(module)->AugLoad_singleton); |
| 474 | Py_VISIT(astmodulestate(module)->AugLoad_type); |
| 475 | Py_VISIT(astmodulestate(module)->AugStore_singleton); |
| 476 | Py_VISIT(astmodulestate(module)->AugStore_type); |
| 477 | Py_VISIT(astmodulestate(module)->Await_type); |
| 478 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 479 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 480 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 481 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 482 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 483 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 485 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 486 | Py_VISIT(astmodulestate(module)->Break_type); |
| 487 | Py_VISIT(astmodulestate(module)->Call_type); |
| 488 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 489 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 490 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 491 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 492 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 493 | Py_VISIT(astmodulestate(module)->Del_type); |
| 494 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 495 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 496 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 497 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 498 | Py_VISIT(astmodulestate(module)->Div_type); |
| 499 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 500 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 501 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 502 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 503 | Py_VISIT(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 504 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 505 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 506 | Py_VISIT(astmodulestate(module)->For_type); |
| 507 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 508 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 509 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 510 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 511 | Py_VISIT(astmodulestate(module)->Global_type); |
| 512 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 513 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 514 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 515 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 516 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 517 | Py_VISIT(astmodulestate(module)->If_type); |
| 518 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 519 | Py_VISIT(astmodulestate(module)->Import_type); |
| 520 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 521 | Py_VISIT(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 522 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 523 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 525 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 526 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 527 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 528 | Py_VISIT(astmodulestate(module)->Is_type); |
| 529 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 530 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 531 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 532 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 533 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 534 | Py_VISIT(astmodulestate(module)->List_type); |
| 535 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 536 | Py_VISIT(astmodulestate(module)->Load_type); |
| 537 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 539 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 540 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 541 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 542 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 543 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 544 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 545 | Py_VISIT(astmodulestate(module)->Module_type); |
| 546 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 547 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 548 | Py_VISIT(astmodulestate(module)->Name_type); |
| 549 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 550 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 551 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 552 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 553 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 554 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 555 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 556 | Py_VISIT(astmodulestate(module)->Not_type); |
| 557 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 558 | Py_VISIT(astmodulestate(module)->Or_type); |
| 559 | Py_VISIT(astmodulestate(module)->Param_singleton); |
| 560 | Py_VISIT(astmodulestate(module)->Param_type); |
| 561 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 562 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 563 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 564 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 565 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 566 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 567 | Py_VISIT(astmodulestate(module)->Return_type); |
| 568 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 569 | Py_VISIT(astmodulestate(module)->Set_type); |
| 570 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 571 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 572 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 573 | Py_VISIT(astmodulestate(module)->Store_type); |
| 574 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 575 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 576 | Py_VISIT(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 577 | Py_VISIT(astmodulestate(module)->Try_type); |
| 578 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 579 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 580 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 581 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 582 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 583 | Py_VISIT(astmodulestate(module)->USub_type); |
| 584 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 585 | Py_VISIT(astmodulestate(module)->While_type); |
| 586 | Py_VISIT(astmodulestate(module)->With_type); |
| 587 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 588 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 589 | Py_VISIT(astmodulestate(module)->__dict__); |
| 590 | Py_VISIT(astmodulestate(module)->__module__); |
| 591 | Py_VISIT(astmodulestate(module)->_ast); |
| 592 | Py_VISIT(astmodulestate(module)->_attributes); |
| 593 | Py_VISIT(astmodulestate(module)->_fields); |
| 594 | Py_VISIT(astmodulestate(module)->alias_type); |
| 595 | Py_VISIT(astmodulestate(module)->annotation); |
| 596 | Py_VISIT(astmodulestate(module)->arg); |
| 597 | Py_VISIT(astmodulestate(module)->arg_type); |
| 598 | Py_VISIT(astmodulestate(module)->args); |
| 599 | Py_VISIT(astmodulestate(module)->argtypes); |
| 600 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 601 | Py_VISIT(astmodulestate(module)->asname); |
| 602 | Py_VISIT(astmodulestate(module)->attr); |
| 603 | Py_VISIT(astmodulestate(module)->bases); |
| 604 | Py_VISIT(astmodulestate(module)->body); |
| 605 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 606 | Py_VISIT(astmodulestate(module)->cause); |
| 607 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 608 | Py_VISIT(astmodulestate(module)->col_offset); |
| 609 | Py_VISIT(astmodulestate(module)->comparators); |
| 610 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 611 | Py_VISIT(astmodulestate(module)->context_expr); |
| 612 | Py_VISIT(astmodulestate(module)->conversion); |
| 613 | Py_VISIT(astmodulestate(module)->ctx); |
| 614 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 615 | Py_VISIT(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 616 | Py_VISIT(astmodulestate(module)->elt); |
| 617 | Py_VISIT(astmodulestate(module)->elts); |
| 618 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 619 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 620 | Py_VISIT(astmodulestate(module)->exc); |
| 621 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 622 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 623 | Py_VISIT(astmodulestate(module)->expr_type); |
| 624 | Py_VISIT(astmodulestate(module)->finalbody); |
| 625 | Py_VISIT(astmodulestate(module)->format_spec); |
| 626 | Py_VISIT(astmodulestate(module)->func); |
| 627 | Py_VISIT(astmodulestate(module)->generators); |
| 628 | Py_VISIT(astmodulestate(module)->handlers); |
| 629 | Py_VISIT(astmodulestate(module)->id); |
| 630 | Py_VISIT(astmodulestate(module)->ifs); |
| 631 | Py_VISIT(astmodulestate(module)->is_async); |
| 632 | Py_VISIT(astmodulestate(module)->items); |
| 633 | Py_VISIT(astmodulestate(module)->iter); |
| 634 | Py_VISIT(astmodulestate(module)->key); |
| 635 | Py_VISIT(astmodulestate(module)->keys); |
| 636 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 637 | Py_VISIT(astmodulestate(module)->keywords); |
| 638 | Py_VISIT(astmodulestate(module)->kind); |
| 639 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 640 | Py_VISIT(astmodulestate(module)->kwarg); |
| 641 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 642 | Py_VISIT(astmodulestate(module)->left); |
| 643 | Py_VISIT(astmodulestate(module)->level); |
| 644 | Py_VISIT(astmodulestate(module)->lineno); |
| 645 | Py_VISIT(astmodulestate(module)->lower); |
| 646 | Py_VISIT(astmodulestate(module)->mod_type); |
| 647 | Py_VISIT(astmodulestate(module)->module); |
| 648 | Py_VISIT(astmodulestate(module)->msg); |
| 649 | Py_VISIT(astmodulestate(module)->name); |
| 650 | Py_VISIT(astmodulestate(module)->names); |
| 651 | Py_VISIT(astmodulestate(module)->op); |
| 652 | Py_VISIT(astmodulestate(module)->operand); |
| 653 | Py_VISIT(astmodulestate(module)->operator_type); |
| 654 | Py_VISIT(astmodulestate(module)->ops); |
| 655 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 656 | Py_VISIT(astmodulestate(module)->orelse); |
| 657 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 658 | Py_VISIT(astmodulestate(module)->returns); |
| 659 | Py_VISIT(astmodulestate(module)->right); |
| 660 | Py_VISIT(astmodulestate(module)->simple); |
| 661 | Py_VISIT(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 662 | Py_VISIT(astmodulestate(module)->step); |
| 663 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 664 | Py_VISIT(astmodulestate(module)->tag); |
| 665 | Py_VISIT(astmodulestate(module)->target); |
| 666 | Py_VISIT(astmodulestate(module)->targets); |
| 667 | Py_VISIT(astmodulestate(module)->test); |
| 668 | Py_VISIT(astmodulestate(module)->type); |
| 669 | Py_VISIT(astmodulestate(module)->type_comment); |
| 670 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 671 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 672 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 673 | Py_VISIT(astmodulestate(module)->upper); |
| 674 | Py_VISIT(astmodulestate(module)->value); |
| 675 | Py_VISIT(astmodulestate(module)->values); |
| 676 | Py_VISIT(astmodulestate(module)->vararg); |
| 677 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | static void astmodule_free(void* module) { |
| 683 | astmodule_clear((PyObject*)module); |
| 684 | } |
| 685 | |
| 686 | static struct PyModuleDef _astmodule = { |
| 687 | PyModuleDef_HEAD_INIT, |
| 688 | "_ast", |
| 689 | NULL, |
| 690 | sizeof(astmodulestate), |
| 691 | NULL, |
| 692 | NULL, |
| 693 | astmodule_traverse, |
| 694 | astmodule_clear, |
| 695 | astmodule_free, |
| 696 | }; |
| 697 | |
| 698 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 699 | |
| 700 | static int init_identifiers(void) |
| 701 | { |
| 702 | astmodulestate *state = astmodulestate_global; |
| 703 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
| 704 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
| 705 | if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0; |
| 706 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 707 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 708 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 709 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 710 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 711 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 712 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
| 713 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 714 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 715 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 716 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 717 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 718 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 719 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 720 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 721 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 722 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 723 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 724 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 725 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 726 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 727 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 728 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 729 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 730 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 731 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 732 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 733 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 734 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 735 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 736 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 737 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 738 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 739 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 740 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 741 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 742 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 743 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 744 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 745 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 746 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 747 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 748 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 749 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 750 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 751 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 752 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 753 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 754 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 755 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 756 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 757 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 758 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 759 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 760 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 761 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 762 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 763 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 764 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 765 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 766 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 767 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 768 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 769 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 770 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 771 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 772 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 773 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 774 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 775 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 776 | return 1; |
| 777 | }; |
| 778 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 779 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 780 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 781 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 782 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 783 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 784 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 785 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 787 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 788 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 789 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 790 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 791 | "argtypes", |
| 792 | "returns", |
| 793 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 794 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 795 | "lineno", |
| 796 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 797 | "end_lineno", |
| 798 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 799 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 800 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 801 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 802 | "name", |
| 803 | "args", |
| 804 | "body", |
| 805 | "decorator_list", |
| 806 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 807 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 808 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 809 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 810 | "name", |
| 811 | "args", |
| 812 | "body", |
| 813 | "decorator_list", |
| 814 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 815 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 816 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 817 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 818 | "name", |
| 819 | "bases", |
| 820 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 821 | "body", |
| 822 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 823 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 824 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 825 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 826 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 827 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 828 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 829 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 830 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 831 | "targets", |
| 832 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 833 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 834 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 835 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 836 | "target", |
| 837 | "op", |
| 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 AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 841 | "target", |
| 842 | "annotation", |
| 843 | "value", |
| 844 | "simple", |
| 845 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 846 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 847 | "target", |
| 848 | "iter", |
| 849 | "body", |
| 850 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 851 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 852 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 853 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 854 | "target", |
| 855 | "iter", |
| 856 | "body", |
| 857 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 858 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 859 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 860 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 861 | "test", |
| 862 | "body", |
| 863 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 864 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 865 | static const char * const If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 866 | "test", |
| 867 | "body", |
| 868 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 870 | static const char * const With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 871 | "items", |
| 872 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 873 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 874 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 875 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 876 | "items", |
| 877 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 878 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 879 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 880 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 881 | "exc", |
| 882 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 883 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 884 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 885 | "body", |
| 886 | "handlers", |
| 887 | "orelse", |
| 888 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 889 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 890 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 891 | "test", |
| 892 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 893 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 894 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 895 | "names", |
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 ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | "module", |
| 899 | "names", |
| 900 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 901 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 902 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 903 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 904 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 905 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 906 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 907 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 908 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 909 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 910 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 911 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 912 | "lineno", |
| 913 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 914 | "end_lineno", |
| 915 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 916 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 917 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 918 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 919 | "op", |
| 920 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 921 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 922 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 923 | "target", |
| 924 | "value", |
| 925 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 926 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 927 | "left", |
| 928 | "op", |
| 929 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 930 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 931 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 932 | "op", |
| 933 | "operand", |
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 Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 936 | "args", |
| 937 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 938 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 939 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 940 | "test", |
| 941 | "body", |
| 942 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 943 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 944 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 945 | "keys", |
| 946 | "values", |
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 Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 949 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 950 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 951 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 952 | "elt", |
| 953 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 954 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 955 | static const char * const SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 956 | "elt", |
| 957 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 958 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 959 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 960 | "key", |
| 961 | "value", |
| 962 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 963 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 964 | static const char * const GeneratorExp_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 Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 969 | "value", |
| 970 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 971 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 972 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 973 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 974 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 975 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 976 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 977 | static const char * const Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 978 | "left", |
| 979 | "ops", |
| 980 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 981 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 982 | static const char * const Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 983 | "func", |
| 984 | "args", |
| 985 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 986 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 987 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 988 | "value", |
| 989 | "conversion", |
| 990 | "format_spec", |
| 991 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 992 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 993 | "values", |
| 994 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 995 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 996 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 997 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 998 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 999 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1000 | "value", |
| 1001 | "attr", |
| 1002 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1003 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1004 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1005 | "value", |
| 1006 | "slice", |
| 1007 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1008 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1009 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1010 | "value", |
| 1011 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1012 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1013 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1014 | "id", |
| 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 List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1018 | "elts", |
| 1019 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1020 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1021 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1022 | "elts", |
| 1023 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1024 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1025 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1026 | "lower", |
| 1027 | "upper", |
| 1028 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1029 | }; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1030 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1031 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1032 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1033 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1034 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1035 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1036 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1037 | "target", |
| 1038 | "iter", |
| 1039 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1040 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1041 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1042 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1043 | "lineno", |
| 1044 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1045 | "end_lineno", |
| 1046 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1047 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1048 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1049 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1050 | "type", |
| 1051 | "name", |
| 1052 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1053 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1054 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1055 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1056 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1057 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1058 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1059 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1060 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1061 | "kwarg", |
| 1062 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1063 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1064 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1065 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1066 | "lineno", |
| 1067 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1068 | "end_lineno", |
| 1069 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1070 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1071 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1072 | "arg", |
| 1073 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1074 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1075 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1076 | static PyObject* ast2obj_keyword(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1077 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1078 | "arg", |
| 1079 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1080 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1081 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1082 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1083 | "name", |
| 1084 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1085 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1086 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1087 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1088 | "context_expr", |
| 1089 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1090 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1091 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1092 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1093 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1094 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1095 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1096 | |
| 1097 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1098 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1099 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1100 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1101 | PyObject *dict; |
| 1102 | } AST_object; |
| 1103 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1104 | static void |
| 1105 | ast_dealloc(AST_object *self) |
| 1106 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1107 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1108 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1109 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1110 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1111 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1112 | assert(free_func != NULL); |
| 1113 | free_func(self); |
| 1114 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1115 | } |
| 1116 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1117 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1118 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1119 | { |
| 1120 | Py_VISIT(self->dict); |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1124 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1125 | ast_clear(AST_object *self) |
| 1126 | { |
| 1127 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1128 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1132 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1133 | { |
| 1134 | Py_ssize_t i, numfields = 0; |
| 1135 | int res = -1; |
| 1136 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1137 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1138 | goto cleanup; |
| 1139 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1140 | if (fields) { |
| 1141 | numfields = PySequence_Size(fields); |
| 1142 | if (numfields == -1) |
| 1143 | goto cleanup; |
| 1144 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1145 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1146 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1147 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1148 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1149 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1150 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1151 | numfields, numfields == 1 ? "" : "s"); |
| 1152 | res = -1; |
| 1153 | goto cleanup; |
| 1154 | } |
| 1155 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1156 | /* cannot be reached when fields is NULL */ |
| 1157 | PyObject *name = PySequence_GetItem(fields, i); |
| 1158 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1159 | res = -1; |
| 1160 | goto cleanup; |
| 1161 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1162 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1163 | Py_DECREF(name); |
| 1164 | if (res < 0) |
| 1165 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1166 | } |
| 1167 | if (kw) { |
| 1168 | i = 0; /* needed by PyDict_Next */ |
| 1169 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1170 | res = PyObject_SetAttr(self, key, value); |
| 1171 | if (res < 0) |
| 1172 | goto cleanup; |
| 1173 | } |
| 1174 | } |
| 1175 | cleanup: |
| 1176 | Py_XDECREF(fields); |
| 1177 | return res; |
| 1178 | } |
| 1179 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1180 | /* Pickling support */ |
| 1181 | static PyObject * |
| 1182 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1183 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1184 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1185 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1186 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1187 | } |
| 1188 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1189 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1190 | } |
| 1191 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1192 | } |
| 1193 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1194 | static PyMemberDef ast_type_members[] = { |
| 1195 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1196 | {NULL} /* Sentinel */ |
| 1197 | }; |
| 1198 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1199 | static PyMethodDef ast_type_methods[] = { |
| 1200 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1201 | {NULL} |
| 1202 | }; |
| 1203 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1204 | static PyGetSetDef ast_type_getsets[] = { |
| 1205 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1206 | {NULL} |
| 1207 | }; |
| 1208 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1209 | static PyType_Slot AST_type_slots[] = { |
| 1210 | {Py_tp_dealloc, ast_dealloc}, |
| 1211 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1212 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1213 | {Py_tp_traverse, ast_traverse}, |
| 1214 | {Py_tp_clear, ast_clear}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1215 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1216 | {Py_tp_methods, ast_type_methods}, |
| 1217 | {Py_tp_getset, ast_type_getsets}, |
| 1218 | {Py_tp_init, ast_type_init}, |
| 1219 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1220 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1221 | {Py_tp_free, PyObject_GC_Del}, |
| 1222 | {0, 0}, |
| 1223 | }; |
| 1224 | |
| 1225 | static PyType_Spec AST_type_spec = { |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1226 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1227 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1228 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1229 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1230 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1231 | }; |
| 1232 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1233 | static PyObject * |
| 1234 | 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] | 1235 | { |
| 1236 | PyObject *fnames, *result; |
| 1237 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1238 | fnames = PyTuple_New(num_fields); |
| 1239 | if (!fnames) return NULL; |
| 1240 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1241 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1242 | if (!field) { |
| 1243 | Py_DECREF(fnames); |
| 1244 | return NULL; |
| 1245 | } |
| 1246 | PyTuple_SET_ITEM(fnames, i, field); |
| 1247 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1248 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 1249 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1250 | astmodulestate_global->_fields, fnames, |
| 1251 | astmodulestate_global->__module__, |
| 1252 | astmodulestate_global->_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1253 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1254 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1257 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1258 | 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] | 1259 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1260 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1261 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1262 | if (!l) |
| 1263 | return 0; |
| 1264 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1265 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1266 | if (!s) { |
| 1267 | Py_DECREF(l); |
| 1268 | return 0; |
| 1269 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1270 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1271 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1272 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1273 | Py_DECREF(l); |
| 1274 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1277 | /* Conversion AST -> Python */ |
| 1278 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1279 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1280 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1281 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1282 | PyObject *result = PyList_New(n); |
| 1283 | PyObject *value; |
| 1284 | if (!result) |
| 1285 | return NULL; |
| 1286 | for (i = 0; i < n; i++) { |
| 1287 | value = func(asdl_seq_GET(seq, i)); |
| 1288 | if (!value) { |
| 1289 | Py_DECREF(result); |
| 1290 | return NULL; |
| 1291 | } |
| 1292 | PyList_SET_ITEM(result, i, value); |
| 1293 | } |
| 1294 | return result; |
| 1295 | } |
| 1296 | |
| 1297 | static PyObject* ast2obj_object(void *o) |
| 1298 | { |
| 1299 | if (!o) |
| 1300 | o = Py_None; |
| 1301 | Py_INCREF((PyObject*)o); |
| 1302 | return (PyObject*)o; |
| 1303 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1304 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1305 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1306 | #define ast2obj_identifier ast2obj_object |
| 1307 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1308 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1309 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1310 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1311 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1312 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1315 | /* Conversion Python -> AST */ |
| 1316 | |
| 1317 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1318 | { |
| 1319 | if (obj == Py_None) |
| 1320 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1321 | if (obj) { |
| 1322 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1323 | *out = NULL; |
| 1324 | return -1; |
| 1325 | } |
| 1326 | Py_INCREF(obj); |
| 1327 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1328 | *out = obj; |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1332 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1333 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1334 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1335 | *out = NULL; |
| 1336 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1337 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1338 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1339 | *out = obj; |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1343 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1344 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1345 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1346 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1347 | return 1; |
| 1348 | } |
| 1349 | return obj2ast_object(obj, out, arena); |
| 1350 | } |
| 1351 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1352 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1353 | { |
| 1354 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1355 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1356 | return 1; |
| 1357 | } |
| 1358 | return obj2ast_object(obj, out, arena); |
| 1359 | } |
| 1360 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1361 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1362 | { |
| 1363 | int i; |
| 1364 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1365 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1366 | return 1; |
| 1367 | } |
| 1368 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1369 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1370 | if (i == -1 && PyErr_Occurred()) |
| 1371 | return 1; |
| 1372 | *out = i; |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1376 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1377 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1378 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1379 | empty_tuple = PyTuple_New(0); |
| 1380 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1381 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1382 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1383 | Py_XDECREF(empty_tuple); |
| 1384 | return -1; |
| 1385 | } |
| 1386 | Py_DECREF(empty_tuple); |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1390 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1391 | static int init_types(void) |
| 1392 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1393 | PyObject *m; |
| 1394 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1395 | m = PyModule_Create(&_astmodule); |
| 1396 | if (!m) return 0; |
| 1397 | PyState_AddModule(m, &_astmodule); |
| 1398 | } |
| 1399 | astmodulestate *state = astmodulestate_global; |
| 1400 | if (state->initialized) return 1; |
| 1401 | if (init_identifiers() < 0) return 0; |
| 1402 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1403 | if (!state->AST_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1404 | if (add_ast_fields() < 0) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1405 | state->mod_type = make_type("mod", state->AST_type, NULL, 0); |
| 1406 | if (!state->mod_type) return 0; |
| 1407 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
| 1408 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2); |
| 1409 | if (!state->Module_type) return 0; |
| 1410 | state->Interactive_type = make_type("Interactive", state->mod_type, |
| 1411 | Interactive_fields, 1); |
| 1412 | if (!state->Interactive_type) return 0; |
| 1413 | state->Expression_type = make_type("Expression", state->mod_type, |
| 1414 | Expression_fields, 1); |
| 1415 | if (!state->Expression_type) return 0; |
| 1416 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
| 1417 | FunctionType_fields, 2); |
| 1418 | if (!state->FunctionType_type) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1419 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0); |
| 1420 | if (!state->stmt_type) return 0; |
| 1421 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1422 | if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) |
| 1423 | return 0; |
| 1424 | if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == |
| 1425 | -1) |
| 1426 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1427 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
| 1428 | FunctionDef_fields, 6); |
| 1429 | if (!state->FunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1430 | if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == |
| 1431 | -1) |
| 1432 | return 0; |
| 1433 | if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) |
| 1434 | == -1) |
| 1435 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1436 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1437 | state->stmt_type, |
| 1438 | AsyncFunctionDef_fields, 6); |
| 1439 | if (!state->AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1440 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) |
| 1441 | == -1) |
| 1442 | return 0; |
| 1443 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, |
| 1444 | Py_None) == -1) |
| 1445 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1446 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
| 1447 | ClassDef_fields, 5); |
| 1448 | if (!state->ClassDef_type) return 0; |
| 1449 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, |
| 1450 | 1); |
| 1451 | if (!state->Return_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1452 | if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) |
| 1453 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1454 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, |
| 1455 | 1); |
| 1456 | if (!state->Delete_type) return 0; |
| 1457 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, |
| 1458 | 3); |
| 1459 | if (!state->Assign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1460 | if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == |
| 1461 | -1) |
| 1462 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1463 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
| 1464 | AugAssign_fields, 3); |
| 1465 | if (!state->AugAssign_type) return 0; |
| 1466 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
| 1467 | AnnAssign_fields, 4); |
| 1468 | if (!state->AnnAssign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1469 | if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) |
| 1470 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1471 | state->For_type = make_type("For", state->stmt_type, For_fields, 5); |
| 1472 | if (!state->For_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1473 | if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) |
| 1474 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1475 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
| 1476 | AsyncFor_fields, 5); |
| 1477 | if (!state->AsyncFor_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1478 | if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == |
| 1479 | -1) |
| 1480 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1481 | state->While_type = make_type("While", state->stmt_type, While_fields, 3); |
| 1482 | if (!state->While_type) return 0; |
| 1483 | state->If_type = make_type("If", state->stmt_type, If_fields, 3); |
| 1484 | if (!state->If_type) return 0; |
| 1485 | state->With_type = make_type("With", state->stmt_type, With_fields, 3); |
| 1486 | if (!state->With_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1487 | if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) |
| 1488 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1489 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
| 1490 | AsyncWith_fields, 3); |
| 1491 | if (!state->AsyncWith_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1492 | if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) |
| 1493 | == -1) |
| 1494 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1495 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2); |
| 1496 | if (!state->Raise_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1497 | if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) |
| 1498 | return 0; |
| 1499 | if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) |
| 1500 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1501 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4); |
| 1502 | if (!state->Try_type) return 0; |
| 1503 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, |
| 1504 | 2); |
| 1505 | if (!state->Assert_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1506 | if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) |
| 1507 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1508 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, |
| 1509 | 1); |
| 1510 | if (!state->Import_type) return 0; |
| 1511 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
| 1512 | ImportFrom_fields, 3); |
| 1513 | if (!state->ImportFrom_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1514 | if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) |
| 1515 | return 0; |
| 1516 | if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) |
| 1517 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1518 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, |
| 1519 | 1); |
| 1520 | if (!state->Global_type) return 0; |
| 1521 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
| 1522 | Nonlocal_fields, 1); |
| 1523 | if (!state->Nonlocal_type) return 0; |
| 1524 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1); |
| 1525 | if (!state->Expr_type) return 0; |
| 1526 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0); |
| 1527 | if (!state->Pass_type) return 0; |
| 1528 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0); |
| 1529 | if (!state->Break_type) return 0; |
| 1530 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0); |
| 1531 | if (!state->Continue_type) return 0; |
| 1532 | state->expr_type = make_type("expr", state->AST_type, NULL, 0); |
| 1533 | if (!state->expr_type) return 0; |
| 1534 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1535 | if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) |
| 1536 | return 0; |
| 1537 | if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == |
| 1538 | -1) |
| 1539 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1540 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, |
| 1541 | 2); |
| 1542 | if (!state->BoolOp_type) return 0; |
| 1543 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
| 1544 | NamedExpr_fields, 2); |
| 1545 | if (!state->NamedExpr_type) return 0; |
| 1546 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3); |
| 1547 | if (!state->BinOp_type) return 0; |
| 1548 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
| 1549 | UnaryOp_fields, 2); |
| 1550 | if (!state->UnaryOp_type) return 0; |
| 1551 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, |
| 1552 | 2); |
| 1553 | if (!state->Lambda_type) return 0; |
| 1554 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3); |
| 1555 | if (!state->IfExp_type) return 0; |
| 1556 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2); |
| 1557 | if (!state->Dict_type) return 0; |
| 1558 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1); |
| 1559 | if (!state->Set_type) return 0; |
| 1560 | state->ListComp_type = make_type("ListComp", state->expr_type, |
| 1561 | ListComp_fields, 2); |
| 1562 | if (!state->ListComp_type) return 0; |
| 1563 | state->SetComp_type = make_type("SetComp", state->expr_type, |
| 1564 | SetComp_fields, 2); |
| 1565 | if (!state->SetComp_type) return 0; |
| 1566 | state->DictComp_type = make_type("DictComp", state->expr_type, |
| 1567 | DictComp_fields, 3); |
| 1568 | if (!state->DictComp_type) return 0; |
| 1569 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
| 1570 | GeneratorExp_fields, 2); |
| 1571 | if (!state->GeneratorExp_type) return 0; |
| 1572 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1); |
| 1573 | if (!state->Await_type) return 0; |
| 1574 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1); |
| 1575 | if (!state->Yield_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1576 | if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) |
| 1577 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1578 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
| 1579 | YieldFrom_fields, 1); |
| 1580 | if (!state->YieldFrom_type) return 0; |
| 1581 | state->Compare_type = make_type("Compare", state->expr_type, |
| 1582 | Compare_fields, 3); |
| 1583 | if (!state->Compare_type) return 0; |
| 1584 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3); |
| 1585 | if (!state->Call_type) return 0; |
| 1586 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
| 1587 | FormattedValue_fields, 3); |
| 1588 | if (!state->FormattedValue_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1589 | if (PyObject_SetAttr(state->FormattedValue_type, state->conversion, |
| 1590 | Py_None) == -1) |
| 1591 | return 0; |
| 1592 | if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, |
| 1593 | Py_None) == -1) |
| 1594 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1595 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
| 1596 | JoinedStr_fields, 1); |
| 1597 | if (!state->JoinedStr_type) return 0; |
| 1598 | state->Constant_type = make_type("Constant", state->expr_type, |
| 1599 | Constant_fields, 2); |
| 1600 | if (!state->Constant_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1601 | if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) |
| 1602 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1603 | state->Attribute_type = make_type("Attribute", state->expr_type, |
| 1604 | Attribute_fields, 3); |
| 1605 | if (!state->Attribute_type) return 0; |
| 1606 | state->Subscript_type = make_type("Subscript", state->expr_type, |
| 1607 | Subscript_fields, 3); |
| 1608 | if (!state->Subscript_type) return 0; |
| 1609 | state->Starred_type = make_type("Starred", state->expr_type, |
| 1610 | Starred_fields, 2); |
| 1611 | if (!state->Starred_type) return 0; |
| 1612 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2); |
| 1613 | if (!state->Name_type) return 0; |
| 1614 | state->List_type = make_type("List", state->expr_type, List_fields, 2); |
| 1615 | if (!state->List_type) return 0; |
| 1616 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2); |
| 1617 | if (!state->Tuple_type) return 0; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1618 | state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3); |
| 1619 | if (!state->Slice_type) return 0; |
| 1620 | if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) |
| 1621 | return 0; |
| 1622 | if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1) |
| 1623 | return 0; |
| 1624 | if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) |
| 1625 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1626 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
| 1627 | 0); |
| 1628 | if (!state->expr_context_type) return 0; |
| 1629 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
| 1630 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0); |
| 1631 | if (!state->Load_type) return 0; |
| 1632 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1633 | NULL, NULL); |
| 1634 | if (!state->Load_singleton) return 0; |
| 1635 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0); |
| 1636 | if (!state->Store_type) return 0; |
| 1637 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1638 | *)state->Store_type, NULL, NULL); |
| 1639 | if (!state->Store_singleton) return 0; |
| 1640 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0); |
| 1641 | if (!state->Del_type) return 0; |
| 1642 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1643 | NULL, NULL); |
| 1644 | if (!state->Del_singleton) return 0; |
| 1645 | state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL, |
| 1646 | 0); |
| 1647 | if (!state->AugLoad_type) return 0; |
| 1648 | state->AugLoad_singleton = PyType_GenericNew((PyTypeObject |
| 1649 | *)state->AugLoad_type, NULL, |
| 1650 | NULL); |
| 1651 | if (!state->AugLoad_singleton) return 0; |
| 1652 | state->AugStore_type = make_type("AugStore", state->expr_context_type, |
| 1653 | NULL, 0); |
| 1654 | if (!state->AugStore_type) return 0; |
| 1655 | state->AugStore_singleton = PyType_GenericNew((PyTypeObject |
| 1656 | *)state->AugStore_type, NULL, |
| 1657 | NULL); |
| 1658 | if (!state->AugStore_singleton) return 0; |
| 1659 | state->Param_type = make_type("Param", state->expr_context_type, NULL, 0); |
| 1660 | if (!state->Param_type) return 0; |
| 1661 | state->Param_singleton = PyType_GenericNew((PyTypeObject |
| 1662 | *)state->Param_type, NULL, NULL); |
| 1663 | if (!state->Param_singleton) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1664 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0); |
| 1665 | if (!state->boolop_type) return 0; |
| 1666 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
| 1667 | state->And_type = make_type("And", state->boolop_type, NULL, 0); |
| 1668 | if (!state->And_type) return 0; |
| 1669 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1670 | NULL, NULL); |
| 1671 | if (!state->And_singleton) return 0; |
| 1672 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0); |
| 1673 | if (!state->Or_type) return 0; |
| 1674 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1675 | NULL, NULL); |
| 1676 | if (!state->Or_singleton) return 0; |
| 1677 | state->operator_type = make_type("operator", state->AST_type, NULL, 0); |
| 1678 | if (!state->operator_type) return 0; |
| 1679 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
| 1680 | state->Add_type = make_type("Add", state->operator_type, NULL, 0); |
| 1681 | if (!state->Add_type) return 0; |
| 1682 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1683 | NULL, NULL); |
| 1684 | if (!state->Add_singleton) return 0; |
| 1685 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0); |
| 1686 | if (!state->Sub_type) return 0; |
| 1687 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1688 | NULL, NULL); |
| 1689 | if (!state->Sub_singleton) return 0; |
| 1690 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0); |
| 1691 | if (!state->Mult_type) return 0; |
| 1692 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1693 | NULL, NULL); |
| 1694 | if (!state->Mult_singleton) return 0; |
| 1695 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0); |
| 1696 | if (!state->MatMult_type) return 0; |
| 1697 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1698 | *)state->MatMult_type, NULL, |
| 1699 | NULL); |
| 1700 | if (!state->MatMult_singleton) return 0; |
| 1701 | state->Div_type = make_type("Div", state->operator_type, NULL, 0); |
| 1702 | if (!state->Div_type) return 0; |
| 1703 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1704 | NULL, NULL); |
| 1705 | if (!state->Div_singleton) return 0; |
| 1706 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0); |
| 1707 | if (!state->Mod_type) return 0; |
| 1708 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1709 | NULL, NULL); |
| 1710 | if (!state->Mod_singleton) return 0; |
| 1711 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0); |
| 1712 | if (!state->Pow_type) return 0; |
| 1713 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1714 | NULL, NULL); |
| 1715 | if (!state->Pow_singleton) return 0; |
| 1716 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0); |
| 1717 | if (!state->LShift_type) return 0; |
| 1718 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1719 | *)state->LShift_type, NULL, |
| 1720 | NULL); |
| 1721 | if (!state->LShift_singleton) return 0; |
| 1722 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0); |
| 1723 | if (!state->RShift_type) return 0; |
| 1724 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1725 | *)state->RShift_type, NULL, |
| 1726 | NULL); |
| 1727 | if (!state->RShift_singleton) return 0; |
| 1728 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0); |
| 1729 | if (!state->BitOr_type) return 0; |
| 1730 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1731 | *)state->BitOr_type, NULL, NULL); |
| 1732 | if (!state->BitOr_singleton) return 0; |
| 1733 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0); |
| 1734 | if (!state->BitXor_type) return 0; |
| 1735 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1736 | *)state->BitXor_type, NULL, |
| 1737 | NULL); |
| 1738 | if (!state->BitXor_singleton) return 0; |
| 1739 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0); |
| 1740 | if (!state->BitAnd_type) return 0; |
| 1741 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1742 | *)state->BitAnd_type, NULL, |
| 1743 | NULL); |
| 1744 | if (!state->BitAnd_singleton) return 0; |
| 1745 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0); |
| 1746 | if (!state->FloorDiv_type) return 0; |
| 1747 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1748 | *)state->FloorDiv_type, NULL, |
| 1749 | NULL); |
| 1750 | if (!state->FloorDiv_singleton) return 0; |
| 1751 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0); |
| 1752 | if (!state->unaryop_type) return 0; |
| 1753 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
| 1754 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0); |
| 1755 | if (!state->Invert_type) return 0; |
| 1756 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1757 | *)state->Invert_type, NULL, |
| 1758 | NULL); |
| 1759 | if (!state->Invert_singleton) return 0; |
| 1760 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0); |
| 1761 | if (!state->Not_type) return 0; |
| 1762 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1763 | NULL, NULL); |
| 1764 | if (!state->Not_singleton) return 0; |
| 1765 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0); |
| 1766 | if (!state->UAdd_type) return 0; |
| 1767 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1768 | NULL, NULL); |
| 1769 | if (!state->UAdd_singleton) return 0; |
| 1770 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0); |
| 1771 | if (!state->USub_type) return 0; |
| 1772 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1773 | NULL, NULL); |
| 1774 | if (!state->USub_singleton) return 0; |
| 1775 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0); |
| 1776 | if (!state->cmpop_type) return 0; |
| 1777 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
| 1778 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0); |
| 1779 | if (!state->Eq_type) return 0; |
| 1780 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1781 | NULL, NULL); |
| 1782 | if (!state->Eq_singleton) return 0; |
| 1783 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0); |
| 1784 | if (!state->NotEq_type) return 0; |
| 1785 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1786 | *)state->NotEq_type, NULL, NULL); |
| 1787 | if (!state->NotEq_singleton) return 0; |
| 1788 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0); |
| 1789 | if (!state->Lt_type) return 0; |
| 1790 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1791 | NULL, NULL); |
| 1792 | if (!state->Lt_singleton) return 0; |
| 1793 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0); |
| 1794 | if (!state->LtE_type) return 0; |
| 1795 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1796 | NULL, NULL); |
| 1797 | if (!state->LtE_singleton) return 0; |
| 1798 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0); |
| 1799 | if (!state->Gt_type) return 0; |
| 1800 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1801 | NULL, NULL); |
| 1802 | if (!state->Gt_singleton) return 0; |
| 1803 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0); |
| 1804 | if (!state->GtE_type) return 0; |
| 1805 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1806 | NULL, NULL); |
| 1807 | if (!state->GtE_singleton) return 0; |
| 1808 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0); |
| 1809 | if (!state->Is_type) return 0; |
| 1810 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1811 | NULL, NULL); |
| 1812 | if (!state->Is_singleton) return 0; |
| 1813 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0); |
| 1814 | if (!state->IsNot_type) return 0; |
| 1815 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1816 | *)state->IsNot_type, NULL, NULL); |
| 1817 | if (!state->IsNot_singleton) return 0; |
| 1818 | state->In_type = make_type("In", state->cmpop_type, NULL, 0); |
| 1819 | if (!state->In_type) return 0; |
| 1820 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1821 | NULL, NULL); |
| 1822 | if (!state->In_singleton) return 0; |
| 1823 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0); |
| 1824 | if (!state->NotIn_type) return 0; |
| 1825 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1826 | *)state->NotIn_type, NULL, NULL); |
| 1827 | if (!state->NotIn_singleton) return 0; |
| 1828 | state->comprehension_type = make_type("comprehension", state->AST_type, |
| 1829 | comprehension_fields, 4); |
| 1830 | if (!state->comprehension_type) return 0; |
| 1831 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1832 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
| 1833 | NULL, 0); |
| 1834 | if (!state->excepthandler_type) return 0; |
| 1835 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1836 | 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1837 | if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) |
| 1838 | == -1) |
| 1839 | return 0; |
| 1840 | if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, |
| 1841 | Py_None) == -1) |
| 1842 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1843 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1844 | state->excepthandler_type, |
| 1845 | ExceptHandler_fields, 3); |
| 1846 | if (!state->ExceptHandler_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1847 | if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1) |
| 1848 | return 0; |
| 1849 | if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) |
| 1850 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1851 | state->arguments_type = make_type("arguments", state->AST_type, |
| 1852 | arguments_fields, 7); |
| 1853 | if (!state->arguments_type) return 0; |
| 1854 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1855 | if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) |
| 1856 | return 0; |
| 1857 | if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) |
| 1858 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1859 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3); |
| 1860 | if (!state->arg_type) return 0; |
| 1861 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1862 | if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) |
| 1863 | return 0; |
| 1864 | if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) |
| 1865 | return 0; |
| 1866 | if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1) |
| 1867 | return 0; |
| 1868 | if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) |
| 1869 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1870 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
| 1871 | 2); |
| 1872 | if (!state->keyword_type) return 0; |
| 1873 | if (!add_attributes(state->keyword_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1874 | if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) |
| 1875 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1876 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2); |
| 1877 | if (!state->alias_type) return 0; |
| 1878 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1879 | if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) |
| 1880 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1881 | state->withitem_type = make_type("withitem", state->AST_type, |
| 1882 | withitem_fields, 2); |
| 1883 | if (!state->withitem_type) return 0; |
| 1884 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1885 | if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) |
| 1886 | == -1) |
| 1887 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1888 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, |
| 1889 | 0); |
| 1890 | if (!state->type_ignore_type) return 0; |
| 1891 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 1892 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
| 1893 | TypeIgnore_fields, 2); |
| 1894 | if (!state->TypeIgnore_type) return 0; |
| 1895 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1896 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1897 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1898 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1899 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1900 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1901 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1902 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1903 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1904 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1905 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1906 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1907 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1908 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1909 | arena); |
| 1910 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1911 | arena); |
| 1912 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1913 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1914 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1915 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1916 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1917 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1918 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1919 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1920 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1921 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1922 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1923 | mod_ty p; |
| 1924 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1925 | if (!p) |
| 1926 | return NULL; |
| 1927 | p->kind = Module_kind; |
| 1928 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1929 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1930 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1934 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1935 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1936 | mod_ty p; |
| 1937 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1938 | if (!p) |
| 1939 | return NULL; |
| 1940 | p->kind = Interactive_kind; |
| 1941 | p->v.Interactive.body = body; |
| 1942 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1946 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1947 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1948 | mod_ty p; |
| 1949 | if (!body) { |
| 1950 | PyErr_SetString(PyExc_ValueError, |
| 1951 | "field body is required for Expression"); |
| 1952 | return NULL; |
| 1953 | } |
| 1954 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1955 | if (!p) |
| 1956 | return NULL; |
| 1957 | p->kind = Expression_kind; |
| 1958 | p->v.Expression.body = body; |
| 1959 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1963 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1964 | { |
| 1965 | mod_ty p; |
| 1966 | if (!returns) { |
| 1967 | PyErr_SetString(PyExc_ValueError, |
| 1968 | "field returns is required for FunctionType"); |
| 1969 | return NULL; |
| 1970 | } |
| 1971 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1972 | if (!p) |
| 1973 | return NULL; |
| 1974 | p->kind = FunctionType_kind; |
| 1975 | p->v.FunctionType.argtypes = argtypes; |
| 1976 | p->v.FunctionType.returns = returns; |
| 1977 | return p; |
| 1978 | } |
| 1979 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1980 | stmt_ty |
| 1981 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1982 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 1983 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1984 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1985 | stmt_ty p; |
| 1986 | if (!name) { |
| 1987 | PyErr_SetString(PyExc_ValueError, |
| 1988 | "field name is required for FunctionDef"); |
| 1989 | return NULL; |
| 1990 | } |
| 1991 | if (!args) { |
| 1992 | PyErr_SetString(PyExc_ValueError, |
| 1993 | "field args is required for FunctionDef"); |
| 1994 | return NULL; |
| 1995 | } |
| 1996 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1997 | if (!p) |
| 1998 | return NULL; |
| 1999 | p->kind = FunctionDef_kind; |
| 2000 | p->v.FunctionDef.name = name; |
| 2001 | p->v.FunctionDef.args = args; |
| 2002 | p->v.FunctionDef.body = body; |
| 2003 | p->v.FunctionDef.decorator_list = decorator_list; |
| 2004 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2005 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2006 | p->lineno = lineno; |
| 2007 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2008 | p->end_lineno = end_lineno; |
| 2009 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2010 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2014 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2015 | * decorator_list, expr_ty returns, string type_comment, int |
| 2016 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2017 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2018 | { |
| 2019 | stmt_ty p; |
| 2020 | if (!name) { |
| 2021 | PyErr_SetString(PyExc_ValueError, |
| 2022 | "field name is required for AsyncFunctionDef"); |
| 2023 | return NULL; |
| 2024 | } |
| 2025 | if (!args) { |
| 2026 | PyErr_SetString(PyExc_ValueError, |
| 2027 | "field args is required for AsyncFunctionDef"); |
| 2028 | return NULL; |
| 2029 | } |
| 2030 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2031 | if (!p) |
| 2032 | return NULL; |
| 2033 | p->kind = AsyncFunctionDef_kind; |
| 2034 | p->v.AsyncFunctionDef.name = name; |
| 2035 | p->v.AsyncFunctionDef.args = args; |
| 2036 | p->v.AsyncFunctionDef.body = body; |
| 2037 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 2038 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2039 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2040 | p->lineno = lineno; |
| 2041 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2042 | p->end_lineno = end_lineno; |
| 2043 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2044 | return p; |
| 2045 | } |
| 2046 | |
| 2047 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2048 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2049 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2050 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2051 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2052 | stmt_ty p; |
| 2053 | if (!name) { |
| 2054 | PyErr_SetString(PyExc_ValueError, |
| 2055 | "field name is required for ClassDef"); |
| 2056 | return NULL; |
| 2057 | } |
| 2058 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2059 | if (!p) |
| 2060 | return NULL; |
| 2061 | p->kind = ClassDef_kind; |
| 2062 | p->v.ClassDef.name = name; |
| 2063 | p->v.ClassDef.bases = bases; |
| 2064 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2065 | p->v.ClassDef.body = body; |
| 2066 | p->v.ClassDef.decorator_list = decorator_list; |
| 2067 | p->lineno = lineno; |
| 2068 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2069 | p->end_lineno = end_lineno; |
| 2070 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2071 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2075 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2076 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2077 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2078 | stmt_ty p; |
| 2079 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2080 | if (!p) |
| 2081 | return NULL; |
| 2082 | p->kind = Return_kind; |
| 2083 | p->v.Return.value = value; |
| 2084 | p->lineno = lineno; |
| 2085 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2086 | p->end_lineno = end_lineno; |
| 2087 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2088 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2092 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2093 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2094 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2095 | stmt_ty p; |
| 2096 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2097 | if (!p) |
| 2098 | return NULL; |
| 2099 | p->kind = Delete_kind; |
| 2100 | p->v.Delete.targets = targets; |
| 2101 | p->lineno = lineno; |
| 2102 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2103 | p->end_lineno = end_lineno; |
| 2104 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2105 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2109 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2110 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2111 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2112 | stmt_ty p; |
| 2113 | if (!value) { |
| 2114 | PyErr_SetString(PyExc_ValueError, |
| 2115 | "field value is required for Assign"); |
| 2116 | return NULL; |
| 2117 | } |
| 2118 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2119 | if (!p) |
| 2120 | return NULL; |
| 2121 | p->kind = Assign_kind; |
| 2122 | p->v.Assign.targets = targets; |
| 2123 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2124 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2125 | p->lineno = lineno; |
| 2126 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2127 | p->end_lineno = end_lineno; |
| 2128 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2129 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2133 | 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] | 2134 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2135 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2136 | stmt_ty p; |
| 2137 | if (!target) { |
| 2138 | PyErr_SetString(PyExc_ValueError, |
| 2139 | "field target is required for AugAssign"); |
| 2140 | return NULL; |
| 2141 | } |
| 2142 | if (!op) { |
| 2143 | PyErr_SetString(PyExc_ValueError, |
| 2144 | "field op is required for AugAssign"); |
| 2145 | return NULL; |
| 2146 | } |
| 2147 | if (!value) { |
| 2148 | PyErr_SetString(PyExc_ValueError, |
| 2149 | "field value is required for AugAssign"); |
| 2150 | return NULL; |
| 2151 | } |
| 2152 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2153 | if (!p) |
| 2154 | return NULL; |
| 2155 | p->kind = AugAssign_kind; |
| 2156 | p->v.AugAssign.target = target; |
| 2157 | p->v.AugAssign.op = op; |
| 2158 | p->v.AugAssign.value = value; |
| 2159 | p->lineno = lineno; |
| 2160 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2161 | p->end_lineno = end_lineno; |
| 2162 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2163 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2167 | 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] | 2168 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2169 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2170 | { |
| 2171 | stmt_ty p; |
| 2172 | if (!target) { |
| 2173 | PyErr_SetString(PyExc_ValueError, |
| 2174 | "field target is required for AnnAssign"); |
| 2175 | return NULL; |
| 2176 | } |
| 2177 | if (!annotation) { |
| 2178 | PyErr_SetString(PyExc_ValueError, |
| 2179 | "field annotation is required for AnnAssign"); |
| 2180 | return NULL; |
| 2181 | } |
| 2182 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2183 | if (!p) |
| 2184 | return NULL; |
| 2185 | p->kind = AnnAssign_kind; |
| 2186 | p->v.AnnAssign.target = target; |
| 2187 | p->v.AnnAssign.annotation = annotation; |
| 2188 | p->v.AnnAssign.value = value; |
| 2189 | p->v.AnnAssign.simple = simple; |
| 2190 | p->lineno = lineno; |
| 2191 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2192 | p->end_lineno = end_lineno; |
| 2193 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2194 | return p; |
| 2195 | } |
| 2196 | |
| 2197 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2198 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2199 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2200 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2201 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2202 | stmt_ty p; |
| 2203 | if (!target) { |
| 2204 | PyErr_SetString(PyExc_ValueError, |
| 2205 | "field target is required for For"); |
| 2206 | return NULL; |
| 2207 | } |
| 2208 | if (!iter) { |
| 2209 | PyErr_SetString(PyExc_ValueError, |
| 2210 | "field iter is required for For"); |
| 2211 | return NULL; |
| 2212 | } |
| 2213 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2214 | if (!p) |
| 2215 | return NULL; |
| 2216 | p->kind = For_kind; |
| 2217 | p->v.For.target = target; |
| 2218 | p->v.For.iter = iter; |
| 2219 | p->v.For.body = body; |
| 2220 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2221 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2222 | p->lineno = lineno; |
| 2223 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2224 | p->end_lineno = end_lineno; |
| 2225 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2226 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2230 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2231 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2232 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2233 | { |
| 2234 | stmt_ty p; |
| 2235 | if (!target) { |
| 2236 | PyErr_SetString(PyExc_ValueError, |
| 2237 | "field target is required for AsyncFor"); |
| 2238 | return NULL; |
| 2239 | } |
| 2240 | if (!iter) { |
| 2241 | PyErr_SetString(PyExc_ValueError, |
| 2242 | "field iter is required for AsyncFor"); |
| 2243 | return NULL; |
| 2244 | } |
| 2245 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2246 | if (!p) |
| 2247 | return NULL; |
| 2248 | p->kind = AsyncFor_kind; |
| 2249 | p->v.AsyncFor.target = target; |
| 2250 | p->v.AsyncFor.iter = iter; |
| 2251 | p->v.AsyncFor.body = body; |
| 2252 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2253 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2254 | p->lineno = lineno; |
| 2255 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2256 | p->end_lineno = end_lineno; |
| 2257 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2258 | return p; |
| 2259 | } |
| 2260 | |
| 2261 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2262 | 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] | 2263 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2264 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2265 | stmt_ty p; |
| 2266 | if (!test) { |
| 2267 | PyErr_SetString(PyExc_ValueError, |
| 2268 | "field test is required for While"); |
| 2269 | return NULL; |
| 2270 | } |
| 2271 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2272 | if (!p) |
| 2273 | return NULL; |
| 2274 | p->kind = While_kind; |
| 2275 | p->v.While.test = test; |
| 2276 | p->v.While.body = body; |
| 2277 | p->v.While.orelse = orelse; |
| 2278 | p->lineno = lineno; |
| 2279 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2280 | p->end_lineno = end_lineno; |
| 2281 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2282 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2286 | 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] | 2287 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2288 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2289 | stmt_ty p; |
| 2290 | if (!test) { |
| 2291 | PyErr_SetString(PyExc_ValueError, |
| 2292 | "field test is required for If"); |
| 2293 | return NULL; |
| 2294 | } |
| 2295 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2296 | if (!p) |
| 2297 | return NULL; |
| 2298 | p->kind = If_kind; |
| 2299 | p->v.If.test = test; |
| 2300 | p->v.If.body = body; |
| 2301 | p->v.If.orelse = orelse; |
| 2302 | p->lineno = lineno; |
| 2303 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2304 | p->end_lineno = end_lineno; |
| 2305 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2306 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2310 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2311 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2312 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2313 | stmt_ty p; |
| 2314 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2315 | if (!p) |
| 2316 | return NULL; |
| 2317 | p->kind = With_kind; |
| 2318 | p->v.With.items = items; |
| 2319 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2320 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2321 | p->lineno = lineno; |
| 2322 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2323 | p->end_lineno = end_lineno; |
| 2324 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2325 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2329 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2330 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2331 | { |
| 2332 | stmt_ty p; |
| 2333 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2334 | if (!p) |
| 2335 | return NULL; |
| 2336 | p->kind = AsyncWith_kind; |
| 2337 | p->v.AsyncWith.items = items; |
| 2338 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2339 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2340 | p->lineno = lineno; |
| 2341 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2342 | p->end_lineno = end_lineno; |
| 2343 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2344 | return p; |
| 2345 | } |
| 2346 | |
| 2347 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2348 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2349 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2350 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2351 | stmt_ty p; |
| 2352 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2353 | if (!p) |
| 2354 | return NULL; |
| 2355 | p->kind = Raise_kind; |
| 2356 | p->v.Raise.exc = exc; |
| 2357 | p->v.Raise.cause = cause; |
| 2358 | p->lineno = lineno; |
| 2359 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2360 | p->end_lineno = end_lineno; |
| 2361 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2362 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2366 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2367 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2368 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2369 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2370 | stmt_ty p; |
| 2371 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2372 | if (!p) |
| 2373 | return NULL; |
| 2374 | p->kind = Try_kind; |
| 2375 | p->v.Try.body = body; |
| 2376 | p->v.Try.handlers = handlers; |
| 2377 | p->v.Try.orelse = orelse; |
| 2378 | p->v.Try.finalbody = finalbody; |
| 2379 | p->lineno = lineno; |
| 2380 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2381 | p->end_lineno = end_lineno; |
| 2382 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2383 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2387 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2388 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2389 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2390 | stmt_ty p; |
| 2391 | if (!test) { |
| 2392 | PyErr_SetString(PyExc_ValueError, |
| 2393 | "field test is required for Assert"); |
| 2394 | return NULL; |
| 2395 | } |
| 2396 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2397 | if (!p) |
| 2398 | return NULL; |
| 2399 | p->kind = Assert_kind; |
| 2400 | p->v.Assert.test = test; |
| 2401 | p->v.Assert.msg = msg; |
| 2402 | p->lineno = lineno; |
| 2403 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2404 | p->end_lineno = end_lineno; |
| 2405 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2406 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2410 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2411 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2412 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2413 | stmt_ty p; |
| 2414 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2415 | if (!p) |
| 2416 | return NULL; |
| 2417 | p->kind = Import_kind; |
| 2418 | p->v.Import.names = names; |
| 2419 | p->lineno = lineno; |
| 2420 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2421 | p->end_lineno = end_lineno; |
| 2422 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2423 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2427 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2428 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2429 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2430 | stmt_ty p; |
| 2431 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2432 | if (!p) |
| 2433 | return NULL; |
| 2434 | p->kind = ImportFrom_kind; |
| 2435 | p->v.ImportFrom.module = module; |
| 2436 | p->v.ImportFrom.names = names; |
| 2437 | p->v.ImportFrom.level = level; |
| 2438 | p->lineno = lineno; |
| 2439 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2440 | p->end_lineno = end_lineno; |
| 2441 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2442 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2446 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2447 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2448 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2449 | stmt_ty p; |
| 2450 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2451 | if (!p) |
| 2452 | return NULL; |
| 2453 | p->kind = Global_kind; |
| 2454 | p->v.Global.names = names; |
| 2455 | p->lineno = lineno; |
| 2456 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2457 | p->end_lineno = end_lineno; |
| 2458 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2459 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2463 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2464 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2465 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2466 | stmt_ty p; |
| 2467 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2468 | if (!p) |
| 2469 | return NULL; |
| 2470 | p->kind = Nonlocal_kind; |
| 2471 | p->v.Nonlocal.names = names; |
| 2472 | p->lineno = lineno; |
| 2473 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2474 | p->end_lineno = end_lineno; |
| 2475 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2476 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2480 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2481 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2482 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2483 | stmt_ty p; |
| 2484 | if (!value) { |
| 2485 | PyErr_SetString(PyExc_ValueError, |
| 2486 | "field value is required for Expr"); |
| 2487 | return NULL; |
| 2488 | } |
| 2489 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2490 | if (!p) |
| 2491 | return NULL; |
| 2492 | p->kind = Expr_kind; |
| 2493 | p->v.Expr.value = value; |
| 2494 | p->lineno = lineno; |
| 2495 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2496 | p->end_lineno = end_lineno; |
| 2497 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2498 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2502 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2503 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2504 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2505 | stmt_ty p; |
| 2506 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2507 | if (!p) |
| 2508 | return NULL; |
| 2509 | p->kind = Pass_kind; |
| 2510 | p->lineno = lineno; |
| 2511 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2512 | p->end_lineno = end_lineno; |
| 2513 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2514 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2518 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2519 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2520 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2521 | stmt_ty p; |
| 2522 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2523 | if (!p) |
| 2524 | return NULL; |
| 2525 | p->kind = Break_kind; |
| 2526 | p->lineno = lineno; |
| 2527 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2528 | p->end_lineno = end_lineno; |
| 2529 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2530 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2534 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2535 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2536 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2537 | stmt_ty p; |
| 2538 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2539 | if (!p) |
| 2540 | return NULL; |
| 2541 | p->kind = Continue_kind; |
| 2542 | p->lineno = lineno; |
| 2543 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2544 | p->end_lineno = end_lineno; |
| 2545 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2546 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2550 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2551 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2552 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2553 | expr_ty p; |
| 2554 | if (!op) { |
| 2555 | PyErr_SetString(PyExc_ValueError, |
| 2556 | "field op is required for BoolOp"); |
| 2557 | return NULL; |
| 2558 | } |
| 2559 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2560 | if (!p) |
| 2561 | return NULL; |
| 2562 | p->kind = BoolOp_kind; |
| 2563 | p->v.BoolOp.op = op; |
| 2564 | p->v.BoolOp.values = values; |
| 2565 | p->lineno = lineno; |
| 2566 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2567 | p->end_lineno = end_lineno; |
| 2568 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2569 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2573 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2574 | end_lineno, int end_col_offset, PyArena *arena) |
| 2575 | { |
| 2576 | expr_ty p; |
| 2577 | if (!target) { |
| 2578 | PyErr_SetString(PyExc_ValueError, |
| 2579 | "field target is required for NamedExpr"); |
| 2580 | return NULL; |
| 2581 | } |
| 2582 | if (!value) { |
| 2583 | PyErr_SetString(PyExc_ValueError, |
| 2584 | "field value is required for NamedExpr"); |
| 2585 | return NULL; |
| 2586 | } |
| 2587 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2588 | if (!p) |
| 2589 | return NULL; |
| 2590 | p->kind = NamedExpr_kind; |
| 2591 | p->v.NamedExpr.target = target; |
| 2592 | p->v.NamedExpr.value = value; |
| 2593 | p->lineno = lineno; |
| 2594 | p->col_offset = col_offset; |
| 2595 | p->end_lineno = end_lineno; |
| 2596 | p->end_col_offset = end_col_offset; |
| 2597 | return p; |
| 2598 | } |
| 2599 | |
| 2600 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2601 | 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] | 2602 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2603 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2604 | expr_ty p; |
| 2605 | if (!left) { |
| 2606 | PyErr_SetString(PyExc_ValueError, |
| 2607 | "field left is required for BinOp"); |
| 2608 | return NULL; |
| 2609 | } |
| 2610 | if (!op) { |
| 2611 | PyErr_SetString(PyExc_ValueError, |
| 2612 | "field op is required for BinOp"); |
| 2613 | return NULL; |
| 2614 | } |
| 2615 | if (!right) { |
| 2616 | PyErr_SetString(PyExc_ValueError, |
| 2617 | "field right is required for BinOp"); |
| 2618 | return NULL; |
| 2619 | } |
| 2620 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2621 | if (!p) |
| 2622 | return NULL; |
| 2623 | p->kind = BinOp_kind; |
| 2624 | p->v.BinOp.left = left; |
| 2625 | p->v.BinOp.op = op; |
| 2626 | p->v.BinOp.right = right; |
| 2627 | p->lineno = lineno; |
| 2628 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2629 | p->end_lineno = end_lineno; |
| 2630 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2631 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2635 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2636 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2637 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2638 | expr_ty p; |
| 2639 | if (!op) { |
| 2640 | PyErr_SetString(PyExc_ValueError, |
| 2641 | "field op is required for UnaryOp"); |
| 2642 | return NULL; |
| 2643 | } |
| 2644 | if (!operand) { |
| 2645 | PyErr_SetString(PyExc_ValueError, |
| 2646 | "field operand is required for UnaryOp"); |
| 2647 | return NULL; |
| 2648 | } |
| 2649 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2650 | if (!p) |
| 2651 | return NULL; |
| 2652 | p->kind = UnaryOp_kind; |
| 2653 | p->v.UnaryOp.op = op; |
| 2654 | p->v.UnaryOp.operand = operand; |
| 2655 | p->lineno = lineno; |
| 2656 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2657 | p->end_lineno = end_lineno; |
| 2658 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2659 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2663 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2664 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2665 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2666 | expr_ty p; |
| 2667 | if (!args) { |
| 2668 | PyErr_SetString(PyExc_ValueError, |
| 2669 | "field args is required for Lambda"); |
| 2670 | return NULL; |
| 2671 | } |
| 2672 | if (!body) { |
| 2673 | PyErr_SetString(PyExc_ValueError, |
| 2674 | "field body is required for Lambda"); |
| 2675 | return NULL; |
| 2676 | } |
| 2677 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2678 | if (!p) |
| 2679 | return NULL; |
| 2680 | p->kind = Lambda_kind; |
| 2681 | p->v.Lambda.args = args; |
| 2682 | p->v.Lambda.body = body; |
| 2683 | p->lineno = lineno; |
| 2684 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2685 | p->end_lineno = end_lineno; |
| 2686 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2687 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2691 | 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] | 2692 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2693 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2694 | expr_ty p; |
| 2695 | if (!test) { |
| 2696 | PyErr_SetString(PyExc_ValueError, |
| 2697 | "field test is required for IfExp"); |
| 2698 | return NULL; |
| 2699 | } |
| 2700 | if (!body) { |
| 2701 | PyErr_SetString(PyExc_ValueError, |
| 2702 | "field body is required for IfExp"); |
| 2703 | return NULL; |
| 2704 | } |
| 2705 | if (!orelse) { |
| 2706 | PyErr_SetString(PyExc_ValueError, |
| 2707 | "field orelse is required for IfExp"); |
| 2708 | return NULL; |
| 2709 | } |
| 2710 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2711 | if (!p) |
| 2712 | return NULL; |
| 2713 | p->kind = IfExp_kind; |
| 2714 | p->v.IfExp.test = test; |
| 2715 | p->v.IfExp.body = body; |
| 2716 | p->v.IfExp.orelse = orelse; |
| 2717 | p->lineno = lineno; |
| 2718 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2719 | p->end_lineno = end_lineno; |
| 2720 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2721 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2725 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2726 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2727 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2728 | expr_ty p; |
| 2729 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2730 | if (!p) |
| 2731 | return NULL; |
| 2732 | p->kind = Dict_kind; |
| 2733 | p->v.Dict.keys = keys; |
| 2734 | p->v.Dict.values = values; |
| 2735 | p->lineno = lineno; |
| 2736 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2737 | p->end_lineno = end_lineno; |
| 2738 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2739 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2743 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2744 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2745 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2746 | expr_ty p; |
| 2747 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2748 | if (!p) |
| 2749 | return NULL; |
| 2750 | p->kind = Set_kind; |
| 2751 | p->v.Set.elts = elts; |
| 2752 | p->lineno = lineno; |
| 2753 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2754 | p->end_lineno = end_lineno; |
| 2755 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2756 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2760 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2761 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2762 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2763 | expr_ty p; |
| 2764 | if (!elt) { |
| 2765 | PyErr_SetString(PyExc_ValueError, |
| 2766 | "field elt is required for ListComp"); |
| 2767 | return NULL; |
| 2768 | } |
| 2769 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2770 | if (!p) |
| 2771 | return NULL; |
| 2772 | p->kind = ListComp_kind; |
| 2773 | p->v.ListComp.elt = elt; |
| 2774 | p->v.ListComp.generators = generators; |
| 2775 | p->lineno = lineno; |
| 2776 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2777 | p->end_lineno = end_lineno; |
| 2778 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2779 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2783 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2784 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2785 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2786 | expr_ty p; |
| 2787 | if (!elt) { |
| 2788 | PyErr_SetString(PyExc_ValueError, |
| 2789 | "field elt is required for SetComp"); |
| 2790 | return NULL; |
| 2791 | } |
| 2792 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2793 | if (!p) |
| 2794 | return NULL; |
| 2795 | p->kind = SetComp_kind; |
| 2796 | p->v.SetComp.elt = elt; |
| 2797 | p->v.SetComp.generators = generators; |
| 2798 | p->lineno = lineno; |
| 2799 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2800 | p->end_lineno = end_lineno; |
| 2801 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2802 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2806 | 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] | 2807 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2808 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2809 | expr_ty p; |
| 2810 | if (!key) { |
| 2811 | PyErr_SetString(PyExc_ValueError, |
| 2812 | "field key is required for DictComp"); |
| 2813 | return NULL; |
| 2814 | } |
| 2815 | if (!value) { |
| 2816 | PyErr_SetString(PyExc_ValueError, |
| 2817 | "field value is required for DictComp"); |
| 2818 | return NULL; |
| 2819 | } |
| 2820 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2821 | if (!p) |
| 2822 | return NULL; |
| 2823 | p->kind = DictComp_kind; |
| 2824 | p->v.DictComp.key = key; |
| 2825 | p->v.DictComp.value = value; |
| 2826 | p->v.DictComp.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; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2835 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2836 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2837 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2838 | expr_ty p; |
| 2839 | if (!elt) { |
| 2840 | PyErr_SetString(PyExc_ValueError, |
| 2841 | "field elt is required for GeneratorExp"); |
| 2842 | return NULL; |
| 2843 | } |
| 2844 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2845 | if (!p) |
| 2846 | return NULL; |
| 2847 | p->kind = GeneratorExp_kind; |
| 2848 | p->v.GeneratorExp.elt = elt; |
| 2849 | p->v.GeneratorExp.generators = generators; |
| 2850 | p->lineno = lineno; |
| 2851 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2852 | p->end_lineno = end_lineno; |
| 2853 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2854 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2858 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2859 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2860 | { |
| 2861 | expr_ty p; |
| 2862 | if (!value) { |
| 2863 | PyErr_SetString(PyExc_ValueError, |
| 2864 | "field value is required for Await"); |
| 2865 | return NULL; |
| 2866 | } |
| 2867 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2868 | if (!p) |
| 2869 | return NULL; |
| 2870 | p->kind = Await_kind; |
| 2871 | p->v.Await.value = value; |
| 2872 | p->lineno = lineno; |
| 2873 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2874 | p->end_lineno = end_lineno; |
| 2875 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2876 | return p; |
| 2877 | } |
| 2878 | |
| 2879 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2880 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2881 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2882 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2883 | expr_ty p; |
| 2884 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2885 | if (!p) |
| 2886 | return NULL; |
| 2887 | p->kind = Yield_kind; |
| 2888 | p->v.Yield.value = value; |
| 2889 | p->lineno = lineno; |
| 2890 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2891 | p->end_lineno = end_lineno; |
| 2892 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2893 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2897 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2898 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2899 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2900 | expr_ty p; |
| 2901 | if (!value) { |
| 2902 | PyErr_SetString(PyExc_ValueError, |
| 2903 | "field value is required for YieldFrom"); |
| 2904 | return NULL; |
| 2905 | } |
| 2906 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2907 | if (!p) |
| 2908 | return NULL; |
| 2909 | p->kind = YieldFrom_kind; |
| 2910 | p->v.YieldFrom.value = value; |
| 2911 | p->lineno = lineno; |
| 2912 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2913 | p->end_lineno = end_lineno; |
| 2914 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2915 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2919 | 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] | 2920 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2921 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2922 | expr_ty p; |
| 2923 | if (!left) { |
| 2924 | PyErr_SetString(PyExc_ValueError, |
| 2925 | "field left is required for Compare"); |
| 2926 | return NULL; |
| 2927 | } |
| 2928 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2929 | if (!p) |
| 2930 | return NULL; |
| 2931 | p->kind = Compare_kind; |
| 2932 | p->v.Compare.left = left; |
| 2933 | p->v.Compare.ops = ops; |
| 2934 | p->v.Compare.comparators = comparators; |
| 2935 | p->lineno = lineno; |
| 2936 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2937 | p->end_lineno = end_lineno; |
| 2938 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2939 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2943 | 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] | 2944 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2945 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2946 | expr_ty p; |
| 2947 | if (!func) { |
| 2948 | PyErr_SetString(PyExc_ValueError, |
| 2949 | "field func is required for Call"); |
| 2950 | return NULL; |
| 2951 | } |
| 2952 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2953 | if (!p) |
| 2954 | return NULL; |
| 2955 | p->kind = Call_kind; |
| 2956 | p->v.Call.func = func; |
| 2957 | p->v.Call.args = args; |
| 2958 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2959 | p->lineno = lineno; |
| 2960 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2961 | p->end_lineno = end_lineno; |
| 2962 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2963 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 2967 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2968 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2969 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2970 | { |
| 2971 | expr_ty p; |
| 2972 | if (!value) { |
| 2973 | PyErr_SetString(PyExc_ValueError, |
| 2974 | "field value is required for FormattedValue"); |
| 2975 | return NULL; |
| 2976 | } |
| 2977 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2978 | if (!p) |
| 2979 | return NULL; |
| 2980 | p->kind = FormattedValue_kind; |
| 2981 | p->v.FormattedValue.value = value; |
| 2982 | p->v.FormattedValue.conversion = conversion; |
| 2983 | p->v.FormattedValue.format_spec = format_spec; |
| 2984 | p->lineno = lineno; |
| 2985 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2986 | p->end_lineno = end_lineno; |
| 2987 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2988 | return p; |
| 2989 | } |
| 2990 | |
| 2991 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2992 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2993 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2994 | { |
| 2995 | expr_ty p; |
| 2996 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2997 | if (!p) |
| 2998 | return NULL; |
| 2999 | p->kind = JoinedStr_kind; |
| 3000 | p->v.JoinedStr.values = values; |
| 3001 | p->lineno = lineno; |
| 3002 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3003 | p->end_lineno = end_lineno; |
| 3004 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3005 | return p; |
| 3006 | } |
| 3007 | |
| 3008 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3009 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 3010 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3011 | { |
| 3012 | expr_ty p; |
| 3013 | if (!value) { |
| 3014 | PyErr_SetString(PyExc_ValueError, |
| 3015 | "field value is required for Constant"); |
| 3016 | return NULL; |
| 3017 | } |
| 3018 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3019 | if (!p) |
| 3020 | return NULL; |
| 3021 | p->kind = Constant_kind; |
| 3022 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3023 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3024 | p->lineno = lineno; |
| 3025 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3026 | p->end_lineno = end_lineno; |
| 3027 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3028 | return p; |
| 3029 | } |
| 3030 | |
| 3031 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3032 | 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] | 3033 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3034 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3035 | expr_ty p; |
| 3036 | if (!value) { |
| 3037 | PyErr_SetString(PyExc_ValueError, |
| 3038 | "field value is required for Attribute"); |
| 3039 | return NULL; |
| 3040 | } |
| 3041 | if (!attr) { |
| 3042 | PyErr_SetString(PyExc_ValueError, |
| 3043 | "field attr is required for Attribute"); |
| 3044 | return NULL; |
| 3045 | } |
| 3046 | if (!ctx) { |
| 3047 | PyErr_SetString(PyExc_ValueError, |
| 3048 | "field ctx is required for Attribute"); |
| 3049 | return NULL; |
| 3050 | } |
| 3051 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3052 | if (!p) |
| 3053 | return NULL; |
| 3054 | p->kind = Attribute_kind; |
| 3055 | p->v.Attribute.value = value; |
| 3056 | p->v.Attribute.attr = attr; |
| 3057 | p->v.Attribute.ctx = ctx; |
| 3058 | p->lineno = lineno; |
| 3059 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3060 | p->end_lineno = end_lineno; |
| 3061 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3062 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | expr_ty |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3066 | Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3067 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3068 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3069 | expr_ty p; |
| 3070 | if (!value) { |
| 3071 | PyErr_SetString(PyExc_ValueError, |
| 3072 | "field value is required for Subscript"); |
| 3073 | return NULL; |
| 3074 | } |
| 3075 | if (!slice) { |
| 3076 | PyErr_SetString(PyExc_ValueError, |
| 3077 | "field slice is required for Subscript"); |
| 3078 | return NULL; |
| 3079 | } |
| 3080 | if (!ctx) { |
| 3081 | PyErr_SetString(PyExc_ValueError, |
| 3082 | "field ctx is required for Subscript"); |
| 3083 | return NULL; |
| 3084 | } |
| 3085 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3086 | if (!p) |
| 3087 | return NULL; |
| 3088 | p->kind = Subscript_kind; |
| 3089 | p->v.Subscript.value = value; |
| 3090 | p->v.Subscript.slice = slice; |
| 3091 | p->v.Subscript.ctx = ctx; |
| 3092 | p->lineno = lineno; |
| 3093 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3094 | p->end_lineno = end_lineno; |
| 3095 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3096 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3100 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3101 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3102 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3103 | expr_ty p; |
| 3104 | if (!value) { |
| 3105 | PyErr_SetString(PyExc_ValueError, |
| 3106 | "field value is required for Starred"); |
| 3107 | return NULL; |
| 3108 | } |
| 3109 | if (!ctx) { |
| 3110 | PyErr_SetString(PyExc_ValueError, |
| 3111 | "field ctx is required for Starred"); |
| 3112 | return NULL; |
| 3113 | } |
| 3114 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3115 | if (!p) |
| 3116 | return NULL; |
| 3117 | p->kind = Starred_kind; |
| 3118 | p->v.Starred.value = value; |
| 3119 | p->v.Starred.ctx = ctx; |
| 3120 | p->lineno = lineno; |
| 3121 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3122 | p->end_lineno = end_lineno; |
| 3123 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3124 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3128 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3129 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3130 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3131 | expr_ty p; |
| 3132 | if (!id) { |
| 3133 | PyErr_SetString(PyExc_ValueError, |
| 3134 | "field id is required for Name"); |
| 3135 | return NULL; |
| 3136 | } |
| 3137 | if (!ctx) { |
| 3138 | PyErr_SetString(PyExc_ValueError, |
| 3139 | "field ctx is required for Name"); |
| 3140 | return NULL; |
| 3141 | } |
| 3142 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3143 | if (!p) |
| 3144 | return NULL; |
| 3145 | p->kind = Name_kind; |
| 3146 | p->v.Name.id = id; |
| 3147 | p->v.Name.ctx = ctx; |
| 3148 | p->lineno = lineno; |
| 3149 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3150 | p->end_lineno = end_lineno; |
| 3151 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3152 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3156 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3157 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3158 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3159 | expr_ty p; |
| 3160 | if (!ctx) { |
| 3161 | PyErr_SetString(PyExc_ValueError, |
| 3162 | "field ctx is required for List"); |
| 3163 | return NULL; |
| 3164 | } |
| 3165 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3166 | if (!p) |
| 3167 | return NULL; |
| 3168 | p->kind = List_kind; |
| 3169 | p->v.List.elts = elts; |
| 3170 | p->v.List.ctx = ctx; |
| 3171 | p->lineno = lineno; |
| 3172 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3173 | p->end_lineno = end_lineno; |
| 3174 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3175 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3179 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3180 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3181 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3182 | expr_ty p; |
| 3183 | if (!ctx) { |
| 3184 | PyErr_SetString(PyExc_ValueError, |
| 3185 | "field ctx is required for Tuple"); |
| 3186 | return NULL; |
| 3187 | } |
| 3188 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3189 | if (!p) |
| 3190 | return NULL; |
| 3191 | p->kind = Tuple_kind; |
| 3192 | p->v.Tuple.elts = elts; |
| 3193 | p->v.Tuple.ctx = ctx; |
| 3194 | p->lineno = lineno; |
| 3195 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3196 | p->end_lineno = end_lineno; |
| 3197 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3198 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3199 | } |
| 3200 | |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3201 | expr_ty |
| 3202 | Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset, |
| 3203 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3204 | { |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3205 | expr_ty p; |
| 3206 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3207 | if (!p) |
| 3208 | return NULL; |
| 3209 | p->kind = Slice_kind; |
| 3210 | p->v.Slice.lower = lower; |
| 3211 | p->v.Slice.upper = upper; |
| 3212 | p->v.Slice.step = step; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3213 | p->lineno = lineno; |
| 3214 | p->col_offset = col_offset; |
| 3215 | p->end_lineno = end_lineno; |
| 3216 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3217 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3221 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3222 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3223 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3224 | comprehension_ty p; |
| 3225 | if (!target) { |
| 3226 | PyErr_SetString(PyExc_ValueError, |
| 3227 | "field target is required for comprehension"); |
| 3228 | return NULL; |
| 3229 | } |
| 3230 | if (!iter) { |
| 3231 | PyErr_SetString(PyExc_ValueError, |
| 3232 | "field iter is required for comprehension"); |
| 3233 | return NULL; |
| 3234 | } |
| 3235 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3236 | if (!p) |
| 3237 | return NULL; |
| 3238 | p->target = target; |
| 3239 | p->iter = iter; |
| 3240 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3241 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3242 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3246 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3247 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3248 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3249 | excepthandler_ty p; |
| 3250 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3251 | if (!p) |
| 3252 | return NULL; |
| 3253 | p->kind = ExceptHandler_kind; |
| 3254 | p->v.ExceptHandler.type = type; |
| 3255 | p->v.ExceptHandler.name = name; |
| 3256 | p->v.ExceptHandler.body = body; |
| 3257 | p->lineno = lineno; |
| 3258 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3259 | p->end_lineno = end_lineno; |
| 3260 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3261 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3265 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3266 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3267 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3268 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3269 | arguments_ty p; |
| 3270 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3271 | if (!p) |
| 3272 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3273 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3274 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3275 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3276 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3277 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3278 | p->kwarg = kwarg; |
| 3279 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3280 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3283 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3284 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3285 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3286 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3287 | arg_ty p; |
| 3288 | if (!arg) { |
| 3289 | PyErr_SetString(PyExc_ValueError, |
| 3290 | "field arg is required for arg"); |
| 3291 | return NULL; |
| 3292 | } |
| 3293 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3294 | if (!p) |
| 3295 | return NULL; |
| 3296 | p->arg = arg; |
| 3297 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3298 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3299 | p->lineno = lineno; |
| 3300 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3301 | p->end_lineno = end_lineno; |
| 3302 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3303 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3304 | } |
| 3305 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3306 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3307 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3308 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3309 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3310 | if (!value) { |
| 3311 | PyErr_SetString(PyExc_ValueError, |
| 3312 | "field value is required for keyword"); |
| 3313 | return NULL; |
| 3314 | } |
| 3315 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3316 | if (!p) |
| 3317 | return NULL; |
| 3318 | p->arg = arg; |
| 3319 | p->value = value; |
| 3320 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3324 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3325 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3326 | alias_ty p; |
| 3327 | if (!name) { |
| 3328 | PyErr_SetString(PyExc_ValueError, |
| 3329 | "field name is required for alias"); |
| 3330 | return NULL; |
| 3331 | } |
| 3332 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3333 | if (!p) |
| 3334 | return NULL; |
| 3335 | p->name = name; |
| 3336 | p->asname = asname; |
| 3337 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3338 | } |
| 3339 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3340 | withitem_ty |
| 3341 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3342 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3343 | withitem_ty p; |
| 3344 | if (!context_expr) { |
| 3345 | PyErr_SetString(PyExc_ValueError, |
| 3346 | "field context_expr is required for withitem"); |
| 3347 | return NULL; |
| 3348 | } |
| 3349 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3350 | if (!p) |
| 3351 | return NULL; |
| 3352 | p->context_expr = context_expr; |
| 3353 | p->optional_vars = optional_vars; |
| 3354 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3355 | } |
| 3356 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3357 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3358 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3359 | { |
| 3360 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3361 | if (!tag) { |
| 3362 | PyErr_SetString(PyExc_ValueError, |
| 3363 | "field tag is required for TypeIgnore"); |
| 3364 | return NULL; |
| 3365 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3366 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3367 | if (!p) |
| 3368 | return NULL; |
| 3369 | p->kind = TypeIgnore_kind; |
| 3370 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3371 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3372 | return p; |
| 3373 | } |
| 3374 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3375 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3376 | PyObject* |
| 3377 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3378 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3379 | mod_ty o = (mod_ty)_o; |
| 3380 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3381 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3382 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3383 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3384 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3385 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3386 | switch (o->kind) { |
| 3387 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3388 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3389 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3390 | if (!result) goto failed; |
| 3391 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3392 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3393 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3394 | goto failed; |
| 3395 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3396 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3397 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3398 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3399 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3400 | goto failed; |
| 3401 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3402 | break; |
| 3403 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3404 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3405 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3406 | if (!result) goto failed; |
| 3407 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3408 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3409 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3410 | goto failed; |
| 3411 | Py_DECREF(value); |
| 3412 | break; |
| 3413 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3414 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3415 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3416 | if (!result) goto failed; |
| 3417 | value = ast2obj_expr(o->v.Expression.body); |
| 3418 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3419 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3420 | goto failed; |
| 3421 | Py_DECREF(value); |
| 3422 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3423 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3424 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3425 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3426 | if (!result) goto failed; |
| 3427 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3428 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3429 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3430 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3431 | goto failed; |
| 3432 | Py_DECREF(value); |
| 3433 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3434 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3435 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3436 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3437 | goto failed; |
| 3438 | Py_DECREF(value); |
| 3439 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3440 | } |
| 3441 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3442 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3443 | Py_XDECREF(value); |
| 3444 | Py_XDECREF(result); |
| 3445 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3446 | } |
| 3447 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3448 | PyObject* |
| 3449 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3450 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3451 | stmt_ty o = (stmt_ty)_o; |
| 3452 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3453 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3454 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3455 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3456 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3457 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3458 | switch (o->kind) { |
| 3459 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3460 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3461 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3462 | if (!result) goto failed; |
| 3463 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3464 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3465 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3466 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3467 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3468 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3469 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3470 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3471 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3472 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3473 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3474 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3475 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3476 | goto failed; |
| 3477 | Py_DECREF(value); |
| 3478 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3479 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3480 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3481 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3482 | goto failed; |
| 3483 | Py_DECREF(value); |
| 3484 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3485 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3486 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3487 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3488 | goto failed; |
| 3489 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3490 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3491 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3492 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3493 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3494 | goto failed; |
| 3495 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3496 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3497 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3498 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3499 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3500 | if (!result) goto failed; |
| 3501 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3502 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3503 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3504 | goto failed; |
| 3505 | Py_DECREF(value); |
| 3506 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3507 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3508 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3509 | goto failed; |
| 3510 | Py_DECREF(value); |
| 3511 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3512 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3513 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3514 | goto failed; |
| 3515 | Py_DECREF(value); |
| 3516 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3517 | ast2obj_expr); |
| 3518 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3519 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3520 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3521 | goto failed; |
| 3522 | Py_DECREF(value); |
| 3523 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3524 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3525 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3526 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3527 | goto failed; |
| 3528 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3529 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3530 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3531 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3532 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3533 | goto failed; |
| 3534 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3535 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3536 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3537 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3538 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3539 | if (!result) goto failed; |
| 3540 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3541 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3542 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3543 | goto failed; |
| 3544 | Py_DECREF(value); |
| 3545 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3546 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3547 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3548 | goto failed; |
| 3549 | Py_DECREF(value); |
| 3550 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3551 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3552 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3553 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3554 | goto failed; |
| 3555 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3556 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3557 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3558 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3559 | goto failed; |
| 3560 | Py_DECREF(value); |
| 3561 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3562 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3563 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3564 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3565 | goto failed; |
| 3566 | Py_DECREF(value); |
| 3567 | break; |
| 3568 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3569 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3570 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3571 | if (!result) goto failed; |
| 3572 | value = ast2obj_expr(o->v.Return.value); |
| 3573 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3574 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3575 | goto failed; |
| 3576 | Py_DECREF(value); |
| 3577 | break; |
| 3578 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3579 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3580 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3581 | if (!result) goto failed; |
| 3582 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3583 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3584 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3585 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3586 | goto failed; |
| 3587 | Py_DECREF(value); |
| 3588 | break; |
| 3589 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3590 | tp = (PyTypeObject *)astmodulestate_global->Assign_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_list(o->v.Assign.targets, ast2obj_expr); |
| 3594 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3595 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3596 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3597 | goto failed; |
| 3598 | Py_DECREF(value); |
| 3599 | value = ast2obj_expr(o->v.Assign.value); |
| 3600 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3601 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3602 | goto failed; |
| 3603 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3604 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3605 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3606 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3607 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3608 | goto failed; |
| 3609 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3610 | break; |
| 3611 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3612 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3613 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3614 | if (!result) goto failed; |
| 3615 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3616 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3617 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3618 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3619 | goto failed; |
| 3620 | Py_DECREF(value); |
| 3621 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3622 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3623 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3624 | goto failed; |
| 3625 | Py_DECREF(value); |
| 3626 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3627 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3628 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3629 | goto failed; |
| 3630 | Py_DECREF(value); |
| 3631 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3632 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3633 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3634 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3635 | if (!result) goto failed; |
| 3636 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3637 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3638 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3639 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3640 | goto failed; |
| 3641 | Py_DECREF(value); |
| 3642 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3643 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3644 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3645 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3646 | goto failed; |
| 3647 | Py_DECREF(value); |
| 3648 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3649 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3650 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3651 | goto failed; |
| 3652 | Py_DECREF(value); |
| 3653 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3654 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3655 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3656 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3657 | goto failed; |
| 3658 | Py_DECREF(value); |
| 3659 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3660 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3661 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3662 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3663 | if (!result) goto failed; |
| 3664 | value = ast2obj_expr(o->v.For.target); |
| 3665 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3666 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3667 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3668 | goto failed; |
| 3669 | Py_DECREF(value); |
| 3670 | value = ast2obj_expr(o->v.For.iter); |
| 3671 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3672 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3673 | goto failed; |
| 3674 | Py_DECREF(value); |
| 3675 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3676 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3677 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3678 | goto failed; |
| 3679 | Py_DECREF(value); |
| 3680 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3681 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3682 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3683 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3684 | goto failed; |
| 3685 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3686 | value = ast2obj_string(o->v.For.type_comment); |
| 3687 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3688 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3689 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3690 | goto failed; |
| 3691 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3692 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3693 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3694 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3695 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3696 | if (!result) goto failed; |
| 3697 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3698 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3699 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3700 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3701 | goto failed; |
| 3702 | Py_DECREF(value); |
| 3703 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3704 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3705 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3706 | goto failed; |
| 3707 | Py_DECREF(value); |
| 3708 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3709 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3710 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3711 | goto failed; |
| 3712 | Py_DECREF(value); |
| 3713 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3714 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3715 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3716 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3717 | goto failed; |
| 3718 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3719 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3720 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3721 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3722 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3723 | goto failed; |
| 3724 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3725 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3726 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3727 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3728 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3729 | if (!result) goto failed; |
| 3730 | value = ast2obj_expr(o->v.While.test); |
| 3731 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3732 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3733 | goto failed; |
| 3734 | Py_DECREF(value); |
| 3735 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3736 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3737 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3738 | goto failed; |
| 3739 | Py_DECREF(value); |
| 3740 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3741 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3742 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3743 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3744 | goto failed; |
| 3745 | Py_DECREF(value); |
| 3746 | break; |
| 3747 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3748 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3749 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3750 | if (!result) goto failed; |
| 3751 | value = ast2obj_expr(o->v.If.test); |
| 3752 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3753 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3754 | goto failed; |
| 3755 | Py_DECREF(value); |
| 3756 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3757 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3758 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3759 | goto failed; |
| 3760 | Py_DECREF(value); |
| 3761 | value = ast2obj_list(o->v.If.orelse, 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->orelse, value) == |
| 3764 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3765 | goto failed; |
| 3766 | Py_DECREF(value); |
| 3767 | break; |
| 3768 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3769 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3770 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3771 | if (!result) goto failed; |
| 3772 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3773 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3774 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3775 | goto failed; |
| 3776 | Py_DECREF(value); |
| 3777 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3778 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3779 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3780 | goto failed; |
| 3781 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3782 | value = ast2obj_string(o->v.With.type_comment); |
| 3783 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3784 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3785 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3786 | goto failed; |
| 3787 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3788 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3789 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3790 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3791 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3792 | if (!result) goto failed; |
| 3793 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3794 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3795 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3796 | goto failed; |
| 3797 | Py_DECREF(value); |
| 3798 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3799 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3800 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3801 | goto failed; |
| 3802 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3803 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3804 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3805 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3806 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3807 | goto failed; |
| 3808 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3809 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3810 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3811 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3812 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3813 | if (!result) goto failed; |
| 3814 | value = ast2obj_expr(o->v.Raise.exc); |
| 3815 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3816 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3817 | goto failed; |
| 3818 | Py_DECREF(value); |
| 3819 | value = ast2obj_expr(o->v.Raise.cause); |
| 3820 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3821 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3822 | goto failed; |
| 3823 | Py_DECREF(value); |
| 3824 | break; |
| 3825 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3826 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3827 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3828 | if (!result) goto failed; |
| 3829 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3830 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3831 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3832 | goto failed; |
| 3833 | Py_DECREF(value); |
| 3834 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3835 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3836 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3837 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3838 | goto failed; |
| 3839 | Py_DECREF(value); |
| 3840 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3841 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3842 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3843 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3844 | goto failed; |
| 3845 | Py_DECREF(value); |
| 3846 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3847 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3848 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3849 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3850 | goto failed; |
| 3851 | Py_DECREF(value); |
| 3852 | break; |
| 3853 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3854 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3855 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3856 | if (!result) goto failed; |
| 3857 | value = ast2obj_expr(o->v.Assert.test); |
| 3858 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3859 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3860 | goto failed; |
| 3861 | Py_DECREF(value); |
| 3862 | value = ast2obj_expr(o->v.Assert.msg); |
| 3863 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3864 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3865 | goto failed; |
| 3866 | Py_DECREF(value); |
| 3867 | break; |
| 3868 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3869 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 3870 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3871 | if (!result) goto failed; |
| 3872 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3873 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3874 | if (PyObject_SetAttr(result, astmodulestate_global->names, 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 ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3879 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_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_identifier(o->v.ImportFrom.module); |
| 3883 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3884 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 3885 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3886 | goto failed; |
| 3887 | Py_DECREF(value); |
| 3888 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3889 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3890 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | goto failed; |
| 3892 | Py_DECREF(value); |
| 3893 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3894 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3895 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3896 | goto failed; |
| 3897 | Py_DECREF(value); |
| 3898 | break; |
| 3899 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3900 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 3901 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3902 | if (!result) goto failed; |
| 3903 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3904 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3905 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3906 | goto failed; |
| 3907 | Py_DECREF(value); |
| 3908 | break; |
| 3909 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3910 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 3911 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3912 | if (!result) goto failed; |
| 3913 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3914 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3915 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3916 | goto failed; |
| 3917 | Py_DECREF(value); |
| 3918 | break; |
| 3919 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3920 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 3921 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3922 | if (!result) goto failed; |
| 3923 | value = ast2obj_expr(o->v.Expr.value); |
| 3924 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3925 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3926 | goto failed; |
| 3927 | Py_DECREF(value); |
| 3928 | break; |
| 3929 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3930 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 3931 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3932 | if (!result) goto failed; |
| 3933 | break; |
| 3934 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3935 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 3936 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3937 | if (!result) goto failed; |
| 3938 | break; |
| 3939 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3940 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 3941 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3942 | if (!result) goto failed; |
| 3943 | break; |
| 3944 | } |
| 3945 | value = ast2obj_int(o->lineno); |
| 3946 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3947 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3948 | goto failed; |
| 3949 | Py_DECREF(value); |
| 3950 | value = ast2obj_int(o->col_offset); |
| 3951 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3952 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3953 | goto failed; |
| 3954 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3955 | value = ast2obj_int(o->end_lineno); |
| 3956 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3957 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3958 | goto failed; |
| 3959 | Py_DECREF(value); |
| 3960 | value = ast2obj_int(o->end_col_offset); |
| 3961 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3962 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 3963 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3964 | goto failed; |
| 3965 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3966 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3967 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3968 | Py_XDECREF(value); |
| 3969 | Py_XDECREF(result); |
| 3970 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3971 | } |
| 3972 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3973 | PyObject* |
| 3974 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3975 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | expr_ty o = (expr_ty)_o; |
| 3977 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3978 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3979 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3980 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3981 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3982 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3983 | switch (o->kind) { |
| 3984 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3985 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 3986 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3987 | if (!result) goto failed; |
| 3988 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3989 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3990 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3991 | goto failed; |
| 3992 | Py_DECREF(value); |
| 3993 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3994 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3995 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 3996 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3997 | goto failed; |
| 3998 | Py_DECREF(value); |
| 3999 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4000 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4001 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 4002 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4003 | if (!result) goto failed; |
| 4004 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 4005 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4006 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 4007 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4008 | goto failed; |
| 4009 | Py_DECREF(value); |
| 4010 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 4011 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4012 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4013 | goto failed; |
| 4014 | Py_DECREF(value); |
| 4015 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4016 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4017 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4018 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4019 | if (!result) goto failed; |
| 4020 | value = ast2obj_expr(o->v.BinOp.left); |
| 4021 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4022 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4023 | goto failed; |
| 4024 | Py_DECREF(value); |
| 4025 | value = ast2obj_operator(o->v.BinOp.op); |
| 4026 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4027 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4028 | goto failed; |
| 4029 | Py_DECREF(value); |
| 4030 | value = ast2obj_expr(o->v.BinOp.right); |
| 4031 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4032 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4033 | goto failed; |
| 4034 | Py_DECREF(value); |
| 4035 | break; |
| 4036 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4037 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4038 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4039 | if (!result) goto failed; |
| 4040 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4041 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4042 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4043 | goto failed; |
| 4044 | Py_DECREF(value); |
| 4045 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4046 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4047 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4048 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4049 | goto failed; |
| 4050 | Py_DECREF(value); |
| 4051 | break; |
| 4052 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4053 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4054 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4055 | if (!result) goto failed; |
| 4056 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4057 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4058 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4059 | goto failed; |
| 4060 | Py_DECREF(value); |
| 4061 | value = ast2obj_expr(o->v.Lambda.body); |
| 4062 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4063 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4064 | goto failed; |
| 4065 | Py_DECREF(value); |
| 4066 | break; |
| 4067 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4068 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4069 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4070 | if (!result) goto failed; |
| 4071 | value = ast2obj_expr(o->v.IfExp.test); |
| 4072 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4073 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4074 | goto failed; |
| 4075 | Py_DECREF(value); |
| 4076 | value = ast2obj_expr(o->v.IfExp.body); |
| 4077 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4078 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4079 | goto failed; |
| 4080 | Py_DECREF(value); |
| 4081 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4082 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4083 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4084 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4085 | goto failed; |
| 4086 | Py_DECREF(value); |
| 4087 | break; |
| 4088 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4089 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4090 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4091 | if (!result) goto failed; |
| 4092 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4093 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4094 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4095 | goto failed; |
| 4096 | Py_DECREF(value); |
| 4097 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4098 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4099 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4100 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4101 | goto failed; |
| 4102 | Py_DECREF(value); |
| 4103 | break; |
| 4104 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4105 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4106 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4107 | if (!result) goto failed; |
| 4108 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4109 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4110 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4111 | goto failed; |
| 4112 | Py_DECREF(value); |
| 4113 | break; |
| 4114 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4115 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4116 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4117 | if (!result) goto failed; |
| 4118 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4119 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4120 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4121 | goto failed; |
| 4122 | Py_DECREF(value); |
| 4123 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4124 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4125 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4126 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4127 | goto failed; |
| 4128 | Py_DECREF(value); |
| 4129 | break; |
| 4130 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4131 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4132 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4133 | if (!result) goto failed; |
| 4134 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4135 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4136 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4137 | goto failed; |
| 4138 | Py_DECREF(value); |
| 4139 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4140 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4141 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4142 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4143 | goto failed; |
| 4144 | Py_DECREF(value); |
| 4145 | break; |
| 4146 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4147 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4148 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4149 | if (!result) goto failed; |
| 4150 | value = ast2obj_expr(o->v.DictComp.key); |
| 4151 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4152 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4153 | goto failed; |
| 4154 | Py_DECREF(value); |
| 4155 | value = ast2obj_expr(o->v.DictComp.value); |
| 4156 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4157 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4158 | goto failed; |
| 4159 | Py_DECREF(value); |
| 4160 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4161 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4162 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4163 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4164 | goto failed; |
| 4165 | Py_DECREF(value); |
| 4166 | break; |
| 4167 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4168 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_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.GeneratorExp.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.GeneratorExp.generators, |
| 4177 | ast2obj_comprehension); |
| 4178 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4179 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4180 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4181 | goto failed; |
| 4182 | Py_DECREF(value); |
| 4183 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4184 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4185 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4186 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4187 | if (!result) goto failed; |
| 4188 | value = ast2obj_expr(o->v.Await.value); |
| 4189 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4190 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4191 | goto failed; |
| 4192 | Py_DECREF(value); |
| 4193 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4194 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4195 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4196 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4197 | if (!result) goto failed; |
| 4198 | value = ast2obj_expr(o->v.Yield.value); |
| 4199 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4200 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4201 | goto failed; |
| 4202 | Py_DECREF(value); |
| 4203 | break; |
| 4204 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4205 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4206 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4207 | if (!result) goto failed; |
| 4208 | value = ast2obj_expr(o->v.YieldFrom.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 | break; |
| 4214 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4215 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4216 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4217 | if (!result) goto failed; |
| 4218 | value = ast2obj_expr(o->v.Compare.left); |
| 4219 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4220 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4221 | goto failed; |
| 4222 | Py_DECREF(value); |
| 4223 | { |
| 4224 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4225 | value = PyList_New(n); |
| 4226 | if (!value) goto failed; |
| 4227 | for(i = 0; i < n; i++) |
| 4228 | 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] | 4229 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4230 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4231 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4232 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4233 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4234 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4235 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4236 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4237 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4238 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4239 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4240 | break; |
| 4241 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4242 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4243 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4244 | if (!result) goto failed; |
| 4245 | value = ast2obj_expr(o->v.Call.func); |
| 4246 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4247 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4248 | goto failed; |
| 4249 | Py_DECREF(value); |
| 4250 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4251 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4252 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4253 | goto failed; |
| 4254 | Py_DECREF(value); |
| 4255 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4256 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4257 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4258 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4259 | goto failed; |
| 4260 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4261 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4262 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4263 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4264 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4265 | if (!result) goto failed; |
| 4266 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4267 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4268 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4269 | goto failed; |
| 4270 | Py_DECREF(value); |
| 4271 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4272 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4273 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4274 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4275 | goto failed; |
| 4276 | Py_DECREF(value); |
| 4277 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4278 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4279 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4280 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4281 | goto failed; |
| 4282 | Py_DECREF(value); |
| 4283 | break; |
| 4284 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4285 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4286 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4287 | if (!result) goto failed; |
| 4288 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4289 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4290 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4291 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4292 | goto failed; |
| 4293 | Py_DECREF(value); |
| 4294 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4295 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4296 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4297 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4298 | if (!result) goto failed; |
| 4299 | value = ast2obj_constant(o->v.Constant.value); |
| 4300 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4301 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4302 | goto failed; |
| 4303 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4304 | value = ast2obj_string(o->v.Constant.kind); |
| 4305 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4306 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4307 | goto failed; |
| 4308 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4309 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4310 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4311 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4312 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4313 | if (!result) goto failed; |
| 4314 | value = ast2obj_expr(o->v.Attribute.value); |
| 4315 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4316 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4317 | goto failed; |
| 4318 | Py_DECREF(value); |
| 4319 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4320 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4321 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4322 | goto failed; |
| 4323 | Py_DECREF(value); |
| 4324 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4325 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4326 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4327 | goto failed; |
| 4328 | Py_DECREF(value); |
| 4329 | break; |
| 4330 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4331 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4332 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4333 | if (!result) goto failed; |
| 4334 | value = ast2obj_expr(o->v.Subscript.value); |
| 4335 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4336 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4337 | goto failed; |
| 4338 | Py_DECREF(value); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4339 | value = ast2obj_expr(o->v.Subscript.slice); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4340 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4341 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4342 | goto failed; |
| 4343 | Py_DECREF(value); |
| 4344 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4345 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4346 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4347 | goto failed; |
| 4348 | Py_DECREF(value); |
| 4349 | break; |
| 4350 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4351 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4352 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4353 | if (!result) goto failed; |
| 4354 | value = ast2obj_expr(o->v.Starred.value); |
| 4355 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4356 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4357 | goto failed; |
| 4358 | Py_DECREF(value); |
| 4359 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4360 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4361 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4362 | goto failed; |
| 4363 | Py_DECREF(value); |
| 4364 | break; |
| 4365 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4366 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4367 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4368 | if (!result) goto failed; |
| 4369 | value = ast2obj_identifier(o->v.Name.id); |
| 4370 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4371 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4372 | goto failed; |
| 4373 | Py_DECREF(value); |
| 4374 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4375 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4376 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4377 | goto failed; |
| 4378 | Py_DECREF(value); |
| 4379 | break; |
| 4380 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4381 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4382 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4383 | if (!result) goto failed; |
| 4384 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4385 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4386 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4387 | goto failed; |
| 4388 | Py_DECREF(value); |
| 4389 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4390 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4391 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4392 | goto failed; |
| 4393 | Py_DECREF(value); |
| 4394 | break; |
| 4395 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4396 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4397 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4398 | if (!result) goto failed; |
| 4399 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4400 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4401 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4402 | goto failed; |
| 4403 | Py_DECREF(value); |
| 4404 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4405 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4406 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4407 | goto failed; |
| 4408 | Py_DECREF(value); |
| 4409 | break; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4410 | case Slice_kind: |
| 4411 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4412 | result = PyType_GenericNew(tp, NULL, NULL); |
| 4413 | if (!result) goto failed; |
| 4414 | value = ast2obj_expr(o->v.Slice.lower); |
| 4415 | if (!value) goto failed; |
| 4416 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
| 4417 | goto failed; |
| 4418 | Py_DECREF(value); |
| 4419 | value = ast2obj_expr(o->v.Slice.upper); |
| 4420 | if (!value) goto failed; |
| 4421 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
| 4422 | goto failed; |
| 4423 | Py_DECREF(value); |
| 4424 | value = ast2obj_expr(o->v.Slice.step); |
| 4425 | if (!value) goto failed; |
| 4426 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
| 4427 | goto failed; |
| 4428 | Py_DECREF(value); |
| 4429 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4430 | } |
| 4431 | value = ast2obj_int(o->lineno); |
| 4432 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4433 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4434 | goto failed; |
| 4435 | Py_DECREF(value); |
| 4436 | value = ast2obj_int(o->col_offset); |
| 4437 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4438 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4439 | goto failed; |
| 4440 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4441 | value = ast2obj_int(o->end_lineno); |
| 4442 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4443 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4444 | goto failed; |
| 4445 | Py_DECREF(value); |
| 4446 | value = ast2obj_int(o->end_col_offset); |
| 4447 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4448 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4449 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4450 | goto failed; |
| 4451 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4452 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4453 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4454 | Py_XDECREF(value); |
| 4455 | Py_XDECREF(result); |
| 4456 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4457 | } |
| 4458 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4459 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4460 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4461 | switch(o) { |
| 4462 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4463 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4464 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4466 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4467 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4468 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4469 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4470 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4471 | case AugLoad: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4472 | Py_INCREF(astmodulestate_global->AugLoad_singleton); |
| 4473 | return astmodulestate_global->AugLoad_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4474 | case AugStore: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4475 | Py_INCREF(astmodulestate_global->AugStore_singleton); |
| 4476 | return astmodulestate_global->AugStore_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4477 | case Param: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4478 | Py_INCREF(astmodulestate_global->Param_singleton); |
| 4479 | return astmodulestate_global->Param_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4480 | default: |
| 4481 | /* should never happen, but just in case ... */ |
| 4482 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 4483 | return NULL; |
| 4484 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4485 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4486 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4487 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4488 | switch(o) { |
| 4489 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4490 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4491 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4492 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4493 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4494 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4495 | default: |
| 4496 | /* should never happen, but just in case ... */ |
| 4497 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 4498 | return NULL; |
| 4499 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4500 | } |
| 4501 | PyObject* ast2obj_operator(operator_ty o) |
| 4502 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4503 | switch(o) { |
| 4504 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4505 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4506 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4507 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4508 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4509 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4510 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4511 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4512 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4513 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4514 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4515 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4516 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4517 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4518 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4519 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4520 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4521 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4522 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4523 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4524 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4525 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4526 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4527 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4528 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4529 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4530 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4531 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4532 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4533 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4534 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4535 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4536 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4537 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4538 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4539 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4540 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4541 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4542 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4543 | default: |
| 4544 | /* should never happen, but just in case ... */ |
| 4545 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 4546 | return NULL; |
| 4547 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4548 | } |
| 4549 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4550 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4551 | switch(o) { |
| 4552 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4553 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4554 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4555 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4556 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4557 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4558 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4559 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4560 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4561 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4562 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4563 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4564 | default: |
| 4565 | /* should never happen, but just in case ... */ |
| 4566 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 4567 | return NULL; |
| 4568 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4569 | } |
| 4570 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4571 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4572 | switch(o) { |
| 4573 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4574 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4575 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4576 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4577 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4578 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4579 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4580 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4581 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4582 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4583 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4584 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4585 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4586 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4587 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4588 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4589 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4590 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4591 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4592 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4593 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4594 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4595 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4596 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4597 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4598 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4599 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4600 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4601 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4602 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4603 | default: |
| 4604 | /* should never happen, but just in case ... */ |
| 4605 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 4606 | return NULL; |
| 4607 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4608 | } |
| 4609 | PyObject* |
| 4610 | ast2obj_comprehension(void* _o) |
| 4611 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4612 | comprehension_ty o = (comprehension_ty)_o; |
| 4613 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4614 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4615 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4616 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4617 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4618 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4619 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4620 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4621 | if (!result) return NULL; |
| 4622 | value = ast2obj_expr(o->target); |
| 4623 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4624 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4625 | goto failed; |
| 4626 | Py_DECREF(value); |
| 4627 | value = ast2obj_expr(o->iter); |
| 4628 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4629 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4630 | goto failed; |
| 4631 | Py_DECREF(value); |
| 4632 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4633 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4634 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4635 | goto failed; |
| 4636 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4637 | value = ast2obj_int(o->is_async); |
| 4638 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4639 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4640 | goto failed; |
| 4641 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4642 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4643 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4644 | Py_XDECREF(value); |
| 4645 | Py_XDECREF(result); |
| 4646 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4649 | PyObject* |
| 4650 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4651 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4652 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4653 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4654 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4655 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4656 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4657 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4658 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4659 | switch (o->kind) { |
| 4660 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4661 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4662 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4663 | if (!result) goto failed; |
| 4664 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4665 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4666 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4667 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4668 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4669 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4670 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4671 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4672 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4673 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4674 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4675 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4676 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4677 | goto failed; |
| 4678 | Py_DECREF(value); |
| 4679 | break; |
| 4680 | } |
| 4681 | value = ast2obj_int(o->lineno); |
| 4682 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4683 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4684 | goto failed; |
| 4685 | Py_DECREF(value); |
| 4686 | value = ast2obj_int(o->col_offset); |
| 4687 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4688 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4689 | goto failed; |
| 4690 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4691 | value = ast2obj_int(o->end_lineno); |
| 4692 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4693 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4694 | goto failed; |
| 4695 | Py_DECREF(value); |
| 4696 | value = ast2obj_int(o->end_col_offset); |
| 4697 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4698 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4699 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4700 | goto failed; |
| 4701 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4702 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4703 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4704 | Py_XDECREF(value); |
| 4705 | Py_XDECREF(result); |
| 4706 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4709 | PyObject* |
| 4710 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4711 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4712 | arguments_ty o = (arguments_ty)_o; |
| 4713 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4714 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4715 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4716 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4717 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4718 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4719 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4720 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4721 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4722 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4723 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4724 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4725 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4726 | goto failed; |
| 4727 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4728 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4729 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4730 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4731 | goto failed; |
| 4732 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4733 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4734 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4735 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4736 | goto failed; |
| 4737 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4738 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4739 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4740 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4741 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4742 | goto failed; |
| 4743 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4744 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4745 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4746 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4747 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4748 | goto failed; |
| 4749 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4750 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4751 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4752 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4753 | goto failed; |
| 4754 | Py_DECREF(value); |
| 4755 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4756 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4757 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4758 | goto failed; |
| 4759 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4760 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4761 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4762 | Py_XDECREF(value); |
| 4763 | Py_XDECREF(result); |
| 4764 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4765 | } |
| 4766 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4767 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4768 | ast2obj_arg(void* _o) |
| 4769 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4770 | arg_ty o = (arg_ty)_o; |
| 4771 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4772 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4773 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4774 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4775 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4776 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4777 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4778 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4779 | if (!result) return NULL; |
| 4780 | value = ast2obj_identifier(o->arg); |
| 4781 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4782 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4783 | goto failed; |
| 4784 | Py_DECREF(value); |
| 4785 | value = ast2obj_expr(o->annotation); |
| 4786 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4787 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4788 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4789 | goto failed; |
| 4790 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4791 | value = ast2obj_string(o->type_comment); |
| 4792 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4793 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4794 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4795 | goto failed; |
| 4796 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4797 | value = ast2obj_int(o->lineno); |
| 4798 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4799 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4800 | goto failed; |
| 4801 | Py_DECREF(value); |
| 4802 | value = ast2obj_int(o->col_offset); |
| 4803 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4804 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4805 | goto failed; |
| 4806 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4807 | value = ast2obj_int(o->end_lineno); |
| 4808 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4809 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4810 | goto failed; |
| 4811 | Py_DECREF(value); |
| 4812 | value = ast2obj_int(o->end_col_offset); |
| 4813 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4814 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4815 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4816 | goto failed; |
| 4817 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4818 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4819 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4820 | Py_XDECREF(value); |
| 4821 | Py_XDECREF(result); |
| 4822 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4826 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4827 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4828 | keyword_ty o = (keyword_ty)_o; |
| 4829 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4830 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4831 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4832 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4833 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4834 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4835 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4836 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4837 | if (!result) return NULL; |
| 4838 | value = ast2obj_identifier(o->arg); |
| 4839 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4840 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4841 | goto failed; |
| 4842 | Py_DECREF(value); |
| 4843 | value = ast2obj_expr(o->value); |
| 4844 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4845 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4846 | goto failed; |
| 4847 | Py_DECREF(value); |
| 4848 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4849 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4850 | Py_XDECREF(value); |
| 4851 | Py_XDECREF(result); |
| 4852 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4853 | } |
| 4854 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4855 | PyObject* |
| 4856 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4857 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4858 | alias_ty o = (alias_ty)_o; |
| 4859 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4860 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4861 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4862 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4863 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4864 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4865 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 4866 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4867 | if (!result) return NULL; |
| 4868 | value = ast2obj_identifier(o->name); |
| 4869 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4870 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4871 | goto failed; |
| 4872 | Py_DECREF(value); |
| 4873 | value = ast2obj_identifier(o->asname); |
| 4874 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4875 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4876 | goto failed; |
| 4877 | Py_DECREF(value); |
| 4878 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4879 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4880 | Py_XDECREF(value); |
| 4881 | Py_XDECREF(result); |
| 4882 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4885 | PyObject* |
| 4886 | ast2obj_withitem(void* _o) |
| 4887 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4888 | withitem_ty o = (withitem_ty)_o; |
| 4889 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4890 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4891 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4892 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4893 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4894 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4895 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 4896 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4897 | if (!result) return NULL; |
| 4898 | value = ast2obj_expr(o->context_expr); |
| 4899 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4900 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 4901 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4902 | goto failed; |
| 4903 | Py_DECREF(value); |
| 4904 | value = ast2obj_expr(o->optional_vars); |
| 4905 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4906 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 4907 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4908 | goto failed; |
| 4909 | Py_DECREF(value); |
| 4910 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [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; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4915 | } |
| 4916 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4917 | PyObject* |
| 4918 | ast2obj_type_ignore(void* _o) |
| 4919 | { |
| 4920 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4921 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4922 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4923 | if (!o) { |
| 4924 | Py_RETURN_NONE; |
| 4925 | } |
| 4926 | |
| 4927 | switch (o->kind) { |
| 4928 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4929 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 4930 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4931 | if (!result) goto failed; |
| 4932 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4933 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4934 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 4935 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4936 | goto failed; |
| 4937 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4938 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 4939 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4940 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4941 | goto failed; |
| 4942 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4943 | break; |
| 4944 | } |
| 4945 | return result; |
| 4946 | failed: |
| 4947 | Py_XDECREF(value); |
| 4948 | Py_XDECREF(result); |
| 4949 | return NULL; |
| 4950 | } |
| 4951 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4952 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4953 | int |
| 4954 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4955 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4956 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4957 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4958 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4959 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4960 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4961 | if (obj == Py_None) { |
| 4962 | *out = NULL; |
| 4963 | return 0; |
| 4964 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4965 | tp = astmodulestate_global->Module_type; |
| 4966 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4967 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4968 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4969 | } |
| 4970 | if (isinstance) { |
| 4971 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4972 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4973 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4974 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 4975 | return 1; |
| 4976 | } |
| 4977 | if (tmp == NULL) { |
| 4978 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 4979 | return 1; |
| 4980 | } |
| 4981 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4982 | int res; |
| 4983 | Py_ssize_t len; |
| 4984 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4985 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4986 | 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] | 4987 | goto failed; |
| 4988 | } |
| 4989 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 4990 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4991 | if (body == NULL) goto failed; |
| 4992 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 4993 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 4994 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 4995 | Py_INCREF(tmp2); |
| 4996 | res = obj2ast_stmt(tmp2, &val, arena); |
| 4997 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4998 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 4999 | if (len != PyList_GET_SIZE(tmp)) { |
| 5000 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5001 | goto failed; |
| 5002 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5003 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5004 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5005 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5006 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5007 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5008 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5009 | return 1; |
| 5010 | } |
| 5011 | if (tmp == NULL) { |
| 5012 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5013 | return 1; |
| 5014 | } |
| 5015 | else { |
| 5016 | int res; |
| 5017 | Py_ssize_t len; |
| 5018 | Py_ssize_t i; |
| 5019 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5020 | 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] | 5021 | goto failed; |
| 5022 | } |
| 5023 | len = PyList_GET_SIZE(tmp); |
| 5024 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5025 | if (type_ignores == NULL) goto failed; |
| 5026 | for (i = 0; i < len; i++) { |
| 5027 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5028 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5029 | Py_INCREF(tmp2); |
| 5030 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5031 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5032 | if (res != 0) goto failed; |
| 5033 | if (len != PyList_GET_SIZE(tmp)) { |
| 5034 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5035 | goto failed; |
| 5036 | } |
| 5037 | asdl_seq_SET(type_ignores, i, val); |
| 5038 | } |
| 5039 | Py_CLEAR(tmp); |
| 5040 | } |
| 5041 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5042 | if (*out == NULL) goto failed; |
| 5043 | return 0; |
| 5044 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5045 | tp = astmodulestate_global->Interactive_type; |
| 5046 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5047 | if (isinstance == -1) { |
| 5048 | return 1; |
| 5049 | } |
| 5050 | if (isinstance) { |
| 5051 | asdl_seq* body; |
| 5052 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5053 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5054 | return 1; |
| 5055 | } |
| 5056 | if (tmp == NULL) { |
| 5057 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5058 | return 1; |
| 5059 | } |
| 5060 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5061 | int res; |
| 5062 | Py_ssize_t len; |
| 5063 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5064 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5065 | 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] | 5066 | goto failed; |
| 5067 | } |
| 5068 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5069 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5070 | if (body == NULL) goto failed; |
| 5071 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5072 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5073 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5074 | Py_INCREF(tmp2); |
| 5075 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5076 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5077 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5078 | if (len != PyList_GET_SIZE(tmp)) { |
| 5079 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5080 | goto failed; |
| 5081 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5082 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5083 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5084 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5085 | } |
| 5086 | *out = Interactive(body, arena); |
| 5087 | if (*out == NULL) goto failed; |
| 5088 | return 0; |
| 5089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5090 | tp = astmodulestate_global->Expression_type; |
| 5091 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5092 | if (isinstance == -1) { |
| 5093 | return 1; |
| 5094 | } |
| 5095 | if (isinstance) { |
| 5096 | expr_ty body; |
| 5097 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5098 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5099 | return 1; |
| 5100 | } |
| 5101 | if (tmp == NULL) { |
| 5102 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5103 | return 1; |
| 5104 | } |
| 5105 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5106 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5107 | res = obj2ast_expr(tmp, &body, arena); |
| 5108 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5109 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5110 | } |
| 5111 | *out = Expression(body, arena); |
| 5112 | if (*out == NULL) goto failed; |
| 5113 | return 0; |
| 5114 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5115 | tp = astmodulestate_global->FunctionType_type; |
| 5116 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5117 | if (isinstance == -1) { |
| 5118 | return 1; |
| 5119 | } |
| 5120 | if (isinstance) { |
| 5121 | asdl_seq* argtypes; |
| 5122 | expr_ty returns; |
| 5123 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5124 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5125 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5126 | return 1; |
| 5127 | } |
| 5128 | if (tmp == NULL) { |
| 5129 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5130 | return 1; |
| 5131 | } |
| 5132 | else { |
| 5133 | int res; |
| 5134 | Py_ssize_t len; |
| 5135 | Py_ssize_t i; |
| 5136 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5137 | 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] | 5138 | goto failed; |
| 5139 | } |
| 5140 | len = PyList_GET_SIZE(tmp); |
| 5141 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5142 | if (argtypes == NULL) goto failed; |
| 5143 | for (i = 0; i < len; i++) { |
| 5144 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5145 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5146 | Py_INCREF(tmp2); |
| 5147 | res = obj2ast_expr(tmp2, &val, arena); |
| 5148 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5149 | if (res != 0) goto failed; |
| 5150 | if (len != PyList_GET_SIZE(tmp)) { |
| 5151 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5152 | goto failed; |
| 5153 | } |
| 5154 | asdl_seq_SET(argtypes, i, val); |
| 5155 | } |
| 5156 | Py_CLEAR(tmp); |
| 5157 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5158 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5159 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5160 | return 1; |
| 5161 | } |
| 5162 | if (tmp == NULL) { |
| 5163 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5164 | return 1; |
| 5165 | } |
| 5166 | else { |
| 5167 | int res; |
| 5168 | res = obj2ast_expr(tmp, &returns, arena); |
| 5169 | if (res != 0) goto failed; |
| 5170 | Py_CLEAR(tmp); |
| 5171 | } |
| 5172 | *out = FunctionType(argtypes, returns, arena); |
| 5173 | if (*out == NULL) goto failed; |
| 5174 | return 0; |
| 5175 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5176 | |
| 5177 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5178 | failed: |
| 5179 | Py_XDECREF(tmp); |
| 5180 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | int |
| 5184 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5185 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5186 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5187 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5188 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5189 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5190 | int lineno; |
| 5191 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5192 | int end_lineno; |
| 5193 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5194 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5195 | if (obj == Py_None) { |
| 5196 | *out = NULL; |
| 5197 | return 0; |
| 5198 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5199 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5200 | return 1; |
| 5201 | } |
| 5202 | if (tmp == NULL) { |
| 5203 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5204 | return 1; |
| 5205 | } |
| 5206 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5207 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5208 | res = obj2ast_int(tmp, &lineno, arena); |
| 5209 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5210 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5211 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5212 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5213 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5214 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5215 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5216 | if (tmp == NULL) { |
| 5217 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5218 | return 1; |
| 5219 | } |
| 5220 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5221 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5222 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5223 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5224 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5225 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5226 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5227 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5228 | return 1; |
| 5229 | } |
| 5230 | if (tmp == NULL || tmp == Py_None) { |
| 5231 | Py_CLEAR(tmp); |
| 5232 | end_lineno = 0; |
| 5233 | } |
| 5234 | else { |
| 5235 | int res; |
| 5236 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5237 | if (res != 0) goto failed; |
| 5238 | Py_CLEAR(tmp); |
| 5239 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5240 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5241 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5242 | return 1; |
| 5243 | } |
| 5244 | if (tmp == NULL || tmp == Py_None) { |
| 5245 | Py_CLEAR(tmp); |
| 5246 | end_col_offset = 0; |
| 5247 | } |
| 5248 | else { |
| 5249 | int res; |
| 5250 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5251 | if (res != 0) goto failed; |
| 5252 | Py_CLEAR(tmp); |
| 5253 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5254 | tp = astmodulestate_global->FunctionDef_type; |
| 5255 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5256 | if (isinstance == -1) { |
| 5257 | return 1; |
| 5258 | } |
| 5259 | if (isinstance) { |
| 5260 | identifier name; |
| 5261 | arguments_ty args; |
| 5262 | asdl_seq* body; |
| 5263 | asdl_seq* decorator_list; |
| 5264 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5265 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5266 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5267 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5268 | return 1; |
| 5269 | } |
| 5270 | if (tmp == NULL) { |
| 5271 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5272 | return 1; |
| 5273 | } |
| 5274 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5275 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5276 | res = obj2ast_identifier(tmp, &name, arena); |
| 5277 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5278 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5279 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5280 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5281 | return 1; |
| 5282 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5283 | if (tmp == NULL) { |
| 5284 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5285 | return 1; |
| 5286 | } |
| 5287 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5288 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5289 | res = obj2ast_arguments(tmp, &args, arena); |
| 5290 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5291 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5292 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5293 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5294 | return 1; |
| 5295 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5296 | if (tmp == NULL) { |
| 5297 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5298 | return 1; |
| 5299 | } |
| 5300 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5301 | int res; |
| 5302 | Py_ssize_t len; |
| 5303 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5304 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5305 | 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] | 5306 | goto failed; |
| 5307 | } |
| 5308 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5309 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5310 | if (body == NULL) goto failed; |
| 5311 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5312 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5313 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5314 | Py_INCREF(tmp2); |
| 5315 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5316 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5317 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5318 | if (len != PyList_GET_SIZE(tmp)) { |
| 5319 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5320 | goto failed; |
| 5321 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5322 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5323 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5324 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5325 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5326 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5327 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5328 | return 1; |
| 5329 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5330 | if (tmp == NULL) { |
| 5331 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5332 | return 1; |
| 5333 | } |
| 5334 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5335 | int res; |
| 5336 | Py_ssize_t len; |
| 5337 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5338 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5339 | 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] | 5340 | goto failed; |
| 5341 | } |
| 5342 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5343 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5344 | if (decorator_list == NULL) goto failed; |
| 5345 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5346 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5347 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5348 | Py_INCREF(tmp2); |
| 5349 | res = obj2ast_expr(tmp2, &val, arena); |
| 5350 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5351 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5352 | if (len != PyList_GET_SIZE(tmp)) { |
| 5353 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5354 | goto failed; |
| 5355 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5356 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5357 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5358 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5359 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5360 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5361 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5362 | return 1; |
| 5363 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5364 | if (tmp == NULL || tmp == Py_None) { |
| 5365 | Py_CLEAR(tmp); |
| 5366 | returns = NULL; |
| 5367 | } |
| 5368 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5369 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5370 | res = obj2ast_expr(tmp, &returns, arena); |
| 5371 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5372 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5374 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5375 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5376 | return 1; |
| 5377 | } |
| 5378 | if (tmp == NULL || tmp == Py_None) { |
| 5379 | Py_CLEAR(tmp); |
| 5380 | type_comment = NULL; |
| 5381 | } |
| 5382 | else { |
| 5383 | int res; |
| 5384 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5385 | if (res != 0) goto failed; |
| 5386 | Py_CLEAR(tmp); |
| 5387 | } |
| 5388 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5389 | type_comment, lineno, col_offset, end_lineno, |
| 5390 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5391 | if (*out == NULL) goto failed; |
| 5392 | return 0; |
| 5393 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5394 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5395 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5396 | if (isinstance == -1) { |
| 5397 | return 1; |
| 5398 | } |
| 5399 | if (isinstance) { |
| 5400 | identifier name; |
| 5401 | arguments_ty args; |
| 5402 | asdl_seq* body; |
| 5403 | asdl_seq* decorator_list; |
| 5404 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5405 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5406 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5407 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5408 | return 1; |
| 5409 | } |
| 5410 | if (tmp == NULL) { |
| 5411 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5412 | return 1; |
| 5413 | } |
| 5414 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5415 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5416 | res = obj2ast_identifier(tmp, &name, arena); |
| 5417 | if (res != 0) goto failed; |
| 5418 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5419 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5420 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5421 | return 1; |
| 5422 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5423 | if (tmp == NULL) { |
| 5424 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5425 | return 1; |
| 5426 | } |
| 5427 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5428 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5429 | res = obj2ast_arguments(tmp, &args, arena); |
| 5430 | if (res != 0) goto failed; |
| 5431 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5432 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5433 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5434 | return 1; |
| 5435 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5436 | if (tmp == NULL) { |
| 5437 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5438 | return 1; |
| 5439 | } |
| 5440 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5441 | int res; |
| 5442 | Py_ssize_t len; |
| 5443 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5444 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5445 | 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] | 5446 | goto failed; |
| 5447 | } |
| 5448 | len = PyList_GET_SIZE(tmp); |
| 5449 | body = _Py_asdl_seq_new(len, arena); |
| 5450 | if (body == NULL) goto failed; |
| 5451 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5452 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5453 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5454 | Py_INCREF(tmp2); |
| 5455 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5456 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5457 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5458 | if (len != PyList_GET_SIZE(tmp)) { |
| 5459 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5460 | goto failed; |
| 5461 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5462 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5463 | } |
| 5464 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5465 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5466 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5467 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5468 | return 1; |
| 5469 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5470 | if (tmp == NULL) { |
| 5471 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5472 | return 1; |
| 5473 | } |
| 5474 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5475 | int res; |
| 5476 | Py_ssize_t len; |
| 5477 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5478 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5479 | 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] | 5480 | goto failed; |
| 5481 | } |
| 5482 | len = PyList_GET_SIZE(tmp); |
| 5483 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5484 | if (decorator_list == NULL) goto failed; |
| 5485 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5486 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5487 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5488 | Py_INCREF(tmp2); |
| 5489 | res = obj2ast_expr(tmp2, &val, arena); |
| 5490 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5491 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5492 | if (len != PyList_GET_SIZE(tmp)) { |
| 5493 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5494 | goto failed; |
| 5495 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5496 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5497 | } |
| 5498 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5499 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5500 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5501 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5502 | return 1; |
| 5503 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5504 | if (tmp == NULL || tmp == Py_None) { |
| 5505 | Py_CLEAR(tmp); |
| 5506 | returns = NULL; |
| 5507 | } |
| 5508 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5509 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5510 | res = obj2ast_expr(tmp, &returns, arena); |
| 5511 | if (res != 0) goto failed; |
| 5512 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5513 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5514 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5515 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5516 | return 1; |
| 5517 | } |
| 5518 | if (tmp == NULL || tmp == Py_None) { |
| 5519 | Py_CLEAR(tmp); |
| 5520 | type_comment = NULL; |
| 5521 | } |
| 5522 | else { |
| 5523 | int res; |
| 5524 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5525 | if (res != 0) goto failed; |
| 5526 | Py_CLEAR(tmp); |
| 5527 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5528 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5529 | type_comment, lineno, col_offset, end_lineno, |
| 5530 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5531 | if (*out == NULL) goto failed; |
| 5532 | return 0; |
| 5533 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5534 | tp = astmodulestate_global->ClassDef_type; |
| 5535 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5536 | if (isinstance == -1) { |
| 5537 | return 1; |
| 5538 | } |
| 5539 | if (isinstance) { |
| 5540 | identifier name; |
| 5541 | asdl_seq* bases; |
| 5542 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5543 | asdl_seq* body; |
| 5544 | asdl_seq* decorator_list; |
| 5545 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5546 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5547 | return 1; |
| 5548 | } |
| 5549 | if (tmp == NULL) { |
| 5550 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5551 | return 1; |
| 5552 | } |
| 5553 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5554 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5555 | res = obj2ast_identifier(tmp, &name, arena); |
| 5556 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5557 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5558 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5559 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [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 \"bases\" missing from ClassDef"); |
| 5564 | return 1; |
| 5565 | } |
| 5566 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5567 | int res; |
| 5568 | Py_ssize_t len; |
| 5569 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5570 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5571 | 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] | 5572 | goto failed; |
| 5573 | } |
| 5574 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5575 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5576 | if (bases == 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); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [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, "ClassDef field \"bases\" 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(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5589 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 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->keywords, &tmp) < |
| 5593 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5594 | return 1; |
| 5595 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5596 | if (tmp == NULL) { |
| 5597 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5598 | return 1; |
| 5599 | } |
| 5600 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5601 | int res; |
| 5602 | Py_ssize_t len; |
| 5603 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5604 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5605 | 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] | 5606 | goto failed; |
| 5607 | } |
| 5608 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5609 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5610 | if (keywords == NULL) goto failed; |
| 5611 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5612 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5613 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5614 | Py_INCREF(tmp2); |
| 5615 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5616 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5617 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5618 | if (len != PyList_GET_SIZE(tmp)) { |
| 5619 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5620 | goto failed; |
| 5621 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5622 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5623 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5624 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5625 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5626 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5627 | return 1; |
| 5628 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5629 | if (tmp == NULL) { |
| 5630 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5631 | return 1; |
| 5632 | } |
| 5633 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5634 | int res; |
| 5635 | Py_ssize_t len; |
| 5636 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5637 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5638 | 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] | 5639 | goto failed; |
| 5640 | } |
| 5641 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5642 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5643 | if (body == NULL) goto failed; |
| 5644 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5645 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5646 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5647 | Py_INCREF(tmp2); |
| 5648 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5649 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5650 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5651 | if (len != PyList_GET_SIZE(tmp)) { |
| 5652 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5653 | goto failed; |
| 5654 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5655 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5656 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5657 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5658 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5659 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5660 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5661 | return 1; |
| 5662 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5663 | if (tmp == NULL) { |
| 5664 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5665 | return 1; |
| 5666 | } |
| 5667 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5668 | int res; |
| 5669 | Py_ssize_t len; |
| 5670 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5671 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5672 | 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] | 5673 | goto failed; |
| 5674 | } |
| 5675 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5676 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5677 | if (decorator_list == NULL) goto failed; |
| 5678 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5679 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5680 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5681 | Py_INCREF(tmp2); |
| 5682 | res = obj2ast_expr(tmp2, &val, arena); |
| 5683 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5684 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5685 | if (len != PyList_GET_SIZE(tmp)) { |
| 5686 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5687 | goto failed; |
| 5688 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5689 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5690 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5691 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5692 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5693 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5694 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5695 | if (*out == NULL) goto failed; |
| 5696 | return 0; |
| 5697 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5698 | tp = astmodulestate_global->Return_type; |
| 5699 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5700 | if (isinstance == -1) { |
| 5701 | return 1; |
| 5702 | } |
| 5703 | if (isinstance) { |
| 5704 | expr_ty value; |
| 5705 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5706 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5707 | return 1; |
| 5708 | } |
| 5709 | if (tmp == NULL || tmp == Py_None) { |
| 5710 | Py_CLEAR(tmp); |
| 5711 | value = NULL; |
| 5712 | } |
| 5713 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5714 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5715 | res = obj2ast_expr(tmp, &value, arena); |
| 5716 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5717 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5718 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5719 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5720 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5721 | if (*out == NULL) goto failed; |
| 5722 | return 0; |
| 5723 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5724 | tp = astmodulestate_global->Delete_type; |
| 5725 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5726 | if (isinstance == -1) { |
| 5727 | return 1; |
| 5728 | } |
| 5729 | if (isinstance) { |
| 5730 | asdl_seq* targets; |
| 5731 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5732 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5733 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5734 | return 1; |
| 5735 | } |
| 5736 | if (tmp == NULL) { |
| 5737 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5738 | return 1; |
| 5739 | } |
| 5740 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5741 | int res; |
| 5742 | Py_ssize_t len; |
| 5743 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5744 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5745 | 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] | 5746 | goto failed; |
| 5747 | } |
| 5748 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5749 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5750 | if (targets == NULL) goto failed; |
| 5751 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5752 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5753 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5754 | Py_INCREF(tmp2); |
| 5755 | res = obj2ast_expr(tmp2, &val, arena); |
| 5756 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5757 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5758 | if (len != PyList_GET_SIZE(tmp)) { |
| 5759 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5760 | goto failed; |
| 5761 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5762 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5763 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5764 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5765 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5766 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5767 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5768 | if (*out == NULL) goto failed; |
| 5769 | return 0; |
| 5770 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5771 | tp = astmodulestate_global->Assign_type; |
| 5772 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5773 | if (isinstance == -1) { |
| 5774 | return 1; |
| 5775 | } |
| 5776 | if (isinstance) { |
| 5777 | asdl_seq* targets; |
| 5778 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5779 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5780 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5781 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5782 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5783 | return 1; |
| 5784 | } |
| 5785 | if (tmp == NULL) { |
| 5786 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5787 | return 1; |
| 5788 | } |
| 5789 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5790 | int res; |
| 5791 | Py_ssize_t len; |
| 5792 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5793 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5794 | 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] | 5795 | goto failed; |
| 5796 | } |
| 5797 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5798 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5799 | if (targets == NULL) goto failed; |
| 5800 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5801 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5802 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5803 | Py_INCREF(tmp2); |
| 5804 | res = obj2ast_expr(tmp2, &val, arena); |
| 5805 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5806 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5807 | if (len != PyList_GET_SIZE(tmp)) { |
| 5808 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5809 | goto failed; |
| 5810 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5811 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5812 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5813 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5814 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5815 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5816 | return 1; |
| 5817 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5818 | if (tmp == NULL) { |
| 5819 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5820 | return 1; |
| 5821 | } |
| 5822 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5823 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5824 | res = obj2ast_expr(tmp, &value, arena); |
| 5825 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5826 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5827 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5828 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5829 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5830 | return 1; |
| 5831 | } |
| 5832 | if (tmp == NULL || tmp == Py_None) { |
| 5833 | Py_CLEAR(tmp); |
| 5834 | type_comment = NULL; |
| 5835 | } |
| 5836 | else { |
| 5837 | int res; |
| 5838 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5839 | if (res != 0) goto failed; |
| 5840 | Py_CLEAR(tmp); |
| 5841 | } |
| 5842 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5843 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5844 | if (*out == NULL) goto failed; |
| 5845 | return 0; |
| 5846 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5847 | tp = astmodulestate_global->AugAssign_type; |
| 5848 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5849 | if (isinstance == -1) { |
| 5850 | return 1; |
| 5851 | } |
| 5852 | if (isinstance) { |
| 5853 | expr_ty target; |
| 5854 | operator_ty op; |
| 5855 | expr_ty value; |
| 5856 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5857 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5858 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5859 | return 1; |
| 5860 | } |
| 5861 | if (tmp == NULL) { |
| 5862 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5863 | return 1; |
| 5864 | } |
| 5865 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5866 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5867 | res = obj2ast_expr(tmp, &target, arena); |
| 5868 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5869 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5870 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5871 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5872 | return 1; |
| 5873 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5874 | if (tmp == NULL) { |
| 5875 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5876 | return 1; |
| 5877 | } |
| 5878 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5879 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5880 | res = obj2ast_operator(tmp, &op, arena); |
| 5881 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5882 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5883 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5884 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5885 | return 1; |
| 5886 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5887 | if (tmp == NULL) { |
| 5888 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5889 | return 1; |
| 5890 | } |
| 5891 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5892 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5893 | res = obj2ast_expr(tmp, &value, arena); |
| 5894 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5895 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5896 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5897 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5898 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5899 | if (*out == NULL) goto failed; |
| 5900 | return 0; |
| 5901 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5902 | tp = astmodulestate_global->AnnAssign_type; |
| 5903 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5904 | if (isinstance == -1) { |
| 5905 | return 1; |
| 5906 | } |
| 5907 | if (isinstance) { |
| 5908 | expr_ty target; |
| 5909 | expr_ty annotation; |
| 5910 | expr_ty value; |
| 5911 | int simple; |
| 5912 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5913 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5914 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5915 | return 1; |
| 5916 | } |
| 5917 | if (tmp == NULL) { |
| 5918 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 5919 | return 1; |
| 5920 | } |
| 5921 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5922 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5923 | res = obj2ast_expr(tmp, &target, arena); |
| 5924 | if (res != 0) goto failed; |
| 5925 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5926 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5927 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 5928 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5929 | return 1; |
| 5930 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5931 | if (tmp == NULL) { |
| 5932 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 5933 | return 1; |
| 5934 | } |
| 5935 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5936 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5937 | res = obj2ast_expr(tmp, &annotation, arena); |
| 5938 | if (res != 0) goto failed; |
| 5939 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5940 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5941 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5942 | return 1; |
| 5943 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5944 | if (tmp == NULL || tmp == Py_None) { |
| 5945 | Py_CLEAR(tmp); |
| 5946 | value = NULL; |
| 5947 | } |
| 5948 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5949 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5950 | res = obj2ast_expr(tmp, &value, arena); |
| 5951 | if (res != 0) goto failed; |
| 5952 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5953 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5954 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 5955 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5956 | return 1; |
| 5957 | } |
| 5958 | if (tmp == NULL) { |
| 5959 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 5960 | return 1; |
| 5961 | } |
| 5962 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5963 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5964 | res = obj2ast_int(tmp, &simple, arena); |
| 5965 | if (res != 0) goto failed; |
| 5966 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5967 | } |
| 5968 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5969 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5970 | if (*out == NULL) goto failed; |
| 5971 | return 0; |
| 5972 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5973 | tp = astmodulestate_global->For_type; |
| 5974 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5975 | if (isinstance == -1) { |
| 5976 | return 1; |
| 5977 | } |
| 5978 | if (isinstance) { |
| 5979 | expr_ty target; |
| 5980 | expr_ty iter; |
| 5981 | asdl_seq* body; |
| 5982 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5983 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5984 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5985 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5986 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5987 | return 1; |
| 5988 | } |
| 5989 | if (tmp == NULL) { |
| 5990 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 5991 | return 1; |
| 5992 | } |
| 5993 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5994 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5995 | res = obj2ast_expr(tmp, &target, arena); |
| 5996 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5997 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5998 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5999 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6000 | return 1; |
| 6001 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6002 | if (tmp == NULL) { |
| 6003 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6004 | return 1; |
| 6005 | } |
| 6006 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6007 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6008 | res = obj2ast_expr(tmp, &iter, arena); |
| 6009 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6010 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6011 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6012 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6013 | return 1; |
| 6014 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6015 | if (tmp == NULL) { |
| 6016 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6017 | return 1; |
| 6018 | } |
| 6019 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6020 | int res; |
| 6021 | Py_ssize_t len; |
| 6022 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6023 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6024 | 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] | 6025 | goto failed; |
| 6026 | } |
| 6027 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6028 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6029 | if (body == NULL) goto failed; |
| 6030 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6031 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6032 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6033 | Py_INCREF(tmp2); |
| 6034 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6035 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6036 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6037 | if (len != PyList_GET_SIZE(tmp)) { |
| 6038 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6039 | goto failed; |
| 6040 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6041 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6042 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6043 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6044 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6045 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6046 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6047 | return 1; |
| 6048 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6049 | if (tmp == NULL) { |
| 6050 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6051 | return 1; |
| 6052 | } |
| 6053 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6054 | int res; |
| 6055 | Py_ssize_t len; |
| 6056 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6057 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6058 | 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] | 6059 | goto failed; |
| 6060 | } |
| 6061 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6062 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6063 | if (orelse == NULL) goto failed; |
| 6064 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6065 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6066 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6067 | Py_INCREF(tmp2); |
| 6068 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6069 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6070 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6071 | if (len != PyList_GET_SIZE(tmp)) { |
| 6072 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6073 | goto failed; |
| 6074 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6075 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6076 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6077 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6078 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6079 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6080 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6081 | return 1; |
| 6082 | } |
| 6083 | if (tmp == NULL || tmp == Py_None) { |
| 6084 | Py_CLEAR(tmp); |
| 6085 | type_comment = NULL; |
| 6086 | } |
| 6087 | else { |
| 6088 | int res; |
| 6089 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6090 | if (res != 0) goto failed; |
| 6091 | Py_CLEAR(tmp); |
| 6092 | } |
| 6093 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6094 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6095 | if (*out == NULL) goto failed; |
| 6096 | return 0; |
| 6097 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6098 | tp = astmodulestate_global->AsyncFor_type; |
| 6099 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6100 | if (isinstance == -1) { |
| 6101 | return 1; |
| 6102 | } |
| 6103 | if (isinstance) { |
| 6104 | expr_ty target; |
| 6105 | expr_ty iter; |
| 6106 | asdl_seq* body; |
| 6107 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6108 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6109 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6110 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6111 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6112 | return 1; |
| 6113 | } |
| 6114 | if (tmp == NULL) { |
| 6115 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6116 | return 1; |
| 6117 | } |
| 6118 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6119 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6120 | res = obj2ast_expr(tmp, &target, arena); |
| 6121 | if (res != 0) goto failed; |
| 6122 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6123 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6124 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6125 | return 1; |
| 6126 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6127 | if (tmp == NULL) { |
| 6128 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6129 | return 1; |
| 6130 | } |
| 6131 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6132 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6133 | res = obj2ast_expr(tmp, &iter, arena); |
| 6134 | if (res != 0) goto failed; |
| 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->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6138 | return 1; |
| 6139 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6140 | if (tmp == NULL) { |
| 6141 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6142 | return 1; |
| 6143 | } |
| 6144 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6145 | int res; |
| 6146 | Py_ssize_t len; |
| 6147 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6148 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6149 | 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] | 6150 | goto failed; |
| 6151 | } |
| 6152 | len = PyList_GET_SIZE(tmp); |
| 6153 | body = _Py_asdl_seq_new(len, arena); |
| 6154 | if (body == NULL) goto failed; |
| 6155 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6156 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6157 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6158 | Py_INCREF(tmp2); |
| 6159 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6160 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6161 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6162 | if (len != PyList_GET_SIZE(tmp)) { |
| 6163 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6164 | goto failed; |
| 6165 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6166 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6167 | } |
| 6168 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6169 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6170 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6171 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6172 | return 1; |
| 6173 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6174 | if (tmp == NULL) { |
| 6175 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6176 | return 1; |
| 6177 | } |
| 6178 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6179 | int res; |
| 6180 | Py_ssize_t len; |
| 6181 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6182 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6183 | 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] | 6184 | goto failed; |
| 6185 | } |
| 6186 | len = PyList_GET_SIZE(tmp); |
| 6187 | orelse = _Py_asdl_seq_new(len, arena); |
| 6188 | if (orelse == NULL) goto failed; |
| 6189 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6190 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6191 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6192 | Py_INCREF(tmp2); |
| 6193 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6194 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6195 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6196 | if (len != PyList_GET_SIZE(tmp)) { |
| 6197 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6198 | goto failed; |
| 6199 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6200 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6201 | } |
| 6202 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6203 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6204 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6205 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6206 | return 1; |
| 6207 | } |
| 6208 | if (tmp == NULL || tmp == Py_None) { |
| 6209 | Py_CLEAR(tmp); |
| 6210 | type_comment = NULL; |
| 6211 | } |
| 6212 | else { |
| 6213 | int res; |
| 6214 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6215 | if (res != 0) goto failed; |
| 6216 | Py_CLEAR(tmp); |
| 6217 | } |
| 6218 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6219 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6220 | if (*out == NULL) goto failed; |
| 6221 | return 0; |
| 6222 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6223 | tp = astmodulestate_global->While_type; |
| 6224 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6225 | if (isinstance == -1) { |
| 6226 | return 1; |
| 6227 | } |
| 6228 | if (isinstance) { |
| 6229 | expr_ty test; |
| 6230 | asdl_seq* body; |
| 6231 | asdl_seq* orelse; |
| 6232 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6233 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6234 | return 1; |
| 6235 | } |
| 6236 | if (tmp == NULL) { |
| 6237 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6238 | return 1; |
| 6239 | } |
| 6240 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6241 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6242 | res = obj2ast_expr(tmp, &test, arena); |
| 6243 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6244 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6245 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6246 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6247 | return 1; |
| 6248 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6249 | if (tmp == NULL) { |
| 6250 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6251 | return 1; |
| 6252 | } |
| 6253 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6254 | int res; |
| 6255 | Py_ssize_t len; |
| 6256 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6257 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6258 | 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] | 6259 | goto failed; |
| 6260 | } |
| 6261 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6262 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6263 | if (body == NULL) goto failed; |
| 6264 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6265 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6266 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6267 | Py_INCREF(tmp2); |
| 6268 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6269 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6270 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6271 | if (len != PyList_GET_SIZE(tmp)) { |
| 6272 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6273 | goto failed; |
| 6274 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6275 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6276 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6277 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6278 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6279 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6280 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6281 | return 1; |
| 6282 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6283 | if (tmp == NULL) { |
| 6284 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6285 | return 1; |
| 6286 | } |
| 6287 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6288 | int res; |
| 6289 | Py_ssize_t len; |
| 6290 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6291 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6292 | 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] | 6293 | goto failed; |
| 6294 | } |
| 6295 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6296 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6297 | if (orelse == NULL) goto failed; |
| 6298 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6299 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6300 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6301 | Py_INCREF(tmp2); |
| 6302 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6303 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6304 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6305 | if (len != PyList_GET_SIZE(tmp)) { |
| 6306 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6307 | goto failed; |
| 6308 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6309 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6310 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6311 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6312 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6313 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6314 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6315 | if (*out == NULL) goto failed; |
| 6316 | return 0; |
| 6317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6318 | tp = astmodulestate_global->If_type; |
| 6319 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6320 | if (isinstance == -1) { |
| 6321 | return 1; |
| 6322 | } |
| 6323 | if (isinstance) { |
| 6324 | expr_ty test; |
| 6325 | asdl_seq* body; |
| 6326 | asdl_seq* orelse; |
| 6327 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6328 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6329 | return 1; |
| 6330 | } |
| 6331 | if (tmp == NULL) { |
| 6332 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6333 | return 1; |
| 6334 | } |
| 6335 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6336 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6337 | res = obj2ast_expr(tmp, &test, arena); |
| 6338 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6339 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6340 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6341 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6342 | return 1; |
| 6343 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6344 | if (tmp == NULL) { |
| 6345 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6346 | return 1; |
| 6347 | } |
| 6348 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6349 | int res; |
| 6350 | Py_ssize_t len; |
| 6351 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6352 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6353 | 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] | 6354 | goto failed; |
| 6355 | } |
| 6356 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6357 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6358 | if (body == NULL) goto failed; |
| 6359 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6360 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6361 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6362 | Py_INCREF(tmp2); |
| 6363 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6364 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6365 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6366 | if (len != PyList_GET_SIZE(tmp)) { |
| 6367 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6368 | goto failed; |
| 6369 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6370 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6371 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6372 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6374 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6375 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6376 | return 1; |
| 6377 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6378 | if (tmp == NULL) { |
| 6379 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6380 | return 1; |
| 6381 | } |
| 6382 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6383 | int res; |
| 6384 | Py_ssize_t len; |
| 6385 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6386 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6387 | 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] | 6388 | goto failed; |
| 6389 | } |
| 6390 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6391 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6392 | if (orelse == NULL) goto failed; |
| 6393 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6394 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6395 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6396 | Py_INCREF(tmp2); |
| 6397 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6398 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6399 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6400 | if (len != PyList_GET_SIZE(tmp)) { |
| 6401 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6402 | goto failed; |
| 6403 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6404 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6405 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6406 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6407 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6408 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6409 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6410 | if (*out == NULL) goto failed; |
| 6411 | return 0; |
| 6412 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6413 | tp = astmodulestate_global->With_type; |
| 6414 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6415 | if (isinstance == -1) { |
| 6416 | return 1; |
| 6417 | } |
| 6418 | if (isinstance) { |
| 6419 | asdl_seq* items; |
| 6420 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6421 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6422 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6423 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6424 | return 1; |
| 6425 | } |
| 6426 | if (tmp == NULL) { |
| 6427 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6428 | return 1; |
| 6429 | } |
| 6430 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6431 | int res; |
| 6432 | Py_ssize_t len; |
| 6433 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6434 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6435 | 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] | 6436 | goto failed; |
| 6437 | } |
| 6438 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6439 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6440 | if (items == NULL) goto failed; |
| 6441 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6442 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6443 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6444 | Py_INCREF(tmp2); |
| 6445 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6446 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6447 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6448 | if (len != PyList_GET_SIZE(tmp)) { |
| 6449 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6450 | goto failed; |
| 6451 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6452 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6453 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6454 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6455 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6456 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6457 | return 1; |
| 6458 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6459 | if (tmp == NULL) { |
| 6460 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6461 | return 1; |
| 6462 | } |
| 6463 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6464 | int res; |
| 6465 | Py_ssize_t len; |
| 6466 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6467 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6468 | 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] | 6469 | goto failed; |
| 6470 | } |
| 6471 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6472 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6473 | if (body == NULL) goto failed; |
| 6474 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6475 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6476 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6477 | Py_INCREF(tmp2); |
| 6478 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6479 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6480 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6481 | if (len != PyList_GET_SIZE(tmp)) { |
| 6482 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6483 | goto failed; |
| 6484 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6485 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6486 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6487 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6488 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6489 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6490 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6491 | return 1; |
| 6492 | } |
| 6493 | if (tmp == NULL || tmp == Py_None) { |
| 6494 | Py_CLEAR(tmp); |
| 6495 | type_comment = NULL; |
| 6496 | } |
| 6497 | else { |
| 6498 | int res; |
| 6499 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6500 | if (res != 0) goto failed; |
| 6501 | Py_CLEAR(tmp); |
| 6502 | } |
| 6503 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6504 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6505 | if (*out == NULL) goto failed; |
| 6506 | return 0; |
| 6507 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6508 | tp = astmodulestate_global->AsyncWith_type; |
| 6509 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6510 | if (isinstance == -1) { |
| 6511 | return 1; |
| 6512 | } |
| 6513 | if (isinstance) { |
| 6514 | asdl_seq* items; |
| 6515 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6516 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6517 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6518 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6519 | return 1; |
| 6520 | } |
| 6521 | if (tmp == NULL) { |
| 6522 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6523 | return 1; |
| 6524 | } |
| 6525 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6526 | int res; |
| 6527 | Py_ssize_t len; |
| 6528 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6529 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6530 | 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] | 6531 | goto failed; |
| 6532 | } |
| 6533 | len = PyList_GET_SIZE(tmp); |
| 6534 | items = _Py_asdl_seq_new(len, arena); |
| 6535 | if (items == NULL) goto failed; |
| 6536 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6537 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6538 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6539 | Py_INCREF(tmp2); |
| 6540 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6541 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6542 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6543 | if (len != PyList_GET_SIZE(tmp)) { |
| 6544 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6545 | goto failed; |
| 6546 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6547 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6548 | } |
| 6549 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6550 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6551 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6552 | return 1; |
| 6553 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6554 | if (tmp == NULL) { |
| 6555 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6556 | return 1; |
| 6557 | } |
| 6558 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6559 | int res; |
| 6560 | Py_ssize_t len; |
| 6561 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6562 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6563 | 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] | 6564 | goto failed; |
| 6565 | } |
| 6566 | len = PyList_GET_SIZE(tmp); |
| 6567 | body = _Py_asdl_seq_new(len, arena); |
| 6568 | if (body == NULL) goto failed; |
| 6569 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6570 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6571 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6572 | Py_INCREF(tmp2); |
| 6573 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6574 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6575 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6576 | if (len != PyList_GET_SIZE(tmp)) { |
| 6577 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6578 | goto failed; |
| 6579 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6580 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6581 | } |
| 6582 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6583 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6584 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6585 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6586 | return 1; |
| 6587 | } |
| 6588 | if (tmp == NULL || tmp == Py_None) { |
| 6589 | Py_CLEAR(tmp); |
| 6590 | type_comment = NULL; |
| 6591 | } |
| 6592 | else { |
| 6593 | int res; |
| 6594 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6595 | if (res != 0) goto failed; |
| 6596 | Py_CLEAR(tmp); |
| 6597 | } |
| 6598 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6599 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6600 | if (*out == NULL) goto failed; |
| 6601 | return 0; |
| 6602 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6603 | tp = astmodulestate_global->Raise_type; |
| 6604 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6605 | if (isinstance == -1) { |
| 6606 | return 1; |
| 6607 | } |
| 6608 | if (isinstance) { |
| 6609 | expr_ty exc; |
| 6610 | expr_ty cause; |
| 6611 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6612 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6613 | return 1; |
| 6614 | } |
| 6615 | if (tmp == NULL || tmp == Py_None) { |
| 6616 | Py_CLEAR(tmp); |
| 6617 | exc = NULL; |
| 6618 | } |
| 6619 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6620 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6621 | res = obj2ast_expr(tmp, &exc, arena); |
| 6622 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6623 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6624 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6625 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6626 | return 1; |
| 6627 | } |
| 6628 | if (tmp == NULL || tmp == Py_None) { |
| 6629 | Py_CLEAR(tmp); |
| 6630 | cause = NULL; |
| 6631 | } |
| 6632 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6633 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6634 | res = obj2ast_expr(tmp, &cause, arena); |
| 6635 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6636 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6637 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6638 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6639 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6640 | if (*out == NULL) goto failed; |
| 6641 | return 0; |
| 6642 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6643 | tp = astmodulestate_global->Try_type; |
| 6644 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6645 | if (isinstance == -1) { |
| 6646 | return 1; |
| 6647 | } |
| 6648 | if (isinstance) { |
| 6649 | asdl_seq* body; |
| 6650 | asdl_seq* handlers; |
| 6651 | asdl_seq* orelse; |
| 6652 | asdl_seq* finalbody; |
| 6653 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6654 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6655 | return 1; |
| 6656 | } |
| 6657 | if (tmp == NULL) { |
| 6658 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6659 | return 1; |
| 6660 | } |
| 6661 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6662 | int res; |
| 6663 | Py_ssize_t len; |
| 6664 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6665 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6666 | 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] | 6667 | goto failed; |
| 6668 | } |
| 6669 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6670 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6671 | if (body == NULL) goto failed; |
| 6672 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6673 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6674 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6675 | Py_INCREF(tmp2); |
| 6676 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6677 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6678 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6679 | if (len != PyList_GET_SIZE(tmp)) { |
| 6680 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6681 | goto failed; |
| 6682 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6683 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6684 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6685 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6686 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6687 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6688 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6689 | return 1; |
| 6690 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6691 | if (tmp == NULL) { |
| 6692 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6693 | return 1; |
| 6694 | } |
| 6695 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6696 | int res; |
| 6697 | Py_ssize_t len; |
| 6698 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6699 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6700 | 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] | 6701 | goto failed; |
| 6702 | } |
| 6703 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6704 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6705 | if (handlers == NULL) goto failed; |
| 6706 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6707 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6708 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6709 | Py_INCREF(tmp2); |
| 6710 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6711 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6712 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6713 | if (len != PyList_GET_SIZE(tmp)) { |
| 6714 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6715 | goto failed; |
| 6716 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6717 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6718 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6719 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6720 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6721 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6722 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6723 | return 1; |
| 6724 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6725 | if (tmp == NULL) { |
| 6726 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6727 | return 1; |
| 6728 | } |
| 6729 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6730 | int res; |
| 6731 | Py_ssize_t len; |
| 6732 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6733 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6734 | 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] | 6735 | goto failed; |
| 6736 | } |
| 6737 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6738 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6739 | if (orelse == NULL) goto failed; |
| 6740 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6741 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6742 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6743 | Py_INCREF(tmp2); |
| 6744 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6745 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6746 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6747 | if (len != PyList_GET_SIZE(tmp)) { |
| 6748 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6749 | goto failed; |
| 6750 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6751 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6752 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6753 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6754 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6755 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6756 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6757 | return 1; |
| 6758 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6759 | if (tmp == NULL) { |
| 6760 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6761 | return 1; |
| 6762 | } |
| 6763 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6764 | int res; |
| 6765 | Py_ssize_t len; |
| 6766 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6767 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6768 | 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] | 6769 | goto failed; |
| 6770 | } |
| 6771 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6772 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6773 | if (finalbody == NULL) goto failed; |
| 6774 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6775 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6776 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6777 | Py_INCREF(tmp2); |
| 6778 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6779 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6780 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6781 | if (len != PyList_GET_SIZE(tmp)) { |
| 6782 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6783 | goto failed; |
| 6784 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6785 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6786 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6787 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6788 | } |
| 6789 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6790 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6791 | if (*out == NULL) goto failed; |
| 6792 | return 0; |
| 6793 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6794 | tp = astmodulestate_global->Assert_type; |
| 6795 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6796 | if (isinstance == -1) { |
| 6797 | return 1; |
| 6798 | } |
| 6799 | if (isinstance) { |
| 6800 | expr_ty test; |
| 6801 | expr_ty msg; |
| 6802 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6803 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6804 | return 1; |
| 6805 | } |
| 6806 | if (tmp == NULL) { |
| 6807 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6808 | return 1; |
| 6809 | } |
| 6810 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6811 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6812 | res = obj2ast_expr(tmp, &test, arena); |
| 6813 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6814 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6815 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6816 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6817 | return 1; |
| 6818 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6819 | if (tmp == NULL || tmp == Py_None) { |
| 6820 | Py_CLEAR(tmp); |
| 6821 | msg = NULL; |
| 6822 | } |
| 6823 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6824 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6825 | res = obj2ast_expr(tmp, &msg, arena); |
| 6826 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6827 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6828 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6829 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6830 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6831 | if (*out == NULL) goto failed; |
| 6832 | return 0; |
| 6833 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6834 | tp = astmodulestate_global->Import_type; |
| 6835 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6836 | if (isinstance == -1) { |
| 6837 | return 1; |
| 6838 | } |
| 6839 | if (isinstance) { |
| 6840 | asdl_seq* names; |
| 6841 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6842 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6843 | return 1; |
| 6844 | } |
| 6845 | if (tmp == NULL) { |
| 6846 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6847 | return 1; |
| 6848 | } |
| 6849 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6850 | int res; |
| 6851 | Py_ssize_t len; |
| 6852 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6853 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6854 | 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] | 6855 | goto failed; |
| 6856 | } |
| 6857 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6858 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6859 | if (names == NULL) goto failed; |
| 6860 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6861 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6862 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6863 | Py_INCREF(tmp2); |
| 6864 | res = obj2ast_alias(tmp2, &val, arena); |
| 6865 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6866 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6867 | if (len != PyList_GET_SIZE(tmp)) { |
| 6868 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 6869 | goto failed; |
| 6870 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6871 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6872 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6873 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6874 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6875 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6876 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6877 | if (*out == NULL) goto failed; |
| 6878 | return 0; |
| 6879 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6880 | tp = astmodulestate_global->ImportFrom_type; |
| 6881 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6882 | if (isinstance == -1) { |
| 6883 | return 1; |
| 6884 | } |
| 6885 | if (isinstance) { |
| 6886 | identifier module; |
| 6887 | asdl_seq* names; |
| 6888 | int level; |
| 6889 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6890 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 6891 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6892 | return 1; |
| 6893 | } |
| 6894 | if (tmp == NULL || tmp == Py_None) { |
| 6895 | Py_CLEAR(tmp); |
| 6896 | module = NULL; |
| 6897 | } |
| 6898 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6899 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6900 | res = obj2ast_identifier(tmp, &module, arena); |
| 6901 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6902 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6903 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6904 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6905 | return 1; |
| 6906 | } |
| 6907 | if (tmp == NULL) { |
| 6908 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 6909 | return 1; |
| 6910 | } |
| 6911 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6912 | int res; |
| 6913 | Py_ssize_t len; |
| 6914 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6915 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6916 | 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] | 6917 | goto failed; |
| 6918 | } |
| 6919 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6920 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6921 | if (names == NULL) goto failed; |
| 6922 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6923 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6924 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6925 | Py_INCREF(tmp2); |
| 6926 | res = obj2ast_alias(tmp2, &val, arena); |
| 6927 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6928 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6929 | if (len != PyList_GET_SIZE(tmp)) { |
| 6930 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 6931 | goto failed; |
| 6932 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6933 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6934 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6935 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6936 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6937 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6938 | return 1; |
| 6939 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6940 | if (tmp == NULL || tmp == Py_None) { |
| 6941 | Py_CLEAR(tmp); |
| 6942 | level = 0; |
| 6943 | } |
| 6944 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6945 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6946 | res = obj2ast_int(tmp, &level, arena); |
| 6947 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6948 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6949 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6950 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 6951 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6952 | if (*out == NULL) goto failed; |
| 6953 | return 0; |
| 6954 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6955 | tp = astmodulestate_global->Global_type; |
| 6956 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6957 | if (isinstance == -1) { |
| 6958 | return 1; |
| 6959 | } |
| 6960 | if (isinstance) { |
| 6961 | asdl_seq* names; |
| 6962 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6963 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6964 | return 1; |
| 6965 | } |
| 6966 | if (tmp == NULL) { |
| 6967 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 6968 | return 1; |
| 6969 | } |
| 6970 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6971 | int res; |
| 6972 | Py_ssize_t len; |
| 6973 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6974 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6975 | 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] | 6976 | goto failed; |
| 6977 | } |
| 6978 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6979 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6980 | if (names == NULL) goto failed; |
| 6981 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6982 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6983 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6984 | Py_INCREF(tmp2); |
| 6985 | res = obj2ast_identifier(tmp2, &val, arena); |
| 6986 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6987 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6988 | if (len != PyList_GET_SIZE(tmp)) { |
| 6989 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 6990 | goto failed; |
| 6991 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6992 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6993 | } |
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 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6996 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6997 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6998 | if (*out == NULL) goto failed; |
| 6999 | return 0; |
| 7000 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7001 | tp = astmodulestate_global->Nonlocal_type; |
| 7002 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7003 | if (isinstance == -1) { |
| 7004 | return 1; |
| 7005 | } |
| 7006 | if (isinstance) { |
| 7007 | asdl_seq* names; |
| 7008 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7009 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7010 | return 1; |
| 7011 | } |
| 7012 | if (tmp == NULL) { |
| 7013 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7014 | return 1; |
| 7015 | } |
| 7016 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7017 | int res; |
| 7018 | Py_ssize_t len; |
| 7019 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7020 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7021 | 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] | 7022 | goto failed; |
| 7023 | } |
| 7024 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7025 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7026 | if (names == NULL) goto failed; |
| 7027 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7028 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7029 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7030 | Py_INCREF(tmp2); |
| 7031 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7032 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7033 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7034 | if (len != PyList_GET_SIZE(tmp)) { |
| 7035 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7036 | goto failed; |
| 7037 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7038 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7039 | } |
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 = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7043 | 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->Expr_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 | expr_ty value; |
| 7054 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7055 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &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 \"value\" missing from Expr"); |
| 7060 | return 1; |
| 7061 | } |
| 7062 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7063 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7064 | res = obj2ast_expr(tmp, &value, arena); |
| 7065 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7066 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7067 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7068 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7069 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7070 | if (*out == NULL) goto failed; |
| 7071 | return 0; |
| 7072 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7073 | tp = astmodulestate_global->Pass_type; |
| 7074 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7075 | if (isinstance == -1) { |
| 7076 | return 1; |
| 7077 | } |
| 7078 | if (isinstance) { |
| 7079 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7080 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7081 | if (*out == NULL) goto failed; |
| 7082 | return 0; |
| 7083 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7084 | tp = astmodulestate_global->Break_type; |
| 7085 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7086 | if (isinstance == -1) { |
| 7087 | return 1; |
| 7088 | } |
| 7089 | if (isinstance) { |
| 7090 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7091 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7092 | if (*out == NULL) goto failed; |
| 7093 | return 0; |
| 7094 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7095 | tp = astmodulestate_global->Continue_type; |
| 7096 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7097 | if (isinstance == -1) { |
| 7098 | return 1; |
| 7099 | } |
| 7100 | if (isinstance) { |
| 7101 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7102 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7103 | if (*out == NULL) goto failed; |
| 7104 | return 0; |
| 7105 | } |
| 7106 | |
| 7107 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7108 | failed: |
| 7109 | Py_XDECREF(tmp); |
| 7110 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7111 | } |
| 7112 | |
| 7113 | int |
| 7114 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7115 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7116 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7117 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7118 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7119 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7120 | int lineno; |
| 7121 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7122 | int end_lineno; |
| 7123 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7124 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7125 | if (obj == Py_None) { |
| 7126 | *out = NULL; |
| 7127 | return 0; |
| 7128 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7129 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7130 | return 1; |
| 7131 | } |
| 7132 | if (tmp == NULL) { |
| 7133 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7134 | return 1; |
| 7135 | } |
| 7136 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7137 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7138 | res = obj2ast_int(tmp, &lineno, arena); |
| 7139 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7140 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7141 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7142 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7143 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7144 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7145 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7146 | if (tmp == NULL) { |
| 7147 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7148 | return 1; |
| 7149 | } |
| 7150 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7151 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7152 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7153 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7154 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7155 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7156 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7157 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7158 | return 1; |
| 7159 | } |
| 7160 | if (tmp == NULL || tmp == Py_None) { |
| 7161 | Py_CLEAR(tmp); |
| 7162 | end_lineno = 0; |
| 7163 | } |
| 7164 | else { |
| 7165 | int res; |
| 7166 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7167 | if (res != 0) goto failed; |
| 7168 | Py_CLEAR(tmp); |
| 7169 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7170 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7171 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7172 | return 1; |
| 7173 | } |
| 7174 | if (tmp == NULL || tmp == Py_None) { |
| 7175 | Py_CLEAR(tmp); |
| 7176 | end_col_offset = 0; |
| 7177 | } |
| 7178 | else { |
| 7179 | int res; |
| 7180 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7181 | if (res != 0) goto failed; |
| 7182 | Py_CLEAR(tmp); |
| 7183 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7184 | tp = astmodulestate_global->BoolOp_type; |
| 7185 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7186 | if (isinstance == -1) { |
| 7187 | return 1; |
| 7188 | } |
| 7189 | if (isinstance) { |
| 7190 | boolop_ty op; |
| 7191 | asdl_seq* values; |
| 7192 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7193 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7194 | return 1; |
| 7195 | } |
| 7196 | if (tmp == NULL) { |
| 7197 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7198 | return 1; |
| 7199 | } |
| 7200 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7201 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7202 | res = obj2ast_boolop(tmp, &op, arena); |
| 7203 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7204 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7205 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7206 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7207 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7208 | return 1; |
| 7209 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7210 | if (tmp == NULL) { |
| 7211 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7212 | return 1; |
| 7213 | } |
| 7214 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7215 | int res; |
| 7216 | Py_ssize_t len; |
| 7217 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7218 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7219 | 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] | 7220 | goto failed; |
| 7221 | } |
| 7222 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7223 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7224 | if (values == NULL) goto failed; |
| 7225 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7226 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7227 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7228 | Py_INCREF(tmp2); |
| 7229 | res = obj2ast_expr(tmp2, &val, arena); |
| 7230 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7231 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7232 | if (len != PyList_GET_SIZE(tmp)) { |
| 7233 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7234 | goto failed; |
| 7235 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7236 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7237 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7238 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7239 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7240 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7241 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7242 | if (*out == NULL) goto failed; |
| 7243 | return 0; |
| 7244 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7245 | tp = astmodulestate_global->NamedExpr_type; |
| 7246 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7247 | if (isinstance == -1) { |
| 7248 | return 1; |
| 7249 | } |
| 7250 | if (isinstance) { |
| 7251 | expr_ty target; |
| 7252 | expr_ty value; |
| 7253 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7254 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7255 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7256 | return 1; |
| 7257 | } |
| 7258 | if (tmp == NULL) { |
| 7259 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7260 | return 1; |
| 7261 | } |
| 7262 | else { |
| 7263 | int res; |
| 7264 | res = obj2ast_expr(tmp, &target, arena); |
| 7265 | if (res != 0) goto failed; |
| 7266 | Py_CLEAR(tmp); |
| 7267 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7268 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7269 | return 1; |
| 7270 | } |
| 7271 | if (tmp == NULL) { |
| 7272 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7273 | return 1; |
| 7274 | } |
| 7275 | else { |
| 7276 | int res; |
| 7277 | res = obj2ast_expr(tmp, &value, arena); |
| 7278 | if (res != 0) goto failed; |
| 7279 | Py_CLEAR(tmp); |
| 7280 | } |
| 7281 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7282 | end_col_offset, arena); |
| 7283 | if (*out == NULL) goto failed; |
| 7284 | return 0; |
| 7285 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7286 | tp = astmodulestate_global->BinOp_type; |
| 7287 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7288 | if (isinstance == -1) { |
| 7289 | return 1; |
| 7290 | } |
| 7291 | if (isinstance) { |
| 7292 | expr_ty left; |
| 7293 | operator_ty op; |
| 7294 | expr_ty right; |
| 7295 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7296 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7297 | return 1; |
| 7298 | } |
| 7299 | if (tmp == NULL) { |
| 7300 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7301 | return 1; |
| 7302 | } |
| 7303 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7304 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7305 | res = obj2ast_expr(tmp, &left, arena); |
| 7306 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7307 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7308 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7309 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7310 | return 1; |
| 7311 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7312 | if (tmp == NULL) { |
| 7313 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7314 | return 1; |
| 7315 | } |
| 7316 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7317 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7318 | res = obj2ast_operator(tmp, &op, arena); |
| 7319 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7320 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7321 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7322 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7323 | return 1; |
| 7324 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7325 | if (tmp == NULL) { |
| 7326 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7327 | return 1; |
| 7328 | } |
| 7329 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7330 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7331 | res = obj2ast_expr(tmp, &right, arena); |
| 7332 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7333 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7334 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7335 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7336 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7337 | if (*out == NULL) goto failed; |
| 7338 | return 0; |
| 7339 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7340 | tp = astmodulestate_global->UnaryOp_type; |
| 7341 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7342 | if (isinstance == -1) { |
| 7343 | return 1; |
| 7344 | } |
| 7345 | if (isinstance) { |
| 7346 | unaryop_ty op; |
| 7347 | expr_ty operand; |
| 7348 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7349 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7350 | return 1; |
| 7351 | } |
| 7352 | if (tmp == NULL) { |
| 7353 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7354 | return 1; |
| 7355 | } |
| 7356 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7357 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7358 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7359 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7360 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7361 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7362 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7363 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7364 | return 1; |
| 7365 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7366 | if (tmp == NULL) { |
| 7367 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7368 | return 1; |
| 7369 | } |
| 7370 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7371 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7372 | res = obj2ast_expr(tmp, &operand, arena); |
| 7373 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7374 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7375 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7376 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7377 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7378 | if (*out == NULL) goto failed; |
| 7379 | return 0; |
| 7380 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7381 | tp = astmodulestate_global->Lambda_type; |
| 7382 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7383 | if (isinstance == -1) { |
| 7384 | return 1; |
| 7385 | } |
| 7386 | if (isinstance) { |
| 7387 | arguments_ty args; |
| 7388 | expr_ty body; |
| 7389 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7390 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7391 | return 1; |
| 7392 | } |
| 7393 | if (tmp == NULL) { |
| 7394 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7395 | return 1; |
| 7396 | } |
| 7397 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7398 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7399 | res = obj2ast_arguments(tmp, &args, arena); |
| 7400 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7401 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7402 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7403 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7404 | return 1; |
| 7405 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7406 | if (tmp == NULL) { |
| 7407 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7408 | return 1; |
| 7409 | } |
| 7410 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7411 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7412 | res = obj2ast_expr(tmp, &body, arena); |
| 7413 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7414 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7415 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7416 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7417 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7418 | if (*out == NULL) goto failed; |
| 7419 | return 0; |
| 7420 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7421 | tp = astmodulestate_global->IfExp_type; |
| 7422 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7423 | if (isinstance == -1) { |
| 7424 | return 1; |
| 7425 | } |
| 7426 | if (isinstance) { |
| 7427 | expr_ty test; |
| 7428 | expr_ty body; |
| 7429 | expr_ty orelse; |
| 7430 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7431 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7432 | return 1; |
| 7433 | } |
| 7434 | if (tmp == NULL) { |
| 7435 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7436 | return 1; |
| 7437 | } |
| 7438 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7439 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7440 | res = obj2ast_expr(tmp, &test, arena); |
| 7441 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7442 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7443 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7444 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7445 | return 1; |
| 7446 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7447 | if (tmp == NULL) { |
| 7448 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7449 | return 1; |
| 7450 | } |
| 7451 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7452 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7453 | res = obj2ast_expr(tmp, &body, arena); |
| 7454 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7455 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7456 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7457 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7458 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7459 | return 1; |
| 7460 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7461 | if (tmp == NULL) { |
| 7462 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7463 | return 1; |
| 7464 | } |
| 7465 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7466 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7467 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7468 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7469 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7470 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7471 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7472 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7473 | if (*out == NULL) goto failed; |
| 7474 | return 0; |
| 7475 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7476 | tp = astmodulestate_global->Dict_type; |
| 7477 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7478 | if (isinstance == -1) { |
| 7479 | return 1; |
| 7480 | } |
| 7481 | if (isinstance) { |
| 7482 | asdl_seq* keys; |
| 7483 | asdl_seq* values; |
| 7484 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7485 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7486 | return 1; |
| 7487 | } |
| 7488 | if (tmp == NULL) { |
| 7489 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7490 | return 1; |
| 7491 | } |
| 7492 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7493 | int res; |
| 7494 | Py_ssize_t len; |
| 7495 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7496 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7497 | 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] | 7498 | goto failed; |
| 7499 | } |
| 7500 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7501 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7502 | if (keys == NULL) goto failed; |
| 7503 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7504 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7505 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7506 | Py_INCREF(tmp2); |
| 7507 | res = obj2ast_expr(tmp2, &val, arena); |
| 7508 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7509 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7510 | if (len != PyList_GET_SIZE(tmp)) { |
| 7511 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7512 | goto failed; |
| 7513 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7514 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7515 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7516 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7517 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7518 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7519 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7520 | return 1; |
| 7521 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7522 | if (tmp == NULL) { |
| 7523 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7524 | return 1; |
| 7525 | } |
| 7526 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7527 | int res; |
| 7528 | Py_ssize_t len; |
| 7529 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7530 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7531 | 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] | 7532 | goto failed; |
| 7533 | } |
| 7534 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7535 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7536 | if (values == NULL) goto failed; |
| 7537 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7538 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7539 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7540 | Py_INCREF(tmp2); |
| 7541 | res = obj2ast_expr(tmp2, &val, arena); |
| 7542 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7543 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7544 | if (len != PyList_GET_SIZE(tmp)) { |
| 7545 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7546 | goto failed; |
| 7547 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7548 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7549 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7550 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7551 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7552 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7553 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7554 | if (*out == NULL) goto failed; |
| 7555 | return 0; |
| 7556 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7557 | tp = astmodulestate_global->Set_type; |
| 7558 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7559 | if (isinstance == -1) { |
| 7560 | return 1; |
| 7561 | } |
| 7562 | if (isinstance) { |
| 7563 | asdl_seq* elts; |
| 7564 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7565 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7566 | return 1; |
| 7567 | } |
| 7568 | if (tmp == NULL) { |
| 7569 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7570 | return 1; |
| 7571 | } |
| 7572 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7573 | int res; |
| 7574 | Py_ssize_t len; |
| 7575 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7576 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7577 | 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] | 7578 | goto failed; |
| 7579 | } |
| 7580 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7581 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7582 | if (elts == NULL) goto failed; |
| 7583 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7584 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7585 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7586 | Py_INCREF(tmp2); |
| 7587 | res = obj2ast_expr(tmp2, &val, arena); |
| 7588 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7589 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7590 | if (len != PyList_GET_SIZE(tmp)) { |
| 7591 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7592 | goto failed; |
| 7593 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7594 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7595 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7596 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7597 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7598 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7599 | if (*out == NULL) goto failed; |
| 7600 | return 0; |
| 7601 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7602 | tp = astmodulestate_global->ListComp_type; |
| 7603 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7604 | if (isinstance == -1) { |
| 7605 | return 1; |
| 7606 | } |
| 7607 | if (isinstance) { |
| 7608 | expr_ty elt; |
| 7609 | asdl_seq* generators; |
| 7610 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7611 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7612 | return 1; |
| 7613 | } |
| 7614 | if (tmp == NULL) { |
| 7615 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7616 | return 1; |
| 7617 | } |
| 7618 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7619 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7620 | res = obj2ast_expr(tmp, &elt, arena); |
| 7621 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7622 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7623 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7624 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7625 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7626 | return 1; |
| 7627 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7628 | if (tmp == NULL) { |
| 7629 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7630 | return 1; |
| 7631 | } |
| 7632 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7633 | int res; |
| 7634 | Py_ssize_t len; |
| 7635 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7636 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7637 | 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] | 7638 | goto failed; |
| 7639 | } |
| 7640 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7641 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7642 | if (generators == NULL) goto failed; |
| 7643 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7644 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7645 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7646 | Py_INCREF(tmp2); |
| 7647 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7648 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7649 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7650 | if (len != PyList_GET_SIZE(tmp)) { |
| 7651 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7652 | goto failed; |
| 7653 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7654 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7655 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7656 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7657 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7658 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7659 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7660 | if (*out == NULL) goto failed; |
| 7661 | return 0; |
| 7662 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7663 | tp = astmodulestate_global->SetComp_type; |
| 7664 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7665 | if (isinstance == -1) { |
| 7666 | return 1; |
| 7667 | } |
| 7668 | if (isinstance) { |
| 7669 | expr_ty elt; |
| 7670 | asdl_seq* generators; |
| 7671 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7672 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7673 | return 1; |
| 7674 | } |
| 7675 | if (tmp == NULL) { |
| 7676 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7677 | return 1; |
| 7678 | } |
| 7679 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7680 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7681 | res = obj2ast_expr(tmp, &elt, arena); |
| 7682 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7683 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7684 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7685 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7686 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7687 | return 1; |
| 7688 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7689 | if (tmp == NULL) { |
| 7690 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7691 | return 1; |
| 7692 | } |
| 7693 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7694 | int res; |
| 7695 | Py_ssize_t len; |
| 7696 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7697 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7698 | 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] | 7699 | goto failed; |
| 7700 | } |
| 7701 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7702 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7703 | if (generators == NULL) goto failed; |
| 7704 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7705 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7706 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7707 | Py_INCREF(tmp2); |
| 7708 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7709 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7710 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7711 | if (len != PyList_GET_SIZE(tmp)) { |
| 7712 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7713 | goto failed; |
| 7714 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7715 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7716 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7717 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7718 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7719 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7720 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7721 | if (*out == NULL) goto failed; |
| 7722 | return 0; |
| 7723 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7724 | tp = astmodulestate_global->DictComp_type; |
| 7725 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7726 | if (isinstance == -1) { |
| 7727 | return 1; |
| 7728 | } |
| 7729 | if (isinstance) { |
| 7730 | expr_ty key; |
| 7731 | expr_ty value; |
| 7732 | asdl_seq* generators; |
| 7733 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7734 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7735 | return 1; |
| 7736 | } |
| 7737 | if (tmp == NULL) { |
| 7738 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7739 | return 1; |
| 7740 | } |
| 7741 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7742 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7743 | res = obj2ast_expr(tmp, &key, arena); |
| 7744 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7745 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7746 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7747 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7748 | return 1; |
| 7749 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7750 | if (tmp == NULL) { |
| 7751 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7752 | return 1; |
| 7753 | } |
| 7754 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7755 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7756 | res = obj2ast_expr(tmp, &value, arena); |
| 7757 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7758 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7759 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7760 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7761 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7762 | return 1; |
| 7763 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7764 | if (tmp == NULL) { |
| 7765 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7766 | return 1; |
| 7767 | } |
| 7768 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7769 | int res; |
| 7770 | Py_ssize_t len; |
| 7771 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7772 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7773 | 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] | 7774 | goto failed; |
| 7775 | } |
| 7776 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7777 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7778 | if (generators == NULL) goto failed; |
| 7779 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7780 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7781 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7782 | Py_INCREF(tmp2); |
| 7783 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7784 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7785 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7786 | if (len != PyList_GET_SIZE(tmp)) { |
| 7787 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7788 | goto failed; |
| 7789 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7790 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7791 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7792 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7793 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7794 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7795 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7796 | if (*out == NULL) goto failed; |
| 7797 | return 0; |
| 7798 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7799 | tp = astmodulestate_global->GeneratorExp_type; |
| 7800 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7801 | if (isinstance == -1) { |
| 7802 | return 1; |
| 7803 | } |
| 7804 | if (isinstance) { |
| 7805 | expr_ty elt; |
| 7806 | asdl_seq* generators; |
| 7807 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7808 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7809 | return 1; |
| 7810 | } |
| 7811 | if (tmp == NULL) { |
| 7812 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7813 | return 1; |
| 7814 | } |
| 7815 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7816 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7817 | res = obj2ast_expr(tmp, &elt, arena); |
| 7818 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7819 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7820 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7821 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7822 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7823 | return 1; |
| 7824 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7825 | if (tmp == NULL) { |
| 7826 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7827 | return 1; |
| 7828 | } |
| 7829 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7830 | int res; |
| 7831 | Py_ssize_t len; |
| 7832 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7833 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7834 | 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] | 7835 | goto failed; |
| 7836 | } |
| 7837 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7838 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7839 | if (generators == NULL) goto failed; |
| 7840 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7841 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7842 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7843 | Py_INCREF(tmp2); |
| 7844 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7845 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7846 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7847 | if (len != PyList_GET_SIZE(tmp)) { |
| 7848 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7849 | goto failed; |
| 7850 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7851 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7852 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7853 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7854 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7855 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7856 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7857 | if (*out == NULL) goto failed; |
| 7858 | return 0; |
| 7859 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7860 | tp = astmodulestate_global->Await_type; |
| 7861 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7862 | if (isinstance == -1) { |
| 7863 | return 1; |
| 7864 | } |
| 7865 | if (isinstance) { |
| 7866 | expr_ty value; |
| 7867 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7868 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7869 | return 1; |
| 7870 | } |
| 7871 | if (tmp == NULL) { |
| 7872 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 7873 | return 1; |
| 7874 | } |
| 7875 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7876 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7877 | res = obj2ast_expr(tmp, &value, arena); |
| 7878 | if (res != 0) goto failed; |
| 7879 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7880 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7881 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7882 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7883 | if (*out == NULL) goto failed; |
| 7884 | return 0; |
| 7885 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7886 | tp = astmodulestate_global->Yield_type; |
| 7887 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7888 | if (isinstance == -1) { |
| 7889 | return 1; |
| 7890 | } |
| 7891 | if (isinstance) { |
| 7892 | expr_ty value; |
| 7893 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7894 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7895 | return 1; |
| 7896 | } |
| 7897 | if (tmp == NULL || tmp == Py_None) { |
| 7898 | Py_CLEAR(tmp); |
| 7899 | value = NULL; |
| 7900 | } |
| 7901 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7902 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7903 | res = obj2ast_expr(tmp, &value, arena); |
| 7904 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7905 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7906 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7907 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7908 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7909 | if (*out == NULL) goto failed; |
| 7910 | return 0; |
| 7911 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7912 | tp = astmodulestate_global->YieldFrom_type; |
| 7913 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7914 | if (isinstance == -1) { |
| 7915 | return 1; |
| 7916 | } |
| 7917 | if (isinstance) { |
| 7918 | expr_ty value; |
| 7919 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7920 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7921 | return 1; |
| 7922 | } |
| 7923 | if (tmp == NULL) { |
| 7924 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 7925 | return 1; |
| 7926 | } |
| 7927 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7928 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7929 | res = obj2ast_expr(tmp, &value, arena); |
| 7930 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7931 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7932 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7933 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7934 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7935 | if (*out == NULL) goto failed; |
| 7936 | return 0; |
| 7937 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7938 | tp = astmodulestate_global->Compare_type; |
| 7939 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7940 | if (isinstance == -1) { |
| 7941 | return 1; |
| 7942 | } |
| 7943 | if (isinstance) { |
| 7944 | expr_ty left; |
| 7945 | asdl_int_seq* ops; |
| 7946 | asdl_seq* comparators; |
| 7947 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7948 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7949 | return 1; |
| 7950 | } |
| 7951 | if (tmp == NULL) { |
| 7952 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 7953 | return 1; |
| 7954 | } |
| 7955 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7956 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7957 | res = obj2ast_expr(tmp, &left, arena); |
| 7958 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7959 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7960 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7961 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7962 | return 1; |
| 7963 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7964 | if (tmp == NULL) { |
| 7965 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 7966 | return 1; |
| 7967 | } |
| 7968 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7969 | int res; |
| 7970 | Py_ssize_t len; |
| 7971 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7972 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7973 | 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] | 7974 | goto failed; |
| 7975 | } |
| 7976 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7977 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7978 | if (ops == NULL) goto failed; |
| 7979 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7980 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7981 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7982 | Py_INCREF(tmp2); |
| 7983 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 7984 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7985 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7986 | if (len != PyList_GET_SIZE(tmp)) { |
| 7987 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 7988 | goto failed; |
| 7989 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7990 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7991 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7992 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7993 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7994 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 7995 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7996 | return 1; |
| 7997 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7998 | if (tmp == NULL) { |
| 7999 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8000 | return 1; |
| 8001 | } |
| 8002 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8003 | int res; |
| 8004 | Py_ssize_t len; |
| 8005 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8006 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8007 | 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] | 8008 | goto failed; |
| 8009 | } |
| 8010 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8011 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8012 | if (comparators == NULL) goto failed; |
| 8013 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8014 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8015 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8016 | Py_INCREF(tmp2); |
| 8017 | res = obj2ast_expr(tmp2, &val, arena); |
| 8018 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8019 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8020 | if (len != PyList_GET_SIZE(tmp)) { |
| 8021 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8022 | goto failed; |
| 8023 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8024 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8025 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8026 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8027 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8028 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8029 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8030 | if (*out == NULL) goto failed; |
| 8031 | return 0; |
| 8032 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8033 | tp = astmodulestate_global->Call_type; |
| 8034 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8035 | if (isinstance == -1) { |
| 8036 | return 1; |
| 8037 | } |
| 8038 | if (isinstance) { |
| 8039 | expr_ty func; |
| 8040 | asdl_seq* args; |
| 8041 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8042 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8043 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8044 | return 1; |
| 8045 | } |
| 8046 | if (tmp == NULL) { |
| 8047 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8048 | return 1; |
| 8049 | } |
| 8050 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8051 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8052 | res = obj2ast_expr(tmp, &func, arena); |
| 8053 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8054 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8055 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8056 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8057 | return 1; |
| 8058 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8059 | if (tmp == NULL) { |
| 8060 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8061 | return 1; |
| 8062 | } |
| 8063 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8064 | int res; |
| 8065 | Py_ssize_t len; |
| 8066 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8067 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8068 | 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] | 8069 | goto failed; |
| 8070 | } |
| 8071 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8072 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8073 | if (args == NULL) goto failed; |
| 8074 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8075 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8076 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8077 | Py_INCREF(tmp2); |
| 8078 | res = obj2ast_expr(tmp2, &val, arena); |
| 8079 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8080 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8081 | if (len != PyList_GET_SIZE(tmp)) { |
| 8082 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8083 | goto failed; |
| 8084 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8085 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8086 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8087 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8088 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8089 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8090 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8091 | return 1; |
| 8092 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8093 | if (tmp == NULL) { |
| 8094 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8095 | return 1; |
| 8096 | } |
| 8097 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8098 | int res; |
| 8099 | Py_ssize_t len; |
| 8100 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8101 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8102 | 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] | 8103 | goto failed; |
| 8104 | } |
| 8105 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8106 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8107 | if (keywords == NULL) goto failed; |
| 8108 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8109 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8110 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8111 | Py_INCREF(tmp2); |
| 8112 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8113 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8114 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8115 | if (len != PyList_GET_SIZE(tmp)) { |
| 8116 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8117 | goto failed; |
| 8118 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8119 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8120 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8121 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8122 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8123 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8124 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8125 | if (*out == NULL) goto failed; |
| 8126 | return 0; |
| 8127 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8128 | tp = astmodulestate_global->FormattedValue_type; |
| 8129 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8130 | if (isinstance == -1) { |
| 8131 | return 1; |
| 8132 | } |
| 8133 | if (isinstance) { |
| 8134 | expr_ty value; |
| 8135 | int conversion; |
| 8136 | expr_ty format_spec; |
| 8137 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8138 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8139 | return 1; |
| 8140 | } |
| 8141 | if (tmp == NULL) { |
| 8142 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8143 | return 1; |
| 8144 | } |
| 8145 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8146 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8147 | res = obj2ast_expr(tmp, &value, arena); |
| 8148 | if (res != 0) goto failed; |
| 8149 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8150 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8151 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8152 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8153 | return 1; |
| 8154 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8155 | if (tmp == NULL || tmp == Py_None) { |
| 8156 | Py_CLEAR(tmp); |
| 8157 | conversion = 0; |
| 8158 | } |
| 8159 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8160 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8161 | res = obj2ast_int(tmp, &conversion, arena); |
| 8162 | if (res != 0) goto failed; |
| 8163 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8164 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8165 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8166 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8167 | return 1; |
| 8168 | } |
| 8169 | if (tmp == NULL || tmp == Py_None) { |
| 8170 | Py_CLEAR(tmp); |
| 8171 | format_spec = NULL; |
| 8172 | } |
| 8173 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8174 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8175 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8176 | if (res != 0) goto failed; |
| 8177 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8178 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8179 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8180 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8181 | if (*out == NULL) goto failed; |
| 8182 | return 0; |
| 8183 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8184 | tp = astmodulestate_global->JoinedStr_type; |
| 8185 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8186 | if (isinstance == -1) { |
| 8187 | return 1; |
| 8188 | } |
| 8189 | if (isinstance) { |
| 8190 | asdl_seq* values; |
| 8191 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8192 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8193 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8194 | return 1; |
| 8195 | } |
| 8196 | if (tmp == NULL) { |
| 8197 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8198 | return 1; |
| 8199 | } |
| 8200 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8201 | int res; |
| 8202 | Py_ssize_t len; |
| 8203 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8204 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8205 | 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] | 8206 | goto failed; |
| 8207 | } |
| 8208 | len = PyList_GET_SIZE(tmp); |
| 8209 | values = _Py_asdl_seq_new(len, arena); |
| 8210 | if (values == NULL) goto failed; |
| 8211 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8212 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8213 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8214 | Py_INCREF(tmp2); |
| 8215 | res = obj2ast_expr(tmp2, &val, arena); |
| 8216 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8217 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8218 | if (len != PyList_GET_SIZE(tmp)) { |
| 8219 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8220 | goto failed; |
| 8221 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8222 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8223 | } |
| 8224 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8225 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8226 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8227 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8228 | if (*out == NULL) goto failed; |
| 8229 | return 0; |
| 8230 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8231 | tp = astmodulestate_global->Constant_type; |
| 8232 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8233 | if (isinstance == -1) { |
| 8234 | return 1; |
| 8235 | } |
| 8236 | if (isinstance) { |
| 8237 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8238 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8239 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8240 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8241 | return 1; |
| 8242 | } |
| 8243 | if (tmp == NULL) { |
| 8244 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8245 | return 1; |
| 8246 | } |
| 8247 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8248 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8249 | res = obj2ast_constant(tmp, &value, arena); |
| 8250 | if (res != 0) goto failed; |
| 8251 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8252 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8253 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8254 | return 1; |
| 8255 | } |
| 8256 | if (tmp == NULL || tmp == Py_None) { |
| 8257 | Py_CLEAR(tmp); |
| 8258 | kind = NULL; |
| 8259 | } |
| 8260 | else { |
| 8261 | int res; |
| 8262 | res = obj2ast_string(tmp, &kind, arena); |
| 8263 | if (res != 0) goto failed; |
| 8264 | Py_CLEAR(tmp); |
| 8265 | } |
| 8266 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8267 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8268 | if (*out == NULL) goto failed; |
| 8269 | return 0; |
| 8270 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8271 | tp = astmodulestate_global->Attribute_type; |
| 8272 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8273 | if (isinstance == -1) { |
| 8274 | return 1; |
| 8275 | } |
| 8276 | if (isinstance) { |
| 8277 | expr_ty value; |
| 8278 | identifier attr; |
| 8279 | expr_context_ty ctx; |
| 8280 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8281 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8282 | return 1; |
| 8283 | } |
| 8284 | if (tmp == NULL) { |
| 8285 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8286 | return 1; |
| 8287 | } |
| 8288 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8289 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8290 | res = obj2ast_expr(tmp, &value, arena); |
| 8291 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8292 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8293 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8294 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8295 | return 1; |
| 8296 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8297 | if (tmp == NULL) { |
| 8298 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8299 | return 1; |
| 8300 | } |
| 8301 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8302 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8303 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8304 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8305 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8306 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8307 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8308 | return 1; |
| 8309 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8310 | if (tmp == NULL) { |
| 8311 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8312 | return 1; |
| 8313 | } |
| 8314 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8315 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8316 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8317 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8318 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8319 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8320 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8321 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8322 | if (*out == NULL) goto failed; |
| 8323 | return 0; |
| 8324 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8325 | tp = astmodulestate_global->Subscript_type; |
| 8326 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8327 | if (isinstance == -1) { |
| 8328 | return 1; |
| 8329 | } |
| 8330 | if (isinstance) { |
| 8331 | expr_ty value; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8332 | expr_ty slice; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8333 | expr_context_ty ctx; |
| 8334 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8335 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8336 | return 1; |
| 8337 | } |
| 8338 | if (tmp == NULL) { |
| 8339 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8340 | return 1; |
| 8341 | } |
| 8342 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8343 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8344 | res = obj2ast_expr(tmp, &value, arena); |
| 8345 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8346 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8347 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8348 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8349 | return 1; |
| 8350 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8351 | if (tmp == NULL) { |
| 8352 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8353 | return 1; |
| 8354 | } |
| 8355 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8356 | int res; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8357 | res = obj2ast_expr(tmp, &slice, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8358 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8359 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8360 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8361 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8362 | return 1; |
| 8363 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8364 | if (tmp == NULL) { |
| 8365 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8366 | return 1; |
| 8367 | } |
| 8368 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8369 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8370 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8371 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8372 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8373 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8374 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8375 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8376 | if (*out == NULL) goto failed; |
| 8377 | return 0; |
| 8378 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8379 | tp = astmodulestate_global->Starred_type; |
| 8380 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8381 | if (isinstance == -1) { |
| 8382 | return 1; |
| 8383 | } |
| 8384 | if (isinstance) { |
| 8385 | expr_ty value; |
| 8386 | expr_context_ty ctx; |
| 8387 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8388 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8389 | return 1; |
| 8390 | } |
| 8391 | if (tmp == NULL) { |
| 8392 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8393 | return 1; |
| 8394 | } |
| 8395 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8396 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8397 | res = obj2ast_expr(tmp, &value, arena); |
| 8398 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8399 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8400 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8401 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8402 | return 1; |
| 8403 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8404 | if (tmp == NULL) { |
| 8405 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8406 | return 1; |
| 8407 | } |
| 8408 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8409 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8410 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8411 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8412 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8413 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8414 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8415 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8416 | if (*out == NULL) goto failed; |
| 8417 | return 0; |
| 8418 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8419 | tp = astmodulestate_global->Name_type; |
| 8420 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8421 | if (isinstance == -1) { |
| 8422 | return 1; |
| 8423 | } |
| 8424 | if (isinstance) { |
| 8425 | identifier id; |
| 8426 | expr_context_ty ctx; |
| 8427 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8428 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8429 | return 1; |
| 8430 | } |
| 8431 | if (tmp == NULL) { |
| 8432 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8433 | return 1; |
| 8434 | } |
| 8435 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8436 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8437 | res = obj2ast_identifier(tmp, &id, arena); |
| 8438 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8439 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8440 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8441 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8442 | return 1; |
| 8443 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8444 | if (tmp == NULL) { |
| 8445 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8446 | return 1; |
| 8447 | } |
| 8448 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8449 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8450 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8451 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8452 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8453 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8454 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8455 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8456 | if (*out == NULL) goto failed; |
| 8457 | return 0; |
| 8458 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8459 | tp = astmodulestate_global->List_type; |
| 8460 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8461 | if (isinstance == -1) { |
| 8462 | return 1; |
| 8463 | } |
| 8464 | if (isinstance) { |
| 8465 | asdl_seq* elts; |
| 8466 | expr_context_ty ctx; |
| 8467 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8468 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8469 | return 1; |
| 8470 | } |
| 8471 | if (tmp == NULL) { |
| 8472 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8473 | return 1; |
| 8474 | } |
| 8475 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8476 | int res; |
| 8477 | Py_ssize_t len; |
| 8478 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8479 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8480 | 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] | 8481 | goto failed; |
| 8482 | } |
| 8483 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8484 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8485 | if (elts == NULL) goto failed; |
| 8486 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8487 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8488 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8489 | Py_INCREF(tmp2); |
| 8490 | res = obj2ast_expr(tmp2, &val, arena); |
| 8491 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8492 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8493 | if (len != PyList_GET_SIZE(tmp)) { |
| 8494 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8495 | goto failed; |
| 8496 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8497 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8498 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8499 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8500 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8501 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8502 | return 1; |
| 8503 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8504 | if (tmp == NULL) { |
| 8505 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8506 | return 1; |
| 8507 | } |
| 8508 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8509 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8510 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8511 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8512 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8513 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8514 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8515 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8516 | if (*out == NULL) goto failed; |
| 8517 | return 0; |
| 8518 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8519 | tp = astmodulestate_global->Tuple_type; |
| 8520 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8521 | if (isinstance == -1) { |
| 8522 | return 1; |
| 8523 | } |
| 8524 | if (isinstance) { |
| 8525 | asdl_seq* elts; |
| 8526 | expr_context_ty ctx; |
| 8527 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8528 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8529 | return 1; |
| 8530 | } |
| 8531 | if (tmp == NULL) { |
| 8532 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8533 | return 1; |
| 8534 | } |
| 8535 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8536 | int res; |
| 8537 | Py_ssize_t len; |
| 8538 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8539 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8540 | 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] | 8541 | goto failed; |
| 8542 | } |
| 8543 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8544 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8545 | if (elts == NULL) goto failed; |
| 8546 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8547 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8548 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8549 | Py_INCREF(tmp2); |
| 8550 | res = obj2ast_expr(tmp2, &val, arena); |
| 8551 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8552 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8553 | if (len != PyList_GET_SIZE(tmp)) { |
| 8554 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8555 | goto failed; |
| 8556 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8557 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8558 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8559 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8560 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8561 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8562 | return 1; |
| 8563 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8564 | if (tmp == NULL) { |
| 8565 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8566 | return 1; |
| 8567 | } |
| 8568 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8569 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8570 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8571 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8572 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8573 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8574 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8575 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8576 | if (*out == NULL) goto failed; |
| 8577 | return 0; |
| 8578 | } |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8579 | tp = astmodulestate_global->Slice_type; |
| 8580 | isinstance = PyObject_IsInstance(obj, tp); |
| 8581 | if (isinstance == -1) { |
| 8582 | return 1; |
| 8583 | } |
| 8584 | if (isinstance) { |
| 8585 | expr_ty lower; |
| 8586 | expr_ty upper; |
| 8587 | expr_ty step; |
| 8588 | |
| 8589 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
| 8590 | return 1; |
| 8591 | } |
| 8592 | if (tmp == NULL || tmp == Py_None) { |
| 8593 | Py_CLEAR(tmp); |
| 8594 | lower = NULL; |
| 8595 | } |
| 8596 | else { |
| 8597 | int res; |
| 8598 | res = obj2ast_expr(tmp, &lower, arena); |
| 8599 | if (res != 0) goto failed; |
| 8600 | Py_CLEAR(tmp); |
| 8601 | } |
| 8602 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
| 8603 | return 1; |
| 8604 | } |
| 8605 | if (tmp == NULL || tmp == Py_None) { |
| 8606 | Py_CLEAR(tmp); |
| 8607 | upper = NULL; |
| 8608 | } |
| 8609 | else { |
| 8610 | int res; |
| 8611 | res = obj2ast_expr(tmp, &upper, arena); |
| 8612 | if (res != 0) goto failed; |
| 8613 | Py_CLEAR(tmp); |
| 8614 | } |
| 8615 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
| 8616 | return 1; |
| 8617 | } |
| 8618 | if (tmp == NULL || tmp == Py_None) { |
| 8619 | Py_CLEAR(tmp); |
| 8620 | step = NULL; |
| 8621 | } |
| 8622 | else { |
| 8623 | int res; |
| 8624 | res = obj2ast_expr(tmp, &step, arena); |
| 8625 | if (res != 0) goto failed; |
| 8626 | Py_CLEAR(tmp); |
| 8627 | } |
| 8628 | *out = Slice(lower, upper, step, lineno, col_offset, end_lineno, |
| 8629 | end_col_offset, arena); |
| 8630 | if (*out == NULL) goto failed; |
| 8631 | return 0; |
| 8632 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8633 | |
| 8634 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8635 | failed: |
| 8636 | Py_XDECREF(tmp); |
| 8637 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8638 | } |
| 8639 | |
| 8640 | int |
| 8641 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8642 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8643 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8644 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8645 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8646 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8647 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8648 | } |
| 8649 | if (isinstance) { |
| 8650 | *out = Load; |
| 8651 | return 0; |
| 8652 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8653 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8654 | if (isinstance == -1) { |
| 8655 | return 1; |
| 8656 | } |
| 8657 | if (isinstance) { |
| 8658 | *out = Store; |
| 8659 | return 0; |
| 8660 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8661 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8662 | if (isinstance == -1) { |
| 8663 | return 1; |
| 8664 | } |
| 8665 | if (isinstance) { |
| 8666 | *out = Del; |
| 8667 | return 0; |
| 8668 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8669 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8670 | if (isinstance == -1) { |
| 8671 | return 1; |
| 8672 | } |
| 8673 | if (isinstance) { |
| 8674 | *out = AugLoad; |
| 8675 | return 0; |
| 8676 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8677 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8678 | if (isinstance == -1) { |
| 8679 | return 1; |
| 8680 | } |
| 8681 | if (isinstance) { |
| 8682 | *out = AugStore; |
| 8683 | return 0; |
| 8684 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8685 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8686 | if (isinstance == -1) { |
| 8687 | return 1; |
| 8688 | } |
| 8689 | if (isinstance) { |
| 8690 | *out = Param; |
| 8691 | return 0; |
| 8692 | } |
| 8693 | |
| 8694 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8695 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8696 | } |
| 8697 | |
| 8698 | int |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8699 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8700 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8701 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8702 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8703 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8704 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8705 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8706 | } |
| 8707 | if (isinstance) { |
| 8708 | *out = And; |
| 8709 | return 0; |
| 8710 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8711 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8712 | if (isinstance == -1) { |
| 8713 | return 1; |
| 8714 | } |
| 8715 | if (isinstance) { |
| 8716 | *out = Or; |
| 8717 | return 0; |
| 8718 | } |
| 8719 | |
| 8720 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8721 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8722 | } |
| 8723 | |
| 8724 | int |
| 8725 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8726 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8727 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8728 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8729 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8730 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8731 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8732 | } |
| 8733 | if (isinstance) { |
| 8734 | *out = Add; |
| 8735 | return 0; |
| 8736 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8737 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8738 | if (isinstance == -1) { |
| 8739 | return 1; |
| 8740 | } |
| 8741 | if (isinstance) { |
| 8742 | *out = Sub; |
| 8743 | return 0; |
| 8744 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8745 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8746 | if (isinstance == -1) { |
| 8747 | return 1; |
| 8748 | } |
| 8749 | if (isinstance) { |
| 8750 | *out = Mult; |
| 8751 | return 0; |
| 8752 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8753 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8754 | if (isinstance == -1) { |
| 8755 | return 1; |
| 8756 | } |
| 8757 | if (isinstance) { |
| 8758 | *out = MatMult; |
| 8759 | return 0; |
| 8760 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8761 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8762 | if (isinstance == -1) { |
| 8763 | return 1; |
| 8764 | } |
| 8765 | if (isinstance) { |
| 8766 | *out = Div; |
| 8767 | return 0; |
| 8768 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8769 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8770 | if (isinstance == -1) { |
| 8771 | return 1; |
| 8772 | } |
| 8773 | if (isinstance) { |
| 8774 | *out = Mod; |
| 8775 | return 0; |
| 8776 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8777 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8778 | if (isinstance == -1) { |
| 8779 | return 1; |
| 8780 | } |
| 8781 | if (isinstance) { |
| 8782 | *out = Pow; |
| 8783 | return 0; |
| 8784 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8785 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8786 | if (isinstance == -1) { |
| 8787 | return 1; |
| 8788 | } |
| 8789 | if (isinstance) { |
| 8790 | *out = LShift; |
| 8791 | return 0; |
| 8792 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8793 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8794 | if (isinstance == -1) { |
| 8795 | return 1; |
| 8796 | } |
| 8797 | if (isinstance) { |
| 8798 | *out = RShift; |
| 8799 | return 0; |
| 8800 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8801 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8802 | if (isinstance == -1) { |
| 8803 | return 1; |
| 8804 | } |
| 8805 | if (isinstance) { |
| 8806 | *out = BitOr; |
| 8807 | return 0; |
| 8808 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8809 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8810 | if (isinstance == -1) { |
| 8811 | return 1; |
| 8812 | } |
| 8813 | if (isinstance) { |
| 8814 | *out = BitXor; |
| 8815 | return 0; |
| 8816 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8817 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8818 | if (isinstance == -1) { |
| 8819 | return 1; |
| 8820 | } |
| 8821 | if (isinstance) { |
| 8822 | *out = BitAnd; |
| 8823 | return 0; |
| 8824 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8825 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8826 | if (isinstance == -1) { |
| 8827 | return 1; |
| 8828 | } |
| 8829 | if (isinstance) { |
| 8830 | *out = FloorDiv; |
| 8831 | return 0; |
| 8832 | } |
| 8833 | |
| 8834 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8835 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8836 | } |
| 8837 | |
| 8838 | int |
| 8839 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8840 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8841 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8842 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8843 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8844 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8845 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8846 | } |
| 8847 | if (isinstance) { |
| 8848 | *out = Invert; |
| 8849 | return 0; |
| 8850 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8851 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8852 | if (isinstance == -1) { |
| 8853 | return 1; |
| 8854 | } |
| 8855 | if (isinstance) { |
| 8856 | *out = Not; |
| 8857 | return 0; |
| 8858 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8859 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8860 | if (isinstance == -1) { |
| 8861 | return 1; |
| 8862 | } |
| 8863 | if (isinstance) { |
| 8864 | *out = UAdd; |
| 8865 | return 0; |
| 8866 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8867 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8868 | if (isinstance == -1) { |
| 8869 | return 1; |
| 8870 | } |
| 8871 | if (isinstance) { |
| 8872 | *out = USub; |
| 8873 | return 0; |
| 8874 | } |
| 8875 | |
| 8876 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 8877 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8878 | } |
| 8879 | |
| 8880 | int |
| 8881 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 8882 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8883 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8884 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8885 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8886 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8887 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8888 | } |
| 8889 | if (isinstance) { |
| 8890 | *out = Eq; |
| 8891 | return 0; |
| 8892 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8893 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8894 | if (isinstance == -1) { |
| 8895 | return 1; |
| 8896 | } |
| 8897 | if (isinstance) { |
| 8898 | *out = NotEq; |
| 8899 | return 0; |
| 8900 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8901 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8902 | if (isinstance == -1) { |
| 8903 | return 1; |
| 8904 | } |
| 8905 | if (isinstance) { |
| 8906 | *out = Lt; |
| 8907 | return 0; |
| 8908 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8909 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8910 | if (isinstance == -1) { |
| 8911 | return 1; |
| 8912 | } |
| 8913 | if (isinstance) { |
| 8914 | *out = LtE; |
| 8915 | return 0; |
| 8916 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8917 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_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 = Gt; |
| 8923 | return 0; |
| 8924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8925 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_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 = GtE; |
| 8931 | return 0; |
| 8932 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8933 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8934 | if (isinstance == -1) { |
| 8935 | return 1; |
| 8936 | } |
| 8937 | if (isinstance) { |
| 8938 | *out = Is; |
| 8939 | return 0; |
| 8940 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8941 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_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 = IsNot; |
| 8947 | return 0; |
| 8948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8949 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_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 = In; |
| 8955 | return 0; |
| 8956 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8957 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_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 = NotIn; |
| 8963 | return 0; |
| 8964 | } |
| 8965 | |
| 8966 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 8967 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8968 | } |
| 8969 | |
| 8970 | int |
| 8971 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 8972 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8973 | PyObject* tmp = NULL; |
| 8974 | expr_ty target; |
| 8975 | expr_ty iter; |
| 8976 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 8977 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8978 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8979 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8980 | return 1; |
| 8981 | } |
| 8982 | if (tmp == NULL) { |
| 8983 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 8984 | return 1; |
| 8985 | } |
| 8986 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8987 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8988 | res = obj2ast_expr(tmp, &target, arena); |
| 8989 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8990 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8991 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8992 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8993 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8994 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8995 | if (tmp == NULL) { |
| 8996 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 8997 | return 1; |
| 8998 | } |
| 8999 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9000 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9001 | res = obj2ast_expr(tmp, &iter, arena); |
| 9002 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9003 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9004 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9005 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9006 | return 1; |
| 9007 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9008 | if (tmp == NULL) { |
| 9009 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9010 | return 1; |
| 9011 | } |
| 9012 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9013 | int res; |
| 9014 | Py_ssize_t len; |
| 9015 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9016 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9017 | 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] | 9018 | goto failed; |
| 9019 | } |
| 9020 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9021 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9022 | if (ifs == NULL) goto failed; |
| 9023 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9024 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9025 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9026 | Py_INCREF(tmp2); |
| 9027 | res = obj2ast_expr(tmp2, &val, arena); |
| 9028 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9029 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9030 | if (len != PyList_GET_SIZE(tmp)) { |
| 9031 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9032 | goto failed; |
| 9033 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9034 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9035 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9036 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9037 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9038 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9039 | return 1; |
| 9040 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9041 | if (tmp == NULL) { |
| 9042 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9043 | return 1; |
| 9044 | } |
| 9045 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9046 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9047 | res = obj2ast_int(tmp, &is_async, arena); |
| 9048 | if (res != 0) goto failed; |
| 9049 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9050 | } |
| 9051 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9052 | return 0; |
| 9053 | failed: |
| 9054 | Py_XDECREF(tmp); |
| 9055 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9056 | } |
| 9057 | |
| 9058 | int |
| 9059 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9060 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9061 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9062 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9063 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9064 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9065 | int lineno; |
| 9066 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9067 | int end_lineno; |
| 9068 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9069 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9070 | if (obj == Py_None) { |
| 9071 | *out = NULL; |
| 9072 | return 0; |
| 9073 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9074 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9075 | return 1; |
| 9076 | } |
| 9077 | if (tmp == NULL) { |
| 9078 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9079 | return 1; |
| 9080 | } |
| 9081 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9082 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9083 | res = obj2ast_int(tmp, &lineno, arena); |
| 9084 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9085 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9086 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9087 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9088 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9089 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9090 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9091 | if (tmp == NULL) { |
| 9092 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9093 | return 1; |
| 9094 | } |
| 9095 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9096 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9097 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9098 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9099 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9100 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9101 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9102 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9103 | return 1; |
| 9104 | } |
| 9105 | if (tmp == NULL || tmp == Py_None) { |
| 9106 | Py_CLEAR(tmp); |
| 9107 | end_lineno = 0; |
| 9108 | } |
| 9109 | else { |
| 9110 | int res; |
| 9111 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9112 | if (res != 0) goto failed; |
| 9113 | Py_CLEAR(tmp); |
| 9114 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9115 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9116 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9117 | return 1; |
| 9118 | } |
| 9119 | if (tmp == NULL || tmp == Py_None) { |
| 9120 | Py_CLEAR(tmp); |
| 9121 | end_col_offset = 0; |
| 9122 | } |
| 9123 | else { |
| 9124 | int res; |
| 9125 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9126 | if (res != 0) goto failed; |
| 9127 | Py_CLEAR(tmp); |
| 9128 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9129 | tp = astmodulestate_global->ExceptHandler_type; |
| 9130 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9131 | if (isinstance == -1) { |
| 9132 | return 1; |
| 9133 | } |
| 9134 | if (isinstance) { |
| 9135 | expr_ty type; |
| 9136 | identifier name; |
| 9137 | asdl_seq* body; |
| 9138 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9139 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9140 | return 1; |
| 9141 | } |
| 9142 | if (tmp == NULL || tmp == Py_None) { |
| 9143 | Py_CLEAR(tmp); |
| 9144 | type = NULL; |
| 9145 | } |
| 9146 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9147 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9148 | res = obj2ast_expr(tmp, &type, arena); |
| 9149 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9150 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9151 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9152 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9153 | return 1; |
| 9154 | } |
| 9155 | if (tmp == NULL || tmp == Py_None) { |
| 9156 | Py_CLEAR(tmp); |
| 9157 | name = NULL; |
| 9158 | } |
| 9159 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9160 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9161 | res = obj2ast_identifier(tmp, &name, arena); |
| 9162 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9163 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9164 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9165 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9166 | return 1; |
| 9167 | } |
| 9168 | if (tmp == NULL) { |
| 9169 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9170 | return 1; |
| 9171 | } |
| 9172 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9173 | int res; |
| 9174 | Py_ssize_t len; |
| 9175 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9176 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9177 | 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] | 9178 | goto failed; |
| 9179 | } |
| 9180 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9181 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9182 | if (body == NULL) goto failed; |
| 9183 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9184 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9185 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9186 | Py_INCREF(tmp2); |
| 9187 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9188 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9189 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9190 | if (len != PyList_GET_SIZE(tmp)) { |
| 9191 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9192 | goto failed; |
| 9193 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9194 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9195 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9196 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9197 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9198 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9199 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9200 | if (*out == NULL) goto failed; |
| 9201 | return 0; |
| 9202 | } |
| 9203 | |
| 9204 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9205 | failed: |
| 9206 | Py_XDECREF(tmp); |
| 9207 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9208 | } |
| 9209 | |
| 9210 | int |
| 9211 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9212 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9213 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9214 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9215 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9216 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9217 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9218 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9219 | arg_ty kwarg; |
| 9220 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9221 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9222 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9223 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9224 | return 1; |
| 9225 | } |
| 9226 | if (tmp == NULL) { |
| 9227 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9228 | return 1; |
| 9229 | } |
| 9230 | else { |
| 9231 | int res; |
| 9232 | Py_ssize_t len; |
| 9233 | Py_ssize_t i; |
| 9234 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9235 | 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] | 9236 | goto failed; |
| 9237 | } |
| 9238 | len = PyList_GET_SIZE(tmp); |
| 9239 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9240 | if (posonlyargs == NULL) goto failed; |
| 9241 | for (i = 0; i < len; i++) { |
| 9242 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9243 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9244 | Py_INCREF(tmp2); |
| 9245 | res = obj2ast_arg(tmp2, &val, arena); |
| 9246 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9247 | if (res != 0) goto failed; |
| 9248 | if (len != PyList_GET_SIZE(tmp)) { |
| 9249 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9250 | goto failed; |
| 9251 | } |
| 9252 | asdl_seq_SET(posonlyargs, i, val); |
| 9253 | } |
| 9254 | Py_CLEAR(tmp); |
| 9255 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9256 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9257 | return 1; |
| 9258 | } |
| 9259 | if (tmp == NULL) { |
| 9260 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9261 | return 1; |
| 9262 | } |
| 9263 | else { |
| 9264 | int res; |
| 9265 | Py_ssize_t len; |
| 9266 | Py_ssize_t i; |
| 9267 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9268 | 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] | 9269 | goto failed; |
| 9270 | } |
| 9271 | len = PyList_GET_SIZE(tmp); |
| 9272 | args = _Py_asdl_seq_new(len, arena); |
| 9273 | if (args == NULL) goto failed; |
| 9274 | for (i = 0; i < len; i++) { |
| 9275 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9276 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9277 | Py_INCREF(tmp2); |
| 9278 | res = obj2ast_arg(tmp2, &val, arena); |
| 9279 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9280 | if (res != 0) goto failed; |
| 9281 | if (len != PyList_GET_SIZE(tmp)) { |
| 9282 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9283 | goto failed; |
| 9284 | } |
| 9285 | asdl_seq_SET(args, i, val); |
| 9286 | } |
| 9287 | Py_CLEAR(tmp); |
| 9288 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9289 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9290 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9291 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9292 | if (tmp == NULL || tmp == Py_None) { |
| 9293 | Py_CLEAR(tmp); |
| 9294 | vararg = NULL; |
| 9295 | } |
| 9296 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9297 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9298 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9299 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9300 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9301 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9302 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9303 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9304 | return 1; |
| 9305 | } |
| 9306 | if (tmp == NULL) { |
| 9307 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9308 | return 1; |
| 9309 | } |
| 9310 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9311 | int res; |
| 9312 | Py_ssize_t len; |
| 9313 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9314 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9315 | 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] | 9316 | goto failed; |
| 9317 | } |
| 9318 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9319 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9320 | if (kwonlyargs == NULL) goto failed; |
| 9321 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9322 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9323 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9324 | Py_INCREF(tmp2); |
| 9325 | res = obj2ast_arg(tmp2, &val, arena); |
| 9326 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9327 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9328 | if (len != PyList_GET_SIZE(tmp)) { |
| 9329 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9330 | goto failed; |
| 9331 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9332 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9333 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9334 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9335 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9336 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9337 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9338 | return 1; |
| 9339 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9340 | if (tmp == NULL) { |
| 9341 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9342 | return 1; |
| 9343 | } |
| 9344 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9345 | int res; |
| 9346 | Py_ssize_t len; |
| 9347 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9348 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9349 | 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] | 9350 | goto failed; |
| 9351 | } |
| 9352 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9353 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9354 | if (kw_defaults == NULL) goto failed; |
| 9355 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9356 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9357 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9358 | Py_INCREF(tmp2); |
| 9359 | res = obj2ast_expr(tmp2, &val, arena); |
| 9360 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9361 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9362 | if (len != PyList_GET_SIZE(tmp)) { |
| 9363 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9364 | goto failed; |
| 9365 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9366 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9367 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9368 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9369 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9370 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9371 | return 1; |
| 9372 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9373 | if (tmp == NULL || tmp == Py_None) { |
| 9374 | Py_CLEAR(tmp); |
| 9375 | kwarg = NULL; |
| 9376 | } |
| 9377 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9378 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9379 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9380 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9381 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9382 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9383 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9384 | return 1; |
| 9385 | } |
| 9386 | if (tmp == NULL) { |
| 9387 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9388 | return 1; |
| 9389 | } |
| 9390 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9391 | int res; |
| 9392 | Py_ssize_t len; |
| 9393 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9394 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9395 | 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] | 9396 | goto failed; |
| 9397 | } |
| 9398 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9399 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9400 | if (defaults == NULL) goto failed; |
| 9401 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9402 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9403 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9404 | Py_INCREF(tmp2); |
| 9405 | res = obj2ast_expr(tmp2, &val, arena); |
| 9406 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9407 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9408 | if (len != PyList_GET_SIZE(tmp)) { |
| 9409 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9410 | goto failed; |
| 9411 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9412 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9413 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9414 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9415 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9416 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9417 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9418 | return 0; |
| 9419 | failed: |
| 9420 | Py_XDECREF(tmp); |
| 9421 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9422 | } |
| 9423 | |
| 9424 | int |
| 9425 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9426 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9427 | PyObject* tmp = NULL; |
| 9428 | identifier arg; |
| 9429 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9430 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9431 | int lineno; |
| 9432 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9433 | int end_lineno; |
| 9434 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9435 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9436 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9437 | return 1; |
| 9438 | } |
| 9439 | if (tmp == NULL) { |
| 9440 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9441 | return 1; |
| 9442 | } |
| 9443 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9444 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9445 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9446 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9447 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9448 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9449 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9450 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9451 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9452 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9453 | if (tmp == NULL || tmp == Py_None) { |
| 9454 | Py_CLEAR(tmp); |
| 9455 | annotation = NULL; |
| 9456 | } |
| 9457 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9458 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9459 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9460 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9461 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9462 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9463 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9464 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9465 | return 1; |
| 9466 | } |
| 9467 | if (tmp == NULL || tmp == Py_None) { |
| 9468 | Py_CLEAR(tmp); |
| 9469 | type_comment = NULL; |
| 9470 | } |
| 9471 | else { |
| 9472 | int res; |
| 9473 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9474 | if (res != 0) goto failed; |
| 9475 | Py_CLEAR(tmp); |
| 9476 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9477 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9478 | return 1; |
| 9479 | } |
| 9480 | if (tmp == NULL) { |
| 9481 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9482 | return 1; |
| 9483 | } |
| 9484 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9485 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9486 | res = obj2ast_int(tmp, &lineno, arena); |
| 9487 | if (res != 0) goto failed; |
| 9488 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9489 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9490 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9491 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9492 | return 1; |
| 9493 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9494 | if (tmp == NULL) { |
| 9495 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9496 | return 1; |
| 9497 | } |
| 9498 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9499 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9500 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9501 | if (res != 0) goto failed; |
| 9502 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9503 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9504 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9505 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9506 | return 1; |
| 9507 | } |
| 9508 | if (tmp == NULL || tmp == Py_None) { |
| 9509 | Py_CLEAR(tmp); |
| 9510 | end_lineno = 0; |
| 9511 | } |
| 9512 | else { |
| 9513 | int res; |
| 9514 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9515 | if (res != 0) goto failed; |
| 9516 | Py_CLEAR(tmp); |
| 9517 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9518 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9519 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9520 | return 1; |
| 9521 | } |
| 9522 | if (tmp == NULL || tmp == Py_None) { |
| 9523 | Py_CLEAR(tmp); |
| 9524 | end_col_offset = 0; |
| 9525 | } |
| 9526 | else { |
| 9527 | int res; |
| 9528 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9529 | if (res != 0) goto failed; |
| 9530 | Py_CLEAR(tmp); |
| 9531 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9532 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9533 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9534 | return 0; |
| 9535 | failed: |
| 9536 | Py_XDECREF(tmp); |
| 9537 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9538 | } |
| 9539 | |
| 9540 | int |
| 9541 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9542 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9543 | PyObject* tmp = NULL; |
| 9544 | identifier arg; |
| 9545 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9546 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9547 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9548 | return 1; |
| 9549 | } |
| 9550 | if (tmp == NULL || tmp == Py_None) { |
| 9551 | Py_CLEAR(tmp); |
| 9552 | arg = NULL; |
| 9553 | } |
| 9554 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9555 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9556 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9557 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9558 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9559 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9560 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9561 | return 1; |
| 9562 | } |
| 9563 | if (tmp == NULL) { |
| 9564 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9565 | return 1; |
| 9566 | } |
| 9567 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9568 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9569 | res = obj2ast_expr(tmp, &value, arena); |
| 9570 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9571 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9572 | } |
| 9573 | *out = keyword(arg, value, arena); |
| 9574 | return 0; |
| 9575 | failed: |
| 9576 | Py_XDECREF(tmp); |
| 9577 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9578 | } |
| 9579 | |
| 9580 | int |
| 9581 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9582 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9583 | PyObject* tmp = NULL; |
| 9584 | identifier name; |
| 9585 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9586 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9587 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9588 | return 1; |
| 9589 | } |
| 9590 | if (tmp == NULL) { |
| 9591 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9592 | return 1; |
| 9593 | } |
| 9594 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9595 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9596 | res = obj2ast_identifier(tmp, &name, arena); |
| 9597 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9598 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9599 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9600 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9601 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9602 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9603 | if (tmp == NULL || tmp == Py_None) { |
| 9604 | Py_CLEAR(tmp); |
| 9605 | asname = NULL; |
| 9606 | } |
| 9607 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9608 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9609 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9610 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9611 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9612 | } |
| 9613 | *out = alias(name, asname, arena); |
| 9614 | return 0; |
| 9615 | failed: |
| 9616 | Py_XDECREF(tmp); |
| 9617 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9618 | } |
| 9619 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9620 | int |
| 9621 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9622 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9623 | PyObject* tmp = NULL; |
| 9624 | expr_ty context_expr; |
| 9625 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9626 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9627 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9628 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9629 | return 1; |
| 9630 | } |
| 9631 | if (tmp == NULL) { |
| 9632 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9633 | return 1; |
| 9634 | } |
| 9635 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9636 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9637 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9638 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9639 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9640 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9641 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9642 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9643 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9644 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9645 | if (tmp == NULL || tmp == Py_None) { |
| 9646 | Py_CLEAR(tmp); |
| 9647 | optional_vars = NULL; |
| 9648 | } |
| 9649 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9650 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9651 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9652 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9653 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9654 | } |
| 9655 | *out = withitem(context_expr, optional_vars, arena); |
| 9656 | return 0; |
| 9657 | failed: |
| 9658 | Py_XDECREF(tmp); |
| 9659 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9660 | } |
| 9661 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9662 | int |
| 9663 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9664 | { |
| 9665 | int isinstance; |
| 9666 | |
| 9667 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9668 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9669 | |
| 9670 | if (obj == Py_None) { |
| 9671 | *out = NULL; |
| 9672 | return 0; |
| 9673 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9674 | tp = astmodulestate_global->TypeIgnore_type; |
| 9675 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9676 | if (isinstance == -1) { |
| 9677 | return 1; |
| 9678 | } |
| 9679 | if (isinstance) { |
| 9680 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9681 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9682 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9683 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9684 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9685 | return 1; |
| 9686 | } |
| 9687 | if (tmp == NULL) { |
| 9688 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9689 | return 1; |
| 9690 | } |
| 9691 | else { |
| 9692 | int res; |
| 9693 | res = obj2ast_int(tmp, &lineno, arena); |
| 9694 | if (res != 0) goto failed; |
| 9695 | Py_CLEAR(tmp); |
| 9696 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9697 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9698 | return 1; |
| 9699 | } |
| 9700 | if (tmp == NULL) { |
| 9701 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9702 | return 1; |
| 9703 | } |
| 9704 | else { |
| 9705 | int res; |
| 9706 | res = obj2ast_string(tmp, &tag, arena); |
| 9707 | if (res != 0) goto failed; |
| 9708 | Py_CLEAR(tmp); |
| 9709 | } |
| 9710 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9711 | if (*out == NULL) goto failed; |
| 9712 | return 0; |
| 9713 | } |
| 9714 | |
| 9715 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9716 | failed: |
| 9717 | Py_XDECREF(tmp); |
| 9718 | return 1; |
| 9719 | } |
| 9720 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9721 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9722 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9723 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9724 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9725 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9726 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9727 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9728 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9729 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9730 | goto error; |
| 9731 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9732 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9733 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9734 | goto error; |
| 9735 | } |
| 9736 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9737 | goto error; |
| 9738 | } |
| 9739 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9740 | goto error; |
| 9741 | } |
| 9742 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9743 | goto error; |
| 9744 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9745 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9746 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9747 | 0) { |
| 9748 | goto error; |
| 9749 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9750 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9751 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9752 | astmodulestate_global->Interactive_type) < 0) { |
| 9753 | goto error; |
| 9754 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9755 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9756 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9757 | astmodulestate_global->Expression_type) < 0) { |
| 9758 | goto error; |
| 9759 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9760 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9761 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9762 | astmodulestate_global->FunctionType_type) < 0) { |
| 9763 | goto error; |
| 9764 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9765 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9766 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9767 | goto error; |
| 9768 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9769 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9770 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9771 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9772 | goto error; |
| 9773 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9774 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9775 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9776 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9777 | goto error; |
| 9778 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9779 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9780 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9781 | < 0) { |
| 9782 | goto error; |
| 9783 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9784 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9785 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9786 | 0) { |
| 9787 | goto error; |
| 9788 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9789 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9790 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9791 | 0) { |
| 9792 | goto error; |
| 9793 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9794 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9795 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9796 | 0) { |
| 9797 | goto error; |
| 9798 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9799 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9800 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9801 | astmodulestate_global->AugAssign_type) < 0) { |
| 9802 | goto error; |
| 9803 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9804 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9805 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9806 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9807 | goto error; |
| 9808 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9809 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9810 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9811 | goto error; |
| 9812 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9813 | Py_INCREF(astmodulestate(m)->For_type); |
| 9814 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9815 | < 0) { |
| 9816 | goto error; |
| 9817 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9818 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9819 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 9820 | goto error; |
| 9821 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9822 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9823 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 9824 | goto error; |
| 9825 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9826 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9827 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 9828 | goto error; |
| 9829 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9830 | Py_INCREF(astmodulestate(m)->With_type); |
| 9831 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9832 | astmodulestate_global->AsyncWith_type) < 0) { |
| 9833 | goto error; |
| 9834 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9835 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9836 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 9837 | goto error; |
| 9838 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9839 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9840 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 9841 | goto error; |
| 9842 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9843 | Py_INCREF(astmodulestate(m)->Try_type); |
| 9844 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9845 | 0) { |
| 9846 | goto error; |
| 9847 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9848 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 9849 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9850 | 0) { |
| 9851 | goto error; |
| 9852 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9853 | Py_INCREF(astmodulestate(m)->Import_type); |
| 9854 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9855 | astmodulestate_global->ImportFrom_type) < 0) { |
| 9856 | goto error; |
| 9857 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9858 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 9859 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9860 | 0) { |
| 9861 | goto error; |
| 9862 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9863 | Py_INCREF(astmodulestate(m)->Global_type); |
| 9864 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9865 | < 0) { |
| 9866 | goto error; |
| 9867 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9868 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9869 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { |
| 9870 | goto error; |
| 9871 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9872 | Py_INCREF(astmodulestate(m)->Expr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9873 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 9874 | goto error; |
| 9875 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9876 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9877 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 9878 | goto error; |
| 9879 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9880 | Py_INCREF(astmodulestate(m)->Break_type); |
| 9881 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9882 | < 0) { |
| 9883 | goto error; |
| 9884 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9885 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9886 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 9887 | goto error; |
| 9888 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9889 | Py_INCREF(astmodulestate(m)->expr_type); |
| 9890 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9891 | 0) { |
| 9892 | goto error; |
| 9893 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9894 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 9895 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9896 | astmodulestate_global->NamedExpr_type) < 0) { |
| 9897 | goto error; |
| 9898 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9899 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9900 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 9901 | goto error; |
| 9902 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9903 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 9904 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9905 | 0) { |
| 9906 | goto error; |
| 9907 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9908 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 9909 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9910 | 0) { |
| 9911 | goto error; |
| 9912 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9913 | Py_INCREF(astmodulestate(m)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9914 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 9915 | goto error; |
| 9916 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9917 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9918 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 9919 | goto error; |
| 9920 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9921 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9922 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 9923 | goto error; |
| 9924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9925 | Py_INCREF(astmodulestate(m)->Set_type); |
| 9926 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_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)->ListComp_type); |
| 9931 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9932 | 0) { |
| 9933 | goto error; |
| 9934 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9935 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 9936 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9937 | < 0) { |
| 9938 | goto error; |
| 9939 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9940 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 9941 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9942 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 9943 | goto error; |
| 9944 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9945 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9946 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 9947 | goto error; |
| 9948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9949 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9950 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 9951 | goto error; |
| 9952 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9953 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 9954 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9955 | astmodulestate_global->YieldFrom_type) < 0) { |
| 9956 | goto error; |
| 9957 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9958 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 9959 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9960 | 0) { |
| 9961 | goto error; |
| 9962 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9963 | Py_INCREF(astmodulestate(m)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9964 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 9965 | goto error; |
| 9966 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9967 | Py_INCREF(astmodulestate(m)->Call_type); |
| 9968 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9969 | astmodulestate_global->FormattedValue_type) < 0) { |
| 9970 | goto error; |
| 9971 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9972 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 9973 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9974 | astmodulestate_global->JoinedStr_type) < 0) { |
| 9975 | goto error; |
| 9976 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9977 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 9978 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9979 | < 0) { |
| 9980 | goto error; |
| 9981 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9982 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 9983 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9984 | astmodulestate_global->Attribute_type) < 0) { |
| 9985 | goto error; |
| 9986 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9987 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 9988 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9989 | astmodulestate_global->Subscript_type) < 0) { |
| 9990 | goto error; |
| 9991 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9992 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 9993 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9994 | 0) { |
| 9995 | goto error; |
| 9996 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9997 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9998 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 9999 | goto error; |
| 10000 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10001 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10002 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10003 | goto error; |
| 10004 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10005 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10006 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10007 | goto error; |
| 10008 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10009 | Py_INCREF(astmodulestate(m)->Tuple_type); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 10010 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10011 | goto error; |
| 10012 | } |
| 10013 | Py_INCREF(astmodulestate(m)->Slice_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10014 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10015 | astmodulestate_global->expr_context_type) < 0) { |
| 10016 | goto error; |
| 10017 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10018 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10019 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10020 | goto error; |
| 10021 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10022 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10023 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10024 | goto error; |
| 10025 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10026 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10027 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10028 | goto error; |
| 10029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10030 | Py_INCREF(astmodulestate(m)->Del_type); |
| 10031 | if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10032 | 0) { |
| 10033 | goto error; |
| 10034 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10035 | Py_INCREF(astmodulestate(m)->AugLoad_type); |
| 10036 | if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10037 | < 0) { |
| 10038 | goto error; |
| 10039 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10040 | Py_INCREF(astmodulestate(m)->AugStore_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10041 | if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) { |
| 10042 | goto error; |
| 10043 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10044 | Py_INCREF(astmodulestate(m)->Param_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10045 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10046 | 0) { |
| 10047 | goto error; |
| 10048 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10049 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10050 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10051 | goto error; |
| 10052 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10053 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10054 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10055 | goto error; |
| 10056 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10057 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10058 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10059 | < 0) { |
| 10060 | goto error; |
| 10061 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10062 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10063 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10064 | goto error; |
| 10065 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10066 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10067 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10068 | goto error; |
| 10069 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10070 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10071 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10072 | goto error; |
| 10073 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10074 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10075 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10076 | 0) { |
| 10077 | goto error; |
| 10078 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10079 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10080 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10081 | goto error; |
| 10082 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10083 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10084 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10085 | goto error; |
| 10086 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10087 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10088 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10089 | goto error; |
| 10090 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10091 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10092 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10093 | 0) { |
| 10094 | goto error; |
| 10095 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10096 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10097 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10098 | 0) { |
| 10099 | goto error; |
| 10100 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10101 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10102 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10103 | goto error; |
| 10104 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10105 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10106 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_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)->BitXor_type); |
| 10111 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_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)->BitAnd_type); |
| 10116 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_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)->FloorDiv_type); |
| 10121 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10122 | 0) { |
| 10123 | goto error; |
| 10124 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10125 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10126 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10127 | 0) { |
| 10128 | goto error; |
| 10129 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10130 | Py_INCREF(astmodulestate(m)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10131 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10132 | goto error; |
| 10133 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10134 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10135 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10136 | goto error; |
| 10137 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10138 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10139 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10140 | goto error; |
| 10141 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10142 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10143 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10144 | goto error; |
| 10145 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10146 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10147 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10148 | goto error; |
| 10149 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10150 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10151 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10152 | goto error; |
| 10153 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10154 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10155 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10156 | goto error; |
| 10157 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10158 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10159 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10160 | goto error; |
| 10161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10162 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10163 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10164 | goto error; |
| 10165 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10166 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10167 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10168 | goto error; |
| 10169 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10170 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10171 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10172 | goto error; |
| 10173 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10174 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10175 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10176 | goto error; |
| 10177 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10178 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10179 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10180 | goto error; |
| 10181 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10182 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10183 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10184 | goto error; |
| 10185 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10186 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10187 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10188 | astmodulestate_global->comprehension_type) < 0) { |
| 10189 | goto error; |
| 10190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10191 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10192 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10193 | astmodulestate_global->excepthandler_type) < 0) { |
| 10194 | goto error; |
| 10195 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10196 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10197 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10198 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10199 | goto error; |
| 10200 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10201 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10202 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10203 | astmodulestate_global->arguments_type) < 0) { |
| 10204 | goto error; |
| 10205 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10206 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10207 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10208 | goto error; |
| 10209 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10210 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10211 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10212 | 0) { |
| 10213 | goto error; |
| 10214 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10215 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10216 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10217 | goto error; |
| 10218 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10219 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10220 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10221 | < 0) { |
| 10222 | goto error; |
| 10223 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10224 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10225 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10226 | astmodulestate_global->type_ignore_type) < 0) { |
| 10227 | goto error; |
| 10228 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10229 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10230 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10231 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10232 | goto error; |
| 10233 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10234 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10235 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10236 | error: |
| 10237 | Py_DECREF(m); |
| 10238 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10239 | } |
| 10240 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10241 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10242 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10243 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10244 | if (!init_types()) |
| 10245 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10246 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10247 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10248 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10249 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10250 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10251 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10252 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10253 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10254 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10255 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10256 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10257 | return NULL; |
| 10258 | } |
| 10259 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10260 | req_type[0] = astmodulestate_global->Module_type; |
| 10261 | req_type[1] = astmodulestate_global->Expression_type; |
| 10262 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10263 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10264 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10265 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10266 | if (!init_types()) |
| 10267 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10268 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10269 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10270 | if (isinstance == -1) |
| 10271 | return NULL; |
| 10272 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10273 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10274 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10275 | return NULL; |
| 10276 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10277 | |
| 10278 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10279 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10280 | return NULL; |
| 10281 | else |
| 10282 | return res; |
| 10283 | } |
| 10284 | |
| 10285 | int PyAST_Check(PyObject* obj) |
| 10286 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10287 | if (!init_types()) |
| 10288 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10289 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10290 | } |
| 10291 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10292 | |