Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 3 | #include <stddef.h> |
| 4 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5 | #include "Python.h" |
| 6 | #include "Python-ast.h" |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 7 | #include "structmember.h" |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9 | typedef struct { |
| 10 | int initialized; |
| 11 | PyObject *AST_type; |
| 12 | PyObject *Add_singleton; |
| 13 | PyObject *Add_type; |
| 14 | PyObject *And_singleton; |
| 15 | PyObject *And_type; |
| 16 | PyObject *AnnAssign_type; |
| 17 | PyObject *Assert_type; |
| 18 | PyObject *Assign_type; |
| 19 | PyObject *AsyncFor_type; |
| 20 | PyObject *AsyncFunctionDef_type; |
| 21 | PyObject *AsyncWith_type; |
| 22 | PyObject *Attribute_type; |
| 23 | PyObject *AugAssign_type; |
| 24 | PyObject *AugLoad_singleton; |
| 25 | PyObject *AugLoad_type; |
| 26 | PyObject *AugStore_singleton; |
| 27 | PyObject *AugStore_type; |
| 28 | PyObject *Await_type; |
| 29 | PyObject *BinOp_type; |
| 30 | PyObject *BitAnd_singleton; |
| 31 | PyObject *BitAnd_type; |
| 32 | PyObject *BitOr_singleton; |
| 33 | PyObject *BitOr_type; |
| 34 | PyObject *BitXor_singleton; |
| 35 | PyObject *BitXor_type; |
| 36 | PyObject *BoolOp_type; |
| 37 | PyObject *Break_type; |
| 38 | PyObject *Call_type; |
| 39 | PyObject *ClassDef_type; |
| 40 | PyObject *Compare_type; |
| 41 | PyObject *Constant_type; |
| 42 | PyObject *Continue_type; |
| 43 | PyObject *Del_singleton; |
| 44 | PyObject *Del_type; |
| 45 | PyObject *Delete_type; |
| 46 | PyObject *DictComp_type; |
| 47 | PyObject *Dict_type; |
| 48 | PyObject *Div_singleton; |
| 49 | PyObject *Div_type; |
| 50 | PyObject *Eq_singleton; |
| 51 | PyObject *Eq_type; |
| 52 | PyObject *ExceptHandler_type; |
| 53 | PyObject *Expr_type; |
| 54 | PyObject *Expression_type; |
| 55 | PyObject *ExtSlice_type; |
| 56 | PyObject *FloorDiv_singleton; |
| 57 | PyObject *FloorDiv_type; |
| 58 | PyObject *For_type; |
| 59 | PyObject *FormattedValue_type; |
| 60 | PyObject *FunctionDef_type; |
| 61 | PyObject *FunctionType_type; |
| 62 | PyObject *GeneratorExp_type; |
| 63 | PyObject *Global_type; |
| 64 | PyObject *GtE_singleton; |
| 65 | PyObject *GtE_type; |
| 66 | PyObject *Gt_singleton; |
| 67 | PyObject *Gt_type; |
| 68 | PyObject *IfExp_type; |
| 69 | PyObject *If_type; |
| 70 | PyObject *ImportFrom_type; |
| 71 | PyObject *Import_type; |
| 72 | PyObject *In_singleton; |
| 73 | PyObject *In_type; |
| 74 | PyObject *Index_type; |
| 75 | PyObject *Interactive_type; |
| 76 | PyObject *Invert_singleton; |
| 77 | PyObject *Invert_type; |
| 78 | PyObject *IsNot_singleton; |
| 79 | PyObject *IsNot_type; |
| 80 | PyObject *Is_singleton; |
| 81 | PyObject *Is_type; |
| 82 | PyObject *JoinedStr_type; |
| 83 | PyObject *LShift_singleton; |
| 84 | PyObject *LShift_type; |
| 85 | PyObject *Lambda_type; |
| 86 | PyObject *ListComp_type; |
| 87 | PyObject *List_type; |
| 88 | PyObject *Load_singleton; |
| 89 | PyObject *Load_type; |
| 90 | PyObject *LtE_singleton; |
| 91 | PyObject *LtE_type; |
| 92 | PyObject *Lt_singleton; |
| 93 | PyObject *Lt_type; |
| 94 | PyObject *MatMult_singleton; |
| 95 | PyObject *MatMult_type; |
| 96 | PyObject *Mod_singleton; |
| 97 | PyObject *Mod_type; |
| 98 | PyObject *Module_type; |
| 99 | PyObject *Mult_singleton; |
| 100 | PyObject *Mult_type; |
| 101 | PyObject *Name_type; |
| 102 | PyObject *NamedExpr_type; |
| 103 | PyObject *Nonlocal_type; |
| 104 | PyObject *NotEq_singleton; |
| 105 | PyObject *NotEq_type; |
| 106 | PyObject *NotIn_singleton; |
| 107 | PyObject *NotIn_type; |
| 108 | PyObject *Not_singleton; |
| 109 | PyObject *Not_type; |
| 110 | PyObject *Or_singleton; |
| 111 | PyObject *Or_type; |
| 112 | PyObject *Param_singleton; |
| 113 | PyObject *Param_type; |
| 114 | PyObject *Pass_type; |
| 115 | PyObject *Pow_singleton; |
| 116 | PyObject *Pow_type; |
| 117 | PyObject *RShift_singleton; |
| 118 | PyObject *RShift_type; |
| 119 | PyObject *Raise_type; |
| 120 | PyObject *Return_type; |
| 121 | PyObject *SetComp_type; |
| 122 | PyObject *Set_type; |
| 123 | PyObject *Slice_type; |
| 124 | PyObject *Starred_type; |
| 125 | PyObject *Store_singleton; |
| 126 | PyObject *Store_type; |
| 127 | PyObject *Sub_singleton; |
| 128 | PyObject *Sub_type; |
| 129 | PyObject *Subscript_type; |
| 130 | PyObject *Suite_type; |
| 131 | PyObject *Try_type; |
| 132 | PyObject *Tuple_type; |
| 133 | PyObject *TypeIgnore_type; |
| 134 | PyObject *UAdd_singleton; |
| 135 | PyObject *UAdd_type; |
| 136 | PyObject *USub_singleton; |
| 137 | PyObject *USub_type; |
| 138 | PyObject *UnaryOp_type; |
| 139 | PyObject *While_type; |
| 140 | PyObject *With_type; |
| 141 | PyObject *YieldFrom_type; |
| 142 | PyObject *Yield_type; |
| 143 | PyObject *__dict__; |
| 144 | PyObject *__module__; |
| 145 | PyObject *_ast; |
| 146 | PyObject *_attributes; |
| 147 | PyObject *_fields; |
| 148 | PyObject *alias_type; |
| 149 | PyObject *annotation; |
| 150 | PyObject *arg; |
| 151 | PyObject *arg_type; |
| 152 | PyObject *args; |
| 153 | PyObject *argtypes; |
| 154 | PyObject *arguments_type; |
| 155 | PyObject *asname; |
| 156 | PyObject *attr; |
| 157 | PyObject *bases; |
| 158 | PyObject *body; |
| 159 | PyObject *boolop_type; |
| 160 | PyObject *cause; |
| 161 | PyObject *cmpop_type; |
| 162 | PyObject *col_offset; |
| 163 | PyObject *comparators; |
| 164 | PyObject *comprehension_type; |
| 165 | PyObject *context_expr; |
| 166 | PyObject *conversion; |
| 167 | PyObject *ctx; |
| 168 | PyObject *decorator_list; |
| 169 | PyObject *defaults; |
| 170 | PyObject *dims; |
| 171 | PyObject *elt; |
| 172 | PyObject *elts; |
| 173 | PyObject *end_col_offset; |
| 174 | PyObject *end_lineno; |
| 175 | PyObject *exc; |
| 176 | PyObject *excepthandler_type; |
| 177 | PyObject *expr_context_type; |
| 178 | PyObject *expr_type; |
| 179 | PyObject *finalbody; |
| 180 | PyObject *format_spec; |
| 181 | PyObject *func; |
| 182 | PyObject *generators; |
| 183 | PyObject *handlers; |
| 184 | PyObject *id; |
| 185 | PyObject *ifs; |
| 186 | PyObject *is_async; |
| 187 | PyObject *items; |
| 188 | PyObject *iter; |
| 189 | PyObject *key; |
| 190 | PyObject *keys; |
| 191 | PyObject *keyword_type; |
| 192 | PyObject *keywords; |
| 193 | PyObject *kind; |
| 194 | PyObject *kw_defaults; |
| 195 | PyObject *kwarg; |
| 196 | PyObject *kwonlyargs; |
| 197 | PyObject *left; |
| 198 | PyObject *level; |
| 199 | PyObject *lineno; |
| 200 | PyObject *lower; |
| 201 | PyObject *mod_type; |
| 202 | PyObject *module; |
| 203 | PyObject *msg; |
| 204 | PyObject *name; |
| 205 | PyObject *names; |
| 206 | PyObject *op; |
| 207 | PyObject *operand; |
| 208 | PyObject *operator_type; |
| 209 | PyObject *ops; |
| 210 | PyObject *optional_vars; |
| 211 | PyObject *orelse; |
| 212 | PyObject *posonlyargs; |
| 213 | PyObject *returns; |
| 214 | PyObject *right; |
| 215 | PyObject *simple; |
| 216 | PyObject *slice; |
| 217 | PyObject *slice_type; |
| 218 | PyObject *step; |
| 219 | PyObject *stmt_type; |
| 220 | PyObject *tag; |
| 221 | PyObject *target; |
| 222 | PyObject *targets; |
| 223 | PyObject *test; |
| 224 | PyObject *type; |
| 225 | PyObject *type_comment; |
| 226 | PyObject *type_ignore_type; |
| 227 | PyObject *type_ignores; |
| 228 | PyObject *unaryop_type; |
| 229 | PyObject *upper; |
| 230 | PyObject *value; |
| 231 | PyObject *values; |
| 232 | PyObject *vararg; |
| 233 | PyObject *withitem_type; |
| 234 | } astmodulestate; |
| 235 | |
| 236 | |
| 237 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 238 | |
| 239 | static int astmodule_clear(PyObject *module) |
| 240 | { |
| 241 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 242 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 243 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 244 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 245 | Py_CLEAR(astmodulestate(module)->And_type); |
| 246 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 247 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 248 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 249 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 250 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 251 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 252 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 253 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
| 254 | Py_CLEAR(astmodulestate(module)->AugLoad_singleton); |
| 255 | Py_CLEAR(astmodulestate(module)->AugLoad_type); |
| 256 | Py_CLEAR(astmodulestate(module)->AugStore_singleton); |
| 257 | Py_CLEAR(astmodulestate(module)->AugStore_type); |
| 258 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 259 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 260 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 261 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 262 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 263 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 264 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 265 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 266 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 267 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 268 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 269 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 271 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 272 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 273 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 274 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 275 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 276 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 277 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 278 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 279 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 280 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 281 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 282 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 283 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 284 | Py_CLEAR(astmodulestate(module)->Expression_type); |
| 285 | Py_CLEAR(astmodulestate(module)->ExtSlice_type); |
| 286 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 287 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 288 | Py_CLEAR(astmodulestate(module)->For_type); |
| 289 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 290 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 291 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 292 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 293 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 294 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 295 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 296 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 297 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 298 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 299 | Py_CLEAR(astmodulestate(module)->If_type); |
| 300 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 301 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 302 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 303 | Py_CLEAR(astmodulestate(module)->In_type); |
| 304 | Py_CLEAR(astmodulestate(module)->Index_type); |
| 305 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 306 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 307 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 308 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 309 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 310 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 311 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 312 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 313 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 314 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 315 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 316 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 317 | Py_CLEAR(astmodulestate(module)->List_type); |
| 318 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 319 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 320 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 321 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 322 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 323 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 324 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 325 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 326 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 327 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 328 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 329 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 330 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 331 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 332 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 333 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 334 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 335 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 336 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 337 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 338 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 339 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 340 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 341 | Py_CLEAR(astmodulestate(module)->Or_type); |
| 342 | Py_CLEAR(astmodulestate(module)->Param_singleton); |
| 343 | Py_CLEAR(astmodulestate(module)->Param_type); |
| 344 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 345 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 346 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 347 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 348 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 349 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 350 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 351 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 352 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 353 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 354 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 355 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 356 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 357 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 358 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 359 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
| 360 | Py_CLEAR(astmodulestate(module)->Suite_type); |
| 361 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 362 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 363 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 364 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 365 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 366 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 367 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 368 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 369 | Py_CLEAR(astmodulestate(module)->While_type); |
| 370 | Py_CLEAR(astmodulestate(module)->With_type); |
| 371 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 372 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 373 | Py_CLEAR(astmodulestate(module)->__dict__); |
| 374 | Py_CLEAR(astmodulestate(module)->__module__); |
| 375 | Py_CLEAR(astmodulestate(module)->_ast); |
| 376 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 377 | Py_CLEAR(astmodulestate(module)->_fields); |
| 378 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 379 | Py_CLEAR(astmodulestate(module)->annotation); |
| 380 | Py_CLEAR(astmodulestate(module)->arg); |
| 381 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 382 | Py_CLEAR(astmodulestate(module)->args); |
| 383 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 384 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 385 | Py_CLEAR(astmodulestate(module)->asname); |
| 386 | Py_CLEAR(astmodulestate(module)->attr); |
| 387 | Py_CLEAR(astmodulestate(module)->bases); |
| 388 | Py_CLEAR(astmodulestate(module)->body); |
| 389 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 390 | Py_CLEAR(astmodulestate(module)->cause); |
| 391 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 392 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 393 | Py_CLEAR(astmodulestate(module)->comparators); |
| 394 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 395 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 396 | Py_CLEAR(astmodulestate(module)->conversion); |
| 397 | Py_CLEAR(astmodulestate(module)->ctx); |
| 398 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 399 | Py_CLEAR(astmodulestate(module)->defaults); |
| 400 | Py_CLEAR(astmodulestate(module)->dims); |
| 401 | Py_CLEAR(astmodulestate(module)->elt); |
| 402 | Py_CLEAR(astmodulestate(module)->elts); |
| 403 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 404 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 405 | Py_CLEAR(astmodulestate(module)->exc); |
| 406 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 407 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 408 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 409 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 410 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 411 | Py_CLEAR(astmodulestate(module)->func); |
| 412 | Py_CLEAR(astmodulestate(module)->generators); |
| 413 | Py_CLEAR(astmodulestate(module)->handlers); |
| 414 | Py_CLEAR(astmodulestate(module)->id); |
| 415 | Py_CLEAR(astmodulestate(module)->ifs); |
| 416 | Py_CLEAR(astmodulestate(module)->is_async); |
| 417 | Py_CLEAR(astmodulestate(module)->items); |
| 418 | Py_CLEAR(astmodulestate(module)->iter); |
| 419 | Py_CLEAR(astmodulestate(module)->key); |
| 420 | Py_CLEAR(astmodulestate(module)->keys); |
| 421 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 422 | Py_CLEAR(astmodulestate(module)->keywords); |
| 423 | Py_CLEAR(astmodulestate(module)->kind); |
| 424 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 425 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 426 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 427 | Py_CLEAR(astmodulestate(module)->left); |
| 428 | Py_CLEAR(astmodulestate(module)->level); |
| 429 | Py_CLEAR(astmodulestate(module)->lineno); |
| 430 | Py_CLEAR(astmodulestate(module)->lower); |
| 431 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 432 | Py_CLEAR(astmodulestate(module)->module); |
| 433 | Py_CLEAR(astmodulestate(module)->msg); |
| 434 | Py_CLEAR(astmodulestate(module)->name); |
| 435 | Py_CLEAR(astmodulestate(module)->names); |
| 436 | Py_CLEAR(astmodulestate(module)->op); |
| 437 | Py_CLEAR(astmodulestate(module)->operand); |
| 438 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 439 | Py_CLEAR(astmodulestate(module)->ops); |
| 440 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 441 | Py_CLEAR(astmodulestate(module)->orelse); |
| 442 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 443 | Py_CLEAR(astmodulestate(module)->returns); |
| 444 | Py_CLEAR(astmodulestate(module)->right); |
| 445 | Py_CLEAR(astmodulestate(module)->simple); |
| 446 | Py_CLEAR(astmodulestate(module)->slice); |
| 447 | Py_CLEAR(astmodulestate(module)->slice_type); |
| 448 | Py_CLEAR(astmodulestate(module)->step); |
| 449 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 450 | Py_CLEAR(astmodulestate(module)->tag); |
| 451 | Py_CLEAR(astmodulestate(module)->target); |
| 452 | Py_CLEAR(astmodulestate(module)->targets); |
| 453 | Py_CLEAR(astmodulestate(module)->test); |
| 454 | Py_CLEAR(astmodulestate(module)->type); |
| 455 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 456 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 457 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 458 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 459 | Py_CLEAR(astmodulestate(module)->upper); |
| 460 | Py_CLEAR(astmodulestate(module)->value); |
| 461 | Py_CLEAR(astmodulestate(module)->values); |
| 462 | Py_CLEAR(astmodulestate(module)->vararg); |
| 463 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 469 | { |
| 470 | Py_VISIT(astmodulestate(module)->AST_type); |
| 471 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 472 | Py_VISIT(astmodulestate(module)->Add_type); |
| 473 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 474 | Py_VISIT(astmodulestate(module)->And_type); |
| 475 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 476 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 477 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 478 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 479 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 480 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 481 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 482 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
| 483 | Py_VISIT(astmodulestate(module)->AugLoad_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->AugLoad_type); |
| 485 | Py_VISIT(astmodulestate(module)->AugStore_singleton); |
| 486 | Py_VISIT(astmodulestate(module)->AugStore_type); |
| 487 | Py_VISIT(astmodulestate(module)->Await_type); |
| 488 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 489 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 490 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 491 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 492 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 493 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 494 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 495 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 496 | Py_VISIT(astmodulestate(module)->Break_type); |
| 497 | Py_VISIT(astmodulestate(module)->Call_type); |
| 498 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 499 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 500 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 501 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 502 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 503 | Py_VISIT(astmodulestate(module)->Del_type); |
| 504 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 505 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 506 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 507 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 508 | Py_VISIT(astmodulestate(module)->Div_type); |
| 509 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 510 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 511 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 512 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 513 | Py_VISIT(astmodulestate(module)->Expression_type); |
| 514 | Py_VISIT(astmodulestate(module)->ExtSlice_type); |
| 515 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 516 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 517 | Py_VISIT(astmodulestate(module)->For_type); |
| 518 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 519 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 520 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 521 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 522 | Py_VISIT(astmodulestate(module)->Global_type); |
| 523 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 525 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 526 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 527 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 528 | Py_VISIT(astmodulestate(module)->If_type); |
| 529 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 530 | Py_VISIT(astmodulestate(module)->Import_type); |
| 531 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 532 | Py_VISIT(astmodulestate(module)->In_type); |
| 533 | Py_VISIT(astmodulestate(module)->Index_type); |
| 534 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 535 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 536 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 537 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 539 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 540 | Py_VISIT(astmodulestate(module)->Is_type); |
| 541 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 542 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 543 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 544 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 545 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 546 | Py_VISIT(astmodulestate(module)->List_type); |
| 547 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 548 | Py_VISIT(astmodulestate(module)->Load_type); |
| 549 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 550 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 551 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 552 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 553 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 554 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 555 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 556 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 557 | Py_VISIT(astmodulestate(module)->Module_type); |
| 558 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 559 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 560 | Py_VISIT(astmodulestate(module)->Name_type); |
| 561 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 562 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 563 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 564 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 565 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 566 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 567 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 568 | Py_VISIT(astmodulestate(module)->Not_type); |
| 569 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 570 | Py_VISIT(astmodulestate(module)->Or_type); |
| 571 | Py_VISIT(astmodulestate(module)->Param_singleton); |
| 572 | Py_VISIT(astmodulestate(module)->Param_type); |
| 573 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 574 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 575 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 576 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 577 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 578 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 579 | Py_VISIT(astmodulestate(module)->Return_type); |
| 580 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 581 | Py_VISIT(astmodulestate(module)->Set_type); |
| 582 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 583 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 584 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 585 | Py_VISIT(astmodulestate(module)->Store_type); |
| 586 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 587 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 588 | Py_VISIT(astmodulestate(module)->Subscript_type); |
| 589 | Py_VISIT(astmodulestate(module)->Suite_type); |
| 590 | Py_VISIT(astmodulestate(module)->Try_type); |
| 591 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 592 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 593 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 594 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 595 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 596 | Py_VISIT(astmodulestate(module)->USub_type); |
| 597 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 598 | Py_VISIT(astmodulestate(module)->While_type); |
| 599 | Py_VISIT(astmodulestate(module)->With_type); |
| 600 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 601 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 602 | Py_VISIT(astmodulestate(module)->__dict__); |
| 603 | Py_VISIT(astmodulestate(module)->__module__); |
| 604 | Py_VISIT(astmodulestate(module)->_ast); |
| 605 | Py_VISIT(astmodulestate(module)->_attributes); |
| 606 | Py_VISIT(astmodulestate(module)->_fields); |
| 607 | Py_VISIT(astmodulestate(module)->alias_type); |
| 608 | Py_VISIT(astmodulestate(module)->annotation); |
| 609 | Py_VISIT(astmodulestate(module)->arg); |
| 610 | Py_VISIT(astmodulestate(module)->arg_type); |
| 611 | Py_VISIT(astmodulestate(module)->args); |
| 612 | Py_VISIT(astmodulestate(module)->argtypes); |
| 613 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 614 | Py_VISIT(astmodulestate(module)->asname); |
| 615 | Py_VISIT(astmodulestate(module)->attr); |
| 616 | Py_VISIT(astmodulestate(module)->bases); |
| 617 | Py_VISIT(astmodulestate(module)->body); |
| 618 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 619 | Py_VISIT(astmodulestate(module)->cause); |
| 620 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 621 | Py_VISIT(astmodulestate(module)->col_offset); |
| 622 | Py_VISIT(astmodulestate(module)->comparators); |
| 623 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 624 | Py_VISIT(astmodulestate(module)->context_expr); |
| 625 | Py_VISIT(astmodulestate(module)->conversion); |
| 626 | Py_VISIT(astmodulestate(module)->ctx); |
| 627 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 628 | Py_VISIT(astmodulestate(module)->defaults); |
| 629 | Py_VISIT(astmodulestate(module)->dims); |
| 630 | Py_VISIT(astmodulestate(module)->elt); |
| 631 | Py_VISIT(astmodulestate(module)->elts); |
| 632 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 633 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 634 | Py_VISIT(astmodulestate(module)->exc); |
| 635 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 636 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 637 | Py_VISIT(astmodulestate(module)->expr_type); |
| 638 | Py_VISIT(astmodulestate(module)->finalbody); |
| 639 | Py_VISIT(astmodulestate(module)->format_spec); |
| 640 | Py_VISIT(astmodulestate(module)->func); |
| 641 | Py_VISIT(astmodulestate(module)->generators); |
| 642 | Py_VISIT(astmodulestate(module)->handlers); |
| 643 | Py_VISIT(astmodulestate(module)->id); |
| 644 | Py_VISIT(astmodulestate(module)->ifs); |
| 645 | Py_VISIT(astmodulestate(module)->is_async); |
| 646 | Py_VISIT(astmodulestate(module)->items); |
| 647 | Py_VISIT(astmodulestate(module)->iter); |
| 648 | Py_VISIT(astmodulestate(module)->key); |
| 649 | Py_VISIT(astmodulestate(module)->keys); |
| 650 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 651 | Py_VISIT(astmodulestate(module)->keywords); |
| 652 | Py_VISIT(astmodulestate(module)->kind); |
| 653 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 654 | Py_VISIT(astmodulestate(module)->kwarg); |
| 655 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 656 | Py_VISIT(astmodulestate(module)->left); |
| 657 | Py_VISIT(astmodulestate(module)->level); |
| 658 | Py_VISIT(astmodulestate(module)->lineno); |
| 659 | Py_VISIT(astmodulestate(module)->lower); |
| 660 | Py_VISIT(astmodulestate(module)->mod_type); |
| 661 | Py_VISIT(astmodulestate(module)->module); |
| 662 | Py_VISIT(astmodulestate(module)->msg); |
| 663 | Py_VISIT(astmodulestate(module)->name); |
| 664 | Py_VISIT(astmodulestate(module)->names); |
| 665 | Py_VISIT(astmodulestate(module)->op); |
| 666 | Py_VISIT(astmodulestate(module)->operand); |
| 667 | Py_VISIT(astmodulestate(module)->operator_type); |
| 668 | Py_VISIT(astmodulestate(module)->ops); |
| 669 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 670 | Py_VISIT(astmodulestate(module)->orelse); |
| 671 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 672 | Py_VISIT(astmodulestate(module)->returns); |
| 673 | Py_VISIT(astmodulestate(module)->right); |
| 674 | Py_VISIT(astmodulestate(module)->simple); |
| 675 | Py_VISIT(astmodulestate(module)->slice); |
| 676 | Py_VISIT(astmodulestate(module)->slice_type); |
| 677 | Py_VISIT(astmodulestate(module)->step); |
| 678 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 679 | Py_VISIT(astmodulestate(module)->tag); |
| 680 | Py_VISIT(astmodulestate(module)->target); |
| 681 | Py_VISIT(astmodulestate(module)->targets); |
| 682 | Py_VISIT(astmodulestate(module)->test); |
| 683 | Py_VISIT(astmodulestate(module)->type); |
| 684 | Py_VISIT(astmodulestate(module)->type_comment); |
| 685 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 686 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 687 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 688 | Py_VISIT(astmodulestate(module)->upper); |
| 689 | Py_VISIT(astmodulestate(module)->value); |
| 690 | Py_VISIT(astmodulestate(module)->values); |
| 691 | Py_VISIT(astmodulestate(module)->vararg); |
| 692 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 693 | |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | static void astmodule_free(void* module) { |
| 698 | astmodule_clear((PyObject*)module); |
| 699 | } |
| 700 | |
| 701 | static struct PyModuleDef _astmodule = { |
| 702 | PyModuleDef_HEAD_INIT, |
| 703 | "_ast", |
| 704 | NULL, |
| 705 | sizeof(astmodulestate), |
| 706 | NULL, |
| 707 | NULL, |
| 708 | astmodule_traverse, |
| 709 | astmodule_clear, |
| 710 | astmodule_free, |
| 711 | }; |
| 712 | |
| 713 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 714 | |
| 715 | static int init_identifiers(void) |
| 716 | { |
| 717 | astmodulestate *state = astmodulestate_global; |
| 718 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
| 719 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
| 720 | if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0; |
| 721 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 722 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 723 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 724 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 725 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 726 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 727 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
| 728 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 729 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 730 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 731 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 732 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 733 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 734 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 735 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 736 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 737 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 738 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
| 739 | if ((state->dims = PyUnicode_InternFromString("dims")) == NULL) return 0; |
| 740 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 741 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 742 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 743 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 744 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 745 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 746 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 747 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 748 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 749 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 750 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 751 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 752 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 753 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 754 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 755 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 756 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 757 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 758 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 759 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 760 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 761 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 762 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 763 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 764 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 765 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 766 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 767 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 768 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 769 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 770 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 771 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 772 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 773 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 774 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 775 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 776 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 777 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 778 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 779 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 780 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 781 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 782 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 783 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 784 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 785 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 786 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 787 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 788 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 789 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 790 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 791 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 792 | return 1; |
| 793 | }; |
| 794 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 795 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 796 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 797 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 798 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 799 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 800 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 801 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 802 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 803 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 804 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 805 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 806 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 807 | "argtypes", |
| 808 | "returns", |
| 809 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 810 | static const char * const Suite_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 811 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 813 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 814 | "lineno", |
| 815 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 816 | "end_lineno", |
| 817 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 818 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 819 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 820 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 821 | "name", |
| 822 | "args", |
| 823 | "body", |
| 824 | "decorator_list", |
| 825 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 826 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 827 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 828 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 829 | "name", |
| 830 | "args", |
| 831 | "body", |
| 832 | "decorator_list", |
| 833 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 834 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 835 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 836 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 837 | "name", |
| 838 | "bases", |
| 839 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 840 | "body", |
| 841 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 842 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 843 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 844 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 845 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 846 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 847 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 848 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 849 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 850 | "targets", |
| 851 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 852 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 853 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 854 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 855 | "target", |
| 856 | "op", |
| 857 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 858 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 859 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 860 | "target", |
| 861 | "annotation", |
| 862 | "value", |
| 863 | "simple", |
| 864 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 865 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 866 | "target", |
| 867 | "iter", |
| 868 | "body", |
| 869 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 870 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 871 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 872 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 873 | "target", |
| 874 | "iter", |
| 875 | "body", |
| 876 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 877 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 878 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 879 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 880 | "test", |
| 881 | "body", |
| 882 | "orelse", |
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 If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 885 | "test", |
| 886 | "body", |
| 887 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 888 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 889 | static const char * const With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 890 | "items", |
| 891 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 892 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 893 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 894 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 895 | "items", |
| 896 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 897 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 898 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 899 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 900 | "exc", |
| 901 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 902 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 903 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 904 | "body", |
| 905 | "handlers", |
| 906 | "orelse", |
| 907 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 908 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 909 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 910 | "test", |
| 911 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 912 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 913 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 914 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 915 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 916 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 917 | "module", |
| 918 | "names", |
| 919 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 920 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 921 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 923 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 924 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 925 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 926 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 927 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 928 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 929 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 930 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 931 | "lineno", |
| 932 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 933 | "end_lineno", |
| 934 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 935 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 936 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 937 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 938 | "op", |
| 939 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 940 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 941 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 942 | "target", |
| 943 | "value", |
| 944 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 945 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 946 | "left", |
| 947 | "op", |
| 948 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 949 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 950 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 951 | "op", |
| 952 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 953 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 954 | static const char * const Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 955 | "args", |
| 956 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 957 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 958 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 959 | "test", |
| 960 | "body", |
| 961 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 962 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 963 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 964 | "keys", |
| 965 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 966 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 967 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 968 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 969 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 970 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 971 | "elt", |
| 972 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 973 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 974 | static const char * const SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 975 | "elt", |
| 976 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 977 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 978 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 979 | "key", |
| 980 | "value", |
| 981 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 982 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 983 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 984 | "elt", |
| 985 | "generators", |
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 Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 988 | "value", |
| 989 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 990 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 992 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 993 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 994 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 995 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 996 | static const char * const Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 997 | "left", |
| 998 | "ops", |
| 999 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1000 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1001 | static const char * const Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1002 | "func", |
| 1003 | "args", |
| 1004 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1005 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1006 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 1007 | "value", |
| 1008 | "conversion", |
| 1009 | "format_spec", |
| 1010 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1011 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 1012 | "values", |
| 1013 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1014 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1015 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 1016 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1017 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1018 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1019 | "value", |
| 1020 | "attr", |
| 1021 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1022 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1023 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1024 | "value", |
| 1025 | "slice", |
| 1026 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1027 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1028 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1029 | "value", |
| 1030 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 1031 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1032 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1033 | "id", |
| 1034 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1035 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1036 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1037 | "elts", |
| 1038 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1040 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1041 | "elts", |
| 1042 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1043 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1044 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1045 | static PyObject* ast2obj_slice(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1046 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1047 | "lower", |
| 1048 | "upper", |
| 1049 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1050 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1051 | static const char * const ExtSlice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1052 | "dims", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1053 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1054 | static const char * const Index_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1055 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1056 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1057 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1058 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1059 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1060 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1061 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1062 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1063 | "target", |
| 1064 | "iter", |
| 1065 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1066 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1067 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1068 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1069 | "lineno", |
| 1070 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1071 | "end_lineno", |
| 1072 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1073 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1074 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1075 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1076 | "type", |
| 1077 | "name", |
| 1078 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1079 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1080 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1081 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1082 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1083 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1084 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1085 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1086 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1087 | "kwarg", |
| 1088 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1089 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1090 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1091 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1092 | "lineno", |
| 1093 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1094 | "end_lineno", |
| 1095 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1096 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1097 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1098 | "arg", |
| 1099 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1100 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1101 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1102 | static PyObject* ast2obj_keyword(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1103 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1104 | "arg", |
| 1105 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1106 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1107 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1108 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1109 | "name", |
| 1110 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1111 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1112 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1113 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1114 | "context_expr", |
| 1115 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1116 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1117 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1118 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1119 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1120 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1121 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1122 | |
| 1123 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1124 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1125 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1126 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1127 | PyObject *dict; |
| 1128 | } AST_object; |
| 1129 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1130 | static void |
| 1131 | ast_dealloc(AST_object *self) |
| 1132 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1133 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1134 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1135 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1136 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1137 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1138 | assert(free_func != NULL); |
| 1139 | free_func(self); |
| 1140 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1141 | } |
| 1142 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1143 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1144 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1145 | { |
| 1146 | Py_VISIT(self->dict); |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1150 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1151 | ast_clear(AST_object *self) |
| 1152 | { |
| 1153 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1154 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1158 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1159 | { |
| 1160 | Py_ssize_t i, numfields = 0; |
| 1161 | int res = -1; |
| 1162 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1163 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1164 | goto cleanup; |
| 1165 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1166 | if (fields) { |
| 1167 | numfields = PySequence_Size(fields); |
| 1168 | if (numfields == -1) |
| 1169 | goto cleanup; |
| 1170 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1171 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1172 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1173 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1174 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1175 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1176 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1177 | numfields, numfields == 1 ? "" : "s"); |
| 1178 | res = -1; |
| 1179 | goto cleanup; |
| 1180 | } |
| 1181 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1182 | /* cannot be reached when fields is NULL */ |
| 1183 | PyObject *name = PySequence_GetItem(fields, i); |
| 1184 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1185 | res = -1; |
| 1186 | goto cleanup; |
| 1187 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1188 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1189 | Py_DECREF(name); |
| 1190 | if (res < 0) |
| 1191 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1192 | } |
| 1193 | if (kw) { |
| 1194 | i = 0; /* needed by PyDict_Next */ |
| 1195 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1196 | res = PyObject_SetAttr(self, key, value); |
| 1197 | if (res < 0) |
| 1198 | goto cleanup; |
| 1199 | } |
| 1200 | } |
| 1201 | cleanup: |
| 1202 | Py_XDECREF(fields); |
| 1203 | return res; |
| 1204 | } |
| 1205 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1206 | /* Pickling support */ |
| 1207 | static PyObject * |
| 1208 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1209 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1210 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1211 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1212 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1213 | } |
| 1214 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1215 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1216 | } |
| 1217 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1218 | } |
| 1219 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1220 | static PyMemberDef ast_type_members[] = { |
| 1221 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1222 | {NULL} /* Sentinel */ |
| 1223 | }; |
| 1224 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1225 | static PyMethodDef ast_type_methods[] = { |
| 1226 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1227 | {NULL} |
| 1228 | }; |
| 1229 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1230 | static PyGetSetDef ast_type_getsets[] = { |
| 1231 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1232 | {NULL} |
| 1233 | }; |
| 1234 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1235 | static PyType_Slot AST_type_slots[] = { |
| 1236 | {Py_tp_dealloc, ast_dealloc}, |
| 1237 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1238 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1239 | {Py_tp_traverse, ast_traverse}, |
| 1240 | {Py_tp_clear, ast_clear}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1241 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1242 | {Py_tp_methods, ast_type_methods}, |
| 1243 | {Py_tp_getset, ast_type_getsets}, |
| 1244 | {Py_tp_init, ast_type_init}, |
| 1245 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1246 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1247 | {Py_tp_free, PyObject_GC_Del}, |
| 1248 | {0, 0}, |
| 1249 | }; |
| 1250 | |
| 1251 | static PyType_Spec AST_type_spec = { |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1252 | "_ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1253 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1254 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1255 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1256 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1257 | }; |
| 1258 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1259 | static PyObject * |
| 1260 | 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] | 1261 | { |
| 1262 | PyObject *fnames, *result; |
| 1263 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1264 | fnames = PyTuple_New(num_fields); |
| 1265 | if (!fnames) return NULL; |
| 1266 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1267 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1268 | if (!field) { |
| 1269 | Py_DECREF(fnames); |
| 1270 | return NULL; |
| 1271 | } |
| 1272 | PyTuple_SET_ITEM(fnames, i, field); |
| 1273 | } |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1274 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
| 1275 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1276 | astmodulestate_global->_fields, fnames, |
| 1277 | astmodulestate_global->__module__, |
| 1278 | astmodulestate_global->_ast); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1279 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1280 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1283 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1284 | 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] | 1285 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1286 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1287 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1288 | if (!l) |
| 1289 | return 0; |
| 1290 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1291 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1292 | if (!s) { |
| 1293 | Py_DECREF(l); |
| 1294 | return 0; |
| 1295 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1296 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1297 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1298 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1299 | Py_DECREF(l); |
| 1300 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1303 | /* Conversion AST -> Python */ |
| 1304 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1305 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1306 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1307 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1308 | PyObject *result = PyList_New(n); |
| 1309 | PyObject *value; |
| 1310 | if (!result) |
| 1311 | return NULL; |
| 1312 | for (i = 0; i < n; i++) { |
| 1313 | value = func(asdl_seq_GET(seq, i)); |
| 1314 | if (!value) { |
| 1315 | Py_DECREF(result); |
| 1316 | return NULL; |
| 1317 | } |
| 1318 | PyList_SET_ITEM(result, i, value); |
| 1319 | } |
| 1320 | return result; |
| 1321 | } |
| 1322 | |
| 1323 | static PyObject* ast2obj_object(void *o) |
| 1324 | { |
| 1325 | if (!o) |
| 1326 | o = Py_None; |
| 1327 | Py_INCREF((PyObject*)o); |
| 1328 | return (PyObject*)o; |
| 1329 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1330 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1331 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1332 | #define ast2obj_identifier ast2obj_object |
| 1333 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1334 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1335 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1336 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1337 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1338 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1341 | /* Conversion Python -> AST */ |
| 1342 | |
| 1343 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1344 | { |
| 1345 | if (obj == Py_None) |
| 1346 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1347 | if (obj) { |
| 1348 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1349 | *out = NULL; |
| 1350 | return -1; |
| 1351 | } |
| 1352 | Py_INCREF(obj); |
| 1353 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1354 | *out = obj; |
| 1355 | return 0; |
| 1356 | } |
| 1357 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1358 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1359 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1360 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1361 | *out = NULL; |
| 1362 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1363 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1364 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1365 | *out = obj; |
| 1366 | return 0; |
| 1367 | } |
| 1368 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1369 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1370 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1371 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1372 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1373 | return 1; |
| 1374 | } |
| 1375 | return obj2ast_object(obj, out, arena); |
| 1376 | } |
| 1377 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1378 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1379 | { |
| 1380 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1381 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1382 | return 1; |
| 1383 | } |
| 1384 | return obj2ast_object(obj, out, arena); |
| 1385 | } |
| 1386 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1387 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1388 | { |
| 1389 | int i; |
| 1390 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1391 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1392 | return 1; |
| 1393 | } |
| 1394 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1395 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1396 | if (i == -1 && PyErr_Occurred()) |
| 1397 | return 1; |
| 1398 | *out = i; |
| 1399 | return 0; |
| 1400 | } |
| 1401 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1402 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1403 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1404 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1405 | empty_tuple = PyTuple_New(0); |
| 1406 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1407 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1408 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1409 | Py_XDECREF(empty_tuple); |
| 1410 | return -1; |
| 1411 | } |
| 1412 | Py_DECREF(empty_tuple); |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1416 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1417 | static int init_types(void) |
| 1418 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1419 | PyObject *m; |
| 1420 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1421 | m = PyModule_Create(&_astmodule); |
| 1422 | if (!m) return 0; |
| 1423 | PyState_AddModule(m, &_astmodule); |
| 1424 | } |
| 1425 | astmodulestate *state = astmodulestate_global; |
| 1426 | if (state->initialized) return 1; |
| 1427 | if (init_identifiers() < 0) return 0; |
| 1428 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1429 | if (!state->AST_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1430 | if (add_ast_fields() < 0) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1431 | state->mod_type = make_type("mod", state->AST_type, NULL, 0); |
| 1432 | if (!state->mod_type) return 0; |
| 1433 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
| 1434 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2); |
| 1435 | if (!state->Module_type) return 0; |
| 1436 | state->Interactive_type = make_type("Interactive", state->mod_type, |
| 1437 | Interactive_fields, 1); |
| 1438 | if (!state->Interactive_type) return 0; |
| 1439 | state->Expression_type = make_type("Expression", state->mod_type, |
| 1440 | Expression_fields, 1); |
| 1441 | if (!state->Expression_type) return 0; |
| 1442 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
| 1443 | FunctionType_fields, 2); |
| 1444 | if (!state->FunctionType_type) return 0; |
| 1445 | state->Suite_type = make_type("Suite", state->mod_type, Suite_fields, 1); |
| 1446 | if (!state->Suite_type) return 0; |
| 1447 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0); |
| 1448 | if (!state->stmt_type) return 0; |
| 1449 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
| 1450 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
| 1451 | FunctionDef_fields, 6); |
| 1452 | if (!state->FunctionDef_type) return 0; |
| 1453 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1454 | state->stmt_type, |
| 1455 | AsyncFunctionDef_fields, 6); |
| 1456 | if (!state->AsyncFunctionDef_type) return 0; |
| 1457 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
| 1458 | ClassDef_fields, 5); |
| 1459 | if (!state->ClassDef_type) return 0; |
| 1460 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, |
| 1461 | 1); |
| 1462 | if (!state->Return_type) return 0; |
| 1463 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, |
| 1464 | 1); |
| 1465 | if (!state->Delete_type) return 0; |
| 1466 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, |
| 1467 | 3); |
| 1468 | if (!state->Assign_type) return 0; |
| 1469 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
| 1470 | AugAssign_fields, 3); |
| 1471 | if (!state->AugAssign_type) return 0; |
| 1472 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
| 1473 | AnnAssign_fields, 4); |
| 1474 | if (!state->AnnAssign_type) return 0; |
| 1475 | state->For_type = make_type("For", state->stmt_type, For_fields, 5); |
| 1476 | if (!state->For_type) return 0; |
| 1477 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
| 1478 | AsyncFor_fields, 5); |
| 1479 | if (!state->AsyncFor_type) return 0; |
| 1480 | state->While_type = make_type("While", state->stmt_type, While_fields, 3); |
| 1481 | if (!state->While_type) return 0; |
| 1482 | state->If_type = make_type("If", state->stmt_type, If_fields, 3); |
| 1483 | if (!state->If_type) return 0; |
| 1484 | state->With_type = make_type("With", state->stmt_type, With_fields, 3); |
| 1485 | if (!state->With_type) return 0; |
| 1486 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
| 1487 | AsyncWith_fields, 3); |
| 1488 | if (!state->AsyncWith_type) return 0; |
| 1489 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2); |
| 1490 | if (!state->Raise_type) return 0; |
| 1491 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4); |
| 1492 | if (!state->Try_type) return 0; |
| 1493 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, |
| 1494 | 2); |
| 1495 | if (!state->Assert_type) return 0; |
| 1496 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, |
| 1497 | 1); |
| 1498 | if (!state->Import_type) return 0; |
| 1499 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
| 1500 | ImportFrom_fields, 3); |
| 1501 | if (!state->ImportFrom_type) return 0; |
| 1502 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, |
| 1503 | 1); |
| 1504 | if (!state->Global_type) return 0; |
| 1505 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
| 1506 | Nonlocal_fields, 1); |
| 1507 | if (!state->Nonlocal_type) return 0; |
| 1508 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1); |
| 1509 | if (!state->Expr_type) return 0; |
| 1510 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0); |
| 1511 | if (!state->Pass_type) return 0; |
| 1512 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0); |
| 1513 | if (!state->Break_type) return 0; |
| 1514 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0); |
| 1515 | if (!state->Continue_type) return 0; |
| 1516 | state->expr_type = make_type("expr", state->AST_type, NULL, 0); |
| 1517 | if (!state->expr_type) return 0; |
| 1518 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
| 1519 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, |
| 1520 | 2); |
| 1521 | if (!state->BoolOp_type) return 0; |
| 1522 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
| 1523 | NamedExpr_fields, 2); |
| 1524 | if (!state->NamedExpr_type) return 0; |
| 1525 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3); |
| 1526 | if (!state->BinOp_type) return 0; |
| 1527 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
| 1528 | UnaryOp_fields, 2); |
| 1529 | if (!state->UnaryOp_type) return 0; |
| 1530 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, |
| 1531 | 2); |
| 1532 | if (!state->Lambda_type) return 0; |
| 1533 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3); |
| 1534 | if (!state->IfExp_type) return 0; |
| 1535 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2); |
| 1536 | if (!state->Dict_type) return 0; |
| 1537 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1); |
| 1538 | if (!state->Set_type) return 0; |
| 1539 | state->ListComp_type = make_type("ListComp", state->expr_type, |
| 1540 | ListComp_fields, 2); |
| 1541 | if (!state->ListComp_type) return 0; |
| 1542 | state->SetComp_type = make_type("SetComp", state->expr_type, |
| 1543 | SetComp_fields, 2); |
| 1544 | if (!state->SetComp_type) return 0; |
| 1545 | state->DictComp_type = make_type("DictComp", state->expr_type, |
| 1546 | DictComp_fields, 3); |
| 1547 | if (!state->DictComp_type) return 0; |
| 1548 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
| 1549 | GeneratorExp_fields, 2); |
| 1550 | if (!state->GeneratorExp_type) return 0; |
| 1551 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1); |
| 1552 | if (!state->Await_type) return 0; |
| 1553 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1); |
| 1554 | if (!state->Yield_type) return 0; |
| 1555 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
| 1556 | YieldFrom_fields, 1); |
| 1557 | if (!state->YieldFrom_type) return 0; |
| 1558 | state->Compare_type = make_type("Compare", state->expr_type, |
| 1559 | Compare_fields, 3); |
| 1560 | if (!state->Compare_type) return 0; |
| 1561 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3); |
| 1562 | if (!state->Call_type) return 0; |
| 1563 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
| 1564 | FormattedValue_fields, 3); |
| 1565 | if (!state->FormattedValue_type) return 0; |
| 1566 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
| 1567 | JoinedStr_fields, 1); |
| 1568 | if (!state->JoinedStr_type) return 0; |
| 1569 | state->Constant_type = make_type("Constant", state->expr_type, |
| 1570 | Constant_fields, 2); |
| 1571 | if (!state->Constant_type) return 0; |
| 1572 | state->Attribute_type = make_type("Attribute", state->expr_type, |
| 1573 | Attribute_fields, 3); |
| 1574 | if (!state->Attribute_type) return 0; |
| 1575 | state->Subscript_type = make_type("Subscript", state->expr_type, |
| 1576 | Subscript_fields, 3); |
| 1577 | if (!state->Subscript_type) return 0; |
| 1578 | state->Starred_type = make_type("Starred", state->expr_type, |
| 1579 | Starred_fields, 2); |
| 1580 | if (!state->Starred_type) return 0; |
| 1581 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2); |
| 1582 | if (!state->Name_type) return 0; |
| 1583 | state->List_type = make_type("List", state->expr_type, List_fields, 2); |
| 1584 | if (!state->List_type) return 0; |
| 1585 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2); |
| 1586 | if (!state->Tuple_type) return 0; |
| 1587 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
| 1588 | 0); |
| 1589 | if (!state->expr_context_type) return 0; |
| 1590 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
| 1591 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0); |
| 1592 | if (!state->Load_type) return 0; |
| 1593 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1594 | NULL, NULL); |
| 1595 | if (!state->Load_singleton) return 0; |
| 1596 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0); |
| 1597 | if (!state->Store_type) return 0; |
| 1598 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1599 | *)state->Store_type, NULL, NULL); |
| 1600 | if (!state->Store_singleton) return 0; |
| 1601 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0); |
| 1602 | if (!state->Del_type) return 0; |
| 1603 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1604 | NULL, NULL); |
| 1605 | if (!state->Del_singleton) return 0; |
| 1606 | state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL, |
| 1607 | 0); |
| 1608 | if (!state->AugLoad_type) return 0; |
| 1609 | state->AugLoad_singleton = PyType_GenericNew((PyTypeObject |
| 1610 | *)state->AugLoad_type, NULL, |
| 1611 | NULL); |
| 1612 | if (!state->AugLoad_singleton) return 0; |
| 1613 | state->AugStore_type = make_type("AugStore", state->expr_context_type, |
| 1614 | NULL, 0); |
| 1615 | if (!state->AugStore_type) return 0; |
| 1616 | state->AugStore_singleton = PyType_GenericNew((PyTypeObject |
| 1617 | *)state->AugStore_type, NULL, |
| 1618 | NULL); |
| 1619 | if (!state->AugStore_singleton) return 0; |
| 1620 | state->Param_type = make_type("Param", state->expr_context_type, NULL, 0); |
| 1621 | if (!state->Param_type) return 0; |
| 1622 | state->Param_singleton = PyType_GenericNew((PyTypeObject |
| 1623 | *)state->Param_type, NULL, NULL); |
| 1624 | if (!state->Param_singleton) return 0; |
| 1625 | state->slice_type = make_type("slice", state->AST_type, NULL, 0); |
| 1626 | if (!state->slice_type) return 0; |
| 1627 | if (!add_attributes(state->slice_type, NULL, 0)) return 0; |
| 1628 | state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3); |
| 1629 | if (!state->Slice_type) return 0; |
| 1630 | state->ExtSlice_type = make_type("ExtSlice", state->slice_type, |
| 1631 | ExtSlice_fields, 1); |
| 1632 | if (!state->ExtSlice_type) return 0; |
| 1633 | state->Index_type = make_type("Index", state->slice_type, Index_fields, 1); |
| 1634 | if (!state->Index_type) return 0; |
| 1635 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0); |
| 1636 | if (!state->boolop_type) return 0; |
| 1637 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
| 1638 | state->And_type = make_type("And", state->boolop_type, NULL, 0); |
| 1639 | if (!state->And_type) return 0; |
| 1640 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1641 | NULL, NULL); |
| 1642 | if (!state->And_singleton) return 0; |
| 1643 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0); |
| 1644 | if (!state->Or_type) return 0; |
| 1645 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1646 | NULL, NULL); |
| 1647 | if (!state->Or_singleton) return 0; |
| 1648 | state->operator_type = make_type("operator", state->AST_type, NULL, 0); |
| 1649 | if (!state->operator_type) return 0; |
| 1650 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
| 1651 | state->Add_type = make_type("Add", state->operator_type, NULL, 0); |
| 1652 | if (!state->Add_type) return 0; |
| 1653 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1654 | NULL, NULL); |
| 1655 | if (!state->Add_singleton) return 0; |
| 1656 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0); |
| 1657 | if (!state->Sub_type) return 0; |
| 1658 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1659 | NULL, NULL); |
| 1660 | if (!state->Sub_singleton) return 0; |
| 1661 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0); |
| 1662 | if (!state->Mult_type) return 0; |
| 1663 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1664 | NULL, NULL); |
| 1665 | if (!state->Mult_singleton) return 0; |
| 1666 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0); |
| 1667 | if (!state->MatMult_type) return 0; |
| 1668 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1669 | *)state->MatMult_type, NULL, |
| 1670 | NULL); |
| 1671 | if (!state->MatMult_singleton) return 0; |
| 1672 | state->Div_type = make_type("Div", state->operator_type, NULL, 0); |
| 1673 | if (!state->Div_type) return 0; |
| 1674 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1675 | NULL, NULL); |
| 1676 | if (!state->Div_singleton) return 0; |
| 1677 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0); |
| 1678 | if (!state->Mod_type) return 0; |
| 1679 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1680 | NULL, NULL); |
| 1681 | if (!state->Mod_singleton) return 0; |
| 1682 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0); |
| 1683 | if (!state->Pow_type) return 0; |
| 1684 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1685 | NULL, NULL); |
| 1686 | if (!state->Pow_singleton) return 0; |
| 1687 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0); |
| 1688 | if (!state->LShift_type) return 0; |
| 1689 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1690 | *)state->LShift_type, NULL, |
| 1691 | NULL); |
| 1692 | if (!state->LShift_singleton) return 0; |
| 1693 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0); |
| 1694 | if (!state->RShift_type) return 0; |
| 1695 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1696 | *)state->RShift_type, NULL, |
| 1697 | NULL); |
| 1698 | if (!state->RShift_singleton) return 0; |
| 1699 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0); |
| 1700 | if (!state->BitOr_type) return 0; |
| 1701 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1702 | *)state->BitOr_type, NULL, NULL); |
| 1703 | if (!state->BitOr_singleton) return 0; |
| 1704 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0); |
| 1705 | if (!state->BitXor_type) return 0; |
| 1706 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1707 | *)state->BitXor_type, NULL, |
| 1708 | NULL); |
| 1709 | if (!state->BitXor_singleton) return 0; |
| 1710 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0); |
| 1711 | if (!state->BitAnd_type) return 0; |
| 1712 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1713 | *)state->BitAnd_type, NULL, |
| 1714 | NULL); |
| 1715 | if (!state->BitAnd_singleton) return 0; |
| 1716 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0); |
| 1717 | if (!state->FloorDiv_type) return 0; |
| 1718 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1719 | *)state->FloorDiv_type, NULL, |
| 1720 | NULL); |
| 1721 | if (!state->FloorDiv_singleton) return 0; |
| 1722 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0); |
| 1723 | if (!state->unaryop_type) return 0; |
| 1724 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
| 1725 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0); |
| 1726 | if (!state->Invert_type) return 0; |
| 1727 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1728 | *)state->Invert_type, NULL, |
| 1729 | NULL); |
| 1730 | if (!state->Invert_singleton) return 0; |
| 1731 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0); |
| 1732 | if (!state->Not_type) return 0; |
| 1733 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1734 | NULL, NULL); |
| 1735 | if (!state->Not_singleton) return 0; |
| 1736 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0); |
| 1737 | if (!state->UAdd_type) return 0; |
| 1738 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1739 | NULL, NULL); |
| 1740 | if (!state->UAdd_singleton) return 0; |
| 1741 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0); |
| 1742 | if (!state->USub_type) return 0; |
| 1743 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1744 | NULL, NULL); |
| 1745 | if (!state->USub_singleton) return 0; |
| 1746 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0); |
| 1747 | if (!state->cmpop_type) return 0; |
| 1748 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
| 1749 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0); |
| 1750 | if (!state->Eq_type) return 0; |
| 1751 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1752 | NULL, NULL); |
| 1753 | if (!state->Eq_singleton) return 0; |
| 1754 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0); |
| 1755 | if (!state->NotEq_type) return 0; |
| 1756 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1757 | *)state->NotEq_type, NULL, NULL); |
| 1758 | if (!state->NotEq_singleton) return 0; |
| 1759 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0); |
| 1760 | if (!state->Lt_type) return 0; |
| 1761 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1762 | NULL, NULL); |
| 1763 | if (!state->Lt_singleton) return 0; |
| 1764 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0); |
| 1765 | if (!state->LtE_type) return 0; |
| 1766 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1767 | NULL, NULL); |
| 1768 | if (!state->LtE_singleton) return 0; |
| 1769 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0); |
| 1770 | if (!state->Gt_type) return 0; |
| 1771 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1772 | NULL, NULL); |
| 1773 | if (!state->Gt_singleton) return 0; |
| 1774 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0); |
| 1775 | if (!state->GtE_type) return 0; |
| 1776 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1777 | NULL, NULL); |
| 1778 | if (!state->GtE_singleton) return 0; |
| 1779 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0); |
| 1780 | if (!state->Is_type) return 0; |
| 1781 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1782 | NULL, NULL); |
| 1783 | if (!state->Is_singleton) return 0; |
| 1784 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0); |
| 1785 | if (!state->IsNot_type) return 0; |
| 1786 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1787 | *)state->IsNot_type, NULL, NULL); |
| 1788 | if (!state->IsNot_singleton) return 0; |
| 1789 | state->In_type = make_type("In", state->cmpop_type, NULL, 0); |
| 1790 | if (!state->In_type) return 0; |
| 1791 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1792 | NULL, NULL); |
| 1793 | if (!state->In_singleton) return 0; |
| 1794 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0); |
| 1795 | if (!state->NotIn_type) return 0; |
| 1796 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1797 | *)state->NotIn_type, NULL, NULL); |
| 1798 | if (!state->NotIn_singleton) return 0; |
| 1799 | state->comprehension_type = make_type("comprehension", state->AST_type, |
| 1800 | comprehension_fields, 4); |
| 1801 | if (!state->comprehension_type) return 0; |
| 1802 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1803 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
| 1804 | NULL, 0); |
| 1805 | if (!state->excepthandler_type) return 0; |
| 1806 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1807 | 4)) return 0; |
| 1808 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1809 | state->excepthandler_type, |
| 1810 | ExceptHandler_fields, 3); |
| 1811 | if (!state->ExceptHandler_type) return 0; |
| 1812 | state->arguments_type = make_type("arguments", state->AST_type, |
| 1813 | arguments_fields, 7); |
| 1814 | if (!state->arguments_type) return 0; |
| 1815 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
| 1816 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3); |
| 1817 | if (!state->arg_type) return 0; |
| 1818 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
| 1819 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
| 1820 | 2); |
| 1821 | if (!state->keyword_type) return 0; |
| 1822 | if (!add_attributes(state->keyword_type, NULL, 0)) return 0; |
| 1823 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2); |
| 1824 | if (!state->alias_type) return 0; |
| 1825 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
| 1826 | state->withitem_type = make_type("withitem", state->AST_type, |
| 1827 | withitem_fields, 2); |
| 1828 | if (!state->withitem_type) return 0; |
| 1829 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
| 1830 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, |
| 1831 | 0); |
| 1832 | if (!state->type_ignore_type) return 0; |
| 1833 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 1834 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
| 1835 | TypeIgnore_fields, 2); |
| 1836 | if (!state->TypeIgnore_type) return 0; |
| 1837 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1838 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1839 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 1840 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1841 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 1842 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 1843 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 1844 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 1845 | arena); |
| 1846 | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
| 1847 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 1848 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 1849 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 1850 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 1851 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 1852 | arena); |
| 1853 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 1854 | arena); |
| 1855 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 1856 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 1857 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 1858 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1859 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1860 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 1861 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1862 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1863 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1864 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1865 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1866 | mod_ty p; |
| 1867 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1868 | if (!p) |
| 1869 | return NULL; |
| 1870 | p->kind = Module_kind; |
| 1871 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1872 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1873 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1877 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1878 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1879 | mod_ty p; |
| 1880 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1881 | if (!p) |
| 1882 | return NULL; |
| 1883 | p->kind = Interactive_kind; |
| 1884 | p->v.Interactive.body = body; |
| 1885 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1889 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1890 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1891 | mod_ty p; |
| 1892 | if (!body) { |
| 1893 | PyErr_SetString(PyExc_ValueError, |
| 1894 | "field body is required for Expression"); |
| 1895 | return NULL; |
| 1896 | } |
| 1897 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1898 | if (!p) |
| 1899 | return NULL; |
| 1900 | p->kind = Expression_kind; |
| 1901 | p->v.Expression.body = body; |
| 1902 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1906 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 1907 | { |
| 1908 | mod_ty p; |
| 1909 | if (!returns) { |
| 1910 | PyErr_SetString(PyExc_ValueError, |
| 1911 | "field returns is required for FunctionType"); |
| 1912 | return NULL; |
| 1913 | } |
| 1914 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1915 | if (!p) |
| 1916 | return NULL; |
| 1917 | p->kind = FunctionType_kind; |
| 1918 | p->v.FunctionType.argtypes = argtypes; |
| 1919 | p->v.FunctionType.returns = returns; |
| 1920 | return p; |
| 1921 | } |
| 1922 | |
| 1923 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 1924 | Suite(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1925 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1926 | mod_ty p; |
| 1927 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1928 | if (!p) |
| 1929 | return NULL; |
| 1930 | p->kind = Suite_kind; |
| 1931 | p->v.Suite.body = body; |
| 1932 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | stmt_ty |
| 1936 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1937 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 1938 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1939 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1940 | stmt_ty p; |
| 1941 | if (!name) { |
| 1942 | PyErr_SetString(PyExc_ValueError, |
| 1943 | "field name is required for FunctionDef"); |
| 1944 | return NULL; |
| 1945 | } |
| 1946 | if (!args) { |
| 1947 | PyErr_SetString(PyExc_ValueError, |
| 1948 | "field args is required for FunctionDef"); |
| 1949 | return NULL; |
| 1950 | } |
| 1951 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1952 | if (!p) |
| 1953 | return NULL; |
| 1954 | p->kind = FunctionDef_kind; |
| 1955 | p->v.FunctionDef.name = name; |
| 1956 | p->v.FunctionDef.args = args; |
| 1957 | p->v.FunctionDef.body = body; |
| 1958 | p->v.FunctionDef.decorator_list = decorator_list; |
| 1959 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1960 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1961 | p->lineno = lineno; |
| 1962 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1963 | p->end_lineno = end_lineno; |
| 1964 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1965 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1969 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1970 | * decorator_list, expr_ty returns, string type_comment, int |
| 1971 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 1972 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1973 | { |
| 1974 | stmt_ty p; |
| 1975 | if (!name) { |
| 1976 | PyErr_SetString(PyExc_ValueError, |
| 1977 | "field name is required for AsyncFunctionDef"); |
| 1978 | return NULL; |
| 1979 | } |
| 1980 | if (!args) { |
| 1981 | PyErr_SetString(PyExc_ValueError, |
| 1982 | "field args is required for AsyncFunctionDef"); |
| 1983 | return NULL; |
| 1984 | } |
| 1985 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1986 | if (!p) |
| 1987 | return NULL; |
| 1988 | p->kind = AsyncFunctionDef_kind; |
| 1989 | p->v.AsyncFunctionDef.name = name; |
| 1990 | p->v.AsyncFunctionDef.args = args; |
| 1991 | p->v.AsyncFunctionDef.body = body; |
| 1992 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 1993 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1994 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1995 | p->lineno = lineno; |
| 1996 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1997 | p->end_lineno = end_lineno; |
| 1998 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 1999 | return p; |
| 2000 | } |
| 2001 | |
| 2002 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2003 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2004 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2005 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2006 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2007 | stmt_ty p; |
| 2008 | if (!name) { |
| 2009 | PyErr_SetString(PyExc_ValueError, |
| 2010 | "field name is required for ClassDef"); |
| 2011 | return NULL; |
| 2012 | } |
| 2013 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2014 | if (!p) |
| 2015 | return NULL; |
| 2016 | p->kind = ClassDef_kind; |
| 2017 | p->v.ClassDef.name = name; |
| 2018 | p->v.ClassDef.bases = bases; |
| 2019 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2020 | p->v.ClassDef.body = body; |
| 2021 | p->v.ClassDef.decorator_list = decorator_list; |
| 2022 | p->lineno = lineno; |
| 2023 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2024 | p->end_lineno = end_lineno; |
| 2025 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2026 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2030 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2031 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2032 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2033 | stmt_ty p; |
| 2034 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2035 | if (!p) |
| 2036 | return NULL; |
| 2037 | p->kind = Return_kind; |
| 2038 | p->v.Return.value = value; |
| 2039 | p->lineno = lineno; |
| 2040 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2041 | p->end_lineno = end_lineno; |
| 2042 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2043 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2047 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2048 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2049 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2050 | stmt_ty p; |
| 2051 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2052 | if (!p) |
| 2053 | return NULL; |
| 2054 | p->kind = Delete_kind; |
| 2055 | p->v.Delete.targets = targets; |
| 2056 | p->lineno = lineno; |
| 2057 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2058 | p->end_lineno = end_lineno; |
| 2059 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2060 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2064 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2065 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2066 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2067 | stmt_ty p; |
| 2068 | if (!value) { |
| 2069 | PyErr_SetString(PyExc_ValueError, |
| 2070 | "field value is required for Assign"); |
| 2071 | return NULL; |
| 2072 | } |
| 2073 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2074 | if (!p) |
| 2075 | return NULL; |
| 2076 | p->kind = Assign_kind; |
| 2077 | p->v.Assign.targets = targets; |
| 2078 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2079 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2080 | p->lineno = lineno; |
| 2081 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2082 | p->end_lineno = end_lineno; |
| 2083 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2084 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2088 | 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] | 2089 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2090 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2091 | stmt_ty p; |
| 2092 | if (!target) { |
| 2093 | PyErr_SetString(PyExc_ValueError, |
| 2094 | "field target is required for AugAssign"); |
| 2095 | return NULL; |
| 2096 | } |
| 2097 | if (!op) { |
| 2098 | PyErr_SetString(PyExc_ValueError, |
| 2099 | "field op is required for AugAssign"); |
| 2100 | return NULL; |
| 2101 | } |
| 2102 | if (!value) { |
| 2103 | PyErr_SetString(PyExc_ValueError, |
| 2104 | "field value is required for AugAssign"); |
| 2105 | return NULL; |
| 2106 | } |
| 2107 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2108 | if (!p) |
| 2109 | return NULL; |
| 2110 | p->kind = AugAssign_kind; |
| 2111 | p->v.AugAssign.target = target; |
| 2112 | p->v.AugAssign.op = op; |
| 2113 | p->v.AugAssign.value = value; |
| 2114 | p->lineno = lineno; |
| 2115 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2116 | p->end_lineno = end_lineno; |
| 2117 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2118 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2122 | 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] | 2123 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2124 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2125 | { |
| 2126 | stmt_ty p; |
| 2127 | if (!target) { |
| 2128 | PyErr_SetString(PyExc_ValueError, |
| 2129 | "field target is required for AnnAssign"); |
| 2130 | return NULL; |
| 2131 | } |
| 2132 | if (!annotation) { |
| 2133 | PyErr_SetString(PyExc_ValueError, |
| 2134 | "field annotation is required for AnnAssign"); |
| 2135 | return NULL; |
| 2136 | } |
| 2137 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2138 | if (!p) |
| 2139 | return NULL; |
| 2140 | p->kind = AnnAssign_kind; |
| 2141 | p->v.AnnAssign.target = target; |
| 2142 | p->v.AnnAssign.annotation = annotation; |
| 2143 | p->v.AnnAssign.value = value; |
| 2144 | p->v.AnnAssign.simple = simple; |
| 2145 | p->lineno = lineno; |
| 2146 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2147 | p->end_lineno = end_lineno; |
| 2148 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2149 | return p; |
| 2150 | } |
| 2151 | |
| 2152 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2153 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2154 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2155 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2156 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2157 | stmt_ty p; |
| 2158 | if (!target) { |
| 2159 | PyErr_SetString(PyExc_ValueError, |
| 2160 | "field target is required for For"); |
| 2161 | return NULL; |
| 2162 | } |
| 2163 | if (!iter) { |
| 2164 | PyErr_SetString(PyExc_ValueError, |
| 2165 | "field iter is required for For"); |
| 2166 | return NULL; |
| 2167 | } |
| 2168 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2169 | if (!p) |
| 2170 | return NULL; |
| 2171 | p->kind = For_kind; |
| 2172 | p->v.For.target = target; |
| 2173 | p->v.For.iter = iter; |
| 2174 | p->v.For.body = body; |
| 2175 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2176 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2177 | p->lineno = lineno; |
| 2178 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2179 | p->end_lineno = end_lineno; |
| 2180 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2181 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2185 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2186 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2187 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2188 | { |
| 2189 | stmt_ty p; |
| 2190 | if (!target) { |
| 2191 | PyErr_SetString(PyExc_ValueError, |
| 2192 | "field target is required for AsyncFor"); |
| 2193 | return NULL; |
| 2194 | } |
| 2195 | if (!iter) { |
| 2196 | PyErr_SetString(PyExc_ValueError, |
| 2197 | "field iter is required for AsyncFor"); |
| 2198 | return NULL; |
| 2199 | } |
| 2200 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2201 | if (!p) |
| 2202 | return NULL; |
| 2203 | p->kind = AsyncFor_kind; |
| 2204 | p->v.AsyncFor.target = target; |
| 2205 | p->v.AsyncFor.iter = iter; |
| 2206 | p->v.AsyncFor.body = body; |
| 2207 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2208 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2209 | p->lineno = lineno; |
| 2210 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2211 | p->end_lineno = end_lineno; |
| 2212 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2213 | return p; |
| 2214 | } |
| 2215 | |
| 2216 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2217 | 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] | 2218 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2219 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2220 | stmt_ty p; |
| 2221 | if (!test) { |
| 2222 | PyErr_SetString(PyExc_ValueError, |
| 2223 | "field test is required for While"); |
| 2224 | return NULL; |
| 2225 | } |
| 2226 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2227 | if (!p) |
| 2228 | return NULL; |
| 2229 | p->kind = While_kind; |
| 2230 | p->v.While.test = test; |
| 2231 | p->v.While.body = body; |
| 2232 | p->v.While.orelse = orelse; |
| 2233 | p->lineno = lineno; |
| 2234 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2235 | p->end_lineno = end_lineno; |
| 2236 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2237 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2241 | 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] | 2242 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2243 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2244 | stmt_ty p; |
| 2245 | if (!test) { |
| 2246 | PyErr_SetString(PyExc_ValueError, |
| 2247 | "field test is required for If"); |
| 2248 | return NULL; |
| 2249 | } |
| 2250 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2251 | if (!p) |
| 2252 | return NULL; |
| 2253 | p->kind = If_kind; |
| 2254 | p->v.If.test = test; |
| 2255 | p->v.If.body = body; |
| 2256 | p->v.If.orelse = orelse; |
| 2257 | p->lineno = lineno; |
| 2258 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2259 | p->end_lineno = end_lineno; |
| 2260 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2261 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2265 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2266 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2267 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2268 | stmt_ty p; |
| 2269 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2270 | if (!p) |
| 2271 | return NULL; |
| 2272 | p->kind = With_kind; |
| 2273 | p->v.With.items = items; |
| 2274 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2275 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2276 | p->lineno = lineno; |
| 2277 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2278 | p->end_lineno = end_lineno; |
| 2279 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2280 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2284 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2285 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2286 | { |
| 2287 | stmt_ty p; |
| 2288 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2289 | if (!p) |
| 2290 | return NULL; |
| 2291 | p->kind = AsyncWith_kind; |
| 2292 | p->v.AsyncWith.items = items; |
| 2293 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2294 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2295 | p->lineno = lineno; |
| 2296 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2297 | p->end_lineno = end_lineno; |
| 2298 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2299 | return p; |
| 2300 | } |
| 2301 | |
| 2302 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2303 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2304 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2305 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2306 | stmt_ty p; |
| 2307 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2308 | if (!p) |
| 2309 | return NULL; |
| 2310 | p->kind = Raise_kind; |
| 2311 | p->v.Raise.exc = exc; |
| 2312 | p->v.Raise.cause = cause; |
| 2313 | p->lineno = lineno; |
| 2314 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2315 | p->end_lineno = end_lineno; |
| 2316 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2317 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2321 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2322 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2323 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2324 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2325 | stmt_ty p; |
| 2326 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2327 | if (!p) |
| 2328 | return NULL; |
| 2329 | p->kind = Try_kind; |
| 2330 | p->v.Try.body = body; |
| 2331 | p->v.Try.handlers = handlers; |
| 2332 | p->v.Try.orelse = orelse; |
| 2333 | p->v.Try.finalbody = finalbody; |
| 2334 | p->lineno = lineno; |
| 2335 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2336 | p->end_lineno = end_lineno; |
| 2337 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2338 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2342 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2343 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2344 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2345 | stmt_ty p; |
| 2346 | if (!test) { |
| 2347 | PyErr_SetString(PyExc_ValueError, |
| 2348 | "field test is required for Assert"); |
| 2349 | return NULL; |
| 2350 | } |
| 2351 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2352 | if (!p) |
| 2353 | return NULL; |
| 2354 | p->kind = Assert_kind; |
| 2355 | p->v.Assert.test = test; |
| 2356 | p->v.Assert.msg = msg; |
| 2357 | p->lineno = lineno; |
| 2358 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2359 | p->end_lineno = end_lineno; |
| 2360 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2361 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2365 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2366 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2367 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2368 | stmt_ty p; |
| 2369 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2370 | if (!p) |
| 2371 | return NULL; |
| 2372 | p->kind = Import_kind; |
| 2373 | p->v.Import.names = names; |
| 2374 | p->lineno = lineno; |
| 2375 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2376 | p->end_lineno = end_lineno; |
| 2377 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2378 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2382 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2383 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2384 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2385 | stmt_ty p; |
| 2386 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2387 | if (!p) |
| 2388 | return NULL; |
| 2389 | p->kind = ImportFrom_kind; |
| 2390 | p->v.ImportFrom.module = module; |
| 2391 | p->v.ImportFrom.names = names; |
| 2392 | p->v.ImportFrom.level = level; |
| 2393 | p->lineno = lineno; |
| 2394 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2395 | p->end_lineno = end_lineno; |
| 2396 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2397 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2401 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2402 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2403 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2404 | stmt_ty p; |
| 2405 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2406 | if (!p) |
| 2407 | return NULL; |
| 2408 | p->kind = Global_kind; |
| 2409 | p->v.Global.names = names; |
| 2410 | p->lineno = lineno; |
| 2411 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2412 | p->end_lineno = end_lineno; |
| 2413 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2414 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2418 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2419 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2420 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2421 | stmt_ty p; |
| 2422 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2423 | if (!p) |
| 2424 | return NULL; |
| 2425 | p->kind = Nonlocal_kind; |
| 2426 | p->v.Nonlocal.names = names; |
| 2427 | p->lineno = lineno; |
| 2428 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2429 | p->end_lineno = end_lineno; |
| 2430 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2431 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2435 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2436 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2437 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2438 | stmt_ty p; |
| 2439 | if (!value) { |
| 2440 | PyErr_SetString(PyExc_ValueError, |
| 2441 | "field value is required for Expr"); |
| 2442 | return NULL; |
| 2443 | } |
| 2444 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2445 | if (!p) |
| 2446 | return NULL; |
| 2447 | p->kind = Expr_kind; |
| 2448 | p->v.Expr.value = value; |
| 2449 | p->lineno = lineno; |
| 2450 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2451 | p->end_lineno = end_lineno; |
| 2452 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2453 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2457 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2458 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2459 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2460 | stmt_ty p; |
| 2461 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2462 | if (!p) |
| 2463 | return NULL; |
| 2464 | p->kind = Pass_kind; |
| 2465 | p->lineno = lineno; |
| 2466 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2467 | p->end_lineno = end_lineno; |
| 2468 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2469 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2473 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2474 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2475 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2476 | stmt_ty p; |
| 2477 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2478 | if (!p) |
| 2479 | return NULL; |
| 2480 | p->kind = Break_kind; |
| 2481 | p->lineno = lineno; |
| 2482 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2483 | p->end_lineno = end_lineno; |
| 2484 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2485 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2489 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2490 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2491 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2492 | stmt_ty p; |
| 2493 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2494 | if (!p) |
| 2495 | return NULL; |
| 2496 | p->kind = Continue_kind; |
| 2497 | p->lineno = lineno; |
| 2498 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2499 | p->end_lineno = end_lineno; |
| 2500 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2501 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2505 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2506 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2507 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2508 | expr_ty p; |
| 2509 | if (!op) { |
| 2510 | PyErr_SetString(PyExc_ValueError, |
| 2511 | "field op is required for BoolOp"); |
| 2512 | return NULL; |
| 2513 | } |
| 2514 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2515 | if (!p) |
| 2516 | return NULL; |
| 2517 | p->kind = BoolOp_kind; |
| 2518 | p->v.BoolOp.op = op; |
| 2519 | p->v.BoolOp.values = values; |
| 2520 | p->lineno = lineno; |
| 2521 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2522 | p->end_lineno = end_lineno; |
| 2523 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2524 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2528 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2529 | end_lineno, int end_col_offset, PyArena *arena) |
| 2530 | { |
| 2531 | expr_ty p; |
| 2532 | if (!target) { |
| 2533 | PyErr_SetString(PyExc_ValueError, |
| 2534 | "field target is required for NamedExpr"); |
| 2535 | return NULL; |
| 2536 | } |
| 2537 | if (!value) { |
| 2538 | PyErr_SetString(PyExc_ValueError, |
| 2539 | "field value is required for NamedExpr"); |
| 2540 | return NULL; |
| 2541 | } |
| 2542 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2543 | if (!p) |
| 2544 | return NULL; |
| 2545 | p->kind = NamedExpr_kind; |
| 2546 | p->v.NamedExpr.target = target; |
| 2547 | p->v.NamedExpr.value = value; |
| 2548 | p->lineno = lineno; |
| 2549 | p->col_offset = col_offset; |
| 2550 | p->end_lineno = end_lineno; |
| 2551 | p->end_col_offset = end_col_offset; |
| 2552 | return p; |
| 2553 | } |
| 2554 | |
| 2555 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2556 | 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] | 2557 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2558 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2559 | expr_ty p; |
| 2560 | if (!left) { |
| 2561 | PyErr_SetString(PyExc_ValueError, |
| 2562 | "field left is required for BinOp"); |
| 2563 | return NULL; |
| 2564 | } |
| 2565 | if (!op) { |
| 2566 | PyErr_SetString(PyExc_ValueError, |
| 2567 | "field op is required for BinOp"); |
| 2568 | return NULL; |
| 2569 | } |
| 2570 | if (!right) { |
| 2571 | PyErr_SetString(PyExc_ValueError, |
| 2572 | "field right is required for BinOp"); |
| 2573 | return NULL; |
| 2574 | } |
| 2575 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2576 | if (!p) |
| 2577 | return NULL; |
| 2578 | p->kind = BinOp_kind; |
| 2579 | p->v.BinOp.left = left; |
| 2580 | p->v.BinOp.op = op; |
| 2581 | p->v.BinOp.right = right; |
| 2582 | p->lineno = lineno; |
| 2583 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2584 | p->end_lineno = end_lineno; |
| 2585 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2586 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2590 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2591 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2592 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2593 | expr_ty p; |
| 2594 | if (!op) { |
| 2595 | PyErr_SetString(PyExc_ValueError, |
| 2596 | "field op is required for UnaryOp"); |
| 2597 | return NULL; |
| 2598 | } |
| 2599 | if (!operand) { |
| 2600 | PyErr_SetString(PyExc_ValueError, |
| 2601 | "field operand is required for UnaryOp"); |
| 2602 | return NULL; |
| 2603 | } |
| 2604 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2605 | if (!p) |
| 2606 | return NULL; |
| 2607 | p->kind = UnaryOp_kind; |
| 2608 | p->v.UnaryOp.op = op; |
| 2609 | p->v.UnaryOp.operand = operand; |
| 2610 | p->lineno = lineno; |
| 2611 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2612 | p->end_lineno = end_lineno; |
| 2613 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2614 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2618 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2619 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2620 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2621 | expr_ty p; |
| 2622 | if (!args) { |
| 2623 | PyErr_SetString(PyExc_ValueError, |
| 2624 | "field args is required for Lambda"); |
| 2625 | return NULL; |
| 2626 | } |
| 2627 | if (!body) { |
| 2628 | PyErr_SetString(PyExc_ValueError, |
| 2629 | "field body is required for Lambda"); |
| 2630 | return NULL; |
| 2631 | } |
| 2632 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2633 | if (!p) |
| 2634 | return NULL; |
| 2635 | p->kind = Lambda_kind; |
| 2636 | p->v.Lambda.args = args; |
| 2637 | p->v.Lambda.body = body; |
| 2638 | p->lineno = lineno; |
| 2639 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2640 | p->end_lineno = end_lineno; |
| 2641 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2642 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2646 | 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] | 2647 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2648 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2649 | expr_ty p; |
| 2650 | if (!test) { |
| 2651 | PyErr_SetString(PyExc_ValueError, |
| 2652 | "field test is required for IfExp"); |
| 2653 | return NULL; |
| 2654 | } |
| 2655 | if (!body) { |
| 2656 | PyErr_SetString(PyExc_ValueError, |
| 2657 | "field body is required for IfExp"); |
| 2658 | return NULL; |
| 2659 | } |
| 2660 | if (!orelse) { |
| 2661 | PyErr_SetString(PyExc_ValueError, |
| 2662 | "field orelse is required for IfExp"); |
| 2663 | return NULL; |
| 2664 | } |
| 2665 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2666 | if (!p) |
| 2667 | return NULL; |
| 2668 | p->kind = IfExp_kind; |
| 2669 | p->v.IfExp.test = test; |
| 2670 | p->v.IfExp.body = body; |
| 2671 | p->v.IfExp.orelse = orelse; |
| 2672 | p->lineno = lineno; |
| 2673 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2674 | p->end_lineno = end_lineno; |
| 2675 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2676 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2680 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2681 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2682 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2683 | expr_ty p; |
| 2684 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2685 | if (!p) |
| 2686 | return NULL; |
| 2687 | p->kind = Dict_kind; |
| 2688 | p->v.Dict.keys = keys; |
| 2689 | p->v.Dict.values = values; |
| 2690 | p->lineno = lineno; |
| 2691 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2692 | p->end_lineno = end_lineno; |
| 2693 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2694 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2698 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2699 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2700 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2701 | expr_ty p; |
| 2702 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2703 | if (!p) |
| 2704 | return NULL; |
| 2705 | p->kind = Set_kind; |
| 2706 | p->v.Set.elts = elts; |
| 2707 | p->lineno = lineno; |
| 2708 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2709 | p->end_lineno = end_lineno; |
| 2710 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2711 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2715 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2716 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2717 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2718 | expr_ty p; |
| 2719 | if (!elt) { |
| 2720 | PyErr_SetString(PyExc_ValueError, |
| 2721 | "field elt is required for ListComp"); |
| 2722 | return NULL; |
| 2723 | } |
| 2724 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2725 | if (!p) |
| 2726 | return NULL; |
| 2727 | p->kind = ListComp_kind; |
| 2728 | p->v.ListComp.elt = elt; |
| 2729 | p->v.ListComp.generators = generators; |
| 2730 | p->lineno = lineno; |
| 2731 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2732 | p->end_lineno = end_lineno; |
| 2733 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2734 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2738 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2739 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2740 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2741 | expr_ty p; |
| 2742 | if (!elt) { |
| 2743 | PyErr_SetString(PyExc_ValueError, |
| 2744 | "field elt is required for SetComp"); |
| 2745 | return NULL; |
| 2746 | } |
| 2747 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2748 | if (!p) |
| 2749 | return NULL; |
| 2750 | p->kind = SetComp_kind; |
| 2751 | p->v.SetComp.elt = elt; |
| 2752 | p->v.SetComp.generators = generators; |
| 2753 | p->lineno = lineno; |
| 2754 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2755 | p->end_lineno = end_lineno; |
| 2756 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2757 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2761 | 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] | 2762 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2763 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2764 | expr_ty p; |
| 2765 | if (!key) { |
| 2766 | PyErr_SetString(PyExc_ValueError, |
| 2767 | "field key is required for DictComp"); |
| 2768 | return NULL; |
| 2769 | } |
| 2770 | if (!value) { |
| 2771 | PyErr_SetString(PyExc_ValueError, |
| 2772 | "field value is required for DictComp"); |
| 2773 | return NULL; |
| 2774 | } |
| 2775 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2776 | if (!p) |
| 2777 | return NULL; |
| 2778 | p->kind = DictComp_kind; |
| 2779 | p->v.DictComp.key = key; |
| 2780 | p->v.DictComp.value = value; |
| 2781 | p->v.DictComp.generators = generators; |
| 2782 | p->lineno = lineno; |
| 2783 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2784 | p->end_lineno = end_lineno; |
| 2785 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2786 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2790 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2791 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2792 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2793 | expr_ty p; |
| 2794 | if (!elt) { |
| 2795 | PyErr_SetString(PyExc_ValueError, |
| 2796 | "field elt is required for GeneratorExp"); |
| 2797 | return NULL; |
| 2798 | } |
| 2799 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2800 | if (!p) |
| 2801 | return NULL; |
| 2802 | p->kind = GeneratorExp_kind; |
| 2803 | p->v.GeneratorExp.elt = elt; |
| 2804 | p->v.GeneratorExp.generators = generators; |
| 2805 | p->lineno = lineno; |
| 2806 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2807 | p->end_lineno = end_lineno; |
| 2808 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2809 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2813 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2814 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2815 | { |
| 2816 | expr_ty p; |
| 2817 | if (!value) { |
| 2818 | PyErr_SetString(PyExc_ValueError, |
| 2819 | "field value is required for Await"); |
| 2820 | return NULL; |
| 2821 | } |
| 2822 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2823 | if (!p) |
| 2824 | return NULL; |
| 2825 | p->kind = Await_kind; |
| 2826 | p->v.Await.value = value; |
| 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; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2831 | return p; |
| 2832 | } |
| 2833 | |
| 2834 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2835 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2836 | 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 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2840 | if (!p) |
| 2841 | return NULL; |
| 2842 | p->kind = Yield_kind; |
| 2843 | p->v.Yield.value = value; |
| 2844 | p->lineno = lineno; |
| 2845 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2846 | p->end_lineno = end_lineno; |
| 2847 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2848 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2852 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2853 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2854 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2855 | expr_ty p; |
| 2856 | if (!value) { |
| 2857 | PyErr_SetString(PyExc_ValueError, |
| 2858 | "field value is required for YieldFrom"); |
| 2859 | return NULL; |
| 2860 | } |
| 2861 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2862 | if (!p) |
| 2863 | return NULL; |
| 2864 | p->kind = YieldFrom_kind; |
| 2865 | p->v.YieldFrom.value = value; |
| 2866 | p->lineno = lineno; |
| 2867 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2868 | p->end_lineno = end_lineno; |
| 2869 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2870 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2874 | 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] | 2875 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2876 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2877 | expr_ty p; |
| 2878 | if (!left) { |
| 2879 | PyErr_SetString(PyExc_ValueError, |
| 2880 | "field left is required for Compare"); |
| 2881 | return NULL; |
| 2882 | } |
| 2883 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2884 | if (!p) |
| 2885 | return NULL; |
| 2886 | p->kind = Compare_kind; |
| 2887 | p->v.Compare.left = left; |
| 2888 | p->v.Compare.ops = ops; |
| 2889 | p->v.Compare.comparators = comparators; |
| 2890 | p->lineno = lineno; |
| 2891 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2892 | p->end_lineno = end_lineno; |
| 2893 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2894 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2898 | 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] | 2899 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2900 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2901 | expr_ty p; |
| 2902 | if (!func) { |
| 2903 | PyErr_SetString(PyExc_ValueError, |
| 2904 | "field func is required for Call"); |
| 2905 | return NULL; |
| 2906 | } |
| 2907 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2908 | if (!p) |
| 2909 | return NULL; |
| 2910 | p->kind = Call_kind; |
| 2911 | p->v.Call.func = func; |
| 2912 | p->v.Call.args = args; |
| 2913 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2914 | p->lineno = lineno; |
| 2915 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2916 | p->end_lineno = end_lineno; |
| 2917 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2918 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 2922 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 2923 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2924 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2925 | { |
| 2926 | expr_ty p; |
| 2927 | if (!value) { |
| 2928 | PyErr_SetString(PyExc_ValueError, |
| 2929 | "field value is required for FormattedValue"); |
| 2930 | return NULL; |
| 2931 | } |
| 2932 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2933 | if (!p) |
| 2934 | return NULL; |
| 2935 | p->kind = FormattedValue_kind; |
| 2936 | p->v.FormattedValue.value = value; |
| 2937 | p->v.FormattedValue.conversion = conversion; |
| 2938 | p->v.FormattedValue.format_spec = format_spec; |
| 2939 | p->lineno = lineno; |
| 2940 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2941 | p->end_lineno = end_lineno; |
| 2942 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2943 | return p; |
| 2944 | } |
| 2945 | |
| 2946 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2947 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 2948 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2949 | { |
| 2950 | expr_ty p; |
| 2951 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2952 | if (!p) |
| 2953 | return NULL; |
| 2954 | p->kind = JoinedStr_kind; |
| 2955 | p->v.JoinedStr.values = values; |
| 2956 | p->lineno = lineno; |
| 2957 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2958 | p->end_lineno = end_lineno; |
| 2959 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 2960 | return p; |
| 2961 | } |
| 2962 | |
| 2963 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2964 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 2965 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2966 | { |
| 2967 | expr_ty p; |
| 2968 | if (!value) { |
| 2969 | PyErr_SetString(PyExc_ValueError, |
| 2970 | "field value is required for Constant"); |
| 2971 | return NULL; |
| 2972 | } |
| 2973 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2974 | if (!p) |
| 2975 | return NULL; |
| 2976 | p->kind = Constant_kind; |
| 2977 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 2978 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2979 | p->lineno = lineno; |
| 2980 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2981 | p->end_lineno = end_lineno; |
| 2982 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 2983 | return p; |
| 2984 | } |
| 2985 | |
| 2986 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2987 | 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] | 2988 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2989 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2990 | expr_ty p; |
| 2991 | if (!value) { |
| 2992 | PyErr_SetString(PyExc_ValueError, |
| 2993 | "field value is required for Attribute"); |
| 2994 | return NULL; |
| 2995 | } |
| 2996 | if (!attr) { |
| 2997 | PyErr_SetString(PyExc_ValueError, |
| 2998 | "field attr is required for Attribute"); |
| 2999 | return NULL; |
| 3000 | } |
| 3001 | if (!ctx) { |
| 3002 | PyErr_SetString(PyExc_ValueError, |
| 3003 | "field ctx is required for Attribute"); |
| 3004 | return NULL; |
| 3005 | } |
| 3006 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3007 | if (!p) |
| 3008 | return NULL; |
| 3009 | p->kind = Attribute_kind; |
| 3010 | p->v.Attribute.value = value; |
| 3011 | p->v.Attribute.attr = attr; |
| 3012 | p->v.Attribute.ctx = ctx; |
| 3013 | p->lineno = lineno; |
| 3014 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3015 | p->end_lineno = end_lineno; |
| 3016 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3017 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3021 | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3022 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3023 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3024 | expr_ty p; |
| 3025 | if (!value) { |
| 3026 | PyErr_SetString(PyExc_ValueError, |
| 3027 | "field value is required for Subscript"); |
| 3028 | return NULL; |
| 3029 | } |
| 3030 | if (!slice) { |
| 3031 | PyErr_SetString(PyExc_ValueError, |
| 3032 | "field slice is required for Subscript"); |
| 3033 | return NULL; |
| 3034 | } |
| 3035 | if (!ctx) { |
| 3036 | PyErr_SetString(PyExc_ValueError, |
| 3037 | "field ctx is required for Subscript"); |
| 3038 | return NULL; |
| 3039 | } |
| 3040 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3041 | if (!p) |
| 3042 | return NULL; |
| 3043 | p->kind = Subscript_kind; |
| 3044 | p->v.Subscript.value = value; |
| 3045 | p->v.Subscript.slice = slice; |
| 3046 | p->v.Subscript.ctx = ctx; |
| 3047 | p->lineno = lineno; |
| 3048 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3049 | p->end_lineno = end_lineno; |
| 3050 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3051 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3055 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3056 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3057 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3058 | expr_ty p; |
| 3059 | if (!value) { |
| 3060 | PyErr_SetString(PyExc_ValueError, |
| 3061 | "field value is required for Starred"); |
| 3062 | return NULL; |
| 3063 | } |
| 3064 | if (!ctx) { |
| 3065 | PyErr_SetString(PyExc_ValueError, |
| 3066 | "field ctx is required for Starred"); |
| 3067 | return NULL; |
| 3068 | } |
| 3069 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3070 | if (!p) |
| 3071 | return NULL; |
| 3072 | p->kind = Starred_kind; |
| 3073 | p->v.Starred.value = value; |
| 3074 | p->v.Starred.ctx = ctx; |
| 3075 | p->lineno = lineno; |
| 3076 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3077 | p->end_lineno = end_lineno; |
| 3078 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3079 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3083 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3084 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3085 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3086 | expr_ty p; |
| 3087 | if (!id) { |
| 3088 | PyErr_SetString(PyExc_ValueError, |
| 3089 | "field id is required for Name"); |
| 3090 | return NULL; |
| 3091 | } |
| 3092 | if (!ctx) { |
| 3093 | PyErr_SetString(PyExc_ValueError, |
| 3094 | "field ctx is required for Name"); |
| 3095 | return NULL; |
| 3096 | } |
| 3097 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3098 | if (!p) |
| 3099 | return NULL; |
| 3100 | p->kind = Name_kind; |
| 3101 | p->v.Name.id = id; |
| 3102 | p->v.Name.ctx = ctx; |
| 3103 | p->lineno = lineno; |
| 3104 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3105 | p->end_lineno = end_lineno; |
| 3106 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3107 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3111 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3112 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3113 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3114 | expr_ty p; |
| 3115 | if (!ctx) { |
| 3116 | PyErr_SetString(PyExc_ValueError, |
| 3117 | "field ctx is required for List"); |
| 3118 | return NULL; |
| 3119 | } |
| 3120 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3121 | if (!p) |
| 3122 | return NULL; |
| 3123 | p->kind = List_kind; |
| 3124 | p->v.List.elts = elts; |
| 3125 | p->v.List.ctx = ctx; |
| 3126 | p->lineno = lineno; |
| 3127 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3128 | p->end_lineno = end_lineno; |
| 3129 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3130 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3134 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3135 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3136 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3137 | expr_ty p; |
| 3138 | if (!ctx) { |
| 3139 | PyErr_SetString(PyExc_ValueError, |
| 3140 | "field ctx is required for Tuple"); |
| 3141 | return NULL; |
| 3142 | } |
| 3143 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3144 | if (!p) |
| 3145 | return NULL; |
| 3146 | p->kind = Tuple_kind; |
| 3147 | p->v.Tuple.elts = elts; |
| 3148 | p->v.Tuple.ctx = ctx; |
| 3149 | p->lineno = lineno; |
| 3150 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3151 | p->end_lineno = end_lineno; |
| 3152 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3153 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3157 | Slice(expr_ty lower, expr_ty upper, expr_ty step, 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 | slice_ty p; |
| 3160 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3161 | if (!p) |
| 3162 | return NULL; |
| 3163 | p->kind = Slice_kind; |
| 3164 | p->v.Slice.lower = lower; |
| 3165 | p->v.Slice.upper = upper; |
| 3166 | p->v.Slice.step = step; |
| 3167 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3171 | ExtSlice(asdl_seq * dims, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3172 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3173 | slice_ty p; |
| 3174 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3175 | if (!p) |
| 3176 | return NULL; |
| 3177 | p->kind = ExtSlice_kind; |
| 3178 | p->v.ExtSlice.dims = dims; |
| 3179 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | slice_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3183 | Index(expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3184 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3185 | slice_ty p; |
| 3186 | if (!value) { |
| 3187 | PyErr_SetString(PyExc_ValueError, |
| 3188 | "field value is required for Index"); |
| 3189 | return NULL; |
| 3190 | } |
| 3191 | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3192 | if (!p) |
| 3193 | return NULL; |
| 3194 | p->kind = Index_kind; |
| 3195 | p->v.Index.value = value; |
| 3196 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3200 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3201 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3202 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3203 | comprehension_ty p; |
| 3204 | if (!target) { |
| 3205 | PyErr_SetString(PyExc_ValueError, |
| 3206 | "field target is required for comprehension"); |
| 3207 | return NULL; |
| 3208 | } |
| 3209 | if (!iter) { |
| 3210 | PyErr_SetString(PyExc_ValueError, |
| 3211 | "field iter is required for comprehension"); |
| 3212 | return NULL; |
| 3213 | } |
| 3214 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3215 | if (!p) |
| 3216 | return NULL; |
| 3217 | p->target = target; |
| 3218 | p->iter = iter; |
| 3219 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3220 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3221 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3225 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3226 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3227 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3228 | excepthandler_ty p; |
| 3229 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3230 | if (!p) |
| 3231 | return NULL; |
| 3232 | p->kind = ExceptHandler_kind; |
| 3233 | p->v.ExceptHandler.type = type; |
| 3234 | p->v.ExceptHandler.name = name; |
| 3235 | p->v.ExceptHandler.body = body; |
| 3236 | p->lineno = lineno; |
| 3237 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3238 | p->end_lineno = end_lineno; |
| 3239 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3240 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3241 | } |
| 3242 | |
| 3243 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3244 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3245 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3246 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3247 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3248 | arguments_ty p; |
| 3249 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3250 | if (!p) |
| 3251 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3252 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3253 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3254 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3255 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3256 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3257 | p->kwarg = kwarg; |
| 3258 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3259 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3260 | } |
| 3261 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3262 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3263 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3264 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3265 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3266 | arg_ty p; |
| 3267 | if (!arg) { |
| 3268 | PyErr_SetString(PyExc_ValueError, |
| 3269 | "field arg is required for arg"); |
| 3270 | return NULL; |
| 3271 | } |
| 3272 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3273 | if (!p) |
| 3274 | return NULL; |
| 3275 | p->arg = arg; |
| 3276 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3277 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3278 | p->lineno = lineno; |
| 3279 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3280 | p->end_lineno = end_lineno; |
| 3281 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3282 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3283 | } |
| 3284 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3285 | keyword_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3286 | keyword(identifier arg, expr_ty value, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3287 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3288 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3289 | if (!value) { |
| 3290 | PyErr_SetString(PyExc_ValueError, |
| 3291 | "field value is required for keyword"); |
| 3292 | return NULL; |
| 3293 | } |
| 3294 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3295 | if (!p) |
| 3296 | return NULL; |
| 3297 | p->arg = arg; |
| 3298 | p->value = value; |
| 3299 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3303 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3304 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3305 | alias_ty p; |
| 3306 | if (!name) { |
| 3307 | PyErr_SetString(PyExc_ValueError, |
| 3308 | "field name is required for alias"); |
| 3309 | return NULL; |
| 3310 | } |
| 3311 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3312 | if (!p) |
| 3313 | return NULL; |
| 3314 | p->name = name; |
| 3315 | p->asname = asname; |
| 3316 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3317 | } |
| 3318 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3319 | withitem_ty |
| 3320 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3321 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3322 | withitem_ty p; |
| 3323 | if (!context_expr) { |
| 3324 | PyErr_SetString(PyExc_ValueError, |
| 3325 | "field context_expr is required for withitem"); |
| 3326 | return NULL; |
| 3327 | } |
| 3328 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3329 | if (!p) |
| 3330 | return NULL; |
| 3331 | p->context_expr = context_expr; |
| 3332 | p->optional_vars = optional_vars; |
| 3333 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3334 | } |
| 3335 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3336 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3337 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3338 | { |
| 3339 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3340 | if (!tag) { |
| 3341 | PyErr_SetString(PyExc_ValueError, |
| 3342 | "field tag is required for TypeIgnore"); |
| 3343 | return NULL; |
| 3344 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3345 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3346 | if (!p) |
| 3347 | return NULL; |
| 3348 | p->kind = TypeIgnore_kind; |
| 3349 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3350 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3351 | return p; |
| 3352 | } |
| 3353 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3354 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3355 | PyObject* |
| 3356 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3357 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3358 | mod_ty o = (mod_ty)_o; |
| 3359 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3360 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3361 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3362 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3363 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3364 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3365 | switch (o->kind) { |
| 3366 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3367 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3368 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3369 | if (!result) goto failed; |
| 3370 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3371 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3372 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3373 | goto failed; |
| 3374 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3375 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3376 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3377 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3378 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3379 | goto failed; |
| 3380 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3381 | break; |
| 3382 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3383 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3384 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3385 | if (!result) goto failed; |
| 3386 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3387 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3388 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3389 | goto failed; |
| 3390 | Py_DECREF(value); |
| 3391 | break; |
| 3392 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3393 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3394 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3395 | if (!result) goto failed; |
| 3396 | value = ast2obj_expr(o->v.Expression.body); |
| 3397 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3398 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3399 | goto failed; |
| 3400 | Py_DECREF(value); |
| 3401 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3402 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3403 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3404 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3405 | if (!result) goto failed; |
| 3406 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3407 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3408 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3409 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3410 | goto failed; |
| 3411 | Py_DECREF(value); |
| 3412 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3413 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3414 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3415 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3416 | goto failed; |
| 3417 | Py_DECREF(value); |
| 3418 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3419 | case Suite_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3420 | tp = (PyTypeObject *)astmodulestate_global->Suite_type; |
| 3421 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3422 | if (!result) goto failed; |
| 3423 | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
| 3424 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3425 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3426 | goto failed; |
| 3427 | Py_DECREF(value); |
| 3428 | break; |
| 3429 | } |
| 3430 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3431 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3432 | Py_XDECREF(value); |
| 3433 | Py_XDECREF(result); |
| 3434 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3437 | PyObject* |
| 3438 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3439 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3440 | stmt_ty o = (stmt_ty)_o; |
| 3441 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3442 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3443 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3444 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3445 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3446 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3447 | switch (o->kind) { |
| 3448 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3449 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3450 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3451 | if (!result) goto failed; |
| 3452 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3453 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3454 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3455 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3456 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3457 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3458 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3459 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3460 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3461 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3462 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3463 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3464 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3465 | goto failed; |
| 3466 | Py_DECREF(value); |
| 3467 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3468 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3469 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3470 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3471 | goto failed; |
| 3472 | Py_DECREF(value); |
| 3473 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3474 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3475 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3476 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3477 | goto failed; |
| 3478 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3479 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3480 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3481 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3482 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3483 | goto failed; |
| 3484 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3485 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3486 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3487 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3488 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3489 | if (!result) goto failed; |
| 3490 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3491 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3492 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3493 | goto failed; |
| 3494 | Py_DECREF(value); |
| 3495 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3496 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3497 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3498 | goto failed; |
| 3499 | Py_DECREF(value); |
| 3500 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3501 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3502 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3503 | goto failed; |
| 3504 | Py_DECREF(value); |
| 3505 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3506 | ast2obj_expr); |
| 3507 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3508 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3509 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3510 | goto failed; |
| 3511 | Py_DECREF(value); |
| 3512 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3513 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3514 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3515 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3516 | goto failed; |
| 3517 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3518 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3519 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3520 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3521 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3522 | goto failed; |
| 3523 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3524 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3525 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3526 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3527 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3528 | if (!result) goto failed; |
| 3529 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3530 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3531 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3532 | goto failed; |
| 3533 | Py_DECREF(value); |
| 3534 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3535 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3536 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3537 | goto failed; |
| 3538 | Py_DECREF(value); |
| 3539 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3540 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3541 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3542 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3543 | goto failed; |
| 3544 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3545 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3546 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3547 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3548 | goto failed; |
| 3549 | Py_DECREF(value); |
| 3550 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3551 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3552 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3553 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3554 | goto failed; |
| 3555 | Py_DECREF(value); |
| 3556 | break; |
| 3557 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3558 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3559 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3560 | if (!result) goto failed; |
| 3561 | value = ast2obj_expr(o->v.Return.value); |
| 3562 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3563 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3564 | goto failed; |
| 3565 | Py_DECREF(value); |
| 3566 | break; |
| 3567 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3568 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3569 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3570 | if (!result) goto failed; |
| 3571 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3572 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3573 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3574 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3575 | goto failed; |
| 3576 | Py_DECREF(value); |
| 3577 | break; |
| 3578 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3579 | tp = (PyTypeObject *)astmodulestate_global->Assign_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.Assign.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 | value = ast2obj_expr(o->v.Assign.value); |
| 3589 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3590 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3591 | goto failed; |
| 3592 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3593 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3594 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3595 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3596 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3597 | goto failed; |
| 3598 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3599 | break; |
| 3600 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3601 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3602 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3603 | if (!result) goto failed; |
| 3604 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3605 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3606 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3607 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3608 | goto failed; |
| 3609 | Py_DECREF(value); |
| 3610 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3611 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3612 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3613 | goto failed; |
| 3614 | Py_DECREF(value); |
| 3615 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3616 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3617 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3618 | goto failed; |
| 3619 | Py_DECREF(value); |
| 3620 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3621 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3622 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3623 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3624 | if (!result) goto failed; |
| 3625 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3626 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3627 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3628 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3629 | goto failed; |
| 3630 | Py_DECREF(value); |
| 3631 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3632 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3633 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3634 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3635 | goto failed; |
| 3636 | Py_DECREF(value); |
| 3637 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3638 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3639 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3640 | goto failed; |
| 3641 | Py_DECREF(value); |
| 3642 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3643 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3644 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3645 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3646 | goto failed; |
| 3647 | Py_DECREF(value); |
| 3648 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3649 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3650 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3651 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3652 | if (!result) goto failed; |
| 3653 | value = ast2obj_expr(o->v.For.target); |
| 3654 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3655 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3656 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3657 | goto failed; |
| 3658 | Py_DECREF(value); |
| 3659 | value = ast2obj_expr(o->v.For.iter); |
| 3660 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3661 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3662 | goto failed; |
| 3663 | Py_DECREF(value); |
| 3664 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3665 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3666 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3667 | goto failed; |
| 3668 | Py_DECREF(value); |
| 3669 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3670 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3671 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3672 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3673 | goto failed; |
| 3674 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3675 | value = ast2obj_string(o->v.For.type_comment); |
| 3676 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3677 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3678 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3679 | goto failed; |
| 3680 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3681 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3682 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3683 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3684 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3685 | if (!result) goto failed; |
| 3686 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3687 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3688 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3689 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3690 | goto failed; |
| 3691 | Py_DECREF(value); |
| 3692 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3693 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3694 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3695 | goto failed; |
| 3696 | Py_DECREF(value); |
| 3697 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3698 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3699 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3700 | goto failed; |
| 3701 | Py_DECREF(value); |
| 3702 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3703 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3704 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3705 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3706 | goto failed; |
| 3707 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3708 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3709 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3710 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3711 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3712 | goto failed; |
| 3713 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3714 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3715 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3716 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3717 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3718 | if (!result) goto failed; |
| 3719 | value = ast2obj_expr(o->v.While.test); |
| 3720 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3721 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3722 | goto failed; |
| 3723 | Py_DECREF(value); |
| 3724 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3725 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3726 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3727 | goto failed; |
| 3728 | Py_DECREF(value); |
| 3729 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3730 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3731 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3732 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3733 | goto failed; |
| 3734 | Py_DECREF(value); |
| 3735 | break; |
| 3736 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3737 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3738 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3739 | if (!result) goto failed; |
| 3740 | value = ast2obj_expr(o->v.If.test); |
| 3741 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3742 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3743 | goto failed; |
| 3744 | Py_DECREF(value); |
| 3745 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3746 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3747 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3748 | goto failed; |
| 3749 | Py_DECREF(value); |
| 3750 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3751 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3752 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3753 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3754 | goto failed; |
| 3755 | Py_DECREF(value); |
| 3756 | break; |
| 3757 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3758 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3759 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3760 | if (!result) goto failed; |
| 3761 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3762 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3763 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3764 | goto failed; |
| 3765 | Py_DECREF(value); |
| 3766 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3767 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3768 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3769 | goto failed; |
| 3770 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3771 | value = ast2obj_string(o->v.With.type_comment); |
| 3772 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3773 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3774 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3775 | goto failed; |
| 3776 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3777 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3778 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3779 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3780 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3781 | if (!result) goto failed; |
| 3782 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3783 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3784 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3785 | goto failed; |
| 3786 | Py_DECREF(value); |
| 3787 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3788 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3789 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3790 | goto failed; |
| 3791 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3792 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3793 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3794 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3795 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3796 | goto failed; |
| 3797 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3798 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3799 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3800 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3801 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3802 | if (!result) goto failed; |
| 3803 | value = ast2obj_expr(o->v.Raise.exc); |
| 3804 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3805 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3806 | goto failed; |
| 3807 | Py_DECREF(value); |
| 3808 | value = ast2obj_expr(o->v.Raise.cause); |
| 3809 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3810 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3811 | goto failed; |
| 3812 | Py_DECREF(value); |
| 3813 | break; |
| 3814 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3815 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3816 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3817 | if (!result) goto failed; |
| 3818 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3819 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3820 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3821 | goto failed; |
| 3822 | Py_DECREF(value); |
| 3823 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3824 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3825 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3826 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3827 | goto failed; |
| 3828 | Py_DECREF(value); |
| 3829 | value = ast2obj_list(o->v.Try.orelse, 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->orelse, value) == |
| 3832 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3833 | goto failed; |
| 3834 | Py_DECREF(value); |
| 3835 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3836 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3837 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3838 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3839 | goto failed; |
| 3840 | Py_DECREF(value); |
| 3841 | break; |
| 3842 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3843 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3844 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3845 | if (!result) goto failed; |
| 3846 | value = ast2obj_expr(o->v.Assert.test); |
| 3847 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3848 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3849 | goto failed; |
| 3850 | Py_DECREF(value); |
| 3851 | value = ast2obj_expr(o->v.Assert.msg); |
| 3852 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3853 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3854 | goto failed; |
| 3855 | Py_DECREF(value); |
| 3856 | break; |
| 3857 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3858 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 3859 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3860 | if (!result) goto failed; |
| 3861 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 3862 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3863 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3864 | goto failed; |
| 3865 | Py_DECREF(value); |
| 3866 | break; |
| 3867 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3868 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 3869 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3870 | if (!result) goto failed; |
| 3871 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 3872 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3873 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 3874 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3875 | goto failed; |
| 3876 | Py_DECREF(value); |
| 3877 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 3878 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3879 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3880 | goto failed; |
| 3881 | Py_DECREF(value); |
| 3882 | value = ast2obj_int(o->v.ImportFrom.level); |
| 3883 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3884 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3885 | goto failed; |
| 3886 | Py_DECREF(value); |
| 3887 | break; |
| 3888 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3889 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 3890 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | if (!result) goto failed; |
| 3892 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 3893 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3894 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3895 | goto failed; |
| 3896 | Py_DECREF(value); |
| 3897 | break; |
| 3898 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3899 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 3900 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3901 | if (!result) goto failed; |
| 3902 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 3903 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3904 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3905 | goto failed; |
| 3906 | Py_DECREF(value); |
| 3907 | break; |
| 3908 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3909 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 3910 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3911 | if (!result) goto failed; |
| 3912 | value = ast2obj_expr(o->v.Expr.value); |
| 3913 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3914 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3915 | goto failed; |
| 3916 | Py_DECREF(value); |
| 3917 | break; |
| 3918 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3919 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 3920 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3921 | if (!result) goto failed; |
| 3922 | break; |
| 3923 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3924 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 3925 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3926 | if (!result) goto failed; |
| 3927 | break; |
| 3928 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3929 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 3930 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3931 | if (!result) goto failed; |
| 3932 | break; |
| 3933 | } |
| 3934 | value = ast2obj_int(o->lineno); |
| 3935 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3936 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3937 | goto failed; |
| 3938 | Py_DECREF(value); |
| 3939 | value = ast2obj_int(o->col_offset); |
| 3940 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3941 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3942 | goto failed; |
| 3943 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3944 | value = ast2obj_int(o->end_lineno); |
| 3945 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3946 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3947 | goto failed; |
| 3948 | Py_DECREF(value); |
| 3949 | value = ast2obj_int(o->end_col_offset); |
| 3950 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3951 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 3952 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3953 | goto failed; |
| 3954 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3955 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3956 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3957 | Py_XDECREF(value); |
| 3958 | Py_XDECREF(result); |
| 3959 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3962 | PyObject* |
| 3963 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3964 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3965 | expr_ty o = (expr_ty)_o; |
| 3966 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3967 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3968 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3969 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3970 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3971 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3972 | switch (o->kind) { |
| 3973 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3974 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 3975 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | if (!result) goto failed; |
| 3977 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 3978 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3979 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3980 | goto failed; |
| 3981 | Py_DECREF(value); |
| 3982 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 3983 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3984 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 3985 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3986 | goto failed; |
| 3987 | Py_DECREF(value); |
| 3988 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3989 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3990 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 3991 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3992 | if (!result) goto failed; |
| 3993 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 3994 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3995 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3996 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 3997 | goto failed; |
| 3998 | Py_DECREF(value); |
| 3999 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 4000 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4001 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4002 | goto failed; |
| 4003 | Py_DECREF(value); |
| 4004 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4005 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4006 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4007 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4008 | if (!result) goto failed; |
| 4009 | value = ast2obj_expr(o->v.BinOp.left); |
| 4010 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4011 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4012 | goto failed; |
| 4013 | Py_DECREF(value); |
| 4014 | value = ast2obj_operator(o->v.BinOp.op); |
| 4015 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4016 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4017 | goto failed; |
| 4018 | Py_DECREF(value); |
| 4019 | value = ast2obj_expr(o->v.BinOp.right); |
| 4020 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4021 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4022 | goto failed; |
| 4023 | Py_DECREF(value); |
| 4024 | break; |
| 4025 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4026 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4027 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4028 | if (!result) goto failed; |
| 4029 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4030 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4031 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4032 | goto failed; |
| 4033 | Py_DECREF(value); |
| 4034 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4035 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4036 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4037 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4038 | goto failed; |
| 4039 | Py_DECREF(value); |
| 4040 | break; |
| 4041 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4042 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4043 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | if (!result) goto failed; |
| 4045 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4046 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4047 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4048 | goto failed; |
| 4049 | Py_DECREF(value); |
| 4050 | value = ast2obj_expr(o->v.Lambda.body); |
| 4051 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4052 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4053 | goto failed; |
| 4054 | Py_DECREF(value); |
| 4055 | break; |
| 4056 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4057 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4058 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4059 | if (!result) goto failed; |
| 4060 | value = ast2obj_expr(o->v.IfExp.test); |
| 4061 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4062 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4063 | goto failed; |
| 4064 | Py_DECREF(value); |
| 4065 | value = ast2obj_expr(o->v.IfExp.body); |
| 4066 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4067 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4068 | goto failed; |
| 4069 | Py_DECREF(value); |
| 4070 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4071 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4072 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4073 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4074 | goto failed; |
| 4075 | Py_DECREF(value); |
| 4076 | break; |
| 4077 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4078 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4079 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4080 | if (!result) goto failed; |
| 4081 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4082 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4083 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4084 | goto failed; |
| 4085 | Py_DECREF(value); |
| 4086 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4087 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4088 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4089 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4090 | goto failed; |
| 4091 | Py_DECREF(value); |
| 4092 | break; |
| 4093 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4094 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4095 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4096 | if (!result) goto failed; |
| 4097 | value = ast2obj_list(o->v.Set.elts, 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->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4100 | goto failed; |
| 4101 | Py_DECREF(value); |
| 4102 | break; |
| 4103 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4104 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4105 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4106 | if (!result) goto failed; |
| 4107 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4108 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4109 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4110 | goto failed; |
| 4111 | Py_DECREF(value); |
| 4112 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4113 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4114 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4115 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4116 | goto failed; |
| 4117 | Py_DECREF(value); |
| 4118 | break; |
| 4119 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4120 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4121 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4122 | if (!result) goto failed; |
| 4123 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4124 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4125 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4126 | goto failed; |
| 4127 | Py_DECREF(value); |
| 4128 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4129 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4130 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4131 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4132 | goto failed; |
| 4133 | Py_DECREF(value); |
| 4134 | break; |
| 4135 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4136 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4137 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4138 | if (!result) goto failed; |
| 4139 | value = ast2obj_expr(o->v.DictComp.key); |
| 4140 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4141 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4142 | goto failed; |
| 4143 | Py_DECREF(value); |
| 4144 | value = ast2obj_expr(o->v.DictComp.value); |
| 4145 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4146 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4147 | goto failed; |
| 4148 | Py_DECREF(value); |
| 4149 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4150 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4151 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4152 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4153 | goto failed; |
| 4154 | Py_DECREF(value); |
| 4155 | break; |
| 4156 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4157 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4158 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4159 | if (!result) goto failed; |
| 4160 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4161 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4162 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4163 | goto failed; |
| 4164 | Py_DECREF(value); |
| 4165 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4166 | ast2obj_comprehension); |
| 4167 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4168 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4169 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4170 | goto failed; |
| 4171 | Py_DECREF(value); |
| 4172 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4173 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4174 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4175 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4176 | if (!result) goto failed; |
| 4177 | value = ast2obj_expr(o->v.Await.value); |
| 4178 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4179 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4180 | goto failed; |
| 4181 | Py_DECREF(value); |
| 4182 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4183 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4184 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4185 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4186 | if (!result) goto failed; |
| 4187 | value = ast2obj_expr(o->v.Yield.value); |
| 4188 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4189 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4190 | goto failed; |
| 4191 | Py_DECREF(value); |
| 4192 | break; |
| 4193 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4194 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4195 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4196 | if (!result) goto failed; |
| 4197 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4198 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4199 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4200 | goto failed; |
| 4201 | Py_DECREF(value); |
| 4202 | break; |
| 4203 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4204 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4205 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4206 | if (!result) goto failed; |
| 4207 | value = ast2obj_expr(o->v.Compare.left); |
| 4208 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4209 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4210 | goto failed; |
| 4211 | Py_DECREF(value); |
| 4212 | { |
| 4213 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4214 | value = PyList_New(n); |
| 4215 | if (!value) goto failed; |
| 4216 | for(i = 0; i < n; i++) |
| 4217 | 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] | 4218 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4219 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4220 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4221 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4222 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4223 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4224 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4225 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4226 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4227 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4228 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4229 | break; |
| 4230 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4231 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4232 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4233 | if (!result) goto failed; |
| 4234 | value = ast2obj_expr(o->v.Call.func); |
| 4235 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4236 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4237 | goto failed; |
| 4238 | Py_DECREF(value); |
| 4239 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4240 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4241 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4242 | goto failed; |
| 4243 | Py_DECREF(value); |
| 4244 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4245 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4246 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4247 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4248 | goto failed; |
| 4249 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4250 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4251 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4252 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4253 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4254 | if (!result) goto failed; |
| 4255 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4256 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4257 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4258 | goto failed; |
| 4259 | Py_DECREF(value); |
| 4260 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4261 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4262 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4263 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4264 | goto failed; |
| 4265 | Py_DECREF(value); |
| 4266 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4267 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4268 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4269 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4270 | goto failed; |
| 4271 | Py_DECREF(value); |
| 4272 | break; |
| 4273 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4274 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4275 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4276 | if (!result) goto failed; |
| 4277 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4278 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4279 | if (PyObject_SetAttr(result, astmodulestate_global->values, 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; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4284 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4285 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4286 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4287 | if (!result) goto failed; |
| 4288 | value = ast2obj_constant(o->v.Constant.value); |
| 4289 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4290 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4291 | goto failed; |
| 4292 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4293 | value = ast2obj_string(o->v.Constant.kind); |
| 4294 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4295 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4296 | goto failed; |
| 4297 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4298 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4299 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4300 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4301 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4302 | if (!result) goto failed; |
| 4303 | value = ast2obj_expr(o->v.Attribute.value); |
| 4304 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4305 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4306 | goto failed; |
| 4307 | Py_DECREF(value); |
| 4308 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4309 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4310 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4311 | goto failed; |
| 4312 | Py_DECREF(value); |
| 4313 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4314 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4315 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4316 | goto failed; |
| 4317 | Py_DECREF(value); |
| 4318 | break; |
| 4319 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4320 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4321 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4322 | if (!result) goto failed; |
| 4323 | value = ast2obj_expr(o->v.Subscript.value); |
| 4324 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4325 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4326 | goto failed; |
| 4327 | Py_DECREF(value); |
| 4328 | value = ast2obj_slice(o->v.Subscript.slice); |
| 4329 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4330 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4331 | goto failed; |
| 4332 | Py_DECREF(value); |
| 4333 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4334 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4335 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4336 | goto failed; |
| 4337 | Py_DECREF(value); |
| 4338 | break; |
| 4339 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4340 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4341 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4342 | if (!result) goto failed; |
| 4343 | value = ast2obj_expr(o->v.Starred.value); |
| 4344 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4345 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4346 | goto failed; |
| 4347 | Py_DECREF(value); |
| 4348 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4349 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4350 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4351 | goto failed; |
| 4352 | Py_DECREF(value); |
| 4353 | break; |
| 4354 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4355 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4356 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4357 | if (!result) goto failed; |
| 4358 | value = ast2obj_identifier(o->v.Name.id); |
| 4359 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4360 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4361 | goto failed; |
| 4362 | Py_DECREF(value); |
| 4363 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4364 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4365 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4366 | goto failed; |
| 4367 | Py_DECREF(value); |
| 4368 | break; |
| 4369 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4370 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4371 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4372 | if (!result) goto failed; |
| 4373 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4374 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4375 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4376 | goto failed; |
| 4377 | Py_DECREF(value); |
| 4378 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4379 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4380 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4381 | goto failed; |
| 4382 | Py_DECREF(value); |
| 4383 | break; |
| 4384 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4385 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4386 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4387 | if (!result) goto failed; |
| 4388 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4389 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4390 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4391 | goto failed; |
| 4392 | Py_DECREF(value); |
| 4393 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4394 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4395 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4396 | goto failed; |
| 4397 | Py_DECREF(value); |
| 4398 | break; |
| 4399 | } |
| 4400 | value = ast2obj_int(o->lineno); |
| 4401 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4402 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4403 | goto failed; |
| 4404 | Py_DECREF(value); |
| 4405 | value = ast2obj_int(o->col_offset); |
| 4406 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4407 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4408 | goto failed; |
| 4409 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4410 | value = ast2obj_int(o->end_lineno); |
| 4411 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4412 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4413 | goto failed; |
| 4414 | Py_DECREF(value); |
| 4415 | value = ast2obj_int(o->end_col_offset); |
| 4416 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4417 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4418 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4419 | goto failed; |
| 4420 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4421 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4422 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4423 | Py_XDECREF(value); |
| 4424 | Py_XDECREF(result); |
| 4425 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4428 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4429 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4430 | switch(o) { |
| 4431 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4432 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4433 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4434 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4435 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4436 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4437 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4438 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4439 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4440 | case AugLoad: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4441 | Py_INCREF(astmodulestate_global->AugLoad_singleton); |
| 4442 | return astmodulestate_global->AugLoad_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4443 | case AugStore: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4444 | Py_INCREF(astmodulestate_global->AugStore_singleton); |
| 4445 | return astmodulestate_global->AugStore_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4446 | case Param: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4447 | Py_INCREF(astmodulestate_global->Param_singleton); |
| 4448 | return astmodulestate_global->Param_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4449 | default: |
| 4450 | /* should never happen, but just in case ... */ |
| 4451 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 4452 | return NULL; |
| 4453 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4454 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4455 | PyObject* |
| 4456 | ast2obj_slice(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4457 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4458 | slice_ty o = (slice_ty)_o; |
| 4459 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4460 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4461 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4462 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4463 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4464 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | switch (o->kind) { |
| 4466 | case Slice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4467 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4468 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4469 | if (!result) goto failed; |
| 4470 | value = ast2obj_expr(o->v.Slice.lower); |
| 4471 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4472 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4473 | goto failed; |
| 4474 | Py_DECREF(value); |
| 4475 | value = ast2obj_expr(o->v.Slice.upper); |
| 4476 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4477 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4478 | goto failed; |
| 4479 | Py_DECREF(value); |
| 4480 | value = ast2obj_expr(o->v.Slice.step); |
| 4481 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4482 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4483 | goto failed; |
| 4484 | Py_DECREF(value); |
| 4485 | break; |
| 4486 | case ExtSlice_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4487 | tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type; |
| 4488 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4489 | if (!result) goto failed; |
| 4490 | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
| 4491 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4492 | if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4493 | goto failed; |
| 4494 | Py_DECREF(value); |
| 4495 | break; |
| 4496 | case Index_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4497 | tp = (PyTypeObject *)astmodulestate_global->Index_type; |
| 4498 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4499 | if (!result) goto failed; |
| 4500 | value = ast2obj_expr(o->v.Index.value); |
| 4501 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4502 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4503 | goto failed; |
| 4504 | Py_DECREF(value); |
| 4505 | break; |
| 4506 | } |
| 4507 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4508 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4509 | Py_XDECREF(value); |
| 4510 | Py_XDECREF(result); |
| 4511 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4514 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4515 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4516 | switch(o) { |
| 4517 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4518 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4519 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4520 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4521 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4522 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4523 | default: |
| 4524 | /* should never happen, but just in case ... */ |
| 4525 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 4526 | return NULL; |
| 4527 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4528 | } |
| 4529 | PyObject* ast2obj_operator(operator_ty o) |
| 4530 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4531 | switch(o) { |
| 4532 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4533 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4534 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4535 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4536 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4537 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4538 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4539 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4540 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4541 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4542 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4543 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4544 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4545 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4546 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4547 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4548 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4549 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4550 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4551 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4552 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4553 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4554 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4555 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4556 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4557 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4558 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4559 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4560 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4561 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4562 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4563 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4564 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4565 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4566 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4567 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4568 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4569 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4570 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4571 | default: |
| 4572 | /* should never happen, but just in case ... */ |
| 4573 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 4574 | return NULL; |
| 4575 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4576 | } |
| 4577 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4578 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4579 | switch(o) { |
| 4580 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4581 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4582 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4583 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4584 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4585 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4586 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4587 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4588 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4589 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4590 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4591 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4592 | default: |
| 4593 | /* should never happen, but just in case ... */ |
| 4594 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 4595 | return NULL; |
| 4596 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4597 | } |
| 4598 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4599 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4600 | switch(o) { |
| 4601 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4602 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4603 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4604 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4605 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4606 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4607 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4608 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4609 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4610 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4611 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4612 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4613 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4614 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4615 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4616 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4617 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4618 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4619 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4620 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4621 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4622 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4623 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4624 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4625 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4626 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4627 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4628 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4629 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4630 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4631 | default: |
| 4632 | /* should never happen, but just in case ... */ |
| 4633 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 4634 | return NULL; |
| 4635 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4636 | } |
| 4637 | PyObject* |
| 4638 | ast2obj_comprehension(void* _o) |
| 4639 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4640 | comprehension_ty o = (comprehension_ty)_o; |
| 4641 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4642 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4643 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4644 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4645 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4646 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4647 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4648 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4649 | if (!result) return NULL; |
| 4650 | value = ast2obj_expr(o->target); |
| 4651 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4652 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4653 | goto failed; |
| 4654 | Py_DECREF(value); |
| 4655 | value = ast2obj_expr(o->iter); |
| 4656 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4657 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4658 | goto failed; |
| 4659 | Py_DECREF(value); |
| 4660 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4661 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4662 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4663 | goto failed; |
| 4664 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4665 | value = ast2obj_int(o->is_async); |
| 4666 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4667 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4668 | goto failed; |
| 4669 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4670 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4671 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4672 | Py_XDECREF(value); |
| 4673 | Py_XDECREF(result); |
| 4674 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4677 | PyObject* |
| 4678 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4679 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4680 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4681 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4682 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4683 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4684 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4685 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4686 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4687 | switch (o->kind) { |
| 4688 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4689 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4690 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4691 | if (!result) goto failed; |
| 4692 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4693 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4694 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4695 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4696 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4697 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4698 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4699 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4700 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4701 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4702 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4703 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4704 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4705 | goto failed; |
| 4706 | Py_DECREF(value); |
| 4707 | break; |
| 4708 | } |
| 4709 | value = ast2obj_int(o->lineno); |
| 4710 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4711 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4712 | goto failed; |
| 4713 | Py_DECREF(value); |
| 4714 | value = ast2obj_int(o->col_offset); |
| 4715 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4716 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4717 | goto failed; |
| 4718 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4719 | value = ast2obj_int(o->end_lineno); |
| 4720 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4721 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4722 | goto failed; |
| 4723 | Py_DECREF(value); |
| 4724 | value = ast2obj_int(o->end_col_offset); |
| 4725 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4726 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4727 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4728 | goto failed; |
| 4729 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4730 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4731 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4732 | Py_XDECREF(value); |
| 4733 | Py_XDECREF(result); |
| 4734 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4737 | PyObject* |
| 4738 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4739 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4740 | arguments_ty o = (arguments_ty)_o; |
| 4741 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4742 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4743 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4744 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4745 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4746 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4747 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4748 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4749 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4750 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4751 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4752 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4753 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4754 | goto failed; |
| 4755 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4756 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4757 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4758 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4759 | goto failed; |
| 4760 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4761 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4762 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4763 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4764 | goto failed; |
| 4765 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4766 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4767 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4768 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4769 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4770 | goto failed; |
| 4771 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4772 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4773 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4774 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4775 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4776 | goto failed; |
| 4777 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4778 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4779 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4780 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4781 | goto failed; |
| 4782 | Py_DECREF(value); |
| 4783 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4784 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4785 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4786 | goto failed; |
| 4787 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4788 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4789 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4790 | Py_XDECREF(value); |
| 4791 | Py_XDECREF(result); |
| 4792 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4793 | } |
| 4794 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4795 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4796 | ast2obj_arg(void* _o) |
| 4797 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4798 | arg_ty o = (arg_ty)_o; |
| 4799 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4800 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4801 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4802 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4803 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4804 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4805 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4806 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4807 | if (!result) return NULL; |
| 4808 | value = ast2obj_identifier(o->arg); |
| 4809 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4810 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4811 | goto failed; |
| 4812 | Py_DECREF(value); |
| 4813 | value = ast2obj_expr(o->annotation); |
| 4814 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4815 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4816 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4817 | goto failed; |
| 4818 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4819 | value = ast2obj_string(o->type_comment); |
| 4820 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4821 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4822 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4823 | goto failed; |
| 4824 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4825 | value = ast2obj_int(o->lineno); |
| 4826 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4827 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4828 | goto failed; |
| 4829 | Py_DECREF(value); |
| 4830 | value = ast2obj_int(o->col_offset); |
| 4831 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4832 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4833 | goto failed; |
| 4834 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4835 | value = ast2obj_int(o->end_lineno); |
| 4836 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4837 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4838 | goto failed; |
| 4839 | Py_DECREF(value); |
| 4840 | value = ast2obj_int(o->end_col_offset); |
| 4841 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4842 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4843 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4844 | goto failed; |
| 4845 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4846 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4847 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4848 | Py_XDECREF(value); |
| 4849 | Py_XDECREF(result); |
| 4850 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4851 | } |
| 4852 | |
| 4853 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4854 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4855 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4856 | keyword_ty o = (keyword_ty)_o; |
| 4857 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4858 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4859 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4860 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4861 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4862 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4863 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4864 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4865 | if (!result) return NULL; |
| 4866 | value = ast2obj_identifier(o->arg); |
| 4867 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4868 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4869 | goto failed; |
| 4870 | Py_DECREF(value); |
| 4871 | value = ast2obj_expr(o->value); |
| 4872 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4873 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4874 | goto failed; |
| 4875 | Py_DECREF(value); |
| 4876 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4877 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4878 | Py_XDECREF(value); |
| 4879 | Py_XDECREF(result); |
| 4880 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4881 | } |
| 4882 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4883 | PyObject* |
| 4884 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4885 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4886 | alias_ty o = (alias_ty)_o; |
| 4887 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4888 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4889 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4890 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4891 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4892 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4893 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 4894 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4895 | if (!result) return NULL; |
| 4896 | value = ast2obj_identifier(o->name); |
| 4897 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4898 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4899 | goto failed; |
| 4900 | Py_DECREF(value); |
| 4901 | value = ast2obj_identifier(o->asname); |
| 4902 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4903 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4904 | goto failed; |
| 4905 | Py_DECREF(value); |
| 4906 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4907 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4908 | Py_XDECREF(value); |
| 4909 | Py_XDECREF(result); |
| 4910 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4913 | PyObject* |
| 4914 | ast2obj_withitem(void* _o) |
| 4915 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4916 | withitem_ty o = (withitem_ty)_o; |
| 4917 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4918 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4919 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4920 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4921 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4922 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4923 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 4924 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4925 | if (!result) return NULL; |
| 4926 | value = ast2obj_expr(o->context_expr); |
| 4927 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4928 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 4929 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4930 | goto failed; |
| 4931 | Py_DECREF(value); |
| 4932 | value = ast2obj_expr(o->optional_vars); |
| 4933 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4934 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 4935 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4936 | goto failed; |
| 4937 | Py_DECREF(value); |
| 4938 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4939 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4940 | Py_XDECREF(value); |
| 4941 | Py_XDECREF(result); |
| 4942 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 4943 | } |
| 4944 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4945 | PyObject* |
| 4946 | ast2obj_type_ignore(void* _o) |
| 4947 | { |
| 4948 | type_ignore_ty o = (type_ignore_ty)_o; |
| 4949 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4950 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4951 | if (!o) { |
| 4952 | Py_RETURN_NONE; |
| 4953 | } |
| 4954 | |
| 4955 | switch (o->kind) { |
| 4956 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4957 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 4958 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4959 | if (!result) goto failed; |
| 4960 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 4961 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4962 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 4963 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4964 | goto failed; |
| 4965 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4966 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 4967 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4968 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 4969 | goto failed; |
| 4970 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4971 | break; |
| 4972 | } |
| 4973 | return result; |
| 4974 | failed: |
| 4975 | Py_XDECREF(value); |
| 4976 | Py_XDECREF(result); |
| 4977 | return NULL; |
| 4978 | } |
| 4979 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4980 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4981 | int |
| 4982 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 4983 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4984 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4985 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4986 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4987 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4988 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4989 | if (obj == Py_None) { |
| 4990 | *out = NULL; |
| 4991 | return 0; |
| 4992 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4993 | tp = astmodulestate_global->Module_type; |
| 4994 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4995 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 4996 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4997 | } |
| 4998 | if (isinstance) { |
| 4999 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5000 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5001 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5002 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5003 | return 1; |
| 5004 | } |
| 5005 | if (tmp == NULL) { |
| 5006 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 5007 | return 1; |
| 5008 | } |
| 5009 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5010 | int res; |
| 5011 | Py_ssize_t len; |
| 5012 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5013 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5014 | 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] | 5015 | goto failed; |
| 5016 | } |
| 5017 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5018 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5019 | if (body == NULL) goto failed; |
| 5020 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5021 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5022 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5023 | Py_INCREF(tmp2); |
| 5024 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5025 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5026 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5027 | if (len != PyList_GET_SIZE(tmp)) { |
| 5028 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5029 | goto failed; |
| 5030 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5031 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5032 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5033 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5034 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5035 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5036 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5037 | return 1; |
| 5038 | } |
| 5039 | if (tmp == NULL) { |
| 5040 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5041 | return 1; |
| 5042 | } |
| 5043 | else { |
| 5044 | int res; |
| 5045 | Py_ssize_t len; |
| 5046 | Py_ssize_t i; |
| 5047 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5048 | 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] | 5049 | goto failed; |
| 5050 | } |
| 5051 | len = PyList_GET_SIZE(tmp); |
| 5052 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5053 | if (type_ignores == NULL) goto failed; |
| 5054 | for (i = 0; i < len; i++) { |
| 5055 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5056 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5057 | Py_INCREF(tmp2); |
| 5058 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5059 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5060 | if (res != 0) goto failed; |
| 5061 | if (len != PyList_GET_SIZE(tmp)) { |
| 5062 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5063 | goto failed; |
| 5064 | } |
| 5065 | asdl_seq_SET(type_ignores, i, val); |
| 5066 | } |
| 5067 | Py_CLEAR(tmp); |
| 5068 | } |
| 5069 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5070 | if (*out == NULL) goto failed; |
| 5071 | return 0; |
| 5072 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5073 | tp = astmodulestate_global->Interactive_type; |
| 5074 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5075 | if (isinstance == -1) { |
| 5076 | return 1; |
| 5077 | } |
| 5078 | if (isinstance) { |
| 5079 | asdl_seq* body; |
| 5080 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5081 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5082 | return 1; |
| 5083 | } |
| 5084 | if (tmp == NULL) { |
| 5085 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5086 | return 1; |
| 5087 | } |
| 5088 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5089 | int res; |
| 5090 | Py_ssize_t len; |
| 5091 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5092 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5093 | 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] | 5094 | goto failed; |
| 5095 | } |
| 5096 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5097 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5098 | if (body == NULL) goto failed; |
| 5099 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5100 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5101 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5102 | Py_INCREF(tmp2); |
| 5103 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5104 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5105 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5106 | if (len != PyList_GET_SIZE(tmp)) { |
| 5107 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5108 | goto failed; |
| 5109 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5110 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5111 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5112 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5113 | } |
| 5114 | *out = Interactive(body, arena); |
| 5115 | if (*out == NULL) goto failed; |
| 5116 | return 0; |
| 5117 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5118 | tp = astmodulestate_global->Expression_type; |
| 5119 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5120 | if (isinstance == -1) { |
| 5121 | return 1; |
| 5122 | } |
| 5123 | if (isinstance) { |
| 5124 | expr_ty body; |
| 5125 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5126 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5127 | return 1; |
| 5128 | } |
| 5129 | if (tmp == NULL) { |
| 5130 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5131 | return 1; |
| 5132 | } |
| 5133 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5134 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5135 | res = obj2ast_expr(tmp, &body, arena); |
| 5136 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5137 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5138 | } |
| 5139 | *out = Expression(body, arena); |
| 5140 | if (*out == NULL) goto failed; |
| 5141 | return 0; |
| 5142 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5143 | tp = astmodulestate_global->FunctionType_type; |
| 5144 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5145 | if (isinstance == -1) { |
| 5146 | return 1; |
| 5147 | } |
| 5148 | if (isinstance) { |
| 5149 | asdl_seq* argtypes; |
| 5150 | expr_ty returns; |
| 5151 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5152 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5153 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5154 | return 1; |
| 5155 | } |
| 5156 | if (tmp == NULL) { |
| 5157 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5158 | return 1; |
| 5159 | } |
| 5160 | else { |
| 5161 | int res; |
| 5162 | Py_ssize_t len; |
| 5163 | Py_ssize_t i; |
| 5164 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5165 | 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] | 5166 | goto failed; |
| 5167 | } |
| 5168 | len = PyList_GET_SIZE(tmp); |
| 5169 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5170 | if (argtypes == NULL) goto failed; |
| 5171 | for (i = 0; i < len; i++) { |
| 5172 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5173 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5174 | Py_INCREF(tmp2); |
| 5175 | res = obj2ast_expr(tmp2, &val, arena); |
| 5176 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5177 | if (res != 0) goto failed; |
| 5178 | if (len != PyList_GET_SIZE(tmp)) { |
| 5179 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5180 | goto failed; |
| 5181 | } |
| 5182 | asdl_seq_SET(argtypes, i, val); |
| 5183 | } |
| 5184 | Py_CLEAR(tmp); |
| 5185 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5186 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5187 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5188 | return 1; |
| 5189 | } |
| 5190 | if (tmp == NULL) { |
| 5191 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5192 | return 1; |
| 5193 | } |
| 5194 | else { |
| 5195 | int res; |
| 5196 | res = obj2ast_expr(tmp, &returns, arena); |
| 5197 | if (res != 0) goto failed; |
| 5198 | Py_CLEAR(tmp); |
| 5199 | } |
| 5200 | *out = FunctionType(argtypes, returns, arena); |
| 5201 | if (*out == NULL) goto failed; |
| 5202 | return 0; |
| 5203 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5204 | tp = astmodulestate_global->Suite_type; |
| 5205 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5206 | if (isinstance == -1) { |
| 5207 | return 1; |
| 5208 | } |
| 5209 | if (isinstance) { |
| 5210 | asdl_seq* body; |
| 5211 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5212 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5213 | return 1; |
| 5214 | } |
| 5215 | if (tmp == NULL) { |
| 5216 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
| 5217 | return 1; |
| 5218 | } |
| 5219 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5220 | int res; |
| 5221 | Py_ssize_t len; |
| 5222 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5223 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5224 | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5225 | goto failed; |
| 5226 | } |
| 5227 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5228 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5229 | if (body == NULL) goto failed; |
| 5230 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5231 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5232 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5233 | Py_INCREF(tmp2); |
| 5234 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5235 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5236 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5237 | if (len != PyList_GET_SIZE(tmp)) { |
| 5238 | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
| 5239 | goto failed; |
| 5240 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5241 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5242 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5243 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5244 | } |
| 5245 | *out = Suite(body, arena); |
| 5246 | if (*out == NULL) goto failed; |
| 5247 | return 0; |
| 5248 | } |
| 5249 | |
| 5250 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5251 | failed: |
| 5252 | Py_XDECREF(tmp); |
| 5253 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5254 | } |
| 5255 | |
| 5256 | int |
| 5257 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5258 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5259 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5260 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5261 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5262 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5263 | int lineno; |
| 5264 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5265 | int end_lineno; |
| 5266 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5267 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5268 | if (obj == Py_None) { |
| 5269 | *out = NULL; |
| 5270 | return 0; |
| 5271 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5272 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5273 | return 1; |
| 5274 | } |
| 5275 | if (tmp == NULL) { |
| 5276 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5277 | return 1; |
| 5278 | } |
| 5279 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5280 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5281 | res = obj2ast_int(tmp, &lineno, arena); |
| 5282 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5283 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5284 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5285 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5286 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5287 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5288 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5289 | if (tmp == NULL) { |
| 5290 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5291 | return 1; |
| 5292 | } |
| 5293 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5294 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5295 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5296 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5297 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5298 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5299 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5300 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5301 | return 1; |
| 5302 | } |
| 5303 | if (tmp == NULL || tmp == Py_None) { |
| 5304 | Py_CLEAR(tmp); |
| 5305 | end_lineno = 0; |
| 5306 | } |
| 5307 | else { |
| 5308 | int res; |
| 5309 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5310 | if (res != 0) goto failed; |
| 5311 | Py_CLEAR(tmp); |
| 5312 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5313 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5314 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5315 | return 1; |
| 5316 | } |
| 5317 | if (tmp == NULL || tmp == Py_None) { |
| 5318 | Py_CLEAR(tmp); |
| 5319 | end_col_offset = 0; |
| 5320 | } |
| 5321 | else { |
| 5322 | int res; |
| 5323 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5324 | if (res != 0) goto failed; |
| 5325 | Py_CLEAR(tmp); |
| 5326 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5327 | tp = astmodulestate_global->FunctionDef_type; |
| 5328 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5329 | if (isinstance == -1) { |
| 5330 | return 1; |
| 5331 | } |
| 5332 | if (isinstance) { |
| 5333 | identifier name; |
| 5334 | arguments_ty args; |
| 5335 | asdl_seq* body; |
| 5336 | asdl_seq* decorator_list; |
| 5337 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5338 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5339 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5340 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5341 | return 1; |
| 5342 | } |
| 5343 | if (tmp == NULL) { |
| 5344 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5345 | return 1; |
| 5346 | } |
| 5347 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5348 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5349 | res = obj2ast_identifier(tmp, &name, arena); |
| 5350 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5351 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5352 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5353 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5354 | return 1; |
| 5355 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5356 | if (tmp == NULL) { |
| 5357 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5358 | return 1; |
| 5359 | } |
| 5360 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5361 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5362 | res = obj2ast_arguments(tmp, &args, arena); |
| 5363 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5364 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5365 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5366 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5367 | return 1; |
| 5368 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5369 | if (tmp == NULL) { |
| 5370 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5371 | return 1; |
| 5372 | } |
| 5373 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5374 | int res; |
| 5375 | Py_ssize_t len; |
| 5376 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5377 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5378 | 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] | 5379 | goto failed; |
| 5380 | } |
| 5381 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5382 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5383 | if (body == NULL) goto failed; |
| 5384 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5385 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5386 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5387 | Py_INCREF(tmp2); |
| 5388 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5389 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5390 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5391 | if (len != PyList_GET_SIZE(tmp)) { |
| 5392 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5393 | goto failed; |
| 5394 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5395 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5396 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5397 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5398 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5399 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5400 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5401 | return 1; |
| 5402 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5403 | if (tmp == NULL) { |
| 5404 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5405 | return 1; |
| 5406 | } |
| 5407 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5408 | int res; |
| 5409 | Py_ssize_t len; |
| 5410 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5411 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5412 | 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] | 5413 | goto failed; |
| 5414 | } |
| 5415 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5416 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5417 | if (decorator_list == NULL) goto failed; |
| 5418 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5419 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5420 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5421 | Py_INCREF(tmp2); |
| 5422 | res = obj2ast_expr(tmp2, &val, arena); |
| 5423 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5424 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5425 | if (len != PyList_GET_SIZE(tmp)) { |
| 5426 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5427 | goto failed; |
| 5428 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5429 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5430 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 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->returns, &tmp) < |
| 5434 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5435 | return 1; |
| 5436 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5437 | if (tmp == NULL || tmp == Py_None) { |
| 5438 | Py_CLEAR(tmp); |
| 5439 | returns = NULL; |
| 5440 | } |
| 5441 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5442 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5443 | res = obj2ast_expr(tmp, &returns, arena); |
| 5444 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5445 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5446 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5447 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5448 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5449 | return 1; |
| 5450 | } |
| 5451 | if (tmp == NULL || tmp == Py_None) { |
| 5452 | Py_CLEAR(tmp); |
| 5453 | type_comment = NULL; |
| 5454 | } |
| 5455 | else { |
| 5456 | int res; |
| 5457 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5458 | if (res != 0) goto failed; |
| 5459 | Py_CLEAR(tmp); |
| 5460 | } |
| 5461 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5462 | type_comment, lineno, col_offset, end_lineno, |
| 5463 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5464 | if (*out == NULL) goto failed; |
| 5465 | return 0; |
| 5466 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5467 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5468 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5469 | if (isinstance == -1) { |
| 5470 | return 1; |
| 5471 | } |
| 5472 | if (isinstance) { |
| 5473 | identifier name; |
| 5474 | arguments_ty args; |
| 5475 | asdl_seq* body; |
| 5476 | asdl_seq* decorator_list; |
| 5477 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5478 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5479 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5480 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5481 | return 1; |
| 5482 | } |
| 5483 | if (tmp == NULL) { |
| 5484 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5485 | return 1; |
| 5486 | } |
| 5487 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5488 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5489 | res = obj2ast_identifier(tmp, &name, arena); |
| 5490 | if (res != 0) goto failed; |
| 5491 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5492 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5493 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5494 | return 1; |
| 5495 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5496 | if (tmp == NULL) { |
| 5497 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5498 | return 1; |
| 5499 | } |
| 5500 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5501 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5502 | res = obj2ast_arguments(tmp, &args, arena); |
| 5503 | if (res != 0) goto failed; |
| 5504 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5505 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5506 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5507 | return 1; |
| 5508 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5509 | if (tmp == NULL) { |
| 5510 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5511 | return 1; |
| 5512 | } |
| 5513 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5514 | int res; |
| 5515 | Py_ssize_t len; |
| 5516 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5517 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5518 | 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] | 5519 | goto failed; |
| 5520 | } |
| 5521 | len = PyList_GET_SIZE(tmp); |
| 5522 | body = _Py_asdl_seq_new(len, arena); |
| 5523 | if (body == NULL) goto failed; |
| 5524 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5525 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5526 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5527 | Py_INCREF(tmp2); |
| 5528 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5529 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5530 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5531 | if (len != PyList_GET_SIZE(tmp)) { |
| 5532 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5533 | goto failed; |
| 5534 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5535 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5536 | } |
| 5537 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5538 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5539 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5540 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5541 | return 1; |
| 5542 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5543 | if (tmp == NULL) { |
| 5544 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5545 | return 1; |
| 5546 | } |
| 5547 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5548 | int res; |
| 5549 | Py_ssize_t len; |
| 5550 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5551 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5552 | 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] | 5553 | goto failed; |
| 5554 | } |
| 5555 | len = PyList_GET_SIZE(tmp); |
| 5556 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5557 | if (decorator_list == NULL) goto failed; |
| 5558 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5559 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5560 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5561 | Py_INCREF(tmp2); |
| 5562 | res = obj2ast_expr(tmp2, &val, arena); |
| 5563 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5564 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5565 | if (len != PyList_GET_SIZE(tmp)) { |
| 5566 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5567 | goto failed; |
| 5568 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5569 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5570 | } |
| 5571 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5572 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5573 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5574 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5575 | return 1; |
| 5576 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5577 | if (tmp == NULL || tmp == Py_None) { |
| 5578 | Py_CLEAR(tmp); |
| 5579 | returns = NULL; |
| 5580 | } |
| 5581 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5582 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5583 | res = obj2ast_expr(tmp, &returns, arena); |
| 5584 | if (res != 0) goto failed; |
| 5585 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5586 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5587 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5588 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5589 | return 1; |
| 5590 | } |
| 5591 | if (tmp == NULL || tmp == Py_None) { |
| 5592 | Py_CLEAR(tmp); |
| 5593 | type_comment = NULL; |
| 5594 | } |
| 5595 | else { |
| 5596 | int res; |
| 5597 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5598 | if (res != 0) goto failed; |
| 5599 | Py_CLEAR(tmp); |
| 5600 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5601 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5602 | type_comment, lineno, col_offset, end_lineno, |
| 5603 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5604 | if (*out == NULL) goto failed; |
| 5605 | return 0; |
| 5606 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5607 | tp = astmodulestate_global->ClassDef_type; |
| 5608 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5609 | if (isinstance == -1) { |
| 5610 | return 1; |
| 5611 | } |
| 5612 | if (isinstance) { |
| 5613 | identifier name; |
| 5614 | asdl_seq* bases; |
| 5615 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5616 | asdl_seq* body; |
| 5617 | asdl_seq* decorator_list; |
| 5618 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5619 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5620 | return 1; |
| 5621 | } |
| 5622 | if (tmp == NULL) { |
| 5623 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5624 | return 1; |
| 5625 | } |
| 5626 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5627 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5628 | res = obj2ast_identifier(tmp, &name, arena); |
| 5629 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5630 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5631 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5632 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5633 | return 1; |
| 5634 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5635 | if (tmp == NULL) { |
| 5636 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5637 | return 1; |
| 5638 | } |
| 5639 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5640 | int res; |
| 5641 | Py_ssize_t len; |
| 5642 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5643 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5644 | 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] | 5645 | goto failed; |
| 5646 | } |
| 5647 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5648 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5649 | if (bases == NULL) goto failed; |
| 5650 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5651 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5652 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5653 | Py_INCREF(tmp2); |
| 5654 | res = obj2ast_expr(tmp2, &val, arena); |
| 5655 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5656 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5657 | if (len != PyList_GET_SIZE(tmp)) { |
| 5658 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5659 | goto failed; |
| 5660 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5661 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5662 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5663 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5664 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5665 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5666 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5667 | return 1; |
| 5668 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5669 | if (tmp == NULL) { |
| 5670 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5671 | return 1; |
| 5672 | } |
| 5673 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5674 | int res; |
| 5675 | Py_ssize_t len; |
| 5676 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5677 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5678 | 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] | 5679 | goto failed; |
| 5680 | } |
| 5681 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5682 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5683 | if (keywords == NULL) goto failed; |
| 5684 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5685 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5686 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5687 | Py_INCREF(tmp2); |
| 5688 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5689 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5690 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5691 | if (len != PyList_GET_SIZE(tmp)) { |
| 5692 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5693 | goto failed; |
| 5694 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5695 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5696 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5697 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5698 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5699 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5700 | return 1; |
| 5701 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5702 | if (tmp == NULL) { |
| 5703 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5704 | return 1; |
| 5705 | } |
| 5706 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5707 | int res; |
| 5708 | Py_ssize_t len; |
| 5709 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5710 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5711 | 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] | 5712 | goto failed; |
| 5713 | } |
| 5714 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5715 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5716 | if (body == NULL) goto failed; |
| 5717 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5718 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5719 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5720 | Py_INCREF(tmp2); |
| 5721 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5722 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5723 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5724 | if (len != PyList_GET_SIZE(tmp)) { |
| 5725 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5726 | goto failed; |
| 5727 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5728 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5729 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5730 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5731 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5732 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5733 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5734 | return 1; |
| 5735 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5736 | if (tmp == NULL) { |
| 5737 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 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, "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] | 5746 | goto failed; |
| 5747 | } |
| 5748 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5749 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5750 | if (decorator_list == 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, "ClassDef field \"decorator_list\" 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(decorator_list, 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); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5765 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5766 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5767 | col_offset, end_lineno, end_col_offset, 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->Return_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 | expr_ty value; |
| 5778 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5779 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5780 | return 1; |
| 5781 | } |
| 5782 | if (tmp == NULL || tmp == Py_None) { |
| 5783 | Py_CLEAR(tmp); |
| 5784 | value = NULL; |
| 5785 | } |
| 5786 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5787 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5788 | res = obj2ast_expr(tmp, &value, arena); |
| 5789 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5790 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5791 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5792 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5793 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5794 | if (*out == NULL) goto failed; |
| 5795 | return 0; |
| 5796 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5797 | tp = astmodulestate_global->Delete_type; |
| 5798 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5799 | if (isinstance == -1) { |
| 5800 | return 1; |
| 5801 | } |
| 5802 | if (isinstance) { |
| 5803 | asdl_seq* targets; |
| 5804 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5805 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5806 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5807 | return 1; |
| 5808 | } |
| 5809 | if (tmp == NULL) { |
| 5810 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5811 | return 1; |
| 5812 | } |
| 5813 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5814 | int res; |
| 5815 | Py_ssize_t len; |
| 5816 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5817 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5818 | 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] | 5819 | goto failed; |
| 5820 | } |
| 5821 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5822 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5823 | if (targets == NULL) goto failed; |
| 5824 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5825 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5826 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5827 | Py_INCREF(tmp2); |
| 5828 | res = obj2ast_expr(tmp2, &val, arena); |
| 5829 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5830 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5831 | if (len != PyList_GET_SIZE(tmp)) { |
| 5832 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5833 | goto failed; |
| 5834 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5835 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5836 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5837 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5838 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5839 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5840 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5841 | if (*out == NULL) goto failed; |
| 5842 | return 0; |
| 5843 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5844 | tp = astmodulestate_global->Assign_type; |
| 5845 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5846 | if (isinstance == -1) { |
| 5847 | return 1; |
| 5848 | } |
| 5849 | if (isinstance) { |
| 5850 | asdl_seq* targets; |
| 5851 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5852 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5853 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5854 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5855 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5856 | return 1; |
| 5857 | } |
| 5858 | if (tmp == NULL) { |
| 5859 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5860 | return 1; |
| 5861 | } |
| 5862 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5863 | int res; |
| 5864 | Py_ssize_t len; |
| 5865 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5866 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5867 | 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] | 5868 | goto failed; |
| 5869 | } |
| 5870 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5871 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5872 | if (targets == NULL) goto failed; |
| 5873 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5874 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5875 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5876 | Py_INCREF(tmp2); |
| 5877 | res = obj2ast_expr(tmp2, &val, arena); |
| 5878 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5879 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5880 | if (len != PyList_GET_SIZE(tmp)) { |
| 5881 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5882 | goto failed; |
| 5883 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5884 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5885 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5886 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5887 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5888 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5889 | return 1; |
| 5890 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5891 | if (tmp == NULL) { |
| 5892 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5893 | return 1; |
| 5894 | } |
| 5895 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5896 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5897 | res = obj2ast_expr(tmp, &value, arena); |
| 5898 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5899 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5900 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5901 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5902 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5903 | return 1; |
| 5904 | } |
| 5905 | if (tmp == NULL || tmp == Py_None) { |
| 5906 | Py_CLEAR(tmp); |
| 5907 | type_comment = NULL; |
| 5908 | } |
| 5909 | else { |
| 5910 | int res; |
| 5911 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5912 | if (res != 0) goto failed; |
| 5913 | Py_CLEAR(tmp); |
| 5914 | } |
| 5915 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5916 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5917 | if (*out == NULL) goto failed; |
| 5918 | return 0; |
| 5919 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5920 | tp = astmodulestate_global->AugAssign_type; |
| 5921 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5922 | if (isinstance == -1) { |
| 5923 | return 1; |
| 5924 | } |
| 5925 | if (isinstance) { |
| 5926 | expr_ty target; |
| 5927 | operator_ty op; |
| 5928 | expr_ty value; |
| 5929 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5930 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5931 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5932 | return 1; |
| 5933 | } |
| 5934 | if (tmp == NULL) { |
| 5935 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5936 | return 1; |
| 5937 | } |
| 5938 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5939 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5940 | res = obj2ast_expr(tmp, &target, arena); |
| 5941 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5942 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5943 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5944 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5945 | return 1; |
| 5946 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5947 | if (tmp == NULL) { |
| 5948 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 5949 | return 1; |
| 5950 | } |
| 5951 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5952 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5953 | res = obj2ast_operator(tmp, &op, arena); |
| 5954 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5955 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5956 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5957 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | return 1; |
| 5959 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5960 | if (tmp == NULL) { |
| 5961 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 5962 | return 1; |
| 5963 | } |
| 5964 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5965 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5966 | res = obj2ast_expr(tmp, &value, arena); |
| 5967 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5968 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5969 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5970 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 5971 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5972 | if (*out == NULL) goto failed; |
| 5973 | return 0; |
| 5974 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5975 | tp = astmodulestate_global->AnnAssign_type; |
| 5976 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5977 | if (isinstance == -1) { |
| 5978 | return 1; |
| 5979 | } |
| 5980 | if (isinstance) { |
| 5981 | expr_ty target; |
| 5982 | expr_ty annotation; |
| 5983 | expr_ty value; |
| 5984 | int simple; |
| 5985 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5986 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5987 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5988 | return 1; |
| 5989 | } |
| 5990 | if (tmp == NULL) { |
| 5991 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 5992 | return 1; |
| 5993 | } |
| 5994 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5995 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 5996 | res = obj2ast_expr(tmp, &target, arena); |
| 5997 | if (res != 0) goto failed; |
| 5998 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5999 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6000 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 6001 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6002 | return 1; |
| 6003 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6004 | if (tmp == NULL) { |
| 6005 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 6006 | return 1; |
| 6007 | } |
| 6008 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6009 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6010 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6011 | if (res != 0) goto failed; |
| 6012 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6013 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6014 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6015 | return 1; |
| 6016 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6017 | if (tmp == NULL || tmp == Py_None) { |
| 6018 | Py_CLEAR(tmp); |
| 6019 | value = NULL; |
| 6020 | } |
| 6021 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6022 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6023 | res = obj2ast_expr(tmp, &value, arena); |
| 6024 | if (res != 0) goto failed; |
| 6025 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6026 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6027 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6028 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6029 | return 1; |
| 6030 | } |
| 6031 | if (tmp == NULL) { |
| 6032 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6033 | return 1; |
| 6034 | } |
| 6035 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6036 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6037 | res = obj2ast_int(tmp, &simple, arena); |
| 6038 | if (res != 0) goto failed; |
| 6039 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6040 | } |
| 6041 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6042 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6043 | if (*out == NULL) goto failed; |
| 6044 | return 0; |
| 6045 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6046 | tp = astmodulestate_global->For_type; |
| 6047 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6048 | if (isinstance == -1) { |
| 6049 | return 1; |
| 6050 | } |
| 6051 | if (isinstance) { |
| 6052 | expr_ty target; |
| 6053 | expr_ty iter; |
| 6054 | asdl_seq* body; |
| 6055 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6056 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6057 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6058 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6059 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6060 | return 1; |
| 6061 | } |
| 6062 | if (tmp == NULL) { |
| 6063 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6064 | return 1; |
| 6065 | } |
| 6066 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6067 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6068 | res = obj2ast_expr(tmp, &target, arena); |
| 6069 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6070 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6071 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6072 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6073 | return 1; |
| 6074 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6075 | if (tmp == NULL) { |
| 6076 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6077 | return 1; |
| 6078 | } |
| 6079 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6080 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6081 | res = obj2ast_expr(tmp, &iter, arena); |
| 6082 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6083 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6084 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6085 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6086 | return 1; |
| 6087 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6088 | if (tmp == NULL) { |
| 6089 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6090 | return 1; |
| 6091 | } |
| 6092 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6093 | int res; |
| 6094 | Py_ssize_t len; |
| 6095 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6096 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6097 | 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] | 6098 | goto failed; |
| 6099 | } |
| 6100 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6101 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6102 | if (body == NULL) goto failed; |
| 6103 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6104 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6105 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6106 | Py_INCREF(tmp2); |
| 6107 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6108 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6109 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6110 | if (len != PyList_GET_SIZE(tmp)) { |
| 6111 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6112 | goto failed; |
| 6113 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6114 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6115 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6116 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6117 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6118 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6119 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6120 | return 1; |
| 6121 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6122 | if (tmp == NULL) { |
| 6123 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6124 | return 1; |
| 6125 | } |
| 6126 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6127 | int res; |
| 6128 | Py_ssize_t len; |
| 6129 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6130 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6131 | 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] | 6132 | goto failed; |
| 6133 | } |
| 6134 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6135 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6136 | if (orelse == NULL) goto failed; |
| 6137 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6138 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6139 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6140 | Py_INCREF(tmp2); |
| 6141 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6142 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6143 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6144 | if (len != PyList_GET_SIZE(tmp)) { |
| 6145 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6146 | goto failed; |
| 6147 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6148 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6149 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6150 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6151 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6152 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6153 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6154 | return 1; |
| 6155 | } |
| 6156 | if (tmp == NULL || tmp == Py_None) { |
| 6157 | Py_CLEAR(tmp); |
| 6158 | type_comment = NULL; |
| 6159 | } |
| 6160 | else { |
| 6161 | int res; |
| 6162 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6163 | if (res != 0) goto failed; |
| 6164 | Py_CLEAR(tmp); |
| 6165 | } |
| 6166 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6167 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6168 | if (*out == NULL) goto failed; |
| 6169 | return 0; |
| 6170 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6171 | tp = astmodulestate_global->AsyncFor_type; |
| 6172 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6173 | if (isinstance == -1) { |
| 6174 | return 1; |
| 6175 | } |
| 6176 | if (isinstance) { |
| 6177 | expr_ty target; |
| 6178 | expr_ty iter; |
| 6179 | asdl_seq* body; |
| 6180 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6181 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6182 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6183 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6184 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6185 | return 1; |
| 6186 | } |
| 6187 | if (tmp == NULL) { |
| 6188 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6189 | return 1; |
| 6190 | } |
| 6191 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6192 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6193 | res = obj2ast_expr(tmp, &target, arena); |
| 6194 | if (res != 0) goto failed; |
| 6195 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6196 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6197 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6198 | return 1; |
| 6199 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6200 | if (tmp == NULL) { |
| 6201 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6202 | return 1; |
| 6203 | } |
| 6204 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6205 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6206 | res = obj2ast_expr(tmp, &iter, arena); |
| 6207 | if (res != 0) goto failed; |
| 6208 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6209 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6210 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6211 | return 1; |
| 6212 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6213 | if (tmp == NULL) { |
| 6214 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6215 | return 1; |
| 6216 | } |
| 6217 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6218 | int res; |
| 6219 | Py_ssize_t len; |
| 6220 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6221 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6222 | 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] | 6223 | goto failed; |
| 6224 | } |
| 6225 | len = PyList_GET_SIZE(tmp); |
| 6226 | body = _Py_asdl_seq_new(len, arena); |
| 6227 | if (body == NULL) goto failed; |
| 6228 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6229 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6230 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6231 | Py_INCREF(tmp2); |
| 6232 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6233 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6234 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6235 | if (len != PyList_GET_SIZE(tmp)) { |
| 6236 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6237 | goto failed; |
| 6238 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6239 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6240 | } |
| 6241 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6242 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6243 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6244 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6245 | return 1; |
| 6246 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6247 | if (tmp == NULL) { |
| 6248 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6249 | return 1; |
| 6250 | } |
| 6251 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6252 | int res; |
| 6253 | Py_ssize_t len; |
| 6254 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6255 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6256 | 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] | 6257 | goto failed; |
| 6258 | } |
| 6259 | len = PyList_GET_SIZE(tmp); |
| 6260 | orelse = _Py_asdl_seq_new(len, arena); |
| 6261 | if (orelse == NULL) goto failed; |
| 6262 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6263 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6264 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6265 | Py_INCREF(tmp2); |
| 6266 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6267 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6268 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6269 | if (len != PyList_GET_SIZE(tmp)) { |
| 6270 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6271 | goto failed; |
| 6272 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6273 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6274 | } |
| 6275 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6276 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6277 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6278 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6279 | return 1; |
| 6280 | } |
| 6281 | if (tmp == NULL || tmp == Py_None) { |
| 6282 | Py_CLEAR(tmp); |
| 6283 | type_comment = NULL; |
| 6284 | } |
| 6285 | else { |
| 6286 | int res; |
| 6287 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6288 | if (res != 0) goto failed; |
| 6289 | Py_CLEAR(tmp); |
| 6290 | } |
| 6291 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6292 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6293 | if (*out == NULL) goto failed; |
| 6294 | return 0; |
| 6295 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6296 | tp = astmodulestate_global->While_type; |
| 6297 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6298 | if (isinstance == -1) { |
| 6299 | return 1; |
| 6300 | } |
| 6301 | if (isinstance) { |
| 6302 | expr_ty test; |
| 6303 | asdl_seq* body; |
| 6304 | asdl_seq* orelse; |
| 6305 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6306 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6307 | return 1; |
| 6308 | } |
| 6309 | if (tmp == NULL) { |
| 6310 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6311 | return 1; |
| 6312 | } |
| 6313 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6314 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6315 | res = obj2ast_expr(tmp, &test, arena); |
| 6316 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6317 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6318 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6319 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6320 | return 1; |
| 6321 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6322 | if (tmp == NULL) { |
| 6323 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6324 | return 1; |
| 6325 | } |
| 6326 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6327 | int res; |
| 6328 | Py_ssize_t len; |
| 6329 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6330 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6331 | 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] | 6332 | goto failed; |
| 6333 | } |
| 6334 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6335 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6336 | if (body == NULL) goto failed; |
| 6337 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6338 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6339 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6340 | Py_INCREF(tmp2); |
| 6341 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6342 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6343 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6344 | if (len != PyList_GET_SIZE(tmp)) { |
| 6345 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6346 | goto failed; |
| 6347 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6348 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6349 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6350 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6351 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6352 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6353 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6354 | return 1; |
| 6355 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6356 | if (tmp == NULL) { |
| 6357 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6358 | return 1; |
| 6359 | } |
| 6360 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6361 | int res; |
| 6362 | Py_ssize_t len; |
| 6363 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6364 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6365 | 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] | 6366 | goto failed; |
| 6367 | } |
| 6368 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6369 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6370 | if (orelse == NULL) goto failed; |
| 6371 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6372 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6373 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6374 | Py_INCREF(tmp2); |
| 6375 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6376 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6377 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6378 | if (len != PyList_GET_SIZE(tmp)) { |
| 6379 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6380 | goto failed; |
| 6381 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6382 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6383 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6384 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6385 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6386 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6387 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6388 | if (*out == NULL) goto failed; |
| 6389 | return 0; |
| 6390 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6391 | tp = astmodulestate_global->If_type; |
| 6392 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6393 | if (isinstance == -1) { |
| 6394 | return 1; |
| 6395 | } |
| 6396 | if (isinstance) { |
| 6397 | expr_ty test; |
| 6398 | asdl_seq* body; |
| 6399 | asdl_seq* orelse; |
| 6400 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6401 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6402 | return 1; |
| 6403 | } |
| 6404 | if (tmp == NULL) { |
| 6405 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6406 | return 1; |
| 6407 | } |
| 6408 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6409 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6410 | res = obj2ast_expr(tmp, &test, arena); |
| 6411 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6412 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6413 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6414 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6415 | return 1; |
| 6416 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6417 | if (tmp == NULL) { |
| 6418 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6419 | return 1; |
| 6420 | } |
| 6421 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6422 | int res; |
| 6423 | Py_ssize_t len; |
| 6424 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6425 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6426 | 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] | 6427 | goto failed; |
| 6428 | } |
| 6429 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6430 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6431 | if (body == NULL) goto failed; |
| 6432 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6433 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6434 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6435 | Py_INCREF(tmp2); |
| 6436 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6437 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6438 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6439 | if (len != PyList_GET_SIZE(tmp)) { |
| 6440 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6441 | goto failed; |
| 6442 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6443 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6444 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6445 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6446 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6447 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6448 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6449 | return 1; |
| 6450 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6451 | if (tmp == NULL) { |
| 6452 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6453 | return 1; |
| 6454 | } |
| 6455 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6456 | int res; |
| 6457 | Py_ssize_t len; |
| 6458 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6459 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6460 | 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] | 6461 | goto failed; |
| 6462 | } |
| 6463 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6464 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6465 | if (orelse == NULL) goto failed; |
| 6466 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6467 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6468 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6469 | Py_INCREF(tmp2); |
| 6470 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6471 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6472 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6473 | if (len != PyList_GET_SIZE(tmp)) { |
| 6474 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6475 | goto failed; |
| 6476 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6477 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6478 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6479 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6480 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6481 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6482 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6483 | if (*out == NULL) goto failed; |
| 6484 | return 0; |
| 6485 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6486 | tp = astmodulestate_global->With_type; |
| 6487 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6488 | if (isinstance == -1) { |
| 6489 | return 1; |
| 6490 | } |
| 6491 | if (isinstance) { |
| 6492 | asdl_seq* items; |
| 6493 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6494 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6495 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6496 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6497 | return 1; |
| 6498 | } |
| 6499 | if (tmp == NULL) { |
| 6500 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6501 | return 1; |
| 6502 | } |
| 6503 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6504 | int res; |
| 6505 | Py_ssize_t len; |
| 6506 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6507 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6508 | 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] | 6509 | goto failed; |
| 6510 | } |
| 6511 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6512 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6513 | if (items == NULL) goto failed; |
| 6514 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6515 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6516 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6517 | Py_INCREF(tmp2); |
| 6518 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6519 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6520 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6521 | if (len != PyList_GET_SIZE(tmp)) { |
| 6522 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6523 | goto failed; |
| 6524 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6525 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6526 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6527 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6528 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6529 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6530 | return 1; |
| 6531 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6532 | if (tmp == NULL) { |
| 6533 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6534 | return 1; |
| 6535 | } |
| 6536 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6537 | int res; |
| 6538 | Py_ssize_t len; |
| 6539 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6540 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6541 | 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] | 6542 | goto failed; |
| 6543 | } |
| 6544 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6545 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6546 | if (body == NULL) goto failed; |
| 6547 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6548 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6549 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6550 | Py_INCREF(tmp2); |
| 6551 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6552 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6553 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6554 | if (len != PyList_GET_SIZE(tmp)) { |
| 6555 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6556 | goto failed; |
| 6557 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6558 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6559 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6560 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6561 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6562 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6563 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6564 | return 1; |
| 6565 | } |
| 6566 | if (tmp == NULL || tmp == Py_None) { |
| 6567 | Py_CLEAR(tmp); |
| 6568 | type_comment = NULL; |
| 6569 | } |
| 6570 | else { |
| 6571 | int res; |
| 6572 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6573 | if (res != 0) goto failed; |
| 6574 | Py_CLEAR(tmp); |
| 6575 | } |
| 6576 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6577 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6578 | if (*out == NULL) goto failed; |
| 6579 | return 0; |
| 6580 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6581 | tp = astmodulestate_global->AsyncWith_type; |
| 6582 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6583 | if (isinstance == -1) { |
| 6584 | return 1; |
| 6585 | } |
| 6586 | if (isinstance) { |
| 6587 | asdl_seq* items; |
| 6588 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6589 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6590 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6591 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6592 | return 1; |
| 6593 | } |
| 6594 | if (tmp == NULL) { |
| 6595 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6596 | return 1; |
| 6597 | } |
| 6598 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6599 | int res; |
| 6600 | Py_ssize_t len; |
| 6601 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6602 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6603 | 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] | 6604 | goto failed; |
| 6605 | } |
| 6606 | len = PyList_GET_SIZE(tmp); |
| 6607 | items = _Py_asdl_seq_new(len, arena); |
| 6608 | if (items == NULL) goto failed; |
| 6609 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6610 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6611 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6612 | Py_INCREF(tmp2); |
| 6613 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6614 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6615 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6616 | if (len != PyList_GET_SIZE(tmp)) { |
| 6617 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6618 | goto failed; |
| 6619 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6620 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6621 | } |
| 6622 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6623 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6624 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6625 | return 1; |
| 6626 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6627 | if (tmp == NULL) { |
| 6628 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6629 | return 1; |
| 6630 | } |
| 6631 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6632 | int res; |
| 6633 | Py_ssize_t len; |
| 6634 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6635 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6636 | 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] | 6637 | goto failed; |
| 6638 | } |
| 6639 | len = PyList_GET_SIZE(tmp); |
| 6640 | body = _Py_asdl_seq_new(len, arena); |
| 6641 | if (body == NULL) goto failed; |
| 6642 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6643 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6644 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6645 | Py_INCREF(tmp2); |
| 6646 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6647 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6648 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6649 | if (len != PyList_GET_SIZE(tmp)) { |
| 6650 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6651 | goto failed; |
| 6652 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6653 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6654 | } |
| 6655 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6656 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6657 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6658 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6659 | return 1; |
| 6660 | } |
| 6661 | if (tmp == NULL || tmp == Py_None) { |
| 6662 | Py_CLEAR(tmp); |
| 6663 | type_comment = NULL; |
| 6664 | } |
| 6665 | else { |
| 6666 | int res; |
| 6667 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6668 | if (res != 0) goto failed; |
| 6669 | Py_CLEAR(tmp); |
| 6670 | } |
| 6671 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6672 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6673 | if (*out == NULL) goto failed; |
| 6674 | return 0; |
| 6675 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6676 | tp = astmodulestate_global->Raise_type; |
| 6677 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6678 | if (isinstance == -1) { |
| 6679 | return 1; |
| 6680 | } |
| 6681 | if (isinstance) { |
| 6682 | expr_ty exc; |
| 6683 | expr_ty cause; |
| 6684 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6685 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6686 | return 1; |
| 6687 | } |
| 6688 | if (tmp == NULL || tmp == Py_None) { |
| 6689 | Py_CLEAR(tmp); |
| 6690 | exc = NULL; |
| 6691 | } |
| 6692 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6693 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6694 | res = obj2ast_expr(tmp, &exc, arena); |
| 6695 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6696 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6697 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6698 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6699 | return 1; |
| 6700 | } |
| 6701 | if (tmp == NULL || tmp == Py_None) { |
| 6702 | Py_CLEAR(tmp); |
| 6703 | cause = NULL; |
| 6704 | } |
| 6705 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6706 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6707 | res = obj2ast_expr(tmp, &cause, arena); |
| 6708 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6709 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6710 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6711 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6712 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6713 | if (*out == NULL) goto failed; |
| 6714 | return 0; |
| 6715 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6716 | tp = astmodulestate_global->Try_type; |
| 6717 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6718 | if (isinstance == -1) { |
| 6719 | return 1; |
| 6720 | } |
| 6721 | if (isinstance) { |
| 6722 | asdl_seq* body; |
| 6723 | asdl_seq* handlers; |
| 6724 | asdl_seq* orelse; |
| 6725 | asdl_seq* finalbody; |
| 6726 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6727 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6728 | return 1; |
| 6729 | } |
| 6730 | if (tmp == NULL) { |
| 6731 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6732 | return 1; |
| 6733 | } |
| 6734 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6735 | int res; |
| 6736 | Py_ssize_t len; |
| 6737 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6738 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6739 | 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] | 6740 | goto failed; |
| 6741 | } |
| 6742 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6743 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6744 | if (body == NULL) goto failed; |
| 6745 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6746 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6747 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6748 | Py_INCREF(tmp2); |
| 6749 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6750 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6751 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6752 | if (len != PyList_GET_SIZE(tmp)) { |
| 6753 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6754 | goto failed; |
| 6755 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6756 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6757 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6758 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6759 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6760 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6761 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6762 | return 1; |
| 6763 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6764 | if (tmp == NULL) { |
| 6765 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6766 | return 1; |
| 6767 | } |
| 6768 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6769 | int res; |
| 6770 | Py_ssize_t len; |
| 6771 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6772 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6773 | 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] | 6774 | goto failed; |
| 6775 | } |
| 6776 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6777 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6778 | if (handlers == NULL) goto failed; |
| 6779 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6780 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6781 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6782 | Py_INCREF(tmp2); |
| 6783 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6784 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6785 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6786 | if (len != PyList_GET_SIZE(tmp)) { |
| 6787 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6788 | goto failed; |
| 6789 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6790 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6791 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6792 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6793 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6794 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6795 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6796 | return 1; |
| 6797 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6798 | if (tmp == NULL) { |
| 6799 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6800 | return 1; |
| 6801 | } |
| 6802 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6803 | int res; |
| 6804 | Py_ssize_t len; |
| 6805 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6806 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6807 | 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] | 6808 | goto failed; |
| 6809 | } |
| 6810 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6811 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6812 | if (orelse == NULL) goto failed; |
| 6813 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6814 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6815 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6816 | Py_INCREF(tmp2); |
| 6817 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6818 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6819 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6820 | if (len != PyList_GET_SIZE(tmp)) { |
| 6821 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6822 | goto failed; |
| 6823 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6824 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6825 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6826 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6827 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6828 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6829 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6830 | return 1; |
| 6831 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6832 | if (tmp == NULL) { |
| 6833 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6834 | return 1; |
| 6835 | } |
| 6836 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6837 | int res; |
| 6838 | Py_ssize_t len; |
| 6839 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6840 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6841 | 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] | 6842 | goto failed; |
| 6843 | } |
| 6844 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6845 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6846 | if (finalbody == NULL) goto failed; |
| 6847 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6848 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6849 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6850 | Py_INCREF(tmp2); |
| 6851 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6852 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6853 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6854 | if (len != PyList_GET_SIZE(tmp)) { |
| 6855 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6856 | goto failed; |
| 6857 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6858 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6859 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6860 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6861 | } |
| 6862 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6863 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6864 | if (*out == NULL) goto failed; |
| 6865 | return 0; |
| 6866 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6867 | tp = astmodulestate_global->Assert_type; |
| 6868 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6869 | if (isinstance == -1) { |
| 6870 | return 1; |
| 6871 | } |
| 6872 | if (isinstance) { |
| 6873 | expr_ty test; |
| 6874 | expr_ty msg; |
| 6875 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6876 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6877 | return 1; |
| 6878 | } |
| 6879 | if (tmp == NULL) { |
| 6880 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6881 | return 1; |
| 6882 | } |
| 6883 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6884 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6885 | res = obj2ast_expr(tmp, &test, arena); |
| 6886 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6887 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6888 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6889 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6890 | return 1; |
| 6891 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6892 | if (tmp == NULL || tmp == Py_None) { |
| 6893 | Py_CLEAR(tmp); |
| 6894 | msg = NULL; |
| 6895 | } |
| 6896 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6897 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6898 | res = obj2ast_expr(tmp, &msg, arena); |
| 6899 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6900 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6901 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6902 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6903 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6904 | if (*out == NULL) goto failed; |
| 6905 | return 0; |
| 6906 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6907 | tp = astmodulestate_global->Import_type; |
| 6908 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6909 | if (isinstance == -1) { |
| 6910 | return 1; |
| 6911 | } |
| 6912 | if (isinstance) { |
| 6913 | asdl_seq* names; |
| 6914 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6915 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6916 | return 1; |
| 6917 | } |
| 6918 | if (tmp == NULL) { |
| 6919 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6920 | return 1; |
| 6921 | } |
| 6922 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6923 | int res; |
| 6924 | Py_ssize_t len; |
| 6925 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6926 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6927 | 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] | 6928 | goto failed; |
| 6929 | } |
| 6930 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6931 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6932 | if (names == NULL) goto failed; |
| 6933 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6934 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6935 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6936 | Py_INCREF(tmp2); |
| 6937 | res = obj2ast_alias(tmp2, &val, arena); |
| 6938 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6939 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6940 | if (len != PyList_GET_SIZE(tmp)) { |
| 6941 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 6942 | goto failed; |
| 6943 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6944 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6945 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6946 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6947 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6948 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 6949 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6950 | if (*out == NULL) goto failed; |
| 6951 | return 0; |
| 6952 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6953 | tp = astmodulestate_global->ImportFrom_type; |
| 6954 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6955 | if (isinstance == -1) { |
| 6956 | return 1; |
| 6957 | } |
| 6958 | if (isinstance) { |
| 6959 | identifier module; |
| 6960 | asdl_seq* names; |
| 6961 | int level; |
| 6962 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6963 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 6964 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6965 | return 1; |
| 6966 | } |
| 6967 | if (tmp == NULL || tmp == Py_None) { |
| 6968 | Py_CLEAR(tmp); |
| 6969 | module = NULL; |
| 6970 | } |
| 6971 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6972 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6973 | res = obj2ast_identifier(tmp, &module, arena); |
| 6974 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6975 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6976 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6977 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6978 | return 1; |
| 6979 | } |
| 6980 | if (tmp == NULL) { |
| 6981 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 6982 | return 1; |
| 6983 | } |
| 6984 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6985 | int res; |
| 6986 | Py_ssize_t len; |
| 6987 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6988 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6989 | 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] | 6990 | goto failed; |
| 6991 | } |
| 6992 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6993 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6994 | if (names == NULL) goto failed; |
| 6995 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6996 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6997 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6998 | Py_INCREF(tmp2); |
| 6999 | res = obj2ast_alias(tmp2, &val, arena); |
| 7000 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7001 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7002 | if (len != PyList_GET_SIZE(tmp)) { |
| 7003 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 7004 | goto failed; |
| 7005 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7006 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7007 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7008 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7009 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7010 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7011 | return 1; |
| 7012 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7013 | if (tmp == NULL || tmp == Py_None) { |
| 7014 | Py_CLEAR(tmp); |
| 7015 | level = 0; |
| 7016 | } |
| 7017 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7018 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7019 | res = obj2ast_int(tmp, &level, arena); |
| 7020 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7021 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7022 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7023 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7024 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7025 | if (*out == NULL) goto failed; |
| 7026 | return 0; |
| 7027 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7028 | tp = astmodulestate_global->Global_type; |
| 7029 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7030 | if (isinstance == -1) { |
| 7031 | return 1; |
| 7032 | } |
| 7033 | if (isinstance) { |
| 7034 | asdl_seq* names; |
| 7035 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7036 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7037 | return 1; |
| 7038 | } |
| 7039 | if (tmp == NULL) { |
| 7040 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7041 | return 1; |
| 7042 | } |
| 7043 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7044 | int res; |
| 7045 | Py_ssize_t len; |
| 7046 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7047 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7048 | 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] | 7049 | goto failed; |
| 7050 | } |
| 7051 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7052 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7053 | if (names == NULL) goto failed; |
| 7054 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7055 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7056 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7057 | Py_INCREF(tmp2); |
| 7058 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7059 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7060 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7061 | if (len != PyList_GET_SIZE(tmp)) { |
| 7062 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7063 | goto failed; |
| 7064 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7065 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7066 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7067 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7068 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7069 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7070 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7071 | if (*out == NULL) goto failed; |
| 7072 | return 0; |
| 7073 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7074 | tp = astmodulestate_global->Nonlocal_type; |
| 7075 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7076 | if (isinstance == -1) { |
| 7077 | return 1; |
| 7078 | } |
| 7079 | if (isinstance) { |
| 7080 | asdl_seq* names; |
| 7081 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7082 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7083 | return 1; |
| 7084 | } |
| 7085 | if (tmp == NULL) { |
| 7086 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7087 | return 1; |
| 7088 | } |
| 7089 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7090 | int res; |
| 7091 | Py_ssize_t len; |
| 7092 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7093 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7094 | 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] | 7095 | goto failed; |
| 7096 | } |
| 7097 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7098 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7099 | if (names == NULL) goto failed; |
| 7100 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7101 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7102 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7103 | Py_INCREF(tmp2); |
| 7104 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7105 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7106 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7107 | if (len != PyList_GET_SIZE(tmp)) { |
| 7108 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7109 | goto failed; |
| 7110 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7111 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7112 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7113 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7114 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7115 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7116 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7117 | if (*out == NULL) goto failed; |
| 7118 | return 0; |
| 7119 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7120 | tp = astmodulestate_global->Expr_type; |
| 7121 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7122 | if (isinstance == -1) { |
| 7123 | return 1; |
| 7124 | } |
| 7125 | if (isinstance) { |
| 7126 | expr_ty value; |
| 7127 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7128 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7129 | return 1; |
| 7130 | } |
| 7131 | if (tmp == NULL) { |
| 7132 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7133 | return 1; |
| 7134 | } |
| 7135 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7136 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7137 | res = obj2ast_expr(tmp, &value, arena); |
| 7138 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7139 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7140 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7141 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7142 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7143 | if (*out == NULL) goto failed; |
| 7144 | return 0; |
| 7145 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7146 | tp = astmodulestate_global->Pass_type; |
| 7147 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7148 | if (isinstance == -1) { |
| 7149 | return 1; |
| 7150 | } |
| 7151 | if (isinstance) { |
| 7152 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7153 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7154 | if (*out == NULL) goto failed; |
| 7155 | return 0; |
| 7156 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7157 | tp = astmodulestate_global->Break_type; |
| 7158 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7159 | if (isinstance == -1) { |
| 7160 | return 1; |
| 7161 | } |
| 7162 | if (isinstance) { |
| 7163 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7164 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7165 | if (*out == NULL) goto failed; |
| 7166 | return 0; |
| 7167 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7168 | tp = astmodulestate_global->Continue_type; |
| 7169 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7170 | if (isinstance == -1) { |
| 7171 | return 1; |
| 7172 | } |
| 7173 | if (isinstance) { |
| 7174 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7175 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7176 | if (*out == NULL) goto failed; |
| 7177 | return 0; |
| 7178 | } |
| 7179 | |
| 7180 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7181 | failed: |
| 7182 | Py_XDECREF(tmp); |
| 7183 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
| 7186 | int |
| 7187 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7188 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7189 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7190 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7191 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7192 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7193 | int lineno; |
| 7194 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7195 | int end_lineno; |
| 7196 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7197 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7198 | if (obj == Py_None) { |
| 7199 | *out = NULL; |
| 7200 | return 0; |
| 7201 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7202 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7203 | return 1; |
| 7204 | } |
| 7205 | if (tmp == NULL) { |
| 7206 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7207 | return 1; |
| 7208 | } |
| 7209 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7210 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7211 | res = obj2ast_int(tmp, &lineno, arena); |
| 7212 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7213 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7214 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7215 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7216 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7217 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7218 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7219 | if (tmp == NULL) { |
| 7220 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7221 | return 1; |
| 7222 | } |
| 7223 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7224 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7225 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7226 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7227 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7228 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7229 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7230 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7231 | return 1; |
| 7232 | } |
| 7233 | if (tmp == NULL || tmp == Py_None) { |
| 7234 | Py_CLEAR(tmp); |
| 7235 | end_lineno = 0; |
| 7236 | } |
| 7237 | else { |
| 7238 | int res; |
| 7239 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7240 | if (res != 0) goto failed; |
| 7241 | Py_CLEAR(tmp); |
| 7242 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7243 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7244 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7245 | return 1; |
| 7246 | } |
| 7247 | if (tmp == NULL || tmp == Py_None) { |
| 7248 | Py_CLEAR(tmp); |
| 7249 | end_col_offset = 0; |
| 7250 | } |
| 7251 | else { |
| 7252 | int res; |
| 7253 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7254 | if (res != 0) goto failed; |
| 7255 | Py_CLEAR(tmp); |
| 7256 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7257 | tp = astmodulestate_global->BoolOp_type; |
| 7258 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7259 | if (isinstance == -1) { |
| 7260 | return 1; |
| 7261 | } |
| 7262 | if (isinstance) { |
| 7263 | boolop_ty op; |
| 7264 | asdl_seq* values; |
| 7265 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7266 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7267 | return 1; |
| 7268 | } |
| 7269 | if (tmp == NULL) { |
| 7270 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7271 | return 1; |
| 7272 | } |
| 7273 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7274 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7275 | res = obj2ast_boolop(tmp, &op, arena); |
| 7276 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7277 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7278 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7279 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7280 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7281 | return 1; |
| 7282 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7283 | if (tmp == NULL) { |
| 7284 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7285 | return 1; |
| 7286 | } |
| 7287 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7288 | int res; |
| 7289 | Py_ssize_t len; |
| 7290 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7291 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7292 | 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] | 7293 | goto failed; |
| 7294 | } |
| 7295 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7296 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7297 | if (values == NULL) goto failed; |
| 7298 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7299 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7300 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7301 | Py_INCREF(tmp2); |
| 7302 | res = obj2ast_expr(tmp2, &val, arena); |
| 7303 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7304 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7305 | if (len != PyList_GET_SIZE(tmp)) { |
| 7306 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7307 | goto failed; |
| 7308 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7309 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7310 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7311 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7312 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7313 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7314 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7315 | if (*out == NULL) goto failed; |
| 7316 | return 0; |
| 7317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7318 | tp = astmodulestate_global->NamedExpr_type; |
| 7319 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7320 | if (isinstance == -1) { |
| 7321 | return 1; |
| 7322 | } |
| 7323 | if (isinstance) { |
| 7324 | expr_ty target; |
| 7325 | expr_ty value; |
| 7326 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7327 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7328 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7329 | return 1; |
| 7330 | } |
| 7331 | if (tmp == NULL) { |
| 7332 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7333 | return 1; |
| 7334 | } |
| 7335 | else { |
| 7336 | int res; |
| 7337 | res = obj2ast_expr(tmp, &target, arena); |
| 7338 | if (res != 0) goto failed; |
| 7339 | Py_CLEAR(tmp); |
| 7340 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7341 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7342 | return 1; |
| 7343 | } |
| 7344 | if (tmp == NULL) { |
| 7345 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7346 | return 1; |
| 7347 | } |
| 7348 | else { |
| 7349 | int res; |
| 7350 | res = obj2ast_expr(tmp, &value, arena); |
| 7351 | if (res != 0) goto failed; |
| 7352 | Py_CLEAR(tmp); |
| 7353 | } |
| 7354 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7355 | end_col_offset, arena); |
| 7356 | if (*out == NULL) goto failed; |
| 7357 | return 0; |
| 7358 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7359 | tp = astmodulestate_global->BinOp_type; |
| 7360 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7361 | if (isinstance == -1) { |
| 7362 | return 1; |
| 7363 | } |
| 7364 | if (isinstance) { |
| 7365 | expr_ty left; |
| 7366 | operator_ty op; |
| 7367 | expr_ty right; |
| 7368 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7369 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7370 | return 1; |
| 7371 | } |
| 7372 | if (tmp == NULL) { |
| 7373 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7374 | return 1; |
| 7375 | } |
| 7376 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7377 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7378 | res = obj2ast_expr(tmp, &left, arena); |
| 7379 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7380 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7381 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7382 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7383 | return 1; |
| 7384 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7385 | if (tmp == NULL) { |
| 7386 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7387 | return 1; |
| 7388 | } |
| 7389 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7390 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7391 | res = obj2ast_operator(tmp, &op, arena); |
| 7392 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7393 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7394 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7395 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7396 | return 1; |
| 7397 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7398 | if (tmp == NULL) { |
| 7399 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7400 | return 1; |
| 7401 | } |
| 7402 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7403 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7404 | res = obj2ast_expr(tmp, &right, arena); |
| 7405 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7406 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7407 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7408 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7409 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7410 | if (*out == NULL) goto failed; |
| 7411 | return 0; |
| 7412 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7413 | tp = astmodulestate_global->UnaryOp_type; |
| 7414 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7415 | if (isinstance == -1) { |
| 7416 | return 1; |
| 7417 | } |
| 7418 | if (isinstance) { |
| 7419 | unaryop_ty op; |
| 7420 | expr_ty operand; |
| 7421 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7422 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7423 | return 1; |
| 7424 | } |
| 7425 | if (tmp == NULL) { |
| 7426 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7427 | return 1; |
| 7428 | } |
| 7429 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7430 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7431 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7432 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7433 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7434 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7435 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7436 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7437 | return 1; |
| 7438 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7439 | if (tmp == NULL) { |
| 7440 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7441 | return 1; |
| 7442 | } |
| 7443 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7444 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7445 | res = obj2ast_expr(tmp, &operand, arena); |
| 7446 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7447 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7448 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7449 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7450 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7451 | if (*out == NULL) goto failed; |
| 7452 | return 0; |
| 7453 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7454 | tp = astmodulestate_global->Lambda_type; |
| 7455 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7456 | if (isinstance == -1) { |
| 7457 | return 1; |
| 7458 | } |
| 7459 | if (isinstance) { |
| 7460 | arguments_ty args; |
| 7461 | expr_ty body; |
| 7462 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7463 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7464 | return 1; |
| 7465 | } |
| 7466 | if (tmp == NULL) { |
| 7467 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7468 | return 1; |
| 7469 | } |
| 7470 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7471 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7472 | res = obj2ast_arguments(tmp, &args, arena); |
| 7473 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7474 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7475 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7476 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7477 | return 1; |
| 7478 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7479 | if (tmp == NULL) { |
| 7480 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7481 | return 1; |
| 7482 | } |
| 7483 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7484 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7485 | res = obj2ast_expr(tmp, &body, arena); |
| 7486 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7487 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7488 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7489 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7490 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7491 | if (*out == NULL) goto failed; |
| 7492 | return 0; |
| 7493 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7494 | tp = astmodulestate_global->IfExp_type; |
| 7495 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7496 | if (isinstance == -1) { |
| 7497 | return 1; |
| 7498 | } |
| 7499 | if (isinstance) { |
| 7500 | expr_ty test; |
| 7501 | expr_ty body; |
| 7502 | expr_ty orelse; |
| 7503 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7504 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7505 | return 1; |
| 7506 | } |
| 7507 | if (tmp == NULL) { |
| 7508 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7509 | return 1; |
| 7510 | } |
| 7511 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7512 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7513 | res = obj2ast_expr(tmp, &test, arena); |
| 7514 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7515 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7516 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7517 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7518 | return 1; |
| 7519 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7520 | if (tmp == NULL) { |
| 7521 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7522 | return 1; |
| 7523 | } |
| 7524 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7525 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7526 | res = obj2ast_expr(tmp, &body, arena); |
| 7527 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7528 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7529 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7530 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7531 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7532 | return 1; |
| 7533 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7534 | if (tmp == NULL) { |
| 7535 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7536 | return 1; |
| 7537 | } |
| 7538 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7539 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7540 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7541 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7542 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7543 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7544 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7545 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7546 | if (*out == NULL) goto failed; |
| 7547 | return 0; |
| 7548 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7549 | tp = astmodulestate_global->Dict_type; |
| 7550 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7551 | if (isinstance == -1) { |
| 7552 | return 1; |
| 7553 | } |
| 7554 | if (isinstance) { |
| 7555 | asdl_seq* keys; |
| 7556 | asdl_seq* values; |
| 7557 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7558 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7559 | return 1; |
| 7560 | } |
| 7561 | if (tmp == NULL) { |
| 7562 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7563 | return 1; |
| 7564 | } |
| 7565 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7566 | int res; |
| 7567 | Py_ssize_t len; |
| 7568 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7569 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7570 | 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] | 7571 | goto failed; |
| 7572 | } |
| 7573 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7574 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7575 | if (keys == NULL) goto failed; |
| 7576 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7577 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7578 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7579 | Py_INCREF(tmp2); |
| 7580 | res = obj2ast_expr(tmp2, &val, arena); |
| 7581 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7582 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7583 | if (len != PyList_GET_SIZE(tmp)) { |
| 7584 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7585 | goto failed; |
| 7586 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7587 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7588 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7589 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7590 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7591 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7592 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7593 | return 1; |
| 7594 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7595 | if (tmp == NULL) { |
| 7596 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7597 | return 1; |
| 7598 | } |
| 7599 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7600 | int res; |
| 7601 | Py_ssize_t len; |
| 7602 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7603 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7604 | 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] | 7605 | goto failed; |
| 7606 | } |
| 7607 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7608 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7609 | if (values == NULL) goto failed; |
| 7610 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7611 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7612 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7613 | Py_INCREF(tmp2); |
| 7614 | res = obj2ast_expr(tmp2, &val, arena); |
| 7615 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7616 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7617 | if (len != PyList_GET_SIZE(tmp)) { |
| 7618 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7619 | goto failed; |
| 7620 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7621 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7622 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7623 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7624 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7625 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7626 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7627 | if (*out == NULL) goto failed; |
| 7628 | return 0; |
| 7629 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7630 | tp = astmodulestate_global->Set_type; |
| 7631 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7632 | if (isinstance == -1) { |
| 7633 | return 1; |
| 7634 | } |
| 7635 | if (isinstance) { |
| 7636 | asdl_seq* elts; |
| 7637 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7638 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7639 | return 1; |
| 7640 | } |
| 7641 | if (tmp == NULL) { |
| 7642 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7643 | return 1; |
| 7644 | } |
| 7645 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7646 | int res; |
| 7647 | Py_ssize_t len; |
| 7648 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7649 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7650 | 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] | 7651 | goto failed; |
| 7652 | } |
| 7653 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7654 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7655 | if (elts == NULL) goto failed; |
| 7656 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7657 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7658 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7659 | Py_INCREF(tmp2); |
| 7660 | res = obj2ast_expr(tmp2, &val, arena); |
| 7661 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7662 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7663 | if (len != PyList_GET_SIZE(tmp)) { |
| 7664 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7665 | goto failed; |
| 7666 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7667 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7668 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7669 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7670 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7671 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7672 | if (*out == NULL) goto failed; |
| 7673 | return 0; |
| 7674 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7675 | tp = astmodulestate_global->ListComp_type; |
| 7676 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7677 | if (isinstance == -1) { |
| 7678 | return 1; |
| 7679 | } |
| 7680 | if (isinstance) { |
| 7681 | expr_ty elt; |
| 7682 | asdl_seq* generators; |
| 7683 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7684 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7685 | return 1; |
| 7686 | } |
| 7687 | if (tmp == NULL) { |
| 7688 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7689 | return 1; |
| 7690 | } |
| 7691 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7692 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7693 | res = obj2ast_expr(tmp, &elt, arena); |
| 7694 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7695 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7696 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7697 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7698 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7699 | return 1; |
| 7700 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7701 | if (tmp == NULL) { |
| 7702 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7703 | return 1; |
| 7704 | } |
| 7705 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7706 | int res; |
| 7707 | Py_ssize_t len; |
| 7708 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7709 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7710 | 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] | 7711 | goto failed; |
| 7712 | } |
| 7713 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7714 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7715 | if (generators == NULL) goto failed; |
| 7716 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7717 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7718 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7719 | Py_INCREF(tmp2); |
| 7720 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7721 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7722 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7723 | if (len != PyList_GET_SIZE(tmp)) { |
| 7724 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7725 | goto failed; |
| 7726 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7727 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7728 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7729 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7730 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7731 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7732 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7733 | if (*out == NULL) goto failed; |
| 7734 | return 0; |
| 7735 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7736 | tp = astmodulestate_global->SetComp_type; |
| 7737 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7738 | if (isinstance == -1) { |
| 7739 | return 1; |
| 7740 | } |
| 7741 | if (isinstance) { |
| 7742 | expr_ty elt; |
| 7743 | asdl_seq* generators; |
| 7744 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7745 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7746 | return 1; |
| 7747 | } |
| 7748 | if (tmp == NULL) { |
| 7749 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7750 | return 1; |
| 7751 | } |
| 7752 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7753 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7754 | res = obj2ast_expr(tmp, &elt, arena); |
| 7755 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7756 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7757 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7758 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7759 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7760 | return 1; |
| 7761 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7762 | if (tmp == NULL) { |
| 7763 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7764 | return 1; |
| 7765 | } |
| 7766 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7767 | int res; |
| 7768 | Py_ssize_t len; |
| 7769 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7770 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7771 | 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] | 7772 | goto failed; |
| 7773 | } |
| 7774 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7775 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7776 | if (generators == NULL) goto failed; |
| 7777 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7778 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7779 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7780 | Py_INCREF(tmp2); |
| 7781 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7782 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7783 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7784 | if (len != PyList_GET_SIZE(tmp)) { |
| 7785 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7786 | goto failed; |
| 7787 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7788 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7789 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7790 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7791 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7792 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7793 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7794 | if (*out == NULL) goto failed; |
| 7795 | return 0; |
| 7796 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7797 | tp = astmodulestate_global->DictComp_type; |
| 7798 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7799 | if (isinstance == -1) { |
| 7800 | return 1; |
| 7801 | } |
| 7802 | if (isinstance) { |
| 7803 | expr_ty key; |
| 7804 | expr_ty value; |
| 7805 | asdl_seq* generators; |
| 7806 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7807 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7808 | return 1; |
| 7809 | } |
| 7810 | if (tmp == NULL) { |
| 7811 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7812 | return 1; |
| 7813 | } |
| 7814 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7815 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7816 | res = obj2ast_expr(tmp, &key, arena); |
| 7817 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7818 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7819 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7820 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7821 | return 1; |
| 7822 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7823 | if (tmp == NULL) { |
| 7824 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7825 | return 1; |
| 7826 | } |
| 7827 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7828 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7829 | res = obj2ast_expr(tmp, &value, arena); |
| 7830 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7831 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7832 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7833 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7834 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7835 | return 1; |
| 7836 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7837 | if (tmp == NULL) { |
| 7838 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7839 | return 1; |
| 7840 | } |
| 7841 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7842 | int res; |
| 7843 | Py_ssize_t len; |
| 7844 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7845 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7846 | 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] | 7847 | goto failed; |
| 7848 | } |
| 7849 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7850 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7851 | if (generators == NULL) goto failed; |
| 7852 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7853 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7854 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7855 | Py_INCREF(tmp2); |
| 7856 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7857 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7858 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7859 | if (len != PyList_GET_SIZE(tmp)) { |
| 7860 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7861 | goto failed; |
| 7862 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7863 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7864 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7865 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7866 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7867 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7868 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7869 | if (*out == NULL) goto failed; |
| 7870 | return 0; |
| 7871 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7872 | tp = astmodulestate_global->GeneratorExp_type; |
| 7873 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7874 | if (isinstance == -1) { |
| 7875 | return 1; |
| 7876 | } |
| 7877 | if (isinstance) { |
| 7878 | expr_ty elt; |
| 7879 | asdl_seq* generators; |
| 7880 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7881 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7882 | return 1; |
| 7883 | } |
| 7884 | if (tmp == NULL) { |
| 7885 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7886 | return 1; |
| 7887 | } |
| 7888 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7889 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7890 | res = obj2ast_expr(tmp, &elt, arena); |
| 7891 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7892 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7893 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7894 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7895 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7896 | return 1; |
| 7897 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7898 | if (tmp == NULL) { |
| 7899 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7900 | return 1; |
| 7901 | } |
| 7902 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7903 | int res; |
| 7904 | Py_ssize_t len; |
| 7905 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7906 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7907 | 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] | 7908 | goto failed; |
| 7909 | } |
| 7910 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7911 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7912 | if (generators == NULL) goto failed; |
| 7913 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7914 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7915 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7916 | Py_INCREF(tmp2); |
| 7917 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7918 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7919 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7920 | if (len != PyList_GET_SIZE(tmp)) { |
| 7921 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7922 | goto failed; |
| 7923 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7924 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7925 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7926 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7927 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7928 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7929 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7930 | if (*out == NULL) goto failed; |
| 7931 | return 0; |
| 7932 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7933 | tp = astmodulestate_global->Await_type; |
| 7934 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7935 | if (isinstance == -1) { |
| 7936 | return 1; |
| 7937 | } |
| 7938 | if (isinstance) { |
| 7939 | expr_ty value; |
| 7940 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7941 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7942 | return 1; |
| 7943 | } |
| 7944 | if (tmp == NULL) { |
| 7945 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 7946 | return 1; |
| 7947 | } |
| 7948 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7949 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7950 | res = obj2ast_expr(tmp, &value, arena); |
| 7951 | if (res != 0) goto failed; |
| 7952 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7953 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7954 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7955 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7956 | if (*out == NULL) goto failed; |
| 7957 | return 0; |
| 7958 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7959 | tp = astmodulestate_global->Yield_type; |
| 7960 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7961 | if (isinstance == -1) { |
| 7962 | return 1; |
| 7963 | } |
| 7964 | if (isinstance) { |
| 7965 | expr_ty value; |
| 7966 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7967 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7968 | return 1; |
| 7969 | } |
| 7970 | if (tmp == NULL || tmp == Py_None) { |
| 7971 | Py_CLEAR(tmp); |
| 7972 | value = NULL; |
| 7973 | } |
| 7974 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7975 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7976 | res = obj2ast_expr(tmp, &value, arena); |
| 7977 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7978 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7979 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7980 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7981 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7982 | if (*out == NULL) goto failed; |
| 7983 | return 0; |
| 7984 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7985 | tp = astmodulestate_global->YieldFrom_type; |
| 7986 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7987 | if (isinstance == -1) { |
| 7988 | return 1; |
| 7989 | } |
| 7990 | if (isinstance) { |
| 7991 | expr_ty value; |
| 7992 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7993 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7994 | return 1; |
| 7995 | } |
| 7996 | if (tmp == NULL) { |
| 7997 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 7998 | return 1; |
| 7999 | } |
| 8000 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8001 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8002 | res = obj2ast_expr(tmp, &value, arena); |
| 8003 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8004 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8005 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8006 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8007 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8008 | if (*out == NULL) goto failed; |
| 8009 | return 0; |
| 8010 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8011 | tp = astmodulestate_global->Compare_type; |
| 8012 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8013 | if (isinstance == -1) { |
| 8014 | return 1; |
| 8015 | } |
| 8016 | if (isinstance) { |
| 8017 | expr_ty left; |
| 8018 | asdl_int_seq* ops; |
| 8019 | asdl_seq* comparators; |
| 8020 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8021 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8022 | return 1; |
| 8023 | } |
| 8024 | if (tmp == NULL) { |
| 8025 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8026 | return 1; |
| 8027 | } |
| 8028 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8029 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8030 | res = obj2ast_expr(tmp, &left, arena); |
| 8031 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8032 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8033 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8034 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8035 | return 1; |
| 8036 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8037 | if (tmp == NULL) { |
| 8038 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8039 | return 1; |
| 8040 | } |
| 8041 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8042 | int res; |
| 8043 | Py_ssize_t len; |
| 8044 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8045 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8046 | 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] | 8047 | goto failed; |
| 8048 | } |
| 8049 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8050 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8051 | if (ops == NULL) goto failed; |
| 8052 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8053 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8054 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8055 | Py_INCREF(tmp2); |
| 8056 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8057 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8058 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8059 | if (len != PyList_GET_SIZE(tmp)) { |
| 8060 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8061 | goto failed; |
| 8062 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8063 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8064 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8065 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8066 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8067 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8068 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8069 | return 1; |
| 8070 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8071 | if (tmp == NULL) { |
| 8072 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8073 | return 1; |
| 8074 | } |
| 8075 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8076 | int res; |
| 8077 | Py_ssize_t len; |
| 8078 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8079 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8080 | 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] | 8081 | goto failed; |
| 8082 | } |
| 8083 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8084 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8085 | if (comparators == NULL) goto failed; |
| 8086 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8087 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8088 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8089 | Py_INCREF(tmp2); |
| 8090 | res = obj2ast_expr(tmp2, &val, arena); |
| 8091 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8092 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8093 | if (len != PyList_GET_SIZE(tmp)) { |
| 8094 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8095 | goto failed; |
| 8096 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8097 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8098 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8099 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8100 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8101 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8102 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8103 | if (*out == NULL) goto failed; |
| 8104 | return 0; |
| 8105 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8106 | tp = astmodulestate_global->Call_type; |
| 8107 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8108 | if (isinstance == -1) { |
| 8109 | return 1; |
| 8110 | } |
| 8111 | if (isinstance) { |
| 8112 | expr_ty func; |
| 8113 | asdl_seq* args; |
| 8114 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8115 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8116 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8117 | return 1; |
| 8118 | } |
| 8119 | if (tmp == NULL) { |
| 8120 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8121 | return 1; |
| 8122 | } |
| 8123 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8124 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8125 | res = obj2ast_expr(tmp, &func, arena); |
| 8126 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8127 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8128 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8129 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8130 | return 1; |
| 8131 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8132 | if (tmp == NULL) { |
| 8133 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8134 | return 1; |
| 8135 | } |
| 8136 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8137 | int res; |
| 8138 | Py_ssize_t len; |
| 8139 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8140 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8141 | 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] | 8142 | goto failed; |
| 8143 | } |
| 8144 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8145 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8146 | if (args == NULL) goto failed; |
| 8147 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8148 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8149 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8150 | Py_INCREF(tmp2); |
| 8151 | res = obj2ast_expr(tmp2, &val, arena); |
| 8152 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8153 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8154 | if (len != PyList_GET_SIZE(tmp)) { |
| 8155 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8156 | goto failed; |
| 8157 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8158 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8159 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8160 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8162 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8163 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8164 | return 1; |
| 8165 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8166 | if (tmp == NULL) { |
| 8167 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8168 | return 1; |
| 8169 | } |
| 8170 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8171 | int res; |
| 8172 | Py_ssize_t len; |
| 8173 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8174 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8175 | 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] | 8176 | goto failed; |
| 8177 | } |
| 8178 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8179 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8180 | if (keywords == NULL) goto failed; |
| 8181 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8182 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8183 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8184 | Py_INCREF(tmp2); |
| 8185 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8186 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8187 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8188 | if (len != PyList_GET_SIZE(tmp)) { |
| 8189 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8190 | goto failed; |
| 8191 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8192 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8193 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8194 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8195 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8196 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8197 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8198 | if (*out == NULL) goto failed; |
| 8199 | return 0; |
| 8200 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8201 | tp = astmodulestate_global->FormattedValue_type; |
| 8202 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8203 | if (isinstance == -1) { |
| 8204 | return 1; |
| 8205 | } |
| 8206 | if (isinstance) { |
| 8207 | expr_ty value; |
| 8208 | int conversion; |
| 8209 | expr_ty format_spec; |
| 8210 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8211 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8212 | return 1; |
| 8213 | } |
| 8214 | if (tmp == NULL) { |
| 8215 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8216 | return 1; |
| 8217 | } |
| 8218 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8219 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8220 | res = obj2ast_expr(tmp, &value, arena); |
| 8221 | if (res != 0) goto failed; |
| 8222 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8223 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8224 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8225 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8226 | return 1; |
| 8227 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8228 | if (tmp == NULL || tmp == Py_None) { |
| 8229 | Py_CLEAR(tmp); |
| 8230 | conversion = 0; |
| 8231 | } |
| 8232 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8233 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8234 | res = obj2ast_int(tmp, &conversion, arena); |
| 8235 | if (res != 0) goto failed; |
| 8236 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8237 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8238 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8239 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8240 | return 1; |
| 8241 | } |
| 8242 | if (tmp == NULL || tmp == Py_None) { |
| 8243 | Py_CLEAR(tmp); |
| 8244 | format_spec = NULL; |
| 8245 | } |
| 8246 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8247 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8248 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8249 | if (res != 0) goto failed; |
| 8250 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8251 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8252 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8253 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8254 | if (*out == NULL) goto failed; |
| 8255 | return 0; |
| 8256 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8257 | tp = astmodulestate_global->JoinedStr_type; |
| 8258 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8259 | if (isinstance == -1) { |
| 8260 | return 1; |
| 8261 | } |
| 8262 | if (isinstance) { |
| 8263 | asdl_seq* values; |
| 8264 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8265 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8266 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8267 | return 1; |
| 8268 | } |
| 8269 | if (tmp == NULL) { |
| 8270 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8271 | return 1; |
| 8272 | } |
| 8273 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8274 | int res; |
| 8275 | Py_ssize_t len; |
| 8276 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8277 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8278 | 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] | 8279 | goto failed; |
| 8280 | } |
| 8281 | len = PyList_GET_SIZE(tmp); |
| 8282 | values = _Py_asdl_seq_new(len, arena); |
| 8283 | if (values == NULL) goto failed; |
| 8284 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8285 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8286 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8287 | Py_INCREF(tmp2); |
| 8288 | res = obj2ast_expr(tmp2, &val, arena); |
| 8289 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8290 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8291 | if (len != PyList_GET_SIZE(tmp)) { |
| 8292 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8293 | goto failed; |
| 8294 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8295 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8296 | } |
| 8297 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8298 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8299 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8300 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8301 | if (*out == NULL) goto failed; |
| 8302 | return 0; |
| 8303 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8304 | tp = astmodulestate_global->Constant_type; |
| 8305 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8306 | if (isinstance == -1) { |
| 8307 | return 1; |
| 8308 | } |
| 8309 | if (isinstance) { |
| 8310 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8311 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8312 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8313 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8314 | return 1; |
| 8315 | } |
| 8316 | if (tmp == NULL) { |
| 8317 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8318 | return 1; |
| 8319 | } |
| 8320 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8321 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8322 | res = obj2ast_constant(tmp, &value, arena); |
| 8323 | if (res != 0) goto failed; |
| 8324 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8325 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8326 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8327 | return 1; |
| 8328 | } |
| 8329 | if (tmp == NULL || tmp == Py_None) { |
| 8330 | Py_CLEAR(tmp); |
| 8331 | kind = NULL; |
| 8332 | } |
| 8333 | else { |
| 8334 | int res; |
| 8335 | res = obj2ast_string(tmp, &kind, arena); |
| 8336 | if (res != 0) goto failed; |
| 8337 | Py_CLEAR(tmp); |
| 8338 | } |
| 8339 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8340 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8341 | if (*out == NULL) goto failed; |
| 8342 | return 0; |
| 8343 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8344 | tp = astmodulestate_global->Attribute_type; |
| 8345 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8346 | if (isinstance == -1) { |
| 8347 | return 1; |
| 8348 | } |
| 8349 | if (isinstance) { |
| 8350 | expr_ty value; |
| 8351 | identifier attr; |
| 8352 | expr_context_ty ctx; |
| 8353 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8354 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8355 | return 1; |
| 8356 | } |
| 8357 | if (tmp == NULL) { |
| 8358 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8359 | return 1; |
| 8360 | } |
| 8361 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8362 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8363 | res = obj2ast_expr(tmp, &value, arena); |
| 8364 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8365 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8366 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8367 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8368 | return 1; |
| 8369 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8370 | if (tmp == NULL) { |
| 8371 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8372 | return 1; |
| 8373 | } |
| 8374 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8375 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8376 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8377 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8378 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8379 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8380 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8381 | return 1; |
| 8382 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8383 | if (tmp == NULL) { |
| 8384 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8385 | return 1; |
| 8386 | } |
| 8387 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8388 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8389 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8390 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8391 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8392 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8393 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8394 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8395 | if (*out == NULL) goto failed; |
| 8396 | return 0; |
| 8397 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8398 | tp = astmodulestate_global->Subscript_type; |
| 8399 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8400 | if (isinstance == -1) { |
| 8401 | return 1; |
| 8402 | } |
| 8403 | if (isinstance) { |
| 8404 | expr_ty value; |
| 8405 | slice_ty slice; |
| 8406 | expr_context_ty ctx; |
| 8407 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8408 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8409 | return 1; |
| 8410 | } |
| 8411 | if (tmp == NULL) { |
| 8412 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8413 | return 1; |
| 8414 | } |
| 8415 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8416 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8417 | res = obj2ast_expr(tmp, &value, arena); |
| 8418 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8419 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8420 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8421 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8422 | return 1; |
| 8423 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8424 | if (tmp == NULL) { |
| 8425 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8426 | return 1; |
| 8427 | } |
| 8428 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8429 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8430 | res = obj2ast_slice(tmp, &slice, arena); |
| 8431 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8432 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8433 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8434 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8435 | return 1; |
| 8436 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8437 | if (tmp == NULL) { |
| 8438 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8439 | return 1; |
| 8440 | } |
| 8441 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8442 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8443 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8444 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8445 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8446 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8447 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8448 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8449 | if (*out == NULL) goto failed; |
| 8450 | return 0; |
| 8451 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8452 | tp = astmodulestate_global->Starred_type; |
| 8453 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8454 | if (isinstance == -1) { |
| 8455 | return 1; |
| 8456 | } |
| 8457 | if (isinstance) { |
| 8458 | expr_ty value; |
| 8459 | expr_context_ty ctx; |
| 8460 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8461 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8462 | return 1; |
| 8463 | } |
| 8464 | if (tmp == NULL) { |
| 8465 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8466 | return 1; |
| 8467 | } |
| 8468 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8469 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8470 | res = obj2ast_expr(tmp, &value, arena); |
| 8471 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8472 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8473 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8474 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8475 | return 1; |
| 8476 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8477 | if (tmp == NULL) { |
| 8478 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8479 | return 1; |
| 8480 | } |
| 8481 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8482 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8483 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8484 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8485 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8486 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8487 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8488 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8489 | if (*out == NULL) goto failed; |
| 8490 | return 0; |
| 8491 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8492 | tp = astmodulestate_global->Name_type; |
| 8493 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8494 | if (isinstance == -1) { |
| 8495 | return 1; |
| 8496 | } |
| 8497 | if (isinstance) { |
| 8498 | identifier id; |
| 8499 | expr_context_ty ctx; |
| 8500 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8501 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8502 | return 1; |
| 8503 | } |
| 8504 | if (tmp == NULL) { |
| 8505 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 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_identifier(tmp, &id, arena); |
| 8511 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8512 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8513 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8514 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8515 | return 1; |
| 8516 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8517 | if (tmp == NULL) { |
| 8518 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8519 | return 1; |
| 8520 | } |
| 8521 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8522 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8523 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8524 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8525 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8526 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8527 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8528 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8529 | if (*out == NULL) goto failed; |
| 8530 | return 0; |
| 8531 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8532 | tp = astmodulestate_global->List_type; |
| 8533 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8534 | if (isinstance == -1) { |
| 8535 | return 1; |
| 8536 | } |
| 8537 | if (isinstance) { |
| 8538 | asdl_seq* elts; |
| 8539 | expr_context_ty ctx; |
| 8540 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8541 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8542 | return 1; |
| 8543 | } |
| 8544 | if (tmp == NULL) { |
| 8545 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8546 | return 1; |
| 8547 | } |
| 8548 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8549 | int res; |
| 8550 | Py_ssize_t len; |
| 8551 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8552 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8553 | 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] | 8554 | goto failed; |
| 8555 | } |
| 8556 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8557 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8558 | if (elts == NULL) goto failed; |
| 8559 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8560 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8561 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8562 | Py_INCREF(tmp2); |
| 8563 | res = obj2ast_expr(tmp2, &val, arena); |
| 8564 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8565 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8566 | if (len != PyList_GET_SIZE(tmp)) { |
| 8567 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8568 | goto failed; |
| 8569 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8570 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8571 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8572 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8573 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8574 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8575 | return 1; |
| 8576 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8577 | if (tmp == NULL) { |
| 8578 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8579 | return 1; |
| 8580 | } |
| 8581 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8582 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8583 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8584 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8585 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8586 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8587 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8588 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8589 | if (*out == NULL) goto failed; |
| 8590 | return 0; |
| 8591 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8592 | tp = astmodulestate_global->Tuple_type; |
| 8593 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8594 | if (isinstance == -1) { |
| 8595 | return 1; |
| 8596 | } |
| 8597 | if (isinstance) { |
| 8598 | asdl_seq* elts; |
| 8599 | expr_context_ty ctx; |
| 8600 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8601 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8602 | return 1; |
| 8603 | } |
| 8604 | if (tmp == NULL) { |
| 8605 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8606 | return 1; |
| 8607 | } |
| 8608 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8609 | int res; |
| 8610 | Py_ssize_t len; |
| 8611 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8612 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8613 | 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] | 8614 | goto failed; |
| 8615 | } |
| 8616 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8617 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8618 | if (elts == NULL) goto failed; |
| 8619 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8620 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8621 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8622 | Py_INCREF(tmp2); |
| 8623 | res = obj2ast_expr(tmp2, &val, arena); |
| 8624 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8625 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8626 | if (len != PyList_GET_SIZE(tmp)) { |
| 8627 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8628 | goto failed; |
| 8629 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8630 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8631 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8632 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8633 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8634 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8635 | return 1; |
| 8636 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8637 | if (tmp == NULL) { |
| 8638 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8639 | return 1; |
| 8640 | } |
| 8641 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8642 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8643 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8644 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8645 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8646 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8647 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8648 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8649 | if (*out == NULL) goto failed; |
| 8650 | return 0; |
| 8651 | } |
| 8652 | |
| 8653 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8654 | failed: |
| 8655 | Py_XDECREF(tmp); |
| 8656 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8657 | } |
| 8658 | |
| 8659 | int |
| 8660 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8661 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8662 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8663 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8664 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8665 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8666 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8667 | } |
| 8668 | if (isinstance) { |
| 8669 | *out = Load; |
| 8670 | return 0; |
| 8671 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8672 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8673 | if (isinstance == -1) { |
| 8674 | return 1; |
| 8675 | } |
| 8676 | if (isinstance) { |
| 8677 | *out = Store; |
| 8678 | return 0; |
| 8679 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8680 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8681 | if (isinstance == -1) { |
| 8682 | return 1; |
| 8683 | } |
| 8684 | if (isinstance) { |
| 8685 | *out = Del; |
| 8686 | return 0; |
| 8687 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8688 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8689 | if (isinstance == -1) { |
| 8690 | return 1; |
| 8691 | } |
| 8692 | if (isinstance) { |
| 8693 | *out = AugLoad; |
| 8694 | return 0; |
| 8695 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8696 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8697 | if (isinstance == -1) { |
| 8698 | return 1; |
| 8699 | } |
| 8700 | if (isinstance) { |
| 8701 | *out = AugStore; |
| 8702 | return 0; |
| 8703 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8704 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8705 | if (isinstance == -1) { |
| 8706 | return 1; |
| 8707 | } |
| 8708 | if (isinstance) { |
| 8709 | *out = Param; |
| 8710 | return 0; |
| 8711 | } |
| 8712 | |
| 8713 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8714 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8715 | } |
| 8716 | |
| 8717 | int |
| 8718 | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
| 8719 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8720 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8721 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8722 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8723 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8724 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8725 | if (obj == Py_None) { |
| 8726 | *out = NULL; |
| 8727 | return 0; |
| 8728 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8729 | tp = astmodulestate_global->Slice_type; |
| 8730 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8731 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8732 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8733 | } |
| 8734 | if (isinstance) { |
| 8735 | expr_ty lower; |
| 8736 | expr_ty upper; |
| 8737 | expr_ty step; |
| 8738 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8739 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8740 | return 1; |
| 8741 | } |
| 8742 | if (tmp == NULL || tmp == Py_None) { |
| 8743 | Py_CLEAR(tmp); |
| 8744 | lower = NULL; |
| 8745 | } |
| 8746 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8747 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8748 | res = obj2ast_expr(tmp, &lower, arena); |
| 8749 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8750 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8751 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8752 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8753 | return 1; |
| 8754 | } |
| 8755 | if (tmp == NULL || tmp == Py_None) { |
| 8756 | Py_CLEAR(tmp); |
| 8757 | upper = NULL; |
| 8758 | } |
| 8759 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8760 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8761 | res = obj2ast_expr(tmp, &upper, arena); |
| 8762 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8763 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8764 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8765 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8766 | return 1; |
| 8767 | } |
| 8768 | if (tmp == NULL || tmp == Py_None) { |
| 8769 | Py_CLEAR(tmp); |
| 8770 | step = NULL; |
| 8771 | } |
| 8772 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8773 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8774 | res = obj2ast_expr(tmp, &step, arena); |
| 8775 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8776 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8777 | } |
| 8778 | *out = Slice(lower, upper, step, arena); |
| 8779 | if (*out == NULL) goto failed; |
| 8780 | return 0; |
| 8781 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8782 | tp = astmodulestate_global->ExtSlice_type; |
| 8783 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8784 | if (isinstance == -1) { |
| 8785 | return 1; |
| 8786 | } |
| 8787 | if (isinstance) { |
| 8788 | asdl_seq* dims; |
| 8789 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8790 | if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8791 | return 1; |
| 8792 | } |
| 8793 | if (tmp == NULL) { |
| 8794 | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
| 8795 | return 1; |
| 8796 | } |
| 8797 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8798 | int res; |
| 8799 | Py_ssize_t len; |
| 8800 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8801 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8802 | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp))); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8803 | goto failed; |
| 8804 | } |
| 8805 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8806 | dims = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8807 | if (dims == NULL) goto failed; |
| 8808 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8809 | slice_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8810 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8811 | Py_INCREF(tmp2); |
| 8812 | res = obj2ast_slice(tmp2, &val, arena); |
| 8813 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8814 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8815 | if (len != PyList_GET_SIZE(tmp)) { |
| 8816 | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
| 8817 | goto failed; |
| 8818 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8819 | asdl_seq_SET(dims, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8820 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8821 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8822 | } |
| 8823 | *out = ExtSlice(dims, arena); |
| 8824 | if (*out == NULL) goto failed; |
| 8825 | return 0; |
| 8826 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8827 | tp = astmodulestate_global->Index_type; |
| 8828 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8829 | if (isinstance == -1) { |
| 8830 | return 1; |
| 8831 | } |
| 8832 | if (isinstance) { |
| 8833 | expr_ty value; |
| 8834 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8835 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8836 | return 1; |
| 8837 | } |
| 8838 | if (tmp == NULL) { |
| 8839 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
| 8840 | return 1; |
| 8841 | } |
| 8842 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8843 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8844 | res = obj2ast_expr(tmp, &value, arena); |
| 8845 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8846 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8847 | } |
| 8848 | *out = Index(value, arena); |
| 8849 | if (*out == NULL) goto failed; |
| 8850 | return 0; |
| 8851 | } |
| 8852 | |
| 8853 | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
| 8854 | failed: |
| 8855 | Py_XDECREF(tmp); |
| 8856 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8857 | } |
| 8858 | |
| 8859 | int |
| 8860 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8861 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8862 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8863 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8864 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8865 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8866 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8867 | } |
| 8868 | if (isinstance) { |
| 8869 | *out = And; |
| 8870 | return 0; |
| 8871 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8872 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8873 | if (isinstance == -1) { |
| 8874 | return 1; |
| 8875 | } |
| 8876 | if (isinstance) { |
| 8877 | *out = Or; |
| 8878 | return 0; |
| 8879 | } |
| 8880 | |
| 8881 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8882 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8883 | } |
| 8884 | |
| 8885 | int |
| 8886 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8887 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8888 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8889 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8890 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8891 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8892 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8893 | } |
| 8894 | if (isinstance) { |
| 8895 | *out = Add; |
| 8896 | return 0; |
| 8897 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8898 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8899 | if (isinstance == -1) { |
| 8900 | return 1; |
| 8901 | } |
| 8902 | if (isinstance) { |
| 8903 | *out = Sub; |
| 8904 | return 0; |
| 8905 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8906 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8907 | if (isinstance == -1) { |
| 8908 | return 1; |
| 8909 | } |
| 8910 | if (isinstance) { |
| 8911 | *out = Mult; |
| 8912 | return 0; |
| 8913 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8914 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8915 | if (isinstance == -1) { |
| 8916 | return 1; |
| 8917 | } |
| 8918 | if (isinstance) { |
| 8919 | *out = MatMult; |
| 8920 | return 0; |
| 8921 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8922 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8923 | if (isinstance == -1) { |
| 8924 | return 1; |
| 8925 | } |
| 8926 | if (isinstance) { |
| 8927 | *out = Div; |
| 8928 | return 0; |
| 8929 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8930 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8931 | if (isinstance == -1) { |
| 8932 | return 1; |
| 8933 | } |
| 8934 | if (isinstance) { |
| 8935 | *out = Mod; |
| 8936 | return 0; |
| 8937 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8938 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8939 | if (isinstance == -1) { |
| 8940 | return 1; |
| 8941 | } |
| 8942 | if (isinstance) { |
| 8943 | *out = Pow; |
| 8944 | return 0; |
| 8945 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8946 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8947 | if (isinstance == -1) { |
| 8948 | return 1; |
| 8949 | } |
| 8950 | if (isinstance) { |
| 8951 | *out = LShift; |
| 8952 | return 0; |
| 8953 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8954 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8955 | if (isinstance == -1) { |
| 8956 | return 1; |
| 8957 | } |
| 8958 | if (isinstance) { |
| 8959 | *out = RShift; |
| 8960 | return 0; |
| 8961 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8962 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8963 | if (isinstance == -1) { |
| 8964 | return 1; |
| 8965 | } |
| 8966 | if (isinstance) { |
| 8967 | *out = BitOr; |
| 8968 | return 0; |
| 8969 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8970 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8971 | if (isinstance == -1) { |
| 8972 | return 1; |
| 8973 | } |
| 8974 | if (isinstance) { |
| 8975 | *out = BitXor; |
| 8976 | return 0; |
| 8977 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8978 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8979 | if (isinstance == -1) { |
| 8980 | return 1; |
| 8981 | } |
| 8982 | if (isinstance) { |
| 8983 | *out = BitAnd; |
| 8984 | return 0; |
| 8985 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8986 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8987 | if (isinstance == -1) { |
| 8988 | return 1; |
| 8989 | } |
| 8990 | if (isinstance) { |
| 8991 | *out = FloorDiv; |
| 8992 | return 0; |
| 8993 | } |
| 8994 | |
| 8995 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8996 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8997 | } |
| 8998 | |
| 8999 | int |
| 9000 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 9001 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9002 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9003 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9004 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9005 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9006 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9007 | } |
| 9008 | if (isinstance) { |
| 9009 | *out = Invert; |
| 9010 | return 0; |
| 9011 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9012 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9013 | if (isinstance == -1) { |
| 9014 | return 1; |
| 9015 | } |
| 9016 | if (isinstance) { |
| 9017 | *out = Not; |
| 9018 | return 0; |
| 9019 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9020 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9021 | if (isinstance == -1) { |
| 9022 | return 1; |
| 9023 | } |
| 9024 | if (isinstance) { |
| 9025 | *out = UAdd; |
| 9026 | return 0; |
| 9027 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9028 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9029 | if (isinstance == -1) { |
| 9030 | return 1; |
| 9031 | } |
| 9032 | if (isinstance) { |
| 9033 | *out = USub; |
| 9034 | return 0; |
| 9035 | } |
| 9036 | |
| 9037 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 9038 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9039 | } |
| 9040 | |
| 9041 | int |
| 9042 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 9043 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9044 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9045 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9046 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9047 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9048 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9049 | } |
| 9050 | if (isinstance) { |
| 9051 | *out = Eq; |
| 9052 | return 0; |
| 9053 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9054 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9055 | if (isinstance == -1) { |
| 9056 | return 1; |
| 9057 | } |
| 9058 | if (isinstance) { |
| 9059 | *out = NotEq; |
| 9060 | return 0; |
| 9061 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9062 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9063 | if (isinstance == -1) { |
| 9064 | return 1; |
| 9065 | } |
| 9066 | if (isinstance) { |
| 9067 | *out = Lt; |
| 9068 | return 0; |
| 9069 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9070 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9071 | if (isinstance == -1) { |
| 9072 | return 1; |
| 9073 | } |
| 9074 | if (isinstance) { |
| 9075 | *out = LtE; |
| 9076 | return 0; |
| 9077 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9078 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9079 | if (isinstance == -1) { |
| 9080 | return 1; |
| 9081 | } |
| 9082 | if (isinstance) { |
| 9083 | *out = Gt; |
| 9084 | return 0; |
| 9085 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9086 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9087 | if (isinstance == -1) { |
| 9088 | return 1; |
| 9089 | } |
| 9090 | if (isinstance) { |
| 9091 | *out = GtE; |
| 9092 | return 0; |
| 9093 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9094 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9095 | if (isinstance == -1) { |
| 9096 | return 1; |
| 9097 | } |
| 9098 | if (isinstance) { |
| 9099 | *out = Is; |
| 9100 | return 0; |
| 9101 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9102 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9103 | if (isinstance == -1) { |
| 9104 | return 1; |
| 9105 | } |
| 9106 | if (isinstance) { |
| 9107 | *out = IsNot; |
| 9108 | return 0; |
| 9109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9110 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9111 | if (isinstance == -1) { |
| 9112 | return 1; |
| 9113 | } |
| 9114 | if (isinstance) { |
| 9115 | *out = In; |
| 9116 | return 0; |
| 9117 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9118 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9119 | if (isinstance == -1) { |
| 9120 | return 1; |
| 9121 | } |
| 9122 | if (isinstance) { |
| 9123 | *out = NotIn; |
| 9124 | return 0; |
| 9125 | } |
| 9126 | |
| 9127 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9128 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9129 | } |
| 9130 | |
| 9131 | int |
| 9132 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9133 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9134 | PyObject* tmp = NULL; |
| 9135 | expr_ty target; |
| 9136 | expr_ty iter; |
| 9137 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9138 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9139 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9140 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9141 | return 1; |
| 9142 | } |
| 9143 | if (tmp == NULL) { |
| 9144 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9145 | return 1; |
| 9146 | } |
| 9147 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9148 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9149 | res = obj2ast_expr(tmp, &target, arena); |
| 9150 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9151 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9152 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9153 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9154 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9155 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9156 | if (tmp == NULL) { |
| 9157 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9158 | return 1; |
| 9159 | } |
| 9160 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9161 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9162 | res = obj2ast_expr(tmp, &iter, arena); |
| 9163 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9164 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9165 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9166 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9167 | return 1; |
| 9168 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9169 | if (tmp == NULL) { |
| 9170 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9171 | return 1; |
| 9172 | } |
| 9173 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9174 | int res; |
| 9175 | Py_ssize_t len; |
| 9176 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9177 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9178 | 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] | 9179 | goto failed; |
| 9180 | } |
| 9181 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9182 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9183 | if (ifs == NULL) goto failed; |
| 9184 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9185 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9186 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9187 | Py_INCREF(tmp2); |
| 9188 | res = obj2ast_expr(tmp2, &val, arena); |
| 9189 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9190 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9191 | if (len != PyList_GET_SIZE(tmp)) { |
| 9192 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9193 | goto failed; |
| 9194 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9195 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9196 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9197 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9198 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9199 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9200 | return 1; |
| 9201 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9202 | if (tmp == NULL) { |
| 9203 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9204 | return 1; |
| 9205 | } |
| 9206 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9207 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9208 | res = obj2ast_int(tmp, &is_async, arena); |
| 9209 | if (res != 0) goto failed; |
| 9210 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9211 | } |
| 9212 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9213 | return 0; |
| 9214 | failed: |
| 9215 | Py_XDECREF(tmp); |
| 9216 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9217 | } |
| 9218 | |
| 9219 | int |
| 9220 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9221 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9222 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9223 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9224 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9225 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9226 | int lineno; |
| 9227 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9228 | int end_lineno; |
| 9229 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9230 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9231 | if (obj == Py_None) { |
| 9232 | *out = NULL; |
| 9233 | return 0; |
| 9234 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9235 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9236 | return 1; |
| 9237 | } |
| 9238 | if (tmp == NULL) { |
| 9239 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9240 | return 1; |
| 9241 | } |
| 9242 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9243 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9244 | res = obj2ast_int(tmp, &lineno, arena); |
| 9245 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9246 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9247 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9248 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9249 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9250 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9251 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9252 | if (tmp == NULL) { |
| 9253 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9254 | return 1; |
| 9255 | } |
| 9256 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9257 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9258 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9259 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9260 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9261 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9262 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9263 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9264 | return 1; |
| 9265 | } |
| 9266 | if (tmp == NULL || tmp == Py_None) { |
| 9267 | Py_CLEAR(tmp); |
| 9268 | end_lineno = 0; |
| 9269 | } |
| 9270 | else { |
| 9271 | int res; |
| 9272 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9273 | if (res != 0) goto failed; |
| 9274 | Py_CLEAR(tmp); |
| 9275 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9276 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9277 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9278 | return 1; |
| 9279 | } |
| 9280 | if (tmp == NULL || tmp == Py_None) { |
| 9281 | Py_CLEAR(tmp); |
| 9282 | end_col_offset = 0; |
| 9283 | } |
| 9284 | else { |
| 9285 | int res; |
| 9286 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9287 | if (res != 0) goto failed; |
| 9288 | Py_CLEAR(tmp); |
| 9289 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9290 | tp = astmodulestate_global->ExceptHandler_type; |
| 9291 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9292 | if (isinstance == -1) { |
| 9293 | return 1; |
| 9294 | } |
| 9295 | if (isinstance) { |
| 9296 | expr_ty type; |
| 9297 | identifier name; |
| 9298 | asdl_seq* body; |
| 9299 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9300 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9301 | return 1; |
| 9302 | } |
| 9303 | if (tmp == NULL || tmp == Py_None) { |
| 9304 | Py_CLEAR(tmp); |
| 9305 | type = NULL; |
| 9306 | } |
| 9307 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9308 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9309 | res = obj2ast_expr(tmp, &type, arena); |
| 9310 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9311 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9312 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9313 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9314 | return 1; |
| 9315 | } |
| 9316 | if (tmp == NULL || tmp == Py_None) { |
| 9317 | Py_CLEAR(tmp); |
| 9318 | name = NULL; |
| 9319 | } |
| 9320 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9321 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9322 | res = obj2ast_identifier(tmp, &name, arena); |
| 9323 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9324 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9325 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9326 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9327 | return 1; |
| 9328 | } |
| 9329 | if (tmp == NULL) { |
| 9330 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9331 | return 1; |
| 9332 | } |
| 9333 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9334 | int res; |
| 9335 | Py_ssize_t len; |
| 9336 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9337 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9338 | 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] | 9339 | goto failed; |
| 9340 | } |
| 9341 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9342 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9343 | if (body == NULL) goto failed; |
| 9344 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9345 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9346 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9347 | Py_INCREF(tmp2); |
| 9348 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9349 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9350 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9351 | if (len != PyList_GET_SIZE(tmp)) { |
| 9352 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9353 | goto failed; |
| 9354 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9355 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9356 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9357 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9358 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9359 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9360 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9361 | if (*out == NULL) goto failed; |
| 9362 | return 0; |
| 9363 | } |
| 9364 | |
| 9365 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9366 | failed: |
| 9367 | Py_XDECREF(tmp); |
| 9368 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9369 | } |
| 9370 | |
| 9371 | int |
| 9372 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9373 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9374 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9375 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9376 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9377 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9378 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9379 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9380 | arg_ty kwarg; |
| 9381 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9382 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9383 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9384 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9385 | return 1; |
| 9386 | } |
| 9387 | if (tmp == NULL) { |
| 9388 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9389 | return 1; |
| 9390 | } |
| 9391 | else { |
| 9392 | int res; |
| 9393 | Py_ssize_t len; |
| 9394 | Py_ssize_t i; |
| 9395 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9396 | 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] | 9397 | goto failed; |
| 9398 | } |
| 9399 | len = PyList_GET_SIZE(tmp); |
| 9400 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9401 | if (posonlyargs == NULL) goto failed; |
| 9402 | for (i = 0; i < len; i++) { |
| 9403 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9404 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9405 | Py_INCREF(tmp2); |
| 9406 | res = obj2ast_arg(tmp2, &val, arena); |
| 9407 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9408 | if (res != 0) goto failed; |
| 9409 | if (len != PyList_GET_SIZE(tmp)) { |
| 9410 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9411 | goto failed; |
| 9412 | } |
| 9413 | asdl_seq_SET(posonlyargs, i, val); |
| 9414 | } |
| 9415 | Py_CLEAR(tmp); |
| 9416 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9417 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9418 | return 1; |
| 9419 | } |
| 9420 | if (tmp == NULL) { |
| 9421 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9422 | return 1; |
| 9423 | } |
| 9424 | else { |
| 9425 | int res; |
| 9426 | Py_ssize_t len; |
| 9427 | Py_ssize_t i; |
| 9428 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9429 | 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] | 9430 | goto failed; |
| 9431 | } |
| 9432 | len = PyList_GET_SIZE(tmp); |
| 9433 | args = _Py_asdl_seq_new(len, arena); |
| 9434 | if (args == NULL) goto failed; |
| 9435 | for (i = 0; i < len; i++) { |
| 9436 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9437 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9438 | Py_INCREF(tmp2); |
| 9439 | res = obj2ast_arg(tmp2, &val, arena); |
| 9440 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9441 | if (res != 0) goto failed; |
| 9442 | if (len != PyList_GET_SIZE(tmp)) { |
| 9443 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9444 | goto failed; |
| 9445 | } |
| 9446 | asdl_seq_SET(args, i, val); |
| 9447 | } |
| 9448 | Py_CLEAR(tmp); |
| 9449 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9450 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
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 | vararg = NULL; |
| 9456 | } |
| 9457 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9458 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9459 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 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->kwonlyargs, &tmp) < 0) |
| 9464 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9465 | return 1; |
| 9466 | } |
| 9467 | if (tmp == NULL) { |
| 9468 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9469 | return 1; |
| 9470 | } |
| 9471 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9472 | int res; |
| 9473 | Py_ssize_t len; |
| 9474 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9475 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9476 | PyErr_Format(PyExc_TypeError, "arguments field \"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] | 9477 | goto failed; |
| 9478 | } |
| 9479 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9480 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9481 | if (kwonlyargs == NULL) goto failed; |
| 9482 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9483 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9484 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9485 | Py_INCREF(tmp2); |
| 9486 | res = obj2ast_arg(tmp2, &val, arena); |
| 9487 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9488 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9489 | if (len != PyList_GET_SIZE(tmp)) { |
| 9490 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9491 | goto failed; |
| 9492 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9493 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9494 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9495 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9496 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9497 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9498 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9499 | return 1; |
| 9500 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9501 | if (tmp == NULL) { |
| 9502 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9503 | return 1; |
| 9504 | } |
| 9505 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9506 | int res; |
| 9507 | Py_ssize_t len; |
| 9508 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9509 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9510 | 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] | 9511 | goto failed; |
| 9512 | } |
| 9513 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9514 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9515 | if (kw_defaults == NULL) goto failed; |
| 9516 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9517 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9518 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9519 | Py_INCREF(tmp2); |
| 9520 | res = obj2ast_expr(tmp2, &val, arena); |
| 9521 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9522 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9523 | if (len != PyList_GET_SIZE(tmp)) { |
| 9524 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9525 | goto failed; |
| 9526 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9527 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9528 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9529 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9530 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9531 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9532 | return 1; |
| 9533 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9534 | if (tmp == NULL || tmp == Py_None) { |
| 9535 | Py_CLEAR(tmp); |
| 9536 | kwarg = NULL; |
| 9537 | } |
| 9538 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9539 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9540 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9541 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9542 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9543 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9544 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9545 | return 1; |
| 9546 | } |
| 9547 | if (tmp == NULL) { |
| 9548 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9549 | return 1; |
| 9550 | } |
| 9551 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9552 | int res; |
| 9553 | Py_ssize_t len; |
| 9554 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9555 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9556 | 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] | 9557 | goto failed; |
| 9558 | } |
| 9559 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9560 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9561 | if (defaults == NULL) goto failed; |
| 9562 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9563 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9564 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9565 | Py_INCREF(tmp2); |
| 9566 | res = obj2ast_expr(tmp2, &val, arena); |
| 9567 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9568 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9569 | if (len != PyList_GET_SIZE(tmp)) { |
| 9570 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9571 | goto failed; |
| 9572 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9573 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9574 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9575 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9576 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9577 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9578 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9579 | return 0; |
| 9580 | failed: |
| 9581 | Py_XDECREF(tmp); |
| 9582 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9583 | } |
| 9584 | |
| 9585 | int |
| 9586 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9587 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9588 | PyObject* tmp = NULL; |
| 9589 | identifier arg; |
| 9590 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9591 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9592 | int lineno; |
| 9593 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9594 | int end_lineno; |
| 9595 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9596 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9597 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9598 | return 1; |
| 9599 | } |
| 9600 | if (tmp == NULL) { |
| 9601 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9602 | return 1; |
| 9603 | } |
| 9604 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9605 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9606 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9607 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9608 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9609 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9610 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9611 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9612 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9613 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9614 | if (tmp == NULL || tmp == Py_None) { |
| 9615 | Py_CLEAR(tmp); |
| 9616 | annotation = NULL; |
| 9617 | } |
| 9618 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9619 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9620 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9621 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9622 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9623 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9624 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9625 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9626 | return 1; |
| 9627 | } |
| 9628 | if (tmp == NULL || tmp == Py_None) { |
| 9629 | Py_CLEAR(tmp); |
| 9630 | type_comment = NULL; |
| 9631 | } |
| 9632 | else { |
| 9633 | int res; |
| 9634 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9635 | if (res != 0) goto failed; |
| 9636 | Py_CLEAR(tmp); |
| 9637 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9638 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9639 | return 1; |
| 9640 | } |
| 9641 | if (tmp == NULL) { |
| 9642 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9643 | return 1; |
| 9644 | } |
| 9645 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9646 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9647 | res = obj2ast_int(tmp, &lineno, arena); |
| 9648 | if (res != 0) goto failed; |
| 9649 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9650 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9651 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9652 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9653 | return 1; |
| 9654 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9655 | if (tmp == NULL) { |
| 9656 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9657 | return 1; |
| 9658 | } |
| 9659 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9660 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9661 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9662 | if (res != 0) goto failed; |
| 9663 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9664 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9665 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9666 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9667 | return 1; |
| 9668 | } |
| 9669 | if (tmp == NULL || tmp == Py_None) { |
| 9670 | Py_CLEAR(tmp); |
| 9671 | end_lineno = 0; |
| 9672 | } |
| 9673 | else { |
| 9674 | int res; |
| 9675 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9676 | if (res != 0) goto failed; |
| 9677 | Py_CLEAR(tmp); |
| 9678 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9679 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9680 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9681 | return 1; |
| 9682 | } |
| 9683 | if (tmp == NULL || tmp == Py_None) { |
| 9684 | Py_CLEAR(tmp); |
| 9685 | end_col_offset = 0; |
| 9686 | } |
| 9687 | else { |
| 9688 | int res; |
| 9689 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9690 | if (res != 0) goto failed; |
| 9691 | Py_CLEAR(tmp); |
| 9692 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9693 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9694 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9695 | return 0; |
| 9696 | failed: |
| 9697 | Py_XDECREF(tmp); |
| 9698 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9699 | } |
| 9700 | |
| 9701 | int |
| 9702 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9703 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9704 | PyObject* tmp = NULL; |
| 9705 | identifier arg; |
| 9706 | expr_ty value; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9707 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9708 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9709 | return 1; |
| 9710 | } |
| 9711 | if (tmp == NULL || tmp == Py_None) { |
| 9712 | Py_CLEAR(tmp); |
| 9713 | arg = NULL; |
| 9714 | } |
| 9715 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9716 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9717 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9718 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9719 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9720 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9721 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9722 | return 1; |
| 9723 | } |
| 9724 | if (tmp == NULL) { |
| 9725 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9726 | return 1; |
| 9727 | } |
| 9728 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9729 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9730 | res = obj2ast_expr(tmp, &value, arena); |
| 9731 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9732 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9733 | } |
| 9734 | *out = keyword(arg, value, arena); |
| 9735 | return 0; |
| 9736 | failed: |
| 9737 | Py_XDECREF(tmp); |
| 9738 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9739 | } |
| 9740 | |
| 9741 | int |
| 9742 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9743 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9744 | PyObject* tmp = NULL; |
| 9745 | identifier name; |
| 9746 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9747 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9748 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9749 | return 1; |
| 9750 | } |
| 9751 | if (tmp == NULL) { |
| 9752 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9753 | return 1; |
| 9754 | } |
| 9755 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9756 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9757 | res = obj2ast_identifier(tmp, &name, arena); |
| 9758 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9759 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9760 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9761 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9762 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9763 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9764 | if (tmp == NULL || tmp == Py_None) { |
| 9765 | Py_CLEAR(tmp); |
| 9766 | asname = NULL; |
| 9767 | } |
| 9768 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9769 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9770 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9771 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9772 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9773 | } |
| 9774 | *out = alias(name, asname, arena); |
| 9775 | return 0; |
| 9776 | failed: |
| 9777 | Py_XDECREF(tmp); |
| 9778 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9779 | } |
| 9780 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9781 | int |
| 9782 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9783 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9784 | PyObject* tmp = NULL; |
| 9785 | expr_ty context_expr; |
| 9786 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9787 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9788 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9789 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9790 | return 1; |
| 9791 | } |
| 9792 | if (tmp == NULL) { |
| 9793 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9794 | return 1; |
| 9795 | } |
| 9796 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9797 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9798 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9799 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9800 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9801 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9802 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9803 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9804 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9805 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9806 | if (tmp == NULL || tmp == Py_None) { |
| 9807 | Py_CLEAR(tmp); |
| 9808 | optional_vars = NULL; |
| 9809 | } |
| 9810 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9811 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9812 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9813 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9814 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9815 | } |
| 9816 | *out = withitem(context_expr, optional_vars, arena); |
| 9817 | return 0; |
| 9818 | failed: |
| 9819 | Py_XDECREF(tmp); |
| 9820 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9821 | } |
| 9822 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9823 | int |
| 9824 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9825 | { |
| 9826 | int isinstance; |
| 9827 | |
| 9828 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9829 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9830 | |
| 9831 | if (obj == Py_None) { |
| 9832 | *out = NULL; |
| 9833 | return 0; |
| 9834 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9835 | tp = astmodulestate_global->TypeIgnore_type; |
| 9836 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9837 | if (isinstance == -1) { |
| 9838 | return 1; |
| 9839 | } |
| 9840 | if (isinstance) { |
| 9841 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9842 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9843 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9844 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9845 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9846 | return 1; |
| 9847 | } |
| 9848 | if (tmp == NULL) { |
| 9849 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9850 | return 1; |
| 9851 | } |
| 9852 | else { |
| 9853 | int res; |
| 9854 | res = obj2ast_int(tmp, &lineno, arena); |
| 9855 | if (res != 0) goto failed; |
| 9856 | Py_CLEAR(tmp); |
| 9857 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9858 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9859 | return 1; |
| 9860 | } |
| 9861 | if (tmp == NULL) { |
| 9862 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9863 | return 1; |
| 9864 | } |
| 9865 | else { |
| 9866 | int res; |
| 9867 | res = obj2ast_string(tmp, &tag, arena); |
| 9868 | if (res != 0) goto failed; |
| 9869 | Py_CLEAR(tmp); |
| 9870 | } |
| 9871 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9872 | if (*out == NULL) goto failed; |
| 9873 | return 0; |
| 9874 | } |
| 9875 | |
| 9876 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9877 | failed: |
| 9878 | Py_XDECREF(tmp); |
| 9879 | return 1; |
| 9880 | } |
| 9881 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9882 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9883 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9884 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9885 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9886 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9887 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9888 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9889 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9890 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9891 | goto error; |
| 9892 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9893 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9894 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9895 | goto error; |
| 9896 | } |
| 9897 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9898 | goto error; |
| 9899 | } |
| 9900 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9901 | goto error; |
| 9902 | } |
| 9903 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9904 | goto error; |
| 9905 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9906 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9907 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9908 | 0) { |
| 9909 | goto error; |
| 9910 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9911 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9912 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9913 | astmodulestate_global->Interactive_type) < 0) { |
| 9914 | goto error; |
| 9915 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9916 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9917 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9918 | astmodulestate_global->Expression_type) < 0) { |
| 9919 | goto error; |
| 9920 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9921 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9922 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9923 | astmodulestate_global->FunctionType_type) < 0) { |
| 9924 | goto error; |
| 9925 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9926 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9927 | if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < 0) { |
| 9928 | goto error; |
| 9929 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9930 | Py_INCREF(astmodulestate(m)->Suite_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9931 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9932 | goto error; |
| 9933 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9934 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9935 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9936 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9937 | goto error; |
| 9938 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9939 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9940 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9941 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9942 | goto error; |
| 9943 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9944 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9945 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9946 | < 0) { |
| 9947 | goto error; |
| 9948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9949 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9950 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9951 | 0) { |
| 9952 | goto error; |
| 9953 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9954 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9955 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9956 | 0) { |
| 9957 | goto error; |
| 9958 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9959 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9960 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9961 | 0) { |
| 9962 | goto error; |
| 9963 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9964 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9965 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9966 | astmodulestate_global->AugAssign_type) < 0) { |
| 9967 | goto error; |
| 9968 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9969 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9970 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9971 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9972 | goto error; |
| 9973 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9974 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9975 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9976 | goto error; |
| 9977 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9978 | Py_INCREF(astmodulestate(m)->For_type); |
| 9979 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9980 | < 0) { |
| 9981 | goto error; |
| 9982 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9983 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9984 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 9985 | goto error; |
| 9986 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9987 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9988 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 9989 | goto error; |
| 9990 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9991 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9992 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 9993 | goto error; |
| 9994 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9995 | Py_INCREF(astmodulestate(m)->With_type); |
| 9996 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9997 | astmodulestate_global->AsyncWith_type) < 0) { |
| 9998 | goto error; |
| 9999 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10000 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10001 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 10002 | goto error; |
| 10003 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10004 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10005 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 10006 | goto error; |
| 10007 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10008 | Py_INCREF(astmodulestate(m)->Try_type); |
| 10009 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10010 | 0) { |
| 10011 | goto error; |
| 10012 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10013 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 10014 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10015 | 0) { |
| 10016 | goto error; |
| 10017 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10018 | Py_INCREF(astmodulestate(m)->Import_type); |
| 10019 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10020 | astmodulestate_global->ImportFrom_type) < 0) { |
| 10021 | goto error; |
| 10022 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10023 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 10024 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10025 | 0) { |
| 10026 | goto error; |
| 10027 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10028 | Py_INCREF(astmodulestate(m)->Global_type); |
| 10029 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10030 | < 0) { |
| 10031 | goto error; |
| 10032 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10033 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10034 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { |
| 10035 | goto error; |
| 10036 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10037 | Py_INCREF(astmodulestate(m)->Expr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10038 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 10039 | goto error; |
| 10040 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10041 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10042 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 10043 | goto error; |
| 10044 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10045 | Py_INCREF(astmodulestate(m)->Break_type); |
| 10046 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10047 | < 0) { |
| 10048 | goto error; |
| 10049 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10050 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10051 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 10052 | goto error; |
| 10053 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10054 | Py_INCREF(astmodulestate(m)->expr_type); |
| 10055 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10056 | 0) { |
| 10057 | goto error; |
| 10058 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10059 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 10060 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10061 | astmodulestate_global->NamedExpr_type) < 0) { |
| 10062 | goto error; |
| 10063 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10064 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10065 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 10066 | goto error; |
| 10067 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10068 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 10069 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10070 | 0) { |
| 10071 | goto error; |
| 10072 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10073 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 10074 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10075 | 0) { |
| 10076 | goto error; |
| 10077 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10078 | Py_INCREF(astmodulestate(m)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10079 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 10080 | goto error; |
| 10081 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10082 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10083 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 10084 | goto error; |
| 10085 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10086 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10087 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 10088 | goto error; |
| 10089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10090 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10091 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10092 | < 0) { |
| 10093 | goto error; |
| 10094 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10095 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10096 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10097 | 0) { |
| 10098 | goto error; |
| 10099 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10100 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10101 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10102 | < 0) { |
| 10103 | goto error; |
| 10104 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10105 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10106 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10107 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 10108 | goto error; |
| 10109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10110 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10111 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 10112 | goto error; |
| 10113 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10114 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10115 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 10116 | goto error; |
| 10117 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10118 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10119 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10120 | astmodulestate_global->YieldFrom_type) < 0) { |
| 10121 | goto error; |
| 10122 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10123 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10124 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10125 | 0) { |
| 10126 | goto error; |
| 10127 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10128 | Py_INCREF(astmodulestate(m)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10129 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 10130 | goto error; |
| 10131 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10132 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10133 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10134 | astmodulestate_global->FormattedValue_type) < 0) { |
| 10135 | goto error; |
| 10136 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10137 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10138 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10139 | astmodulestate_global->JoinedStr_type) < 0) { |
| 10140 | goto error; |
| 10141 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10142 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10143 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10144 | < 0) { |
| 10145 | goto error; |
| 10146 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10147 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10148 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10149 | astmodulestate_global->Attribute_type) < 0) { |
| 10150 | goto error; |
| 10151 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10152 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10153 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10154 | astmodulestate_global->Subscript_type) < 0) { |
| 10155 | goto error; |
| 10156 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10157 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10158 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10159 | 0) { |
| 10160 | goto error; |
| 10161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10162 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10163 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 10164 | goto error; |
| 10165 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10166 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10167 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10168 | goto error; |
| 10169 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10170 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10171 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10172 | goto error; |
| 10173 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10174 | Py_INCREF(astmodulestate(m)->Tuple_type); |
| 10175 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10176 | astmodulestate_global->expr_context_type) < 0) { |
| 10177 | goto error; |
| 10178 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10179 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10180 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10181 | goto error; |
| 10182 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10183 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10184 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10185 | goto error; |
| 10186 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10187 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10188 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10189 | goto error; |
| 10190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10191 | Py_INCREF(astmodulestate(m)->Del_type); |
| 10192 | if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10193 | 0) { |
| 10194 | goto error; |
| 10195 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10196 | Py_INCREF(astmodulestate(m)->AugLoad_type); |
| 10197 | if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10198 | < 0) { |
| 10199 | goto error; |
| 10200 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10201 | Py_INCREF(astmodulestate(m)->AugStore_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10202 | if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) { |
| 10203 | goto error; |
| 10204 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10205 | Py_INCREF(astmodulestate(m)->Param_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10206 | if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0) { |
| 10207 | goto error; |
| 10208 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10209 | Py_INCREF(astmodulestate(m)->slice_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10210 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10211 | goto error; |
| 10212 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10213 | Py_INCREF(astmodulestate(m)->Slice_type); |
| 10214 | if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10215 | < 0) { |
| 10216 | goto error; |
| 10217 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10218 | Py_INCREF(astmodulestate(m)->ExtSlice_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10219 | if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0) { |
| 10220 | goto error; |
| 10221 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10222 | Py_INCREF(astmodulestate(m)->Index_type); |
| 10223 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10224 | 0) { |
| 10225 | goto error; |
| 10226 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10227 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10228 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10229 | goto error; |
| 10230 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10231 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10232 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10233 | goto error; |
| 10234 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10235 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10236 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10237 | < 0) { |
| 10238 | goto error; |
| 10239 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10240 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10241 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10242 | goto error; |
| 10243 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10244 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10245 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10246 | goto error; |
| 10247 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10248 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10249 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10250 | goto error; |
| 10251 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10252 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10253 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10254 | 0) { |
| 10255 | goto error; |
| 10256 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10257 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10258 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10259 | goto error; |
| 10260 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10261 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10262 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10263 | goto error; |
| 10264 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10265 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10266 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10267 | goto error; |
| 10268 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10269 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10270 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10271 | 0) { |
| 10272 | goto error; |
| 10273 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10274 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10275 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10276 | 0) { |
| 10277 | goto error; |
| 10278 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10279 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10280 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10281 | goto error; |
| 10282 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10283 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10284 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10285 | 0) { |
| 10286 | goto error; |
| 10287 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10288 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10289 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10290 | 0) { |
| 10291 | goto error; |
| 10292 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10293 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10294 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10295 | < 0) { |
| 10296 | goto error; |
| 10297 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10298 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10299 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10300 | 0) { |
| 10301 | goto error; |
| 10302 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10303 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10304 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10305 | 0) { |
| 10306 | goto error; |
| 10307 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10308 | Py_INCREF(astmodulestate(m)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10309 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10310 | goto error; |
| 10311 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10312 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10313 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10314 | goto error; |
| 10315 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10316 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10317 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10318 | goto error; |
| 10319 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10320 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10321 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10322 | goto error; |
| 10323 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10324 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10325 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10326 | goto error; |
| 10327 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10328 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10329 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10330 | goto error; |
| 10331 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10332 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10333 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10334 | goto error; |
| 10335 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10336 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10337 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10338 | goto error; |
| 10339 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10340 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10341 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10342 | goto error; |
| 10343 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10344 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10345 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10346 | goto error; |
| 10347 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10348 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10349 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10350 | goto error; |
| 10351 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10352 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10353 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10354 | goto error; |
| 10355 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10356 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10357 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10358 | goto error; |
| 10359 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10360 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10361 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10362 | goto error; |
| 10363 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10364 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10365 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10366 | astmodulestate_global->comprehension_type) < 0) { |
| 10367 | goto error; |
| 10368 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10369 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10370 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10371 | astmodulestate_global->excepthandler_type) < 0) { |
| 10372 | goto error; |
| 10373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10374 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10375 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10376 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10377 | goto error; |
| 10378 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10379 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10380 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10381 | astmodulestate_global->arguments_type) < 0) { |
| 10382 | goto error; |
| 10383 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10384 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10385 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10386 | goto error; |
| 10387 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10388 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10389 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10390 | 0) { |
| 10391 | goto error; |
| 10392 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10393 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10394 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10395 | goto error; |
| 10396 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10397 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10398 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10399 | < 0) { |
| 10400 | goto error; |
| 10401 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10402 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10403 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10404 | astmodulestate_global->type_ignore_type) < 0) { |
| 10405 | goto error; |
| 10406 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10407 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10408 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10409 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10410 | goto error; |
| 10411 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10412 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10413 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10414 | error: |
| 10415 | Py_DECREF(m); |
| 10416 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10417 | } |
| 10418 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10419 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10420 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10421 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10422 | if (!init_types()) |
| 10423 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10424 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10425 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10426 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10427 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10428 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10429 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10430 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10431 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10432 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10433 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10434 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10435 | return NULL; |
| 10436 | } |
| 10437 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10438 | req_type[0] = astmodulestate_global->Module_type; |
| 10439 | req_type[1] = astmodulestate_global->Expression_type; |
| 10440 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10441 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10442 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10443 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10444 | if (!init_types()) |
| 10445 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10446 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10447 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10448 | if (isinstance == -1) |
| 10449 | return NULL; |
| 10450 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10451 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10452 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10453 | return NULL; |
| 10454 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10455 | |
| 10456 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10457 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10458 | return NULL; |
| 10459 | else |
| 10460 | return res; |
| 10461 | } |
| 10462 | |
| 10463 | int PyAST_Check(PyObject* obj) |
| 10464 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10465 | if (!init_types()) |
| 10466 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10467 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10468 | } |
| 10469 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10470 | |