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; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 24 | PyObject *Await_type; |
| 25 | PyObject *BinOp_type; |
| 26 | PyObject *BitAnd_singleton; |
| 27 | PyObject *BitAnd_type; |
| 28 | PyObject *BitOr_singleton; |
| 29 | PyObject *BitOr_type; |
| 30 | PyObject *BitXor_singleton; |
| 31 | PyObject *BitXor_type; |
| 32 | PyObject *BoolOp_type; |
| 33 | PyObject *Break_type; |
| 34 | PyObject *Call_type; |
| 35 | PyObject *ClassDef_type; |
| 36 | PyObject *Compare_type; |
| 37 | PyObject *Constant_type; |
| 38 | PyObject *Continue_type; |
| 39 | PyObject *Del_singleton; |
| 40 | PyObject *Del_type; |
| 41 | PyObject *Delete_type; |
| 42 | PyObject *DictComp_type; |
| 43 | PyObject *Dict_type; |
| 44 | PyObject *Div_singleton; |
| 45 | PyObject *Div_type; |
| 46 | PyObject *Eq_singleton; |
| 47 | PyObject *Eq_type; |
| 48 | PyObject *ExceptHandler_type; |
| 49 | PyObject *Expr_type; |
| 50 | PyObject *Expression_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 51 | PyObject *FloorDiv_singleton; |
| 52 | PyObject *FloorDiv_type; |
| 53 | PyObject *For_type; |
| 54 | PyObject *FormattedValue_type; |
| 55 | PyObject *FunctionDef_type; |
| 56 | PyObject *FunctionType_type; |
| 57 | PyObject *GeneratorExp_type; |
| 58 | PyObject *Global_type; |
| 59 | PyObject *GtE_singleton; |
| 60 | PyObject *GtE_type; |
| 61 | PyObject *Gt_singleton; |
| 62 | PyObject *Gt_type; |
| 63 | PyObject *IfExp_type; |
| 64 | PyObject *If_type; |
| 65 | PyObject *ImportFrom_type; |
| 66 | PyObject *Import_type; |
| 67 | PyObject *In_singleton; |
| 68 | PyObject *In_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 69 | PyObject *Interactive_type; |
| 70 | PyObject *Invert_singleton; |
| 71 | PyObject *Invert_type; |
| 72 | PyObject *IsNot_singleton; |
| 73 | PyObject *IsNot_type; |
| 74 | PyObject *Is_singleton; |
| 75 | PyObject *Is_type; |
| 76 | PyObject *JoinedStr_type; |
| 77 | PyObject *LShift_singleton; |
| 78 | PyObject *LShift_type; |
| 79 | PyObject *Lambda_type; |
| 80 | PyObject *ListComp_type; |
| 81 | PyObject *List_type; |
| 82 | PyObject *Load_singleton; |
| 83 | PyObject *Load_type; |
| 84 | PyObject *LtE_singleton; |
| 85 | PyObject *LtE_type; |
| 86 | PyObject *Lt_singleton; |
| 87 | PyObject *Lt_type; |
| 88 | PyObject *MatMult_singleton; |
| 89 | PyObject *MatMult_type; |
| 90 | PyObject *Mod_singleton; |
| 91 | PyObject *Mod_type; |
| 92 | PyObject *Module_type; |
| 93 | PyObject *Mult_singleton; |
| 94 | PyObject *Mult_type; |
| 95 | PyObject *Name_type; |
| 96 | PyObject *NamedExpr_type; |
| 97 | PyObject *Nonlocal_type; |
| 98 | PyObject *NotEq_singleton; |
| 99 | PyObject *NotEq_type; |
| 100 | PyObject *NotIn_singleton; |
| 101 | PyObject *NotIn_type; |
| 102 | PyObject *Not_singleton; |
| 103 | PyObject *Not_type; |
| 104 | PyObject *Or_singleton; |
| 105 | PyObject *Or_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 106 | PyObject *Pass_type; |
| 107 | PyObject *Pow_singleton; |
| 108 | PyObject *Pow_type; |
| 109 | PyObject *RShift_singleton; |
| 110 | PyObject *RShift_type; |
| 111 | PyObject *Raise_type; |
| 112 | PyObject *Return_type; |
| 113 | PyObject *SetComp_type; |
| 114 | PyObject *Set_type; |
| 115 | PyObject *Slice_type; |
| 116 | PyObject *Starred_type; |
| 117 | PyObject *Store_singleton; |
| 118 | PyObject *Store_type; |
| 119 | PyObject *Sub_singleton; |
| 120 | PyObject *Sub_type; |
| 121 | PyObject *Subscript_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 122 | PyObject *Try_type; |
| 123 | PyObject *Tuple_type; |
| 124 | PyObject *TypeIgnore_type; |
| 125 | PyObject *UAdd_singleton; |
| 126 | PyObject *UAdd_type; |
| 127 | PyObject *USub_singleton; |
| 128 | PyObject *USub_type; |
| 129 | PyObject *UnaryOp_type; |
| 130 | PyObject *While_type; |
| 131 | PyObject *With_type; |
| 132 | PyObject *YieldFrom_type; |
| 133 | PyObject *Yield_type; |
| 134 | PyObject *__dict__; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 135 | PyObject *__doc__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 136 | PyObject *__module__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 137 | PyObject *_attributes; |
| 138 | PyObject *_fields; |
| 139 | PyObject *alias_type; |
| 140 | PyObject *annotation; |
| 141 | PyObject *arg; |
| 142 | PyObject *arg_type; |
| 143 | PyObject *args; |
| 144 | PyObject *argtypes; |
| 145 | PyObject *arguments_type; |
| 146 | PyObject *asname; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 147 | PyObject *ast; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 148 | PyObject *attr; |
| 149 | PyObject *bases; |
| 150 | PyObject *body; |
| 151 | PyObject *boolop_type; |
| 152 | PyObject *cause; |
| 153 | PyObject *cmpop_type; |
| 154 | PyObject *col_offset; |
| 155 | PyObject *comparators; |
| 156 | PyObject *comprehension_type; |
| 157 | PyObject *context_expr; |
| 158 | PyObject *conversion; |
| 159 | PyObject *ctx; |
| 160 | PyObject *decorator_list; |
| 161 | PyObject *defaults; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 162 | PyObject *elt; |
| 163 | PyObject *elts; |
| 164 | PyObject *end_col_offset; |
| 165 | PyObject *end_lineno; |
| 166 | PyObject *exc; |
| 167 | PyObject *excepthandler_type; |
| 168 | PyObject *expr_context_type; |
| 169 | PyObject *expr_type; |
| 170 | PyObject *finalbody; |
| 171 | PyObject *format_spec; |
| 172 | PyObject *func; |
| 173 | PyObject *generators; |
| 174 | PyObject *handlers; |
| 175 | PyObject *id; |
| 176 | PyObject *ifs; |
| 177 | PyObject *is_async; |
| 178 | PyObject *items; |
| 179 | PyObject *iter; |
| 180 | PyObject *key; |
| 181 | PyObject *keys; |
| 182 | PyObject *keyword_type; |
| 183 | PyObject *keywords; |
| 184 | PyObject *kind; |
| 185 | PyObject *kw_defaults; |
| 186 | PyObject *kwarg; |
| 187 | PyObject *kwonlyargs; |
| 188 | PyObject *left; |
| 189 | PyObject *level; |
| 190 | PyObject *lineno; |
| 191 | PyObject *lower; |
| 192 | PyObject *mod_type; |
| 193 | PyObject *module; |
| 194 | PyObject *msg; |
| 195 | PyObject *name; |
| 196 | PyObject *names; |
| 197 | PyObject *op; |
| 198 | PyObject *operand; |
| 199 | PyObject *operator_type; |
| 200 | PyObject *ops; |
| 201 | PyObject *optional_vars; |
| 202 | PyObject *orelse; |
| 203 | PyObject *posonlyargs; |
| 204 | PyObject *returns; |
| 205 | PyObject *right; |
| 206 | PyObject *simple; |
| 207 | PyObject *slice; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 208 | PyObject *step; |
| 209 | PyObject *stmt_type; |
| 210 | PyObject *tag; |
| 211 | PyObject *target; |
| 212 | PyObject *targets; |
| 213 | PyObject *test; |
| 214 | PyObject *type; |
| 215 | PyObject *type_comment; |
| 216 | PyObject *type_ignore_type; |
| 217 | PyObject *type_ignores; |
| 218 | PyObject *unaryop_type; |
| 219 | PyObject *upper; |
| 220 | PyObject *value; |
| 221 | PyObject *values; |
| 222 | PyObject *vararg; |
| 223 | PyObject *withitem_type; |
| 224 | } astmodulestate; |
| 225 | |
| 226 | |
| 227 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 228 | |
| 229 | static int astmodule_clear(PyObject *module) |
| 230 | { |
| 231 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 232 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 233 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 234 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 235 | Py_CLEAR(astmodulestate(module)->And_type); |
| 236 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 237 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 238 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 239 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 240 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 241 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 242 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 243 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 244 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 245 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 246 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 247 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 248 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 249 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 250 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 251 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 252 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 253 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 254 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 255 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 256 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 257 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 258 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 259 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 260 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 261 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 262 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 263 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 264 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 265 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 266 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 267 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 268 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 269 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 271 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 272 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 273 | Py_CLEAR(astmodulestate(module)->For_type); |
| 274 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 275 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 276 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 277 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 278 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 279 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 280 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 281 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 282 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 283 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 284 | Py_CLEAR(astmodulestate(module)->If_type); |
| 285 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 286 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 287 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 288 | Py_CLEAR(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 289 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 290 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 291 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 292 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 293 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 294 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 295 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 296 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 297 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 298 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 299 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 300 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 301 | Py_CLEAR(astmodulestate(module)->List_type); |
| 302 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 303 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 304 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 305 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 306 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 307 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 308 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 309 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 310 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 311 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 312 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 313 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 314 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 315 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 316 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 317 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 318 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 319 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 320 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 321 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 322 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 323 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 324 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 325 | Py_CLEAR(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 326 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 327 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 328 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 329 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 330 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 331 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 332 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 333 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 334 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 335 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 336 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 337 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 338 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 339 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 340 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 341 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 342 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 343 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 344 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 345 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 346 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 347 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 348 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 349 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 350 | Py_CLEAR(astmodulestate(module)->While_type); |
| 351 | Py_CLEAR(astmodulestate(module)->With_type); |
| 352 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 353 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 354 | Py_CLEAR(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 355 | Py_CLEAR(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 356 | Py_CLEAR(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 357 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 358 | Py_CLEAR(astmodulestate(module)->_fields); |
| 359 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 360 | Py_CLEAR(astmodulestate(module)->annotation); |
| 361 | Py_CLEAR(astmodulestate(module)->arg); |
| 362 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 363 | Py_CLEAR(astmodulestate(module)->args); |
| 364 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 365 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 366 | Py_CLEAR(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 367 | Py_CLEAR(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 368 | Py_CLEAR(astmodulestate(module)->attr); |
| 369 | Py_CLEAR(astmodulestate(module)->bases); |
| 370 | Py_CLEAR(astmodulestate(module)->body); |
| 371 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 372 | Py_CLEAR(astmodulestate(module)->cause); |
| 373 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 374 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 375 | Py_CLEAR(astmodulestate(module)->comparators); |
| 376 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 377 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 378 | Py_CLEAR(astmodulestate(module)->conversion); |
| 379 | Py_CLEAR(astmodulestate(module)->ctx); |
| 380 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 381 | Py_CLEAR(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 382 | Py_CLEAR(astmodulestate(module)->elt); |
| 383 | Py_CLEAR(astmodulestate(module)->elts); |
| 384 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 385 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 386 | Py_CLEAR(astmodulestate(module)->exc); |
| 387 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 388 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 389 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 390 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 391 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 392 | Py_CLEAR(astmodulestate(module)->func); |
| 393 | Py_CLEAR(astmodulestate(module)->generators); |
| 394 | Py_CLEAR(astmodulestate(module)->handlers); |
| 395 | Py_CLEAR(astmodulestate(module)->id); |
| 396 | Py_CLEAR(astmodulestate(module)->ifs); |
| 397 | Py_CLEAR(astmodulestate(module)->is_async); |
| 398 | Py_CLEAR(astmodulestate(module)->items); |
| 399 | Py_CLEAR(astmodulestate(module)->iter); |
| 400 | Py_CLEAR(astmodulestate(module)->key); |
| 401 | Py_CLEAR(astmodulestate(module)->keys); |
| 402 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 403 | Py_CLEAR(astmodulestate(module)->keywords); |
| 404 | Py_CLEAR(astmodulestate(module)->kind); |
| 405 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 406 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 407 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 408 | Py_CLEAR(astmodulestate(module)->left); |
| 409 | Py_CLEAR(astmodulestate(module)->level); |
| 410 | Py_CLEAR(astmodulestate(module)->lineno); |
| 411 | Py_CLEAR(astmodulestate(module)->lower); |
| 412 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 413 | Py_CLEAR(astmodulestate(module)->module); |
| 414 | Py_CLEAR(astmodulestate(module)->msg); |
| 415 | Py_CLEAR(astmodulestate(module)->name); |
| 416 | Py_CLEAR(astmodulestate(module)->names); |
| 417 | Py_CLEAR(astmodulestate(module)->op); |
| 418 | Py_CLEAR(astmodulestate(module)->operand); |
| 419 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 420 | Py_CLEAR(astmodulestate(module)->ops); |
| 421 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 422 | Py_CLEAR(astmodulestate(module)->orelse); |
| 423 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 424 | Py_CLEAR(astmodulestate(module)->returns); |
| 425 | Py_CLEAR(astmodulestate(module)->right); |
| 426 | Py_CLEAR(astmodulestate(module)->simple); |
| 427 | Py_CLEAR(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 428 | Py_CLEAR(astmodulestate(module)->step); |
| 429 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 430 | Py_CLEAR(astmodulestate(module)->tag); |
| 431 | Py_CLEAR(astmodulestate(module)->target); |
| 432 | Py_CLEAR(astmodulestate(module)->targets); |
| 433 | Py_CLEAR(astmodulestate(module)->test); |
| 434 | Py_CLEAR(astmodulestate(module)->type); |
| 435 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 436 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 437 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 438 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 439 | Py_CLEAR(astmodulestate(module)->upper); |
| 440 | Py_CLEAR(astmodulestate(module)->value); |
| 441 | Py_CLEAR(astmodulestate(module)->values); |
| 442 | Py_CLEAR(astmodulestate(module)->vararg); |
| 443 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 449 | { |
| 450 | Py_VISIT(astmodulestate(module)->AST_type); |
| 451 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 452 | Py_VISIT(astmodulestate(module)->Add_type); |
| 453 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 454 | Py_VISIT(astmodulestate(module)->And_type); |
| 455 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 456 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 457 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 458 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 459 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 460 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 461 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 462 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 463 | Py_VISIT(astmodulestate(module)->Await_type); |
| 464 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 465 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 466 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 467 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 468 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 469 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 470 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 471 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 472 | Py_VISIT(astmodulestate(module)->Break_type); |
| 473 | Py_VISIT(astmodulestate(module)->Call_type); |
| 474 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 475 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 476 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 477 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 478 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 479 | Py_VISIT(astmodulestate(module)->Del_type); |
| 480 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 481 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 482 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 483 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->Div_type); |
| 485 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 486 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 487 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 488 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 489 | Py_VISIT(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 490 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 491 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 492 | Py_VISIT(astmodulestate(module)->For_type); |
| 493 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 494 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 495 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 496 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 497 | Py_VISIT(astmodulestate(module)->Global_type); |
| 498 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 499 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 500 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 501 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 502 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 503 | Py_VISIT(astmodulestate(module)->If_type); |
| 504 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 505 | Py_VISIT(astmodulestate(module)->Import_type); |
| 506 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 507 | Py_VISIT(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 508 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 509 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 510 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 511 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 512 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 513 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 514 | Py_VISIT(astmodulestate(module)->Is_type); |
| 515 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 516 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 517 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 518 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 519 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 520 | Py_VISIT(astmodulestate(module)->List_type); |
| 521 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 522 | Py_VISIT(astmodulestate(module)->Load_type); |
| 523 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 525 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 526 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 527 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 528 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 529 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 530 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 531 | Py_VISIT(astmodulestate(module)->Module_type); |
| 532 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 533 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 534 | Py_VISIT(astmodulestate(module)->Name_type); |
| 535 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 536 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 537 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 539 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 540 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 541 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 542 | Py_VISIT(astmodulestate(module)->Not_type); |
| 543 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 544 | Py_VISIT(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 545 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 546 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 547 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 548 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 549 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 550 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 551 | Py_VISIT(astmodulestate(module)->Return_type); |
| 552 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 553 | Py_VISIT(astmodulestate(module)->Set_type); |
| 554 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 555 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 556 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 557 | Py_VISIT(astmodulestate(module)->Store_type); |
| 558 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 559 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 560 | Py_VISIT(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 561 | Py_VISIT(astmodulestate(module)->Try_type); |
| 562 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 563 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 564 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 565 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 566 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 567 | Py_VISIT(astmodulestate(module)->USub_type); |
| 568 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 569 | Py_VISIT(astmodulestate(module)->While_type); |
| 570 | Py_VISIT(astmodulestate(module)->With_type); |
| 571 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 572 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 573 | Py_VISIT(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 574 | Py_VISIT(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 575 | Py_VISIT(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 576 | Py_VISIT(astmodulestate(module)->_attributes); |
| 577 | Py_VISIT(astmodulestate(module)->_fields); |
| 578 | Py_VISIT(astmodulestate(module)->alias_type); |
| 579 | Py_VISIT(astmodulestate(module)->annotation); |
| 580 | Py_VISIT(astmodulestate(module)->arg); |
| 581 | Py_VISIT(astmodulestate(module)->arg_type); |
| 582 | Py_VISIT(astmodulestate(module)->args); |
| 583 | Py_VISIT(astmodulestate(module)->argtypes); |
| 584 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 585 | Py_VISIT(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 586 | Py_VISIT(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 587 | Py_VISIT(astmodulestate(module)->attr); |
| 588 | Py_VISIT(astmodulestate(module)->bases); |
| 589 | Py_VISIT(astmodulestate(module)->body); |
| 590 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 591 | Py_VISIT(astmodulestate(module)->cause); |
| 592 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 593 | Py_VISIT(astmodulestate(module)->col_offset); |
| 594 | Py_VISIT(astmodulestate(module)->comparators); |
| 595 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 596 | Py_VISIT(astmodulestate(module)->context_expr); |
| 597 | Py_VISIT(astmodulestate(module)->conversion); |
| 598 | Py_VISIT(astmodulestate(module)->ctx); |
| 599 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 600 | Py_VISIT(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 601 | Py_VISIT(astmodulestate(module)->elt); |
| 602 | Py_VISIT(astmodulestate(module)->elts); |
| 603 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 604 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 605 | Py_VISIT(astmodulestate(module)->exc); |
| 606 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 607 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 608 | Py_VISIT(astmodulestate(module)->expr_type); |
| 609 | Py_VISIT(astmodulestate(module)->finalbody); |
| 610 | Py_VISIT(astmodulestate(module)->format_spec); |
| 611 | Py_VISIT(astmodulestate(module)->func); |
| 612 | Py_VISIT(astmodulestate(module)->generators); |
| 613 | Py_VISIT(astmodulestate(module)->handlers); |
| 614 | Py_VISIT(astmodulestate(module)->id); |
| 615 | Py_VISIT(astmodulestate(module)->ifs); |
| 616 | Py_VISIT(astmodulestate(module)->is_async); |
| 617 | Py_VISIT(astmodulestate(module)->items); |
| 618 | Py_VISIT(astmodulestate(module)->iter); |
| 619 | Py_VISIT(astmodulestate(module)->key); |
| 620 | Py_VISIT(astmodulestate(module)->keys); |
| 621 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 622 | Py_VISIT(astmodulestate(module)->keywords); |
| 623 | Py_VISIT(astmodulestate(module)->kind); |
| 624 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 625 | Py_VISIT(astmodulestate(module)->kwarg); |
| 626 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 627 | Py_VISIT(astmodulestate(module)->left); |
| 628 | Py_VISIT(astmodulestate(module)->level); |
| 629 | Py_VISIT(astmodulestate(module)->lineno); |
| 630 | Py_VISIT(astmodulestate(module)->lower); |
| 631 | Py_VISIT(astmodulestate(module)->mod_type); |
| 632 | Py_VISIT(astmodulestate(module)->module); |
| 633 | Py_VISIT(astmodulestate(module)->msg); |
| 634 | Py_VISIT(astmodulestate(module)->name); |
| 635 | Py_VISIT(astmodulestate(module)->names); |
| 636 | Py_VISIT(astmodulestate(module)->op); |
| 637 | Py_VISIT(astmodulestate(module)->operand); |
| 638 | Py_VISIT(astmodulestate(module)->operator_type); |
| 639 | Py_VISIT(astmodulestate(module)->ops); |
| 640 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 641 | Py_VISIT(astmodulestate(module)->orelse); |
| 642 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 643 | Py_VISIT(astmodulestate(module)->returns); |
| 644 | Py_VISIT(astmodulestate(module)->right); |
| 645 | Py_VISIT(astmodulestate(module)->simple); |
| 646 | Py_VISIT(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 647 | Py_VISIT(astmodulestate(module)->step); |
| 648 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 649 | Py_VISIT(astmodulestate(module)->tag); |
| 650 | Py_VISIT(astmodulestate(module)->target); |
| 651 | Py_VISIT(astmodulestate(module)->targets); |
| 652 | Py_VISIT(astmodulestate(module)->test); |
| 653 | Py_VISIT(astmodulestate(module)->type); |
| 654 | Py_VISIT(astmodulestate(module)->type_comment); |
| 655 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 656 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 657 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 658 | Py_VISIT(astmodulestate(module)->upper); |
| 659 | Py_VISIT(astmodulestate(module)->value); |
| 660 | Py_VISIT(astmodulestate(module)->values); |
| 661 | Py_VISIT(astmodulestate(module)->vararg); |
| 662 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static void astmodule_free(void* module) { |
| 668 | astmodule_clear((PyObject*)module); |
| 669 | } |
| 670 | |
| 671 | static struct PyModuleDef _astmodule = { |
| 672 | PyModuleDef_HEAD_INIT, |
| 673 | "_ast", |
| 674 | NULL, |
| 675 | sizeof(astmodulestate), |
| 676 | NULL, |
| 677 | NULL, |
| 678 | astmodule_traverse, |
| 679 | astmodule_clear, |
| 680 | astmodule_free, |
| 681 | }; |
| 682 | |
| 683 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 684 | |
| 685 | static int init_identifiers(void) |
| 686 | { |
| 687 | astmodulestate *state = astmodulestate_global; |
| 688 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 689 | if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 690 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 691 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 692 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 693 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 694 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 695 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 696 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 697 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 698 | if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 699 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 700 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 701 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 702 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 703 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 704 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 705 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 706 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 707 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 708 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 709 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 710 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 711 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 712 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 713 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 714 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 715 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 716 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 717 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 718 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 719 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 720 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 721 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 722 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 723 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 724 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 725 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 726 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 727 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 728 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 729 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 730 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 731 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 732 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 733 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 734 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 735 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 736 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 737 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 738 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 739 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 740 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 741 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 742 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 743 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 744 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 745 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 746 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 747 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 748 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 749 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 750 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 751 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 752 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 753 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 754 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 755 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 756 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 757 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 758 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 759 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 760 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 761 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 762 | return 1; |
| 763 | }; |
| 764 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 766 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 767 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 768 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 769 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 770 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 771 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 773 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 774 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 776 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 777 | "argtypes", |
| 778 | "returns", |
| 779 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 780 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 781 | "lineno", |
| 782 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 783 | "end_lineno", |
| 784 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 787 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 788 | "name", |
| 789 | "args", |
| 790 | "body", |
| 791 | "decorator_list", |
| 792 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 793 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 795 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 796 | "name", |
| 797 | "args", |
| 798 | "body", |
| 799 | "decorator_list", |
| 800 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 801 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 802 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 803 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 804 | "name", |
| 805 | "bases", |
| 806 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 807 | "body", |
| 808 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 809 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 810 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 811 | "value", |
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 Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 814 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 815 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 816 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 817 | "targets", |
| 818 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 819 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 821 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 822 | "target", |
| 823 | "op", |
| 824 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 825 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 826 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 827 | "target", |
| 828 | "annotation", |
| 829 | "value", |
| 830 | "simple", |
| 831 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 832 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 833 | "target", |
| 834 | "iter", |
| 835 | "body", |
| 836 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 837 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 838 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 839 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 840 | "target", |
| 841 | "iter", |
| 842 | "body", |
| 843 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 844 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 845 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 846 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 847 | "test", |
| 848 | "body", |
| 849 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 850 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 851 | static const char * const If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 852 | "test", |
| 853 | "body", |
| 854 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 855 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 856 | static const char * const With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 857 | "items", |
| 858 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 859 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 860 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 861 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 862 | "items", |
| 863 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 864 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 865 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 866 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 867 | "exc", |
| 868 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 870 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 871 | "body", |
| 872 | "handlers", |
| 873 | "orelse", |
| 874 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 875 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 876 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 877 | "test", |
| 878 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 879 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 880 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 881 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 883 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | "module", |
| 885 | "names", |
| 886 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 887 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 888 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 889 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 890 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 891 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 892 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 893 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 894 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 895 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 896 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 897 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | "lineno", |
| 899 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 900 | "end_lineno", |
| 901 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 903 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 904 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 905 | "op", |
| 906 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 907 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 908 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 909 | "target", |
| 910 | "value", |
| 911 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 912 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 913 | "left", |
| 914 | "op", |
| 915 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 916 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 917 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 918 | "op", |
| 919 | "operand", |
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 Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | "args", |
| 923 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 924 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 925 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 926 | "test", |
| 927 | "body", |
| 928 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 929 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 930 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 931 | "keys", |
| 932 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 933 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 934 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 935 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 936 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 937 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 938 | "elt", |
| 939 | "generators", |
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 SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 942 | "elt", |
| 943 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 944 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 945 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 946 | "key", |
| 947 | "value", |
| 948 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 949 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 950 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 951 | "elt", |
| 952 | "generators", |
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 Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 955 | "value", |
| 956 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 957 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 958 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 959 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 960 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 961 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 962 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 963 | static const char * const Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 964 | "left", |
| 965 | "ops", |
| 966 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 967 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 968 | static const char * const Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 969 | "func", |
| 970 | "args", |
| 971 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 972 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 973 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 974 | "value", |
| 975 | "conversion", |
| 976 | "format_spec", |
| 977 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 978 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 979 | "values", |
| 980 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 981 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 982 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 983 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 984 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 985 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 986 | "value", |
| 987 | "attr", |
| 988 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 989 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 990 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | "value", |
| 992 | "slice", |
| 993 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 994 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 995 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 996 | "value", |
| 997 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 998 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 999 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1000 | "id", |
| 1001 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1002 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1003 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1004 | "elts", |
| 1005 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1006 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1007 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1008 | "elts", |
| 1009 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1010 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1011 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1012 | "lower", |
| 1013 | "upper", |
| 1014 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1015 | }; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1016 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1017 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1018 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1019 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1020 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1021 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1022 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1023 | "target", |
| 1024 | "iter", |
| 1025 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1026 | "is_async", |
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 excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1029 | "lineno", |
| 1030 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1031 | "end_lineno", |
| 1032 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1033 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1034 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1035 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1036 | "type", |
| 1037 | "name", |
| 1038 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1040 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1041 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1042 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1043 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1044 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1045 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1046 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1047 | "kwarg", |
| 1048 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1049 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1050 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1051 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1052 | "lineno", |
| 1053 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1054 | "end_lineno", |
| 1055 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1056 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1057 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1058 | "arg", |
| 1059 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1060 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1061 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1062 | static PyObject* ast2obj_keyword(void*); |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 1063 | static const char * const keyword_attributes[] = { |
| 1064 | "lineno", |
| 1065 | "col_offset", |
| 1066 | "end_lineno", |
| 1067 | "end_col_offset", |
| 1068 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1069 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1070 | "arg", |
| 1071 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1072 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1073 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1074 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1075 | "name", |
| 1076 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1077 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1078 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1079 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1080 | "context_expr", |
| 1081 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1082 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1083 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1084 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1085 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1086 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1087 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1088 | |
| 1089 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1090 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1091 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1092 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1093 | PyObject *dict; |
| 1094 | } AST_object; |
| 1095 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1096 | static void |
| 1097 | ast_dealloc(AST_object *self) |
| 1098 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1099 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1100 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1101 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1102 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1103 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1104 | assert(free_func != NULL); |
| 1105 | free_func(self); |
| 1106 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1107 | } |
| 1108 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1109 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1110 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1111 | { |
| 1112 | Py_VISIT(self->dict); |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1116 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1117 | ast_clear(AST_object *self) |
| 1118 | { |
| 1119 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1120 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1124 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1125 | { |
| 1126 | Py_ssize_t i, numfields = 0; |
| 1127 | int res = -1; |
| 1128 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1129 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1130 | goto cleanup; |
| 1131 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1132 | if (fields) { |
| 1133 | numfields = PySequence_Size(fields); |
| 1134 | if (numfields == -1) |
| 1135 | goto cleanup; |
| 1136 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1137 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1138 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1139 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1140 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1141 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1142 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1143 | numfields, numfields == 1 ? "" : "s"); |
| 1144 | res = -1; |
| 1145 | goto cleanup; |
| 1146 | } |
| 1147 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1148 | /* cannot be reached when fields is NULL */ |
| 1149 | PyObject *name = PySequence_GetItem(fields, i); |
| 1150 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1151 | res = -1; |
| 1152 | goto cleanup; |
| 1153 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1154 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1155 | Py_DECREF(name); |
| 1156 | if (res < 0) |
| 1157 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1158 | } |
| 1159 | if (kw) { |
| 1160 | i = 0; /* needed by PyDict_Next */ |
| 1161 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1162 | res = PyObject_SetAttr(self, key, value); |
| 1163 | if (res < 0) |
| 1164 | goto cleanup; |
| 1165 | } |
| 1166 | } |
| 1167 | cleanup: |
| 1168 | Py_XDECREF(fields); |
| 1169 | return res; |
| 1170 | } |
| 1171 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1172 | /* Pickling support */ |
| 1173 | static PyObject * |
| 1174 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1175 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1176 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1177 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1178 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1179 | } |
| 1180 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1181 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1182 | } |
| 1183 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1184 | } |
| 1185 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1186 | static PyMemberDef ast_type_members[] = { |
| 1187 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1188 | {NULL} /* Sentinel */ |
| 1189 | }; |
| 1190 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1191 | static PyMethodDef ast_type_methods[] = { |
| 1192 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1193 | {NULL} |
| 1194 | }; |
| 1195 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1196 | static PyGetSetDef ast_type_getsets[] = { |
| 1197 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1198 | {NULL} |
| 1199 | }; |
| 1200 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1201 | static PyType_Slot AST_type_slots[] = { |
| 1202 | {Py_tp_dealloc, ast_dealloc}, |
| 1203 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1204 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1205 | {Py_tp_traverse, ast_traverse}, |
| 1206 | {Py_tp_clear, ast_clear}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1207 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1208 | {Py_tp_methods, ast_type_methods}, |
| 1209 | {Py_tp_getset, ast_type_getsets}, |
| 1210 | {Py_tp_init, ast_type_init}, |
| 1211 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1212 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1213 | {Py_tp_free, PyObject_GC_Del}, |
| 1214 | {0, 0}, |
| 1215 | }; |
| 1216 | |
| 1217 | static PyType_Spec AST_type_spec = { |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1218 | "ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1219 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1220 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1221 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1222 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1223 | }; |
| 1224 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1225 | static PyObject * |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1226 | make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc) |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1227 | { |
| 1228 | PyObject *fnames, *result; |
| 1229 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1230 | fnames = PyTuple_New(num_fields); |
| 1231 | if (!fnames) return NULL; |
| 1232 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1233 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1234 | if (!field) { |
| 1235 | Py_DECREF(fnames); |
| 1236 | return NULL; |
| 1237 | } |
| 1238 | PyTuple_SET_ITEM(fnames, i, field); |
| 1239 | } |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1240 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1241 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1242 | astmodulestate_global->_fields, fnames, |
| 1243 | astmodulestate_global->__module__, |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1244 | astmodulestate_global->ast, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1245 | astmodulestate_global->__doc__, doc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1246 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1247 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1250 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1251 | 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] | 1252 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1253 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1254 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1255 | if (!l) |
| 1256 | return 0; |
| 1257 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1258 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1259 | if (!s) { |
| 1260 | Py_DECREF(l); |
| 1261 | return 0; |
| 1262 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1263 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1264 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1265 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1266 | Py_DECREF(l); |
| 1267 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1270 | /* Conversion AST -> Python */ |
| 1271 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1272 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1273 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1274 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1275 | PyObject *result = PyList_New(n); |
| 1276 | PyObject *value; |
| 1277 | if (!result) |
| 1278 | return NULL; |
| 1279 | for (i = 0; i < n; i++) { |
| 1280 | value = func(asdl_seq_GET(seq, i)); |
| 1281 | if (!value) { |
| 1282 | Py_DECREF(result); |
| 1283 | return NULL; |
| 1284 | } |
| 1285 | PyList_SET_ITEM(result, i, value); |
| 1286 | } |
| 1287 | return result; |
| 1288 | } |
| 1289 | |
| 1290 | static PyObject* ast2obj_object(void *o) |
| 1291 | { |
| 1292 | if (!o) |
| 1293 | o = Py_None; |
| 1294 | Py_INCREF((PyObject*)o); |
| 1295 | return (PyObject*)o; |
| 1296 | } |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1297 | #define ast2obj_singleton ast2obj_object |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1298 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1299 | #define ast2obj_identifier ast2obj_object |
| 1300 | #define ast2obj_string ast2obj_object |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1301 | #define ast2obj_bytes ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1302 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1303 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1304 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1305 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1308 | /* Conversion Python -> AST */ |
| 1309 | |
| 1310 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1311 | { |
| 1312 | if (obj == Py_None) |
| 1313 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1314 | if (obj) { |
| 1315 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1316 | *out = NULL; |
| 1317 | return -1; |
| 1318 | } |
| 1319 | Py_INCREF(obj); |
| 1320 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1321 | *out = obj; |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1325 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1326 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1327 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1328 | *out = NULL; |
| 1329 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1330 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1331 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1332 | *out = obj; |
| 1333 | return 0; |
| 1334 | } |
| 1335 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1336 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1337 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1338 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1339 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1340 | return 1; |
| 1341 | } |
| 1342 | return obj2ast_object(obj, out, arena); |
| 1343 | } |
| 1344 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1345 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1346 | { |
| 1347 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1348 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1349 | return 1; |
| 1350 | } |
| 1351 | return obj2ast_object(obj, out, arena); |
| 1352 | } |
| 1353 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1354 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1355 | { |
| 1356 | int i; |
| 1357 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1358 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1359 | return 1; |
| 1360 | } |
| 1361 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1362 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1363 | if (i == -1 && PyErr_Occurred()) |
| 1364 | return 1; |
| 1365 | *out = i; |
| 1366 | return 0; |
| 1367 | } |
| 1368 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1369 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1370 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1371 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1372 | empty_tuple = PyTuple_New(0); |
| 1373 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1374 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1375 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1376 | Py_XDECREF(empty_tuple); |
| 1377 | return -1; |
| 1378 | } |
| 1379 | Py_DECREF(empty_tuple); |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1383 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1384 | static int init_types(void) |
| 1385 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1386 | PyObject *m; |
| 1387 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1388 | m = PyModule_Create(&_astmodule); |
| 1389 | if (!m) return 0; |
| 1390 | PyState_AddModule(m, &_astmodule); |
| 1391 | } |
| 1392 | astmodulestate *state = astmodulestate_global; |
| 1393 | if (state->initialized) return 1; |
| 1394 | if (init_identifiers() < 0) return 0; |
| 1395 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1396 | if (!state->AST_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1397 | if (add_ast_fields() < 0) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1398 | state->mod_type = make_type("mod", state->AST_type, NULL, 0, |
| 1399 | "mod = Module(stmt* body, type_ignore* type_ignores)\n" |
| 1400 | " | Interactive(stmt* body)\n" |
| 1401 | " | Expression(expr body)\n" |
| 1402 | " | FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1403 | if (!state->mod_type) return 0; |
| 1404 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1405 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2, |
| 1406 | "Module(stmt* body, type_ignore* type_ignores)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1407 | if (!state->Module_type) return 0; |
| 1408 | state->Interactive_type = make_type("Interactive", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1409 | Interactive_fields, 1, |
| 1410 | "Interactive(stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1411 | if (!state->Interactive_type) return 0; |
| 1412 | state->Expression_type = make_type("Expression", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1413 | Expression_fields, 1, |
| 1414 | "Expression(expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1415 | if (!state->Expression_type) return 0; |
| 1416 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1417 | FunctionType_fields, 2, |
| 1418 | "FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1419 | if (!state->FunctionType_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1420 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0, |
| 1421 | "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1422 | " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1423 | " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" |
| 1424 | " | Return(expr? value)\n" |
| 1425 | " | Delete(expr* targets)\n" |
| 1426 | " | Assign(expr* targets, expr value, string? type_comment)\n" |
| 1427 | " | AugAssign(expr target, operator op, expr value)\n" |
| 1428 | " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n" |
| 1429 | " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1430 | " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1431 | " | While(expr test, stmt* body, stmt* orelse)\n" |
| 1432 | " | If(expr test, stmt* body, stmt* orelse)\n" |
| 1433 | " | With(withitem* items, stmt* body, string? type_comment)\n" |
| 1434 | " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n" |
| 1435 | " | Raise(expr? exc, expr? cause)\n" |
| 1436 | " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n" |
| 1437 | " | Assert(expr test, expr? msg)\n" |
| 1438 | " | Import(alias* names)\n" |
| 1439 | " | ImportFrom(identifier? module, alias* names, int? level)\n" |
| 1440 | " | Global(identifier* names)\n" |
| 1441 | " | Nonlocal(identifier* names)\n" |
| 1442 | " | Expr(expr value)\n" |
| 1443 | " | Pass\n" |
| 1444 | " | Break\n" |
| 1445 | " | Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1446 | if (!state->stmt_type) return 0; |
| 1447 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1448 | if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) |
| 1449 | return 0; |
| 1450 | if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == |
| 1451 | -1) |
| 1452 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1453 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1454 | FunctionDef_fields, 6, |
| 1455 | "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1456 | if (!state->FunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1457 | if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == |
| 1458 | -1) |
| 1459 | return 0; |
| 1460 | if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) |
| 1461 | == -1) |
| 1462 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1463 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1464 | state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1465 | AsyncFunctionDef_fields, 6, |
| 1466 | "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1467 | if (!state->AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1468 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) |
| 1469 | == -1) |
| 1470 | return 0; |
| 1471 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, |
| 1472 | Py_None) == -1) |
| 1473 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1474 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1475 | ClassDef_fields, 5, |
| 1476 | "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1477 | if (!state->ClassDef_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1478 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1, |
| 1479 | "Return(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1480 | if (!state->Return_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1481 | if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) |
| 1482 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1483 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1, |
| 1484 | "Delete(expr* targets)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1485 | if (!state->Delete_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1486 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3, |
| 1487 | "Assign(expr* targets, expr value, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1488 | if (!state->Assign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1489 | if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == |
| 1490 | -1) |
| 1491 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1492 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1493 | AugAssign_fields, 3, |
| 1494 | "AugAssign(expr target, operator op, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1495 | if (!state->AugAssign_type) return 0; |
| 1496 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1497 | AnnAssign_fields, 4, |
| 1498 | "AnnAssign(expr target, expr annotation, expr? value, int simple)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1499 | if (!state->AnnAssign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1500 | if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) |
| 1501 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1502 | state->For_type = make_type("For", state->stmt_type, For_fields, 5, |
| 1503 | "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1504 | if (!state->For_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1505 | if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) |
| 1506 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1507 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1508 | AsyncFor_fields, 5, |
| 1509 | "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1510 | if (!state->AsyncFor_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1511 | if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == |
| 1512 | -1) |
| 1513 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1514 | state->While_type = make_type("While", state->stmt_type, While_fields, 3, |
| 1515 | "While(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1516 | if (!state->While_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1517 | state->If_type = make_type("If", state->stmt_type, If_fields, 3, |
| 1518 | "If(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1519 | if (!state->If_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1520 | state->With_type = make_type("With", state->stmt_type, With_fields, 3, |
| 1521 | "With(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1522 | if (!state->With_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1523 | if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) |
| 1524 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1525 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1526 | AsyncWith_fields, 3, |
| 1527 | "AsyncWith(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1528 | if (!state->AsyncWith_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1529 | if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) |
| 1530 | == -1) |
| 1531 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1532 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2, |
| 1533 | "Raise(expr? exc, expr? cause)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1534 | if (!state->Raise_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1535 | if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) |
| 1536 | return 0; |
| 1537 | if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) |
| 1538 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1539 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4, |
| 1540 | "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1541 | if (!state->Try_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1542 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2, |
| 1543 | "Assert(expr test, expr? msg)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1544 | if (!state->Assert_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1545 | if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) |
| 1546 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1547 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1, |
| 1548 | "Import(alias* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1549 | if (!state->Import_type) return 0; |
| 1550 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1551 | ImportFrom_fields, 3, |
| 1552 | "ImportFrom(identifier? module, alias* names, int? level)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1553 | if (!state->ImportFrom_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1554 | if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) |
| 1555 | return 0; |
| 1556 | if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) |
| 1557 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1558 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1, |
| 1559 | "Global(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1560 | if (!state->Global_type) return 0; |
| 1561 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1562 | Nonlocal_fields, 1, |
| 1563 | "Nonlocal(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1564 | if (!state->Nonlocal_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1565 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1, |
| 1566 | "Expr(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1567 | if (!state->Expr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1568 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0, |
| 1569 | "Pass"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1570 | if (!state->Pass_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1571 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0, |
| 1572 | "Break"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1573 | if (!state->Break_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1574 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0, |
| 1575 | "Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1576 | if (!state->Continue_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1577 | state->expr_type = make_type("expr", state->AST_type, NULL, 0, |
| 1578 | "expr = BoolOp(boolop op, expr* values)\n" |
| 1579 | " | NamedExpr(expr target, expr value)\n" |
| 1580 | " | BinOp(expr left, operator op, expr right)\n" |
| 1581 | " | UnaryOp(unaryop op, expr operand)\n" |
| 1582 | " | Lambda(arguments args, expr body)\n" |
| 1583 | " | IfExp(expr test, expr body, expr orelse)\n" |
| 1584 | " | Dict(expr* keys, expr* values)\n" |
| 1585 | " | Set(expr* elts)\n" |
| 1586 | " | ListComp(expr elt, comprehension* generators)\n" |
| 1587 | " | SetComp(expr elt, comprehension* generators)\n" |
| 1588 | " | DictComp(expr key, expr value, comprehension* generators)\n" |
| 1589 | " | GeneratorExp(expr elt, comprehension* generators)\n" |
| 1590 | " | Await(expr value)\n" |
| 1591 | " | Yield(expr? value)\n" |
| 1592 | " | YieldFrom(expr value)\n" |
| 1593 | " | Compare(expr left, cmpop* ops, expr* comparators)\n" |
| 1594 | " | Call(expr func, expr* args, keyword* keywords)\n" |
| 1595 | " | FormattedValue(expr value, int? conversion, expr? format_spec)\n" |
| 1596 | " | JoinedStr(expr* values)\n" |
| 1597 | " | Constant(constant value, string? kind)\n" |
| 1598 | " | Attribute(expr value, identifier attr, expr_context ctx)\n" |
| 1599 | " | Subscript(expr value, expr slice, expr_context ctx)\n" |
| 1600 | " | Starred(expr value, expr_context ctx)\n" |
| 1601 | " | Name(identifier id, expr_context ctx)\n" |
| 1602 | " | List(expr* elts, expr_context ctx)\n" |
| 1603 | " | Tuple(expr* elts, expr_context ctx)\n" |
| 1604 | " | Slice(expr? lower, expr? upper, expr? step)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1605 | if (!state->expr_type) return 0; |
| 1606 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1607 | if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) |
| 1608 | return 0; |
| 1609 | if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == |
| 1610 | -1) |
| 1611 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1612 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2, |
| 1613 | "BoolOp(boolop op, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1614 | if (!state->BoolOp_type) return 0; |
| 1615 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1616 | NamedExpr_fields, 2, |
| 1617 | "NamedExpr(expr target, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1618 | if (!state->NamedExpr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1619 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3, |
| 1620 | "BinOp(expr left, operator op, expr right)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1621 | if (!state->BinOp_type) return 0; |
| 1622 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1623 | UnaryOp_fields, 2, |
| 1624 | "UnaryOp(unaryop op, expr operand)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1625 | if (!state->UnaryOp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1626 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2, |
| 1627 | "Lambda(arguments args, expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1628 | if (!state->Lambda_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1629 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3, |
| 1630 | "IfExp(expr test, expr body, expr orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1631 | if (!state->IfExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1632 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2, |
| 1633 | "Dict(expr* keys, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1634 | if (!state->Dict_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1635 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1, |
| 1636 | "Set(expr* elts)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1637 | if (!state->Set_type) return 0; |
| 1638 | state->ListComp_type = make_type("ListComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1639 | ListComp_fields, 2, |
| 1640 | "ListComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1641 | if (!state->ListComp_type) return 0; |
| 1642 | state->SetComp_type = make_type("SetComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1643 | SetComp_fields, 2, |
| 1644 | "SetComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1645 | if (!state->SetComp_type) return 0; |
| 1646 | state->DictComp_type = make_type("DictComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1647 | DictComp_fields, 3, |
| 1648 | "DictComp(expr key, expr value, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1649 | if (!state->DictComp_type) return 0; |
| 1650 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1651 | GeneratorExp_fields, 2, |
| 1652 | "GeneratorExp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1653 | if (!state->GeneratorExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1654 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1, |
| 1655 | "Await(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1656 | if (!state->Await_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1657 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1, |
| 1658 | "Yield(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1659 | if (!state->Yield_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1660 | if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) |
| 1661 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1662 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1663 | YieldFrom_fields, 1, |
| 1664 | "YieldFrom(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1665 | if (!state->YieldFrom_type) return 0; |
| 1666 | state->Compare_type = make_type("Compare", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1667 | Compare_fields, 3, |
| 1668 | "Compare(expr left, cmpop* ops, expr* comparators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1669 | if (!state->Compare_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1670 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3, |
| 1671 | "Call(expr func, expr* args, keyword* keywords)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1672 | if (!state->Call_type) return 0; |
| 1673 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1674 | FormattedValue_fields, 3, |
| 1675 | "FormattedValue(expr value, int? conversion, expr? format_spec)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1676 | if (!state->FormattedValue_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1677 | if (PyObject_SetAttr(state->FormattedValue_type, state->conversion, |
| 1678 | Py_None) == -1) |
| 1679 | return 0; |
| 1680 | if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, |
| 1681 | Py_None) == -1) |
| 1682 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1683 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1684 | JoinedStr_fields, 1, |
| 1685 | "JoinedStr(expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1686 | if (!state->JoinedStr_type) return 0; |
| 1687 | state->Constant_type = make_type("Constant", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1688 | Constant_fields, 2, |
| 1689 | "Constant(constant value, string? kind)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1690 | if (!state->Constant_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1691 | if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) |
| 1692 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1693 | state->Attribute_type = make_type("Attribute", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1694 | Attribute_fields, 3, |
| 1695 | "Attribute(expr value, identifier attr, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1696 | if (!state->Attribute_type) return 0; |
| 1697 | state->Subscript_type = make_type("Subscript", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1698 | Subscript_fields, 3, |
| 1699 | "Subscript(expr value, expr slice, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1700 | if (!state->Subscript_type) return 0; |
| 1701 | state->Starred_type = make_type("Starred", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1702 | Starred_fields, 2, |
| 1703 | "Starred(expr value, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1704 | if (!state->Starred_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1705 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2, |
| 1706 | "Name(identifier id, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1707 | if (!state->Name_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1708 | state->List_type = make_type("List", state->expr_type, List_fields, 2, |
| 1709 | "List(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1710 | if (!state->List_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1711 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2, |
| 1712 | "Tuple(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1713 | if (!state->Tuple_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1714 | state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3, |
| 1715 | "Slice(expr? lower, expr? upper, expr? step)"); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1716 | if (!state->Slice_type) return 0; |
| 1717 | if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) |
| 1718 | return 0; |
| 1719 | if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1) |
| 1720 | return 0; |
| 1721 | if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) |
| 1722 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1723 | state->expr_context_type = make_type("expr_context", state->AST_type, NULL, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1724 | 0, |
Serhiy Storchaka | 6b97598 | 2020-03-17 23:41:08 +0200 | [diff] [blame] | 1725 | "expr_context = Load | Store | Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1726 | if (!state->expr_context_type) return 0; |
| 1727 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1728 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0, |
| 1729 | "Load"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1730 | if (!state->Load_type) return 0; |
| 1731 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1732 | NULL, NULL); |
| 1733 | if (!state->Load_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1734 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0, |
| 1735 | "Store"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1736 | if (!state->Store_type) return 0; |
| 1737 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1738 | *)state->Store_type, NULL, NULL); |
| 1739 | if (!state->Store_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1740 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0, |
| 1741 | "Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1742 | if (!state->Del_type) return 0; |
| 1743 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1744 | NULL, NULL); |
| 1745 | if (!state->Del_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1746 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0, |
| 1747 | "boolop = And | Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1748 | if (!state->boolop_type) return 0; |
| 1749 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1750 | state->And_type = make_type("And", state->boolop_type, NULL, 0, |
| 1751 | "And"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1752 | if (!state->And_type) return 0; |
| 1753 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1754 | NULL, NULL); |
| 1755 | if (!state->And_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1756 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0, |
| 1757 | "Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1758 | if (!state->Or_type) return 0; |
| 1759 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1760 | NULL, NULL); |
| 1761 | if (!state->Or_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1762 | state->operator_type = make_type("operator", state->AST_type, NULL, 0, |
| 1763 | "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1764 | if (!state->operator_type) return 0; |
| 1765 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1766 | state->Add_type = make_type("Add", state->operator_type, NULL, 0, |
| 1767 | "Add"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1768 | if (!state->Add_type) return 0; |
| 1769 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1770 | NULL, NULL); |
| 1771 | if (!state->Add_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1772 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0, |
| 1773 | "Sub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1774 | if (!state->Sub_type) return 0; |
| 1775 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1776 | NULL, NULL); |
| 1777 | if (!state->Sub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1778 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0, |
| 1779 | "Mult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1780 | if (!state->Mult_type) return 0; |
| 1781 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1782 | NULL, NULL); |
| 1783 | if (!state->Mult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1784 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0, |
| 1785 | "MatMult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1786 | if (!state->MatMult_type) return 0; |
| 1787 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1788 | *)state->MatMult_type, NULL, |
| 1789 | NULL); |
| 1790 | if (!state->MatMult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1791 | state->Div_type = make_type("Div", state->operator_type, NULL, 0, |
| 1792 | "Div"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1793 | if (!state->Div_type) return 0; |
| 1794 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1795 | NULL, NULL); |
| 1796 | if (!state->Div_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1797 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0, |
| 1798 | "Mod"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1799 | if (!state->Mod_type) return 0; |
| 1800 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1801 | NULL, NULL); |
| 1802 | if (!state->Mod_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1803 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0, |
| 1804 | "Pow"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1805 | if (!state->Pow_type) return 0; |
| 1806 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1807 | NULL, NULL); |
| 1808 | if (!state->Pow_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1809 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0, |
| 1810 | "LShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1811 | if (!state->LShift_type) return 0; |
| 1812 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1813 | *)state->LShift_type, NULL, |
| 1814 | NULL); |
| 1815 | if (!state->LShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1816 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0, |
| 1817 | "RShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1818 | if (!state->RShift_type) return 0; |
| 1819 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1820 | *)state->RShift_type, NULL, |
| 1821 | NULL); |
| 1822 | if (!state->RShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1823 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0, |
| 1824 | "BitOr"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1825 | if (!state->BitOr_type) return 0; |
| 1826 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1827 | *)state->BitOr_type, NULL, NULL); |
| 1828 | if (!state->BitOr_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1829 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0, |
| 1830 | "BitXor"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1831 | if (!state->BitXor_type) return 0; |
| 1832 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1833 | *)state->BitXor_type, NULL, |
| 1834 | NULL); |
| 1835 | if (!state->BitXor_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1836 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0, |
| 1837 | "BitAnd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1838 | if (!state->BitAnd_type) return 0; |
| 1839 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1840 | *)state->BitAnd_type, NULL, |
| 1841 | NULL); |
| 1842 | if (!state->BitAnd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1843 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0, |
| 1844 | "FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1845 | if (!state->FloorDiv_type) return 0; |
| 1846 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1847 | *)state->FloorDiv_type, NULL, |
| 1848 | NULL); |
| 1849 | if (!state->FloorDiv_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1850 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0, |
| 1851 | "unaryop = Invert | Not | UAdd | USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1852 | if (!state->unaryop_type) return 0; |
| 1853 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1854 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0, |
| 1855 | "Invert"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1856 | if (!state->Invert_type) return 0; |
| 1857 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1858 | *)state->Invert_type, NULL, |
| 1859 | NULL); |
| 1860 | if (!state->Invert_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1861 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0, |
| 1862 | "Not"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1863 | if (!state->Not_type) return 0; |
| 1864 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1865 | NULL, NULL); |
| 1866 | if (!state->Not_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1867 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0, |
| 1868 | "UAdd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1869 | if (!state->UAdd_type) return 0; |
| 1870 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1871 | NULL, NULL); |
| 1872 | if (!state->UAdd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1873 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0, |
| 1874 | "USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1875 | if (!state->USub_type) return 0; |
| 1876 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1877 | NULL, NULL); |
| 1878 | if (!state->USub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1879 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0, |
| 1880 | "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1881 | if (!state->cmpop_type) return 0; |
| 1882 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1883 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0, |
| 1884 | "Eq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1885 | if (!state->Eq_type) return 0; |
| 1886 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1887 | NULL, NULL); |
| 1888 | if (!state->Eq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1889 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0, |
| 1890 | "NotEq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1891 | if (!state->NotEq_type) return 0; |
| 1892 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1893 | *)state->NotEq_type, NULL, NULL); |
| 1894 | if (!state->NotEq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1895 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0, |
| 1896 | "Lt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1897 | if (!state->Lt_type) return 0; |
| 1898 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1899 | NULL, NULL); |
| 1900 | if (!state->Lt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1901 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0, |
| 1902 | "LtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1903 | if (!state->LtE_type) return 0; |
| 1904 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1905 | NULL, NULL); |
| 1906 | if (!state->LtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1907 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0, |
| 1908 | "Gt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1909 | if (!state->Gt_type) return 0; |
| 1910 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1911 | NULL, NULL); |
| 1912 | if (!state->Gt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1913 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0, |
| 1914 | "GtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1915 | if (!state->GtE_type) return 0; |
| 1916 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1917 | NULL, NULL); |
| 1918 | if (!state->GtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1919 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0, |
| 1920 | "Is"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1921 | if (!state->Is_type) return 0; |
| 1922 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1923 | NULL, NULL); |
| 1924 | if (!state->Is_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1925 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0, |
| 1926 | "IsNot"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1927 | if (!state->IsNot_type) return 0; |
| 1928 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1929 | *)state->IsNot_type, NULL, NULL); |
| 1930 | if (!state->IsNot_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1931 | state->In_type = make_type("In", state->cmpop_type, NULL, 0, |
| 1932 | "In"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1933 | if (!state->In_type) return 0; |
| 1934 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1935 | NULL, NULL); |
| 1936 | if (!state->In_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1937 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0, |
| 1938 | "NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1939 | if (!state->NotIn_type) return 0; |
| 1940 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1941 | *)state->NotIn_type, NULL, NULL); |
| 1942 | if (!state->NotIn_singleton) return 0; |
| 1943 | state->comprehension_type = make_type("comprehension", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1944 | comprehension_fields, 4, |
| 1945 | "comprehension(expr target, expr iter, expr* ifs, int is_async)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1946 | if (!state->comprehension_type) return 0; |
| 1947 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1948 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1949 | NULL, 0, |
| 1950 | "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1951 | if (!state->excepthandler_type) return 0; |
| 1952 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1953 | 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1954 | if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) |
| 1955 | == -1) |
| 1956 | return 0; |
| 1957 | if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, |
| 1958 | Py_None) == -1) |
| 1959 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1960 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1961 | state->excepthandler_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1962 | ExceptHandler_fields, 3, |
| 1963 | "ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1964 | if (!state->ExceptHandler_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1965 | if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1) |
| 1966 | return 0; |
| 1967 | if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) |
| 1968 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1969 | state->arguments_type = make_type("arguments", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1970 | arguments_fields, 7, |
| 1971 | "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1972 | if (!state->arguments_type) return 0; |
| 1973 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1974 | if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) |
| 1975 | return 0; |
| 1976 | if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) |
| 1977 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1978 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3, |
| 1979 | "arg(identifier arg, expr? annotation, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1980 | if (!state->arg_type) return 0; |
| 1981 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1982 | if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) |
| 1983 | return 0; |
| 1984 | if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) |
| 1985 | return 0; |
| 1986 | if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1) |
| 1987 | return 0; |
| 1988 | if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) |
| 1989 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1990 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1991 | 2, |
| 1992 | "keyword(identifier? arg, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1993 | if (!state->keyword_type) return 0; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 1994 | if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1995 | if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) |
| 1996 | return 0; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 1997 | if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1) |
| 1998 | return 0; |
| 1999 | if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None) |
| 2000 | == -1) |
| 2001 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2002 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2, |
| 2003 | "alias(identifier name, identifier? asname)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2004 | if (!state->alias_type) return 0; |
| 2005 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2006 | if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) |
| 2007 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2008 | state->withitem_type = make_type("withitem", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2009 | withitem_fields, 2, |
| 2010 | "withitem(expr context_expr, expr? optional_vars)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2011 | if (!state->withitem_type) return 0; |
| 2012 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2013 | if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) |
| 2014 | == -1) |
| 2015 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2016 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0, |
| 2017 | "type_ignore = TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2018 | if (!state->type_ignore_type) return 0; |
| 2019 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 2020 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2021 | TypeIgnore_fields, 2, |
| 2022 | "TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2023 | if (!state->TypeIgnore_type) return 0; |
| 2024 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2025 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2026 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2027 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2028 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 2029 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 2030 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 2031 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 2032 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2033 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 2034 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 2035 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 2036 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 2037 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 2038 | arena); |
| 2039 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 2040 | arena); |
| 2041 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 2042 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 2043 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 2044 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2045 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2046 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 2047 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2048 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2049 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2050 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2051 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2052 | mod_ty p; |
| 2053 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2054 | if (!p) |
| 2055 | return NULL; |
| 2056 | p->kind = Module_kind; |
| 2057 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2058 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2059 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2063 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2064 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2065 | mod_ty p; |
| 2066 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2067 | if (!p) |
| 2068 | return NULL; |
| 2069 | p->kind = Interactive_kind; |
| 2070 | p->v.Interactive.body = body; |
| 2071 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2075 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2076 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2077 | mod_ty p; |
| 2078 | if (!body) { |
| 2079 | PyErr_SetString(PyExc_ValueError, |
| 2080 | "field body is required for Expression"); |
| 2081 | return NULL; |
| 2082 | } |
| 2083 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2084 | if (!p) |
| 2085 | return NULL; |
| 2086 | p->kind = Expression_kind; |
| 2087 | p->v.Expression.body = body; |
| 2088 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2092 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 2093 | { |
| 2094 | mod_ty p; |
| 2095 | if (!returns) { |
| 2096 | PyErr_SetString(PyExc_ValueError, |
| 2097 | "field returns is required for FunctionType"); |
| 2098 | return NULL; |
| 2099 | } |
| 2100 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2101 | if (!p) |
| 2102 | return NULL; |
| 2103 | p->kind = FunctionType_kind; |
| 2104 | p->v.FunctionType.argtypes = argtypes; |
| 2105 | p->v.FunctionType.returns = returns; |
| 2106 | return p; |
| 2107 | } |
| 2108 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2109 | stmt_ty |
| 2110 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2111 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 2112 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2113 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2114 | stmt_ty p; |
| 2115 | if (!name) { |
| 2116 | PyErr_SetString(PyExc_ValueError, |
| 2117 | "field name is required for FunctionDef"); |
| 2118 | return NULL; |
| 2119 | } |
| 2120 | if (!args) { |
| 2121 | PyErr_SetString(PyExc_ValueError, |
| 2122 | "field args is required for FunctionDef"); |
| 2123 | return NULL; |
| 2124 | } |
| 2125 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2126 | if (!p) |
| 2127 | return NULL; |
| 2128 | p->kind = FunctionDef_kind; |
| 2129 | p->v.FunctionDef.name = name; |
| 2130 | p->v.FunctionDef.args = args; |
| 2131 | p->v.FunctionDef.body = body; |
| 2132 | p->v.FunctionDef.decorator_list = decorator_list; |
| 2133 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2134 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2135 | p->lineno = lineno; |
| 2136 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2137 | p->end_lineno = end_lineno; |
| 2138 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2139 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2143 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2144 | * decorator_list, expr_ty returns, string type_comment, int |
| 2145 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2146 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2147 | { |
| 2148 | stmt_ty p; |
| 2149 | if (!name) { |
| 2150 | PyErr_SetString(PyExc_ValueError, |
| 2151 | "field name is required for AsyncFunctionDef"); |
| 2152 | return NULL; |
| 2153 | } |
| 2154 | if (!args) { |
| 2155 | PyErr_SetString(PyExc_ValueError, |
| 2156 | "field args is required for AsyncFunctionDef"); |
| 2157 | return NULL; |
| 2158 | } |
| 2159 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2160 | if (!p) |
| 2161 | return NULL; |
| 2162 | p->kind = AsyncFunctionDef_kind; |
| 2163 | p->v.AsyncFunctionDef.name = name; |
| 2164 | p->v.AsyncFunctionDef.args = args; |
| 2165 | p->v.AsyncFunctionDef.body = body; |
| 2166 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 2167 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2168 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2169 | p->lineno = lineno; |
| 2170 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2171 | p->end_lineno = end_lineno; |
| 2172 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2173 | return p; |
| 2174 | } |
| 2175 | |
| 2176 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2177 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2178 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2179 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2180 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2181 | stmt_ty p; |
| 2182 | if (!name) { |
| 2183 | PyErr_SetString(PyExc_ValueError, |
| 2184 | "field name is required for ClassDef"); |
| 2185 | return NULL; |
| 2186 | } |
| 2187 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2188 | if (!p) |
| 2189 | return NULL; |
| 2190 | p->kind = ClassDef_kind; |
| 2191 | p->v.ClassDef.name = name; |
| 2192 | p->v.ClassDef.bases = bases; |
| 2193 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2194 | p->v.ClassDef.body = body; |
| 2195 | p->v.ClassDef.decorator_list = decorator_list; |
| 2196 | p->lineno = lineno; |
| 2197 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2198 | p->end_lineno = end_lineno; |
| 2199 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2200 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2204 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2205 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2206 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2207 | stmt_ty p; |
| 2208 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2209 | if (!p) |
| 2210 | return NULL; |
| 2211 | p->kind = Return_kind; |
| 2212 | p->v.Return.value = value; |
| 2213 | p->lineno = lineno; |
| 2214 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2215 | p->end_lineno = end_lineno; |
| 2216 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2217 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2221 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2222 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2223 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2224 | stmt_ty p; |
| 2225 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2226 | if (!p) |
| 2227 | return NULL; |
| 2228 | p->kind = Delete_kind; |
| 2229 | p->v.Delete.targets = targets; |
| 2230 | p->lineno = lineno; |
| 2231 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2232 | p->end_lineno = end_lineno; |
| 2233 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2234 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2238 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2239 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2240 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2241 | stmt_ty p; |
| 2242 | if (!value) { |
| 2243 | PyErr_SetString(PyExc_ValueError, |
| 2244 | "field value is required for Assign"); |
| 2245 | return NULL; |
| 2246 | } |
| 2247 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2248 | if (!p) |
| 2249 | return NULL; |
| 2250 | p->kind = Assign_kind; |
| 2251 | p->v.Assign.targets = targets; |
| 2252 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2253 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2254 | p->lineno = lineno; |
| 2255 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2256 | p->end_lineno = end_lineno; |
| 2257 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2258 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2262 | 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] | 2263 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2264 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2265 | stmt_ty p; |
| 2266 | if (!target) { |
| 2267 | PyErr_SetString(PyExc_ValueError, |
| 2268 | "field target is required for AugAssign"); |
| 2269 | return NULL; |
| 2270 | } |
| 2271 | if (!op) { |
| 2272 | PyErr_SetString(PyExc_ValueError, |
| 2273 | "field op is required for AugAssign"); |
| 2274 | return NULL; |
| 2275 | } |
| 2276 | if (!value) { |
| 2277 | PyErr_SetString(PyExc_ValueError, |
| 2278 | "field value is required for AugAssign"); |
| 2279 | return NULL; |
| 2280 | } |
| 2281 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2282 | if (!p) |
| 2283 | return NULL; |
| 2284 | p->kind = AugAssign_kind; |
| 2285 | p->v.AugAssign.target = target; |
| 2286 | p->v.AugAssign.op = op; |
| 2287 | p->v.AugAssign.value = value; |
| 2288 | p->lineno = lineno; |
| 2289 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2290 | p->end_lineno = end_lineno; |
| 2291 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2292 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2296 | 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] | 2297 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2298 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2299 | { |
| 2300 | stmt_ty p; |
| 2301 | if (!target) { |
| 2302 | PyErr_SetString(PyExc_ValueError, |
| 2303 | "field target is required for AnnAssign"); |
| 2304 | return NULL; |
| 2305 | } |
| 2306 | if (!annotation) { |
| 2307 | PyErr_SetString(PyExc_ValueError, |
| 2308 | "field annotation is required for AnnAssign"); |
| 2309 | return NULL; |
| 2310 | } |
| 2311 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2312 | if (!p) |
| 2313 | return NULL; |
| 2314 | p->kind = AnnAssign_kind; |
| 2315 | p->v.AnnAssign.target = target; |
| 2316 | p->v.AnnAssign.annotation = annotation; |
| 2317 | p->v.AnnAssign.value = value; |
| 2318 | p->v.AnnAssign.simple = simple; |
| 2319 | p->lineno = lineno; |
| 2320 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2321 | p->end_lineno = end_lineno; |
| 2322 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2323 | return p; |
| 2324 | } |
| 2325 | |
| 2326 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2327 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2328 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2329 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2330 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2331 | stmt_ty p; |
| 2332 | if (!target) { |
| 2333 | PyErr_SetString(PyExc_ValueError, |
| 2334 | "field target is required for For"); |
| 2335 | return NULL; |
| 2336 | } |
| 2337 | if (!iter) { |
| 2338 | PyErr_SetString(PyExc_ValueError, |
| 2339 | "field iter is required for For"); |
| 2340 | return NULL; |
| 2341 | } |
| 2342 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2343 | if (!p) |
| 2344 | return NULL; |
| 2345 | p->kind = For_kind; |
| 2346 | p->v.For.target = target; |
| 2347 | p->v.For.iter = iter; |
| 2348 | p->v.For.body = body; |
| 2349 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2350 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2351 | p->lineno = lineno; |
| 2352 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2353 | p->end_lineno = end_lineno; |
| 2354 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2355 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2359 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2360 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2361 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2362 | { |
| 2363 | stmt_ty p; |
| 2364 | if (!target) { |
| 2365 | PyErr_SetString(PyExc_ValueError, |
| 2366 | "field target is required for AsyncFor"); |
| 2367 | return NULL; |
| 2368 | } |
| 2369 | if (!iter) { |
| 2370 | PyErr_SetString(PyExc_ValueError, |
| 2371 | "field iter is required for AsyncFor"); |
| 2372 | return NULL; |
| 2373 | } |
| 2374 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2375 | if (!p) |
| 2376 | return NULL; |
| 2377 | p->kind = AsyncFor_kind; |
| 2378 | p->v.AsyncFor.target = target; |
| 2379 | p->v.AsyncFor.iter = iter; |
| 2380 | p->v.AsyncFor.body = body; |
| 2381 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2382 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2383 | p->lineno = lineno; |
| 2384 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2385 | p->end_lineno = end_lineno; |
| 2386 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2387 | return p; |
| 2388 | } |
| 2389 | |
| 2390 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2391 | 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] | 2392 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2393 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2394 | stmt_ty p; |
| 2395 | if (!test) { |
| 2396 | PyErr_SetString(PyExc_ValueError, |
| 2397 | "field test is required for While"); |
| 2398 | return NULL; |
| 2399 | } |
| 2400 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2401 | if (!p) |
| 2402 | return NULL; |
| 2403 | p->kind = While_kind; |
| 2404 | p->v.While.test = test; |
| 2405 | p->v.While.body = body; |
| 2406 | p->v.While.orelse = orelse; |
| 2407 | p->lineno = lineno; |
| 2408 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2409 | p->end_lineno = end_lineno; |
| 2410 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2411 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2415 | 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] | 2416 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2417 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2418 | stmt_ty p; |
| 2419 | if (!test) { |
| 2420 | PyErr_SetString(PyExc_ValueError, |
| 2421 | "field test is required for If"); |
| 2422 | return NULL; |
| 2423 | } |
| 2424 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2425 | if (!p) |
| 2426 | return NULL; |
| 2427 | p->kind = If_kind; |
| 2428 | p->v.If.test = test; |
| 2429 | p->v.If.body = body; |
| 2430 | p->v.If.orelse = orelse; |
| 2431 | p->lineno = lineno; |
| 2432 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2433 | p->end_lineno = end_lineno; |
| 2434 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2435 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2439 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2440 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2441 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2442 | stmt_ty p; |
| 2443 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2444 | if (!p) |
| 2445 | return NULL; |
| 2446 | p->kind = With_kind; |
| 2447 | p->v.With.items = items; |
| 2448 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2449 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2450 | p->lineno = lineno; |
| 2451 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2452 | p->end_lineno = end_lineno; |
| 2453 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2454 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2458 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2459 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2460 | { |
| 2461 | stmt_ty p; |
| 2462 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2463 | if (!p) |
| 2464 | return NULL; |
| 2465 | p->kind = AsyncWith_kind; |
| 2466 | p->v.AsyncWith.items = items; |
| 2467 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2468 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2469 | p->lineno = lineno; |
| 2470 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2471 | p->end_lineno = end_lineno; |
| 2472 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2473 | return p; |
| 2474 | } |
| 2475 | |
| 2476 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2477 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2478 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2479 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2480 | stmt_ty p; |
| 2481 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2482 | if (!p) |
| 2483 | return NULL; |
| 2484 | p->kind = Raise_kind; |
| 2485 | p->v.Raise.exc = exc; |
| 2486 | p->v.Raise.cause = cause; |
| 2487 | p->lineno = lineno; |
| 2488 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2489 | p->end_lineno = end_lineno; |
| 2490 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2491 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2495 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2496 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2497 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2498 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2499 | stmt_ty p; |
| 2500 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2501 | if (!p) |
| 2502 | return NULL; |
| 2503 | p->kind = Try_kind; |
| 2504 | p->v.Try.body = body; |
| 2505 | p->v.Try.handlers = handlers; |
| 2506 | p->v.Try.orelse = orelse; |
| 2507 | p->v.Try.finalbody = finalbody; |
| 2508 | p->lineno = lineno; |
| 2509 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2510 | p->end_lineno = end_lineno; |
| 2511 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2512 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2516 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2517 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2518 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2519 | stmt_ty p; |
| 2520 | if (!test) { |
| 2521 | PyErr_SetString(PyExc_ValueError, |
| 2522 | "field test is required for Assert"); |
| 2523 | return NULL; |
| 2524 | } |
| 2525 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2526 | if (!p) |
| 2527 | return NULL; |
| 2528 | p->kind = Assert_kind; |
| 2529 | p->v.Assert.test = test; |
| 2530 | p->v.Assert.msg = msg; |
| 2531 | p->lineno = lineno; |
| 2532 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2533 | p->end_lineno = end_lineno; |
| 2534 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2535 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2539 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2540 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2541 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2542 | stmt_ty p; |
| 2543 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2544 | if (!p) |
| 2545 | return NULL; |
| 2546 | p->kind = Import_kind; |
| 2547 | p->v.Import.names = names; |
| 2548 | p->lineno = lineno; |
| 2549 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2550 | p->end_lineno = end_lineno; |
| 2551 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2552 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2556 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2557 | col_offset, 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 | stmt_ty p; |
| 2560 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2561 | if (!p) |
| 2562 | return NULL; |
| 2563 | p->kind = ImportFrom_kind; |
| 2564 | p->v.ImportFrom.module = module; |
| 2565 | p->v.ImportFrom.names = names; |
| 2566 | p->v.ImportFrom.level = level; |
| 2567 | p->lineno = lineno; |
| 2568 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2569 | p->end_lineno = end_lineno; |
| 2570 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2571 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2575 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2576 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2577 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2578 | stmt_ty p; |
| 2579 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2580 | if (!p) |
| 2581 | return NULL; |
| 2582 | p->kind = Global_kind; |
| 2583 | p->v.Global.names = names; |
| 2584 | p->lineno = lineno; |
| 2585 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2586 | p->end_lineno = end_lineno; |
| 2587 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2588 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2592 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2593 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2594 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2595 | stmt_ty p; |
| 2596 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2597 | if (!p) |
| 2598 | return NULL; |
| 2599 | p->kind = Nonlocal_kind; |
| 2600 | p->v.Nonlocal.names = names; |
| 2601 | p->lineno = lineno; |
| 2602 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2603 | p->end_lineno = end_lineno; |
| 2604 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2605 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2609 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2610 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2611 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2612 | stmt_ty p; |
| 2613 | if (!value) { |
| 2614 | PyErr_SetString(PyExc_ValueError, |
| 2615 | "field value is required for Expr"); |
| 2616 | return NULL; |
| 2617 | } |
| 2618 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2619 | if (!p) |
| 2620 | return NULL; |
| 2621 | p->kind = Expr_kind; |
| 2622 | p->v.Expr.value = value; |
| 2623 | p->lineno = lineno; |
| 2624 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2625 | p->end_lineno = end_lineno; |
| 2626 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2627 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2631 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2632 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2633 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2634 | stmt_ty p; |
| 2635 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2636 | if (!p) |
| 2637 | return NULL; |
| 2638 | p->kind = Pass_kind; |
| 2639 | p->lineno = lineno; |
| 2640 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2641 | p->end_lineno = end_lineno; |
| 2642 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2643 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2647 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2648 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2649 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2650 | stmt_ty p; |
| 2651 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2652 | if (!p) |
| 2653 | return NULL; |
| 2654 | p->kind = Break_kind; |
| 2655 | p->lineno = lineno; |
| 2656 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2657 | p->end_lineno = end_lineno; |
| 2658 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2659 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2663 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2664 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2665 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2666 | stmt_ty p; |
| 2667 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2668 | if (!p) |
| 2669 | return NULL; |
| 2670 | p->kind = Continue_kind; |
| 2671 | p->lineno = lineno; |
| 2672 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2673 | p->end_lineno = end_lineno; |
| 2674 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2675 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2679 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2680 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2681 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2682 | expr_ty p; |
| 2683 | if (!op) { |
| 2684 | PyErr_SetString(PyExc_ValueError, |
| 2685 | "field op is required for BoolOp"); |
| 2686 | return NULL; |
| 2687 | } |
| 2688 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2689 | if (!p) |
| 2690 | return NULL; |
| 2691 | p->kind = BoolOp_kind; |
| 2692 | p->v.BoolOp.op = op; |
| 2693 | p->v.BoolOp.values = values; |
| 2694 | p->lineno = lineno; |
| 2695 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2696 | p->end_lineno = end_lineno; |
| 2697 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2698 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2702 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2703 | end_lineno, int end_col_offset, PyArena *arena) |
| 2704 | { |
| 2705 | expr_ty p; |
| 2706 | if (!target) { |
| 2707 | PyErr_SetString(PyExc_ValueError, |
| 2708 | "field target is required for NamedExpr"); |
| 2709 | return NULL; |
| 2710 | } |
| 2711 | if (!value) { |
| 2712 | PyErr_SetString(PyExc_ValueError, |
| 2713 | "field value is required for NamedExpr"); |
| 2714 | return NULL; |
| 2715 | } |
| 2716 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2717 | if (!p) |
| 2718 | return NULL; |
| 2719 | p->kind = NamedExpr_kind; |
| 2720 | p->v.NamedExpr.target = target; |
| 2721 | p->v.NamedExpr.value = value; |
| 2722 | p->lineno = lineno; |
| 2723 | p->col_offset = col_offset; |
| 2724 | p->end_lineno = end_lineno; |
| 2725 | p->end_col_offset = end_col_offset; |
| 2726 | return p; |
| 2727 | } |
| 2728 | |
| 2729 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2730 | 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] | 2731 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2732 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2733 | expr_ty p; |
| 2734 | if (!left) { |
| 2735 | PyErr_SetString(PyExc_ValueError, |
| 2736 | "field left is required for BinOp"); |
| 2737 | return NULL; |
| 2738 | } |
| 2739 | if (!op) { |
| 2740 | PyErr_SetString(PyExc_ValueError, |
| 2741 | "field op is required for BinOp"); |
| 2742 | return NULL; |
| 2743 | } |
| 2744 | if (!right) { |
| 2745 | PyErr_SetString(PyExc_ValueError, |
| 2746 | "field right is required for BinOp"); |
| 2747 | return NULL; |
| 2748 | } |
| 2749 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2750 | if (!p) |
| 2751 | return NULL; |
| 2752 | p->kind = BinOp_kind; |
| 2753 | p->v.BinOp.left = left; |
| 2754 | p->v.BinOp.op = op; |
| 2755 | p->v.BinOp.right = right; |
| 2756 | p->lineno = lineno; |
| 2757 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2758 | p->end_lineno = end_lineno; |
| 2759 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2760 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2764 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2765 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2766 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2767 | expr_ty p; |
| 2768 | if (!op) { |
| 2769 | PyErr_SetString(PyExc_ValueError, |
| 2770 | "field op is required for UnaryOp"); |
| 2771 | return NULL; |
| 2772 | } |
| 2773 | if (!operand) { |
| 2774 | PyErr_SetString(PyExc_ValueError, |
| 2775 | "field operand is required for UnaryOp"); |
| 2776 | return NULL; |
| 2777 | } |
| 2778 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2779 | if (!p) |
| 2780 | return NULL; |
| 2781 | p->kind = UnaryOp_kind; |
| 2782 | p->v.UnaryOp.op = op; |
| 2783 | p->v.UnaryOp.operand = operand; |
| 2784 | p->lineno = lineno; |
| 2785 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2786 | p->end_lineno = end_lineno; |
| 2787 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2788 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2792 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2793 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2794 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2795 | expr_ty p; |
| 2796 | if (!args) { |
| 2797 | PyErr_SetString(PyExc_ValueError, |
| 2798 | "field args is required for Lambda"); |
| 2799 | return NULL; |
| 2800 | } |
| 2801 | if (!body) { |
| 2802 | PyErr_SetString(PyExc_ValueError, |
| 2803 | "field body is required for Lambda"); |
| 2804 | return NULL; |
| 2805 | } |
| 2806 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2807 | if (!p) |
| 2808 | return NULL; |
| 2809 | p->kind = Lambda_kind; |
| 2810 | p->v.Lambda.args = args; |
| 2811 | p->v.Lambda.body = body; |
| 2812 | p->lineno = lineno; |
| 2813 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2814 | p->end_lineno = end_lineno; |
| 2815 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2816 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2820 | 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] | 2821 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2822 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2823 | expr_ty p; |
| 2824 | if (!test) { |
| 2825 | PyErr_SetString(PyExc_ValueError, |
| 2826 | "field test is required for IfExp"); |
| 2827 | return NULL; |
| 2828 | } |
| 2829 | if (!body) { |
| 2830 | PyErr_SetString(PyExc_ValueError, |
| 2831 | "field body is required for IfExp"); |
| 2832 | return NULL; |
| 2833 | } |
| 2834 | if (!orelse) { |
| 2835 | PyErr_SetString(PyExc_ValueError, |
| 2836 | "field orelse is required for IfExp"); |
| 2837 | return NULL; |
| 2838 | } |
| 2839 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2840 | if (!p) |
| 2841 | return NULL; |
| 2842 | p->kind = IfExp_kind; |
| 2843 | p->v.IfExp.test = test; |
| 2844 | p->v.IfExp.body = body; |
| 2845 | p->v.IfExp.orelse = orelse; |
| 2846 | p->lineno = lineno; |
| 2847 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2848 | p->end_lineno = end_lineno; |
| 2849 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2850 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2854 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2855 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2856 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2857 | expr_ty p; |
| 2858 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2859 | if (!p) |
| 2860 | return NULL; |
| 2861 | p->kind = Dict_kind; |
| 2862 | p->v.Dict.keys = keys; |
| 2863 | p->v.Dict.values = values; |
| 2864 | p->lineno = lineno; |
| 2865 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2866 | p->end_lineno = end_lineno; |
| 2867 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2868 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2872 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2873 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2874 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2875 | expr_ty p; |
| 2876 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2877 | if (!p) |
| 2878 | return NULL; |
| 2879 | p->kind = Set_kind; |
| 2880 | p->v.Set.elts = elts; |
| 2881 | p->lineno = lineno; |
| 2882 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2883 | p->end_lineno = end_lineno; |
| 2884 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2885 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2889 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2890 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2891 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2892 | expr_ty p; |
| 2893 | if (!elt) { |
| 2894 | PyErr_SetString(PyExc_ValueError, |
| 2895 | "field elt is required for ListComp"); |
| 2896 | return NULL; |
| 2897 | } |
| 2898 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2899 | if (!p) |
| 2900 | return NULL; |
| 2901 | p->kind = ListComp_kind; |
| 2902 | p->v.ListComp.elt = elt; |
| 2903 | p->v.ListComp.generators = generators; |
| 2904 | p->lineno = lineno; |
| 2905 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2906 | p->end_lineno = end_lineno; |
| 2907 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2908 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2912 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2913 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2914 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2915 | expr_ty p; |
| 2916 | if (!elt) { |
| 2917 | PyErr_SetString(PyExc_ValueError, |
| 2918 | "field elt is required for SetComp"); |
| 2919 | return NULL; |
| 2920 | } |
| 2921 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2922 | if (!p) |
| 2923 | return NULL; |
| 2924 | p->kind = SetComp_kind; |
| 2925 | p->v.SetComp.elt = elt; |
| 2926 | p->v.SetComp.generators = generators; |
| 2927 | p->lineno = lineno; |
| 2928 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2929 | p->end_lineno = end_lineno; |
| 2930 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2931 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2935 | 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] | 2936 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2937 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2938 | expr_ty p; |
| 2939 | if (!key) { |
| 2940 | PyErr_SetString(PyExc_ValueError, |
| 2941 | "field key is required for DictComp"); |
| 2942 | return NULL; |
| 2943 | } |
| 2944 | if (!value) { |
| 2945 | PyErr_SetString(PyExc_ValueError, |
| 2946 | "field value is required for DictComp"); |
| 2947 | return NULL; |
| 2948 | } |
| 2949 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2950 | if (!p) |
| 2951 | return NULL; |
| 2952 | p->kind = DictComp_kind; |
| 2953 | p->v.DictComp.key = key; |
| 2954 | p->v.DictComp.value = value; |
| 2955 | p->v.DictComp.generators = generators; |
| 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; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2960 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2964 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2965 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2966 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2967 | expr_ty p; |
| 2968 | if (!elt) { |
| 2969 | PyErr_SetString(PyExc_ValueError, |
| 2970 | "field elt is required for GeneratorExp"); |
| 2971 | return NULL; |
| 2972 | } |
| 2973 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2974 | if (!p) |
| 2975 | return NULL; |
| 2976 | p->kind = GeneratorExp_kind; |
| 2977 | p->v.GeneratorExp.elt = elt; |
| 2978 | p->v.GeneratorExp.generators = generators; |
| 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 | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2983 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2987 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2988 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2989 | { |
| 2990 | expr_ty p; |
| 2991 | if (!value) { |
| 2992 | PyErr_SetString(PyExc_ValueError, |
| 2993 | "field value is required for Await"); |
| 2994 | return NULL; |
| 2995 | } |
| 2996 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2997 | if (!p) |
| 2998 | return NULL; |
| 2999 | p->kind = Await_kind; |
| 3000 | p->v.Await.value = value; |
| 3001 | p->lineno = lineno; |
| 3002 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3003 | p->end_lineno = end_lineno; |
| 3004 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3005 | return p; |
| 3006 | } |
| 3007 | |
| 3008 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3009 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3010 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3011 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3012 | expr_ty p; |
| 3013 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3014 | if (!p) |
| 3015 | return NULL; |
| 3016 | p->kind = Yield_kind; |
| 3017 | p->v.Yield.value = value; |
| 3018 | p->lineno = lineno; |
| 3019 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3020 | p->end_lineno = end_lineno; |
| 3021 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3022 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3026 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3027 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3028 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3029 | expr_ty p; |
| 3030 | if (!value) { |
| 3031 | PyErr_SetString(PyExc_ValueError, |
| 3032 | "field value is required for YieldFrom"); |
| 3033 | return NULL; |
| 3034 | } |
| 3035 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3036 | if (!p) |
| 3037 | return NULL; |
| 3038 | p->kind = YieldFrom_kind; |
| 3039 | p->v.YieldFrom.value = value; |
| 3040 | p->lineno = lineno; |
| 3041 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3042 | p->end_lineno = end_lineno; |
| 3043 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3044 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3048 | 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] | 3049 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3050 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3051 | expr_ty p; |
| 3052 | if (!left) { |
| 3053 | PyErr_SetString(PyExc_ValueError, |
| 3054 | "field left is required for Compare"); |
| 3055 | return NULL; |
| 3056 | } |
| 3057 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3058 | if (!p) |
| 3059 | return NULL; |
| 3060 | p->kind = Compare_kind; |
| 3061 | p->v.Compare.left = left; |
| 3062 | p->v.Compare.ops = ops; |
| 3063 | p->v.Compare.comparators = comparators; |
| 3064 | p->lineno = lineno; |
| 3065 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3066 | p->end_lineno = end_lineno; |
| 3067 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3068 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 3072 | 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] | 3073 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3074 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3075 | expr_ty p; |
| 3076 | if (!func) { |
| 3077 | PyErr_SetString(PyExc_ValueError, |
| 3078 | "field func is required for Call"); |
| 3079 | return NULL; |
| 3080 | } |
| 3081 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3082 | if (!p) |
| 3083 | return NULL; |
| 3084 | p->kind = Call_kind; |
| 3085 | p->v.Call.func = func; |
| 3086 | p->v.Call.args = args; |
| 3087 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3088 | p->lineno = lineno; |
| 3089 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3090 | p->end_lineno = end_lineno; |
| 3091 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3092 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 3096 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 3097 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 3098 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3099 | { |
| 3100 | expr_ty p; |
| 3101 | if (!value) { |
| 3102 | PyErr_SetString(PyExc_ValueError, |
| 3103 | "field value is required for FormattedValue"); |
| 3104 | return NULL; |
| 3105 | } |
| 3106 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3107 | if (!p) |
| 3108 | return NULL; |
| 3109 | p->kind = FormattedValue_kind; |
| 3110 | p->v.FormattedValue.value = value; |
| 3111 | p->v.FormattedValue.conversion = conversion; |
| 3112 | p->v.FormattedValue.format_spec = format_spec; |
| 3113 | p->lineno = lineno; |
| 3114 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3115 | p->end_lineno = end_lineno; |
| 3116 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3117 | return p; |
| 3118 | } |
| 3119 | |
| 3120 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3121 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 3122 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3123 | { |
| 3124 | expr_ty p; |
| 3125 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3126 | if (!p) |
| 3127 | return NULL; |
| 3128 | p->kind = JoinedStr_kind; |
| 3129 | p->v.JoinedStr.values = values; |
| 3130 | p->lineno = lineno; |
| 3131 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3132 | p->end_lineno = end_lineno; |
| 3133 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3134 | return p; |
| 3135 | } |
| 3136 | |
| 3137 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3138 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 3139 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3140 | { |
| 3141 | expr_ty p; |
| 3142 | if (!value) { |
| 3143 | PyErr_SetString(PyExc_ValueError, |
| 3144 | "field value is required for Constant"); |
| 3145 | return NULL; |
| 3146 | } |
| 3147 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3148 | if (!p) |
| 3149 | return NULL; |
| 3150 | p->kind = Constant_kind; |
| 3151 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3152 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3153 | p->lineno = lineno; |
| 3154 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3155 | p->end_lineno = end_lineno; |
| 3156 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3157 | return p; |
| 3158 | } |
| 3159 | |
| 3160 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3161 | 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] | 3162 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3163 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3164 | expr_ty p; |
| 3165 | if (!value) { |
| 3166 | PyErr_SetString(PyExc_ValueError, |
| 3167 | "field value is required for Attribute"); |
| 3168 | return NULL; |
| 3169 | } |
| 3170 | if (!attr) { |
| 3171 | PyErr_SetString(PyExc_ValueError, |
| 3172 | "field attr is required for Attribute"); |
| 3173 | return NULL; |
| 3174 | } |
| 3175 | if (!ctx) { |
| 3176 | PyErr_SetString(PyExc_ValueError, |
| 3177 | "field ctx is required for Attribute"); |
| 3178 | return NULL; |
| 3179 | } |
| 3180 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3181 | if (!p) |
| 3182 | return NULL; |
| 3183 | p->kind = Attribute_kind; |
| 3184 | p->v.Attribute.value = value; |
| 3185 | p->v.Attribute.attr = attr; |
| 3186 | p->v.Attribute.ctx = ctx; |
| 3187 | p->lineno = lineno; |
| 3188 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3189 | p->end_lineno = end_lineno; |
| 3190 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3191 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | expr_ty |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3195 | Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3196 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3197 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3198 | expr_ty p; |
| 3199 | if (!value) { |
| 3200 | PyErr_SetString(PyExc_ValueError, |
| 3201 | "field value is required for Subscript"); |
| 3202 | return NULL; |
| 3203 | } |
| 3204 | if (!slice) { |
| 3205 | PyErr_SetString(PyExc_ValueError, |
| 3206 | "field slice is required for Subscript"); |
| 3207 | return NULL; |
| 3208 | } |
| 3209 | if (!ctx) { |
| 3210 | PyErr_SetString(PyExc_ValueError, |
| 3211 | "field ctx is required for Subscript"); |
| 3212 | return NULL; |
| 3213 | } |
| 3214 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3215 | if (!p) |
| 3216 | return NULL; |
| 3217 | p->kind = Subscript_kind; |
| 3218 | p->v.Subscript.value = value; |
| 3219 | p->v.Subscript.slice = slice; |
| 3220 | p->v.Subscript.ctx = ctx; |
| 3221 | p->lineno = lineno; |
| 3222 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3223 | p->end_lineno = end_lineno; |
| 3224 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3225 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3229 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3230 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3231 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3232 | expr_ty p; |
| 3233 | if (!value) { |
| 3234 | PyErr_SetString(PyExc_ValueError, |
| 3235 | "field value is required for Starred"); |
| 3236 | return NULL; |
| 3237 | } |
| 3238 | if (!ctx) { |
| 3239 | PyErr_SetString(PyExc_ValueError, |
| 3240 | "field ctx is required for Starred"); |
| 3241 | return NULL; |
| 3242 | } |
| 3243 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3244 | if (!p) |
| 3245 | return NULL; |
| 3246 | p->kind = Starred_kind; |
| 3247 | p->v.Starred.value = value; |
| 3248 | p->v.Starred.ctx = ctx; |
| 3249 | p->lineno = lineno; |
| 3250 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3251 | p->end_lineno = end_lineno; |
| 3252 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3253 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3257 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3258 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3259 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3260 | expr_ty p; |
| 3261 | if (!id) { |
| 3262 | PyErr_SetString(PyExc_ValueError, |
| 3263 | "field id is required for Name"); |
| 3264 | return NULL; |
| 3265 | } |
| 3266 | if (!ctx) { |
| 3267 | PyErr_SetString(PyExc_ValueError, |
| 3268 | "field ctx is required for Name"); |
| 3269 | return NULL; |
| 3270 | } |
| 3271 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3272 | if (!p) |
| 3273 | return NULL; |
| 3274 | p->kind = Name_kind; |
| 3275 | p->v.Name.id = id; |
| 3276 | p->v.Name.ctx = ctx; |
| 3277 | p->lineno = lineno; |
| 3278 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3279 | p->end_lineno = end_lineno; |
| 3280 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3281 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3285 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3286 | end_lineno, int end_col_offset, 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 | expr_ty p; |
| 3289 | if (!ctx) { |
| 3290 | PyErr_SetString(PyExc_ValueError, |
| 3291 | "field ctx is required for List"); |
| 3292 | return NULL; |
| 3293 | } |
| 3294 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3295 | if (!p) |
| 3296 | return NULL; |
| 3297 | p->kind = List_kind; |
| 3298 | p->v.List.elts = elts; |
| 3299 | p->v.List.ctx = ctx; |
| 3300 | p->lineno = lineno; |
| 3301 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3302 | p->end_lineno = end_lineno; |
| 3303 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3304 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3308 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3309 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3310 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3311 | expr_ty p; |
| 3312 | if (!ctx) { |
| 3313 | PyErr_SetString(PyExc_ValueError, |
| 3314 | "field ctx is required for Tuple"); |
| 3315 | return NULL; |
| 3316 | } |
| 3317 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3318 | if (!p) |
| 3319 | return NULL; |
| 3320 | p->kind = Tuple_kind; |
| 3321 | p->v.Tuple.elts = elts; |
| 3322 | p->v.Tuple.ctx = ctx; |
| 3323 | p->lineno = lineno; |
| 3324 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3325 | p->end_lineno = end_lineno; |
| 3326 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3327 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3330 | expr_ty |
| 3331 | Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset, |
| 3332 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3333 | { |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3334 | expr_ty p; |
| 3335 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3336 | if (!p) |
| 3337 | return NULL; |
| 3338 | p->kind = Slice_kind; |
| 3339 | p->v.Slice.lower = lower; |
| 3340 | p->v.Slice.upper = upper; |
| 3341 | p->v.Slice.step = step; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3342 | p->lineno = lineno; |
| 3343 | p->col_offset = col_offset; |
| 3344 | p->end_lineno = end_lineno; |
| 3345 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3346 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3350 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3351 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3352 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3353 | comprehension_ty p; |
| 3354 | if (!target) { |
| 3355 | PyErr_SetString(PyExc_ValueError, |
| 3356 | "field target is required for comprehension"); |
| 3357 | return NULL; |
| 3358 | } |
| 3359 | if (!iter) { |
| 3360 | PyErr_SetString(PyExc_ValueError, |
| 3361 | "field iter is required for comprehension"); |
| 3362 | return NULL; |
| 3363 | } |
| 3364 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3365 | if (!p) |
| 3366 | return NULL; |
| 3367 | p->target = target; |
| 3368 | p->iter = iter; |
| 3369 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3370 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3371 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3375 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3376 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3377 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3378 | excepthandler_ty p; |
| 3379 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3380 | if (!p) |
| 3381 | return NULL; |
| 3382 | p->kind = ExceptHandler_kind; |
| 3383 | p->v.ExceptHandler.type = type; |
| 3384 | p->v.ExceptHandler.name = name; |
| 3385 | p->v.ExceptHandler.body = body; |
| 3386 | p->lineno = lineno; |
| 3387 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3388 | p->end_lineno = end_lineno; |
| 3389 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3390 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3394 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3395 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3396 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3397 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3398 | arguments_ty p; |
| 3399 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3400 | if (!p) |
| 3401 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3402 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3403 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3404 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3405 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3406 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3407 | p->kwarg = kwarg; |
| 3408 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3409 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3412 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3413 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3414 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3415 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3416 | arg_ty p; |
| 3417 | if (!arg) { |
| 3418 | PyErr_SetString(PyExc_ValueError, |
| 3419 | "field arg is required for arg"); |
| 3420 | return NULL; |
| 3421 | } |
| 3422 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3423 | if (!p) |
| 3424 | return NULL; |
| 3425 | p->arg = arg; |
| 3426 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3427 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3428 | p->lineno = lineno; |
| 3429 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3430 | p->end_lineno = end_lineno; |
| 3431 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3432 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3433 | } |
| 3434 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3435 | keyword_ty |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 3436 | keyword(identifier arg, expr_ty value, int lineno, int col_offset, int |
| 3437 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3438 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3439 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3440 | if (!value) { |
| 3441 | PyErr_SetString(PyExc_ValueError, |
| 3442 | "field value is required for keyword"); |
| 3443 | return NULL; |
| 3444 | } |
| 3445 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3446 | if (!p) |
| 3447 | return NULL; |
| 3448 | p->arg = arg; |
| 3449 | p->value = value; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 3450 | p->lineno = lineno; |
| 3451 | p->col_offset = col_offset; |
| 3452 | p->end_lineno = end_lineno; |
| 3453 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3454 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3458 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3459 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3460 | alias_ty p; |
| 3461 | if (!name) { |
| 3462 | PyErr_SetString(PyExc_ValueError, |
| 3463 | "field name is required for alias"); |
| 3464 | return NULL; |
| 3465 | } |
| 3466 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3467 | if (!p) |
| 3468 | return NULL; |
| 3469 | p->name = name; |
| 3470 | p->asname = asname; |
| 3471 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3474 | withitem_ty |
| 3475 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3476 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3477 | withitem_ty p; |
| 3478 | if (!context_expr) { |
| 3479 | PyErr_SetString(PyExc_ValueError, |
| 3480 | "field context_expr is required for withitem"); |
| 3481 | return NULL; |
| 3482 | } |
| 3483 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3484 | if (!p) |
| 3485 | return NULL; |
| 3486 | p->context_expr = context_expr; |
| 3487 | p->optional_vars = optional_vars; |
| 3488 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3489 | } |
| 3490 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3491 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3492 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3493 | { |
| 3494 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3495 | if (!tag) { |
| 3496 | PyErr_SetString(PyExc_ValueError, |
| 3497 | "field tag is required for TypeIgnore"); |
| 3498 | return NULL; |
| 3499 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3500 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3501 | if (!p) |
| 3502 | return NULL; |
| 3503 | p->kind = TypeIgnore_kind; |
| 3504 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3505 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3506 | return p; |
| 3507 | } |
| 3508 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3509 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3510 | PyObject* |
| 3511 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3512 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3513 | mod_ty o = (mod_ty)_o; |
| 3514 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3515 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3516 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3517 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3518 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3519 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3520 | switch (o->kind) { |
| 3521 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3522 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3523 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3524 | if (!result) goto failed; |
| 3525 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3526 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3527 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3528 | goto failed; |
| 3529 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3530 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3531 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3532 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3533 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3534 | goto failed; |
| 3535 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3536 | break; |
| 3537 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3538 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3539 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3540 | if (!result) goto failed; |
| 3541 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3542 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3543 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3544 | goto failed; |
| 3545 | Py_DECREF(value); |
| 3546 | break; |
| 3547 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3548 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3549 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3550 | if (!result) goto failed; |
| 3551 | value = ast2obj_expr(o->v.Expression.body); |
| 3552 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3553 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3554 | goto failed; |
| 3555 | Py_DECREF(value); |
| 3556 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3557 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3558 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3559 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3560 | if (!result) goto failed; |
| 3561 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3562 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3563 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3564 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3565 | goto failed; |
| 3566 | Py_DECREF(value); |
| 3567 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3568 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3569 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3570 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3571 | goto failed; |
| 3572 | Py_DECREF(value); |
| 3573 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3574 | } |
| 3575 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3576 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3577 | Py_XDECREF(value); |
| 3578 | Py_XDECREF(result); |
| 3579 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3580 | } |
| 3581 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3582 | PyObject* |
| 3583 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3584 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3585 | stmt_ty o = (stmt_ty)_o; |
| 3586 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3587 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3588 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3589 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3590 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3591 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3592 | switch (o->kind) { |
| 3593 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3594 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3595 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3596 | if (!result) goto failed; |
| 3597 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3598 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3599 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3600 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3601 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3602 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3603 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3604 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3605 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3606 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3607 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3608 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3609 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3610 | goto failed; |
| 3611 | Py_DECREF(value); |
| 3612 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3613 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3614 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3615 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3616 | goto failed; |
| 3617 | Py_DECREF(value); |
| 3618 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3619 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3620 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3621 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3622 | goto failed; |
| 3623 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3624 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3625 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3626 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3627 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3628 | goto failed; |
| 3629 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3630 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3631 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3632 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3633 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3634 | if (!result) goto failed; |
| 3635 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3636 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3637 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3638 | goto failed; |
| 3639 | Py_DECREF(value); |
| 3640 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3641 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3642 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3643 | goto failed; |
| 3644 | Py_DECREF(value); |
| 3645 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3646 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3647 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3648 | goto failed; |
| 3649 | Py_DECREF(value); |
| 3650 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3651 | ast2obj_expr); |
| 3652 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3653 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3654 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3655 | goto failed; |
| 3656 | Py_DECREF(value); |
| 3657 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3658 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3659 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3660 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3661 | goto failed; |
| 3662 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3663 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3664 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3665 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3666 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3667 | goto failed; |
| 3668 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3669 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3670 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3671 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3672 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3673 | if (!result) goto failed; |
| 3674 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3675 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3676 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3677 | goto failed; |
| 3678 | Py_DECREF(value); |
| 3679 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3680 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3681 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3682 | goto failed; |
| 3683 | Py_DECREF(value); |
| 3684 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3685 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3686 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3687 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3688 | goto failed; |
| 3689 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3690 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3691 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3692 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3693 | goto failed; |
| 3694 | Py_DECREF(value); |
| 3695 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3696 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3697 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3698 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3699 | goto failed; |
| 3700 | Py_DECREF(value); |
| 3701 | break; |
| 3702 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3703 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3704 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3705 | if (!result) goto failed; |
| 3706 | value = ast2obj_expr(o->v.Return.value); |
| 3707 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3708 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3709 | goto failed; |
| 3710 | Py_DECREF(value); |
| 3711 | break; |
| 3712 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3713 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3714 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3715 | if (!result) goto failed; |
| 3716 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3717 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3718 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3719 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3720 | goto failed; |
| 3721 | Py_DECREF(value); |
| 3722 | break; |
| 3723 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3724 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3725 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3726 | if (!result) goto failed; |
| 3727 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3728 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3729 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3730 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3731 | goto failed; |
| 3732 | Py_DECREF(value); |
| 3733 | value = ast2obj_expr(o->v.Assign.value); |
| 3734 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3735 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3736 | goto failed; |
| 3737 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3738 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3739 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3740 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3741 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3742 | goto failed; |
| 3743 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3744 | break; |
| 3745 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3746 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3747 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3748 | if (!result) goto failed; |
| 3749 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3750 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3751 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3752 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3753 | goto failed; |
| 3754 | Py_DECREF(value); |
| 3755 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3756 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3757 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3758 | goto failed; |
| 3759 | Py_DECREF(value); |
| 3760 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3761 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3762 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3763 | goto failed; |
| 3764 | Py_DECREF(value); |
| 3765 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3766 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3767 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3768 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3769 | if (!result) goto failed; |
| 3770 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3771 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3772 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3773 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3774 | goto failed; |
| 3775 | Py_DECREF(value); |
| 3776 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3777 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3778 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3779 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3780 | goto failed; |
| 3781 | Py_DECREF(value); |
| 3782 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3783 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3784 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3785 | goto failed; |
| 3786 | Py_DECREF(value); |
| 3787 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3788 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3789 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3790 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3791 | goto failed; |
| 3792 | Py_DECREF(value); |
| 3793 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3794 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3795 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3796 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3797 | if (!result) goto failed; |
| 3798 | value = ast2obj_expr(o->v.For.target); |
| 3799 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3800 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3801 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3802 | goto failed; |
| 3803 | Py_DECREF(value); |
| 3804 | value = ast2obj_expr(o->v.For.iter); |
| 3805 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3806 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3807 | goto failed; |
| 3808 | Py_DECREF(value); |
| 3809 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3810 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3811 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3812 | goto failed; |
| 3813 | Py_DECREF(value); |
| 3814 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3815 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3816 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3817 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3818 | goto failed; |
| 3819 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3820 | value = ast2obj_string(o->v.For.type_comment); |
| 3821 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3822 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3823 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3824 | goto failed; |
| 3825 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3826 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3827 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3828 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3829 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3830 | if (!result) goto failed; |
| 3831 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3832 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3833 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3834 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3835 | goto failed; |
| 3836 | Py_DECREF(value); |
| 3837 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3838 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3839 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3840 | goto failed; |
| 3841 | Py_DECREF(value); |
| 3842 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3843 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3844 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3845 | goto failed; |
| 3846 | Py_DECREF(value); |
| 3847 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3848 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3849 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3850 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3851 | goto failed; |
| 3852 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3853 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3854 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3855 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3856 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3857 | goto failed; |
| 3858 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3859 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3860 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3861 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3862 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3863 | if (!result) goto failed; |
| 3864 | value = ast2obj_expr(o->v.While.test); |
| 3865 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3866 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3867 | goto failed; |
| 3868 | Py_DECREF(value); |
| 3869 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3870 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3871 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3872 | goto failed; |
| 3873 | Py_DECREF(value); |
| 3874 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3875 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3876 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3877 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3878 | goto failed; |
| 3879 | Py_DECREF(value); |
| 3880 | break; |
| 3881 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3882 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3883 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3884 | if (!result) goto failed; |
| 3885 | value = ast2obj_expr(o->v.If.test); |
| 3886 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3887 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3888 | goto failed; |
| 3889 | Py_DECREF(value); |
| 3890 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3891 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3892 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3893 | goto failed; |
| 3894 | Py_DECREF(value); |
| 3895 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3896 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3897 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3898 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3899 | goto failed; |
| 3900 | Py_DECREF(value); |
| 3901 | break; |
| 3902 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3903 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3904 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3905 | if (!result) goto failed; |
| 3906 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3907 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3908 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3909 | goto failed; |
| 3910 | Py_DECREF(value); |
| 3911 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3912 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3913 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3914 | goto failed; |
| 3915 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3916 | value = ast2obj_string(o->v.With.type_comment); |
| 3917 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3918 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3919 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3920 | goto failed; |
| 3921 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3922 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3923 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3924 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3925 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3926 | if (!result) goto failed; |
| 3927 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3928 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3929 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3930 | goto failed; |
| 3931 | Py_DECREF(value); |
| 3932 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3933 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3934 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3935 | goto failed; |
| 3936 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3937 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3938 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3939 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3940 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3941 | goto failed; |
| 3942 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3943 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3944 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3945 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3946 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3947 | if (!result) goto failed; |
| 3948 | value = ast2obj_expr(o->v.Raise.exc); |
| 3949 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3950 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3951 | goto failed; |
| 3952 | Py_DECREF(value); |
| 3953 | value = ast2obj_expr(o->v.Raise.cause); |
| 3954 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3955 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3956 | goto failed; |
| 3957 | Py_DECREF(value); |
| 3958 | break; |
| 3959 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3960 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3961 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3962 | if (!result) goto failed; |
| 3963 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3964 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3965 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3966 | goto failed; |
| 3967 | Py_DECREF(value); |
| 3968 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3969 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3970 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3971 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3972 | goto failed; |
| 3973 | Py_DECREF(value); |
| 3974 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3975 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3976 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3977 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3978 | goto failed; |
| 3979 | Py_DECREF(value); |
| 3980 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3981 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3982 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3983 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3984 | goto failed; |
| 3985 | Py_DECREF(value); |
| 3986 | break; |
| 3987 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3988 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3989 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3990 | if (!result) goto failed; |
| 3991 | value = ast2obj_expr(o->v.Assert.test); |
| 3992 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3993 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3994 | goto failed; |
| 3995 | Py_DECREF(value); |
| 3996 | value = ast2obj_expr(o->v.Assert.msg); |
| 3997 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3998 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3999 | goto failed; |
| 4000 | Py_DECREF(value); |
| 4001 | break; |
| 4002 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4003 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 4004 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4005 | if (!result) goto failed; |
| 4006 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 4007 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4008 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4009 | goto failed; |
| 4010 | Py_DECREF(value); |
| 4011 | break; |
| 4012 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4013 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 4014 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4015 | if (!result) goto failed; |
| 4016 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 4017 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4018 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 4019 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4020 | goto failed; |
| 4021 | Py_DECREF(value); |
| 4022 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 4023 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4024 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4025 | goto failed; |
| 4026 | Py_DECREF(value); |
| 4027 | value = ast2obj_int(o->v.ImportFrom.level); |
| 4028 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4029 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4030 | goto failed; |
| 4031 | Py_DECREF(value); |
| 4032 | break; |
| 4033 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4034 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 4035 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4036 | if (!result) goto failed; |
| 4037 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 4038 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4039 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4040 | goto failed; |
| 4041 | Py_DECREF(value); |
| 4042 | break; |
| 4043 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4044 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 4045 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4046 | if (!result) goto failed; |
| 4047 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 4048 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4049 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4050 | goto failed; |
| 4051 | Py_DECREF(value); |
| 4052 | break; |
| 4053 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4054 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 4055 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4056 | if (!result) goto failed; |
| 4057 | value = ast2obj_expr(o->v.Expr.value); |
| 4058 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4059 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4060 | goto failed; |
| 4061 | Py_DECREF(value); |
| 4062 | break; |
| 4063 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4064 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 4065 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4066 | if (!result) goto failed; |
| 4067 | break; |
| 4068 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4069 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 4070 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4071 | if (!result) goto failed; |
| 4072 | break; |
| 4073 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4074 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 4075 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4076 | if (!result) goto failed; |
| 4077 | break; |
| 4078 | } |
| 4079 | value = ast2obj_int(o->lineno); |
| 4080 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4081 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4082 | goto failed; |
| 4083 | Py_DECREF(value); |
| 4084 | value = ast2obj_int(o->col_offset); |
| 4085 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4086 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4087 | goto failed; |
| 4088 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4089 | value = ast2obj_int(o->end_lineno); |
| 4090 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4091 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4092 | goto failed; |
| 4093 | Py_DECREF(value); |
| 4094 | value = ast2obj_int(o->end_col_offset); |
| 4095 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4096 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4097 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4098 | goto failed; |
| 4099 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4100 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4101 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4102 | Py_XDECREF(value); |
| 4103 | Py_XDECREF(result); |
| 4104 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4107 | PyObject* |
| 4108 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4109 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4110 | expr_ty o = (expr_ty)_o; |
| 4111 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4112 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4113 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4114 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4115 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4116 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4117 | switch (o->kind) { |
| 4118 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4119 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 4120 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4121 | if (!result) goto failed; |
| 4122 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 4123 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4124 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4125 | goto failed; |
| 4126 | Py_DECREF(value); |
| 4127 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 4128 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4129 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4130 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4131 | goto failed; |
| 4132 | Py_DECREF(value); |
| 4133 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4134 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4135 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 4136 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4137 | if (!result) goto failed; |
| 4138 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 4139 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4140 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 4141 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4142 | goto failed; |
| 4143 | Py_DECREF(value); |
| 4144 | value = ast2obj_expr(o->v.NamedExpr.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) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4147 | goto failed; |
| 4148 | Py_DECREF(value); |
| 4149 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4150 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4151 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4152 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4153 | if (!result) goto failed; |
| 4154 | value = ast2obj_expr(o->v.BinOp.left); |
| 4155 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4156 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4157 | goto failed; |
| 4158 | Py_DECREF(value); |
| 4159 | value = ast2obj_operator(o->v.BinOp.op); |
| 4160 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4161 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4162 | goto failed; |
| 4163 | Py_DECREF(value); |
| 4164 | value = ast2obj_expr(o->v.BinOp.right); |
| 4165 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4166 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4167 | goto failed; |
| 4168 | Py_DECREF(value); |
| 4169 | break; |
| 4170 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4171 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4172 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4173 | if (!result) goto failed; |
| 4174 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4175 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4176 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4177 | goto failed; |
| 4178 | Py_DECREF(value); |
| 4179 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4180 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4181 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4182 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4183 | goto failed; |
| 4184 | Py_DECREF(value); |
| 4185 | break; |
| 4186 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4187 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4188 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4189 | if (!result) goto failed; |
| 4190 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4191 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4192 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4193 | goto failed; |
| 4194 | Py_DECREF(value); |
| 4195 | value = ast2obj_expr(o->v.Lambda.body); |
| 4196 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4197 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4198 | goto failed; |
| 4199 | Py_DECREF(value); |
| 4200 | break; |
| 4201 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4202 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4203 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4204 | if (!result) goto failed; |
| 4205 | value = ast2obj_expr(o->v.IfExp.test); |
| 4206 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4207 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4208 | goto failed; |
| 4209 | Py_DECREF(value); |
| 4210 | value = ast2obj_expr(o->v.IfExp.body); |
| 4211 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4212 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4213 | goto failed; |
| 4214 | Py_DECREF(value); |
| 4215 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4216 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4217 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4218 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4219 | goto failed; |
| 4220 | Py_DECREF(value); |
| 4221 | break; |
| 4222 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4223 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4224 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4225 | if (!result) goto failed; |
| 4226 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4227 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4228 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4229 | goto failed; |
| 4230 | Py_DECREF(value); |
| 4231 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4232 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4233 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4234 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4235 | goto failed; |
| 4236 | Py_DECREF(value); |
| 4237 | break; |
| 4238 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4239 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4240 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4241 | if (!result) goto failed; |
| 4242 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4243 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4244 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4245 | goto failed; |
| 4246 | Py_DECREF(value); |
| 4247 | break; |
| 4248 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4249 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4250 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4251 | if (!result) goto failed; |
| 4252 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4253 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4254 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4255 | goto failed; |
| 4256 | Py_DECREF(value); |
| 4257 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4258 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4259 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4260 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4261 | goto failed; |
| 4262 | Py_DECREF(value); |
| 4263 | break; |
| 4264 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4265 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4266 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4267 | if (!result) goto failed; |
| 4268 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4269 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4270 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4271 | goto failed; |
| 4272 | Py_DECREF(value); |
| 4273 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4274 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4275 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4276 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4277 | goto failed; |
| 4278 | Py_DECREF(value); |
| 4279 | break; |
| 4280 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4281 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4282 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4283 | if (!result) goto failed; |
| 4284 | value = ast2obj_expr(o->v.DictComp.key); |
| 4285 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4286 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4287 | goto failed; |
| 4288 | Py_DECREF(value); |
| 4289 | value = ast2obj_expr(o->v.DictComp.value); |
| 4290 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4291 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4292 | goto failed; |
| 4293 | Py_DECREF(value); |
| 4294 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4295 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4296 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4297 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4298 | goto failed; |
| 4299 | Py_DECREF(value); |
| 4300 | break; |
| 4301 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4302 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4303 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4304 | if (!result) goto failed; |
| 4305 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4306 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4307 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4308 | goto failed; |
| 4309 | Py_DECREF(value); |
| 4310 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4311 | ast2obj_comprehension); |
| 4312 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4313 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4314 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4315 | goto failed; |
| 4316 | Py_DECREF(value); |
| 4317 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4318 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4319 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4320 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4321 | if (!result) goto failed; |
| 4322 | value = ast2obj_expr(o->v.Await.value); |
| 4323 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4324 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4325 | goto failed; |
| 4326 | Py_DECREF(value); |
| 4327 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4328 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4329 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4330 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4331 | if (!result) goto failed; |
| 4332 | value = ast2obj_expr(o->v.Yield.value); |
| 4333 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4334 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4335 | goto failed; |
| 4336 | Py_DECREF(value); |
| 4337 | break; |
| 4338 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4339 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4340 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4341 | if (!result) goto failed; |
| 4342 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4343 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4344 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4345 | goto failed; |
| 4346 | Py_DECREF(value); |
| 4347 | break; |
| 4348 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4349 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4350 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4351 | if (!result) goto failed; |
| 4352 | value = ast2obj_expr(o->v.Compare.left); |
| 4353 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4354 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4355 | goto failed; |
| 4356 | Py_DECREF(value); |
| 4357 | { |
| 4358 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4359 | value = PyList_New(n); |
| 4360 | if (!value) goto failed; |
| 4361 | for(i = 0; i < n; i++) |
| 4362 | 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] | 4363 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4364 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4365 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4366 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4367 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4368 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4369 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4370 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4371 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4372 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4373 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4374 | break; |
| 4375 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4376 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4377 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4378 | if (!result) goto failed; |
| 4379 | value = ast2obj_expr(o->v.Call.func); |
| 4380 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4381 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4382 | goto failed; |
| 4383 | Py_DECREF(value); |
| 4384 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4385 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4386 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4387 | goto failed; |
| 4388 | Py_DECREF(value); |
| 4389 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4390 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4391 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4392 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4393 | goto failed; |
| 4394 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4395 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4396 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4397 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4398 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4399 | if (!result) goto failed; |
| 4400 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4401 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4402 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4403 | goto failed; |
| 4404 | Py_DECREF(value); |
| 4405 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4406 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4407 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4408 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4409 | goto failed; |
| 4410 | Py_DECREF(value); |
| 4411 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4412 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4413 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4414 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4415 | goto failed; |
| 4416 | Py_DECREF(value); |
| 4417 | break; |
| 4418 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4419 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4420 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4421 | if (!result) goto failed; |
| 4422 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4423 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4424 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4425 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4426 | goto failed; |
| 4427 | Py_DECREF(value); |
| 4428 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4429 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4430 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4431 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4432 | if (!result) goto failed; |
| 4433 | value = ast2obj_constant(o->v.Constant.value); |
| 4434 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4435 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4436 | goto failed; |
| 4437 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4438 | value = ast2obj_string(o->v.Constant.kind); |
| 4439 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4440 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4441 | goto failed; |
| 4442 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4443 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4444 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4445 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4446 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4447 | if (!result) goto failed; |
| 4448 | value = ast2obj_expr(o->v.Attribute.value); |
| 4449 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4450 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4451 | goto failed; |
| 4452 | Py_DECREF(value); |
| 4453 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4454 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4455 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4456 | goto failed; |
| 4457 | Py_DECREF(value); |
| 4458 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4459 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4460 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4461 | goto failed; |
| 4462 | Py_DECREF(value); |
| 4463 | break; |
| 4464 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4465 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4466 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4467 | if (!result) goto failed; |
| 4468 | value = ast2obj_expr(o->v.Subscript.value); |
| 4469 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4470 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4471 | goto failed; |
| 4472 | Py_DECREF(value); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4473 | value = ast2obj_expr(o->v.Subscript.slice); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4474 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4475 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4476 | goto failed; |
| 4477 | Py_DECREF(value); |
| 4478 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4479 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4480 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4481 | goto failed; |
| 4482 | Py_DECREF(value); |
| 4483 | break; |
| 4484 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4485 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4486 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4487 | if (!result) goto failed; |
| 4488 | value = ast2obj_expr(o->v.Starred.value); |
| 4489 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4490 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4491 | goto failed; |
| 4492 | Py_DECREF(value); |
| 4493 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4494 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4495 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4496 | goto failed; |
| 4497 | Py_DECREF(value); |
| 4498 | break; |
| 4499 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4500 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4501 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4502 | if (!result) goto failed; |
| 4503 | value = ast2obj_identifier(o->v.Name.id); |
| 4504 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4505 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4506 | goto failed; |
| 4507 | Py_DECREF(value); |
| 4508 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4509 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4510 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4511 | goto failed; |
| 4512 | Py_DECREF(value); |
| 4513 | break; |
| 4514 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4515 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4516 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4517 | if (!result) goto failed; |
| 4518 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4519 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4520 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4521 | goto failed; |
| 4522 | Py_DECREF(value); |
| 4523 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4524 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4525 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4526 | goto failed; |
| 4527 | Py_DECREF(value); |
| 4528 | break; |
| 4529 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4530 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4531 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4532 | if (!result) goto failed; |
| 4533 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4534 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4535 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4536 | goto failed; |
| 4537 | Py_DECREF(value); |
| 4538 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4539 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4540 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4541 | goto failed; |
| 4542 | Py_DECREF(value); |
| 4543 | break; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4544 | case Slice_kind: |
| 4545 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4546 | result = PyType_GenericNew(tp, NULL, NULL); |
| 4547 | if (!result) goto failed; |
| 4548 | value = ast2obj_expr(o->v.Slice.lower); |
| 4549 | if (!value) goto failed; |
| 4550 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
| 4551 | goto failed; |
| 4552 | Py_DECREF(value); |
| 4553 | value = ast2obj_expr(o->v.Slice.upper); |
| 4554 | if (!value) goto failed; |
| 4555 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
| 4556 | goto failed; |
| 4557 | Py_DECREF(value); |
| 4558 | value = ast2obj_expr(o->v.Slice.step); |
| 4559 | if (!value) goto failed; |
| 4560 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
| 4561 | goto failed; |
| 4562 | Py_DECREF(value); |
| 4563 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4564 | } |
| 4565 | value = ast2obj_int(o->lineno); |
| 4566 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4567 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4568 | goto failed; |
| 4569 | Py_DECREF(value); |
| 4570 | value = ast2obj_int(o->col_offset); |
| 4571 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4572 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4573 | goto failed; |
| 4574 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4575 | value = ast2obj_int(o->end_lineno); |
| 4576 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4577 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4578 | goto failed; |
| 4579 | Py_DECREF(value); |
| 4580 | value = ast2obj_int(o->end_col_offset); |
| 4581 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4582 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4583 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4584 | goto failed; |
| 4585 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4586 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4587 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4588 | Py_XDECREF(value); |
| 4589 | Py_XDECREF(result); |
| 4590 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4593 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4594 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4595 | switch(o) { |
| 4596 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4597 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4598 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4599 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4600 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4601 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4602 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4603 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4604 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4605 | default: |
| 4606 | /* should never happen, but just in case ... */ |
| 4607 | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
| 4608 | return NULL; |
| 4609 | } |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4610 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4611 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4612 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4613 | switch(o) { |
| 4614 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4615 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4616 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4617 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4618 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4619 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4620 | default: |
| 4621 | /* should never happen, but just in case ... */ |
| 4622 | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
| 4623 | return NULL; |
| 4624 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4625 | } |
| 4626 | PyObject* ast2obj_operator(operator_ty o) |
| 4627 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4628 | switch(o) { |
| 4629 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4630 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4631 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4632 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4633 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4634 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4635 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4636 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4637 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4638 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4639 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4640 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4641 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4642 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4643 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4644 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4645 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4646 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4647 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4648 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4649 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4650 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4651 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4652 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4653 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4654 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4655 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4656 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4657 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4658 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4659 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4660 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4661 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4662 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4663 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4664 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4665 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4666 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4667 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4668 | default: |
| 4669 | /* should never happen, but just in case ... */ |
| 4670 | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
| 4671 | return NULL; |
| 4672 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4673 | } |
| 4674 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4675 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4676 | switch(o) { |
| 4677 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4678 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4679 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4680 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4681 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4682 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4683 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4684 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4685 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4686 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4687 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4688 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4689 | default: |
| 4690 | /* should never happen, but just in case ... */ |
| 4691 | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
| 4692 | return NULL; |
| 4693 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4694 | } |
| 4695 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4696 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4697 | switch(o) { |
| 4698 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4699 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4700 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4701 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4702 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4703 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4704 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4705 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4706 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4707 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4708 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4709 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4710 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4711 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4712 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4713 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4714 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4715 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4716 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4717 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4718 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4719 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4720 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4721 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4722 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4723 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4724 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4725 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4726 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4727 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4728 | default: |
| 4729 | /* should never happen, but just in case ... */ |
| 4730 | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
| 4731 | return NULL; |
| 4732 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4733 | } |
| 4734 | PyObject* |
| 4735 | ast2obj_comprehension(void* _o) |
| 4736 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4737 | comprehension_ty o = (comprehension_ty)_o; |
| 4738 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4739 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4740 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4741 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4742 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4743 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4744 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4745 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4746 | if (!result) return NULL; |
| 4747 | value = ast2obj_expr(o->target); |
| 4748 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4749 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4750 | goto failed; |
| 4751 | Py_DECREF(value); |
| 4752 | value = ast2obj_expr(o->iter); |
| 4753 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4754 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4755 | goto failed; |
| 4756 | Py_DECREF(value); |
| 4757 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4758 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4759 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4760 | goto failed; |
| 4761 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4762 | value = ast2obj_int(o->is_async); |
| 4763 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4764 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4765 | goto failed; |
| 4766 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4767 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4768 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4769 | Py_XDECREF(value); |
| 4770 | Py_XDECREF(result); |
| 4771 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4772 | } |
| 4773 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4774 | PyObject* |
| 4775 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4776 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4777 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4778 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4779 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4780 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4781 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4782 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4783 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4784 | switch (o->kind) { |
| 4785 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4786 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4787 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4788 | if (!result) goto failed; |
| 4789 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4790 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4791 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4792 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4793 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4794 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4795 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4796 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4797 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4798 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4799 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4800 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4801 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4802 | goto failed; |
| 4803 | Py_DECREF(value); |
| 4804 | break; |
| 4805 | } |
| 4806 | value = ast2obj_int(o->lineno); |
| 4807 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4808 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4809 | goto failed; |
| 4810 | Py_DECREF(value); |
| 4811 | value = ast2obj_int(o->col_offset); |
| 4812 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4813 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4814 | goto failed; |
| 4815 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4816 | value = ast2obj_int(o->end_lineno); |
| 4817 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4818 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4819 | goto failed; |
| 4820 | Py_DECREF(value); |
| 4821 | value = ast2obj_int(o->end_col_offset); |
| 4822 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4823 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4824 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4825 | goto failed; |
| 4826 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4827 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4828 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4829 | Py_XDECREF(value); |
| 4830 | Py_XDECREF(result); |
| 4831 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4834 | PyObject* |
| 4835 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4836 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4837 | arguments_ty o = (arguments_ty)_o; |
| 4838 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4839 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4840 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4841 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4842 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4843 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4844 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4845 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4846 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4847 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4848 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4849 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4850 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4851 | goto failed; |
| 4852 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4853 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4854 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4855 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4856 | goto failed; |
| 4857 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4858 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4859 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4860 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4861 | goto failed; |
| 4862 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4863 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4864 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4865 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4866 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4867 | goto failed; |
| 4868 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4869 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4870 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4871 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4872 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4873 | goto failed; |
| 4874 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4875 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4876 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4877 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4878 | goto failed; |
| 4879 | Py_DECREF(value); |
| 4880 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4881 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4882 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4883 | goto failed; |
| 4884 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4885 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4886 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4887 | Py_XDECREF(value); |
| 4888 | Py_XDECREF(result); |
| 4889 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4890 | } |
| 4891 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4892 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4893 | ast2obj_arg(void* _o) |
| 4894 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4895 | arg_ty o = (arg_ty)_o; |
| 4896 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4897 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4898 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4899 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4900 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4901 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4902 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4903 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4904 | if (!result) return NULL; |
| 4905 | value = ast2obj_identifier(o->arg); |
| 4906 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4907 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4908 | goto failed; |
| 4909 | Py_DECREF(value); |
| 4910 | value = ast2obj_expr(o->annotation); |
| 4911 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4912 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4913 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4914 | goto failed; |
| 4915 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4916 | value = ast2obj_string(o->type_comment); |
| 4917 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4918 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4919 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4920 | goto failed; |
| 4921 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4922 | value = ast2obj_int(o->lineno); |
| 4923 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4924 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4925 | goto failed; |
| 4926 | Py_DECREF(value); |
| 4927 | value = ast2obj_int(o->col_offset); |
| 4928 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4929 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4930 | goto failed; |
| 4931 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4932 | value = ast2obj_int(o->end_lineno); |
| 4933 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4934 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4935 | goto failed; |
| 4936 | Py_DECREF(value); |
| 4937 | value = ast2obj_int(o->end_col_offset); |
| 4938 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4939 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4940 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4941 | goto failed; |
| 4942 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4943 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4944 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4945 | Py_XDECREF(value); |
| 4946 | Py_XDECREF(result); |
| 4947 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4948 | } |
| 4949 | |
| 4950 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4951 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4952 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4953 | keyword_ty o = (keyword_ty)_o; |
| 4954 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4955 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4956 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4957 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4958 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4959 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4960 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4961 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4962 | if (!result) return NULL; |
| 4963 | value = ast2obj_identifier(o->arg); |
| 4964 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4965 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4966 | goto failed; |
| 4967 | Py_DECREF(value); |
| 4968 | value = ast2obj_expr(o->value); |
| 4969 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4970 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4971 | goto failed; |
| 4972 | Py_DECREF(value); |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 4973 | value = ast2obj_int(o->lineno); |
| 4974 | if (!value) goto failed; |
| 4975 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
| 4976 | goto failed; |
| 4977 | Py_DECREF(value); |
| 4978 | value = ast2obj_int(o->col_offset); |
| 4979 | if (!value) goto failed; |
| 4980 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
| 4981 | goto failed; |
| 4982 | Py_DECREF(value); |
| 4983 | value = ast2obj_int(o->end_lineno); |
| 4984 | if (!value) goto failed; |
| 4985 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
| 4986 | goto failed; |
| 4987 | Py_DECREF(value); |
| 4988 | value = ast2obj_int(o->end_col_offset); |
| 4989 | if (!value) goto failed; |
| 4990 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4991 | < 0) |
| 4992 | goto failed; |
| 4993 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4994 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4995 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4996 | Py_XDECREF(value); |
| 4997 | Py_XDECREF(result); |
| 4998 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4999 | } |
| 5000 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5001 | PyObject* |
| 5002 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5003 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5004 | alias_ty o = (alias_ty)_o; |
| 5005 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5006 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5007 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 5008 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5009 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5010 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5011 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 5012 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5013 | if (!result) return NULL; |
| 5014 | value = ast2obj_identifier(o->name); |
| 5015 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5016 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5017 | goto failed; |
| 5018 | Py_DECREF(value); |
| 5019 | value = ast2obj_identifier(o->asname); |
| 5020 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5021 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5022 | goto failed; |
| 5023 | Py_DECREF(value); |
| 5024 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5025 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5026 | Py_XDECREF(value); |
| 5027 | Py_XDECREF(result); |
| 5028 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5029 | } |
| 5030 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5031 | PyObject* |
| 5032 | ast2obj_withitem(void* _o) |
| 5033 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5034 | withitem_ty o = (withitem_ty)_o; |
| 5035 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5036 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5037 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 5038 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5039 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5040 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5041 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 5042 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5043 | if (!result) return NULL; |
| 5044 | value = ast2obj_expr(o->context_expr); |
| 5045 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5046 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 5047 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5048 | goto failed; |
| 5049 | Py_DECREF(value); |
| 5050 | value = ast2obj_expr(o->optional_vars); |
| 5051 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5052 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 5053 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5054 | goto failed; |
| 5055 | Py_DECREF(value); |
| 5056 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5057 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5058 | Py_XDECREF(value); |
| 5059 | Py_XDECREF(result); |
| 5060 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5061 | } |
| 5062 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5063 | PyObject* |
| 5064 | ast2obj_type_ignore(void* _o) |
| 5065 | { |
| 5066 | type_ignore_ty o = (type_ignore_ty)_o; |
| 5067 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5068 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5069 | if (!o) { |
| 5070 | Py_RETURN_NONE; |
| 5071 | } |
| 5072 | |
| 5073 | switch (o->kind) { |
| 5074 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5075 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 5076 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5077 | if (!result) goto failed; |
| 5078 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 5079 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5080 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 5081 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5082 | goto failed; |
| 5083 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5084 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 5085 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5086 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5087 | goto failed; |
| 5088 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5089 | break; |
| 5090 | } |
| 5091 | return result; |
| 5092 | failed: |
| 5093 | Py_XDECREF(value); |
| 5094 | Py_XDECREF(result); |
| 5095 | return NULL; |
| 5096 | } |
| 5097 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5098 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5099 | int |
| 5100 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 5101 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5102 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5103 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5104 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5105 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5106 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5107 | if (obj == Py_None) { |
| 5108 | *out = NULL; |
| 5109 | return 0; |
| 5110 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5111 | tp = astmodulestate_global->Module_type; |
| 5112 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5113 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5114 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5115 | } |
| 5116 | if (isinstance) { |
| 5117 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5118 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5119 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5120 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5121 | return 1; |
| 5122 | } |
| 5123 | if (tmp == NULL) { |
| 5124 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 5125 | return 1; |
| 5126 | } |
| 5127 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5128 | int res; |
| 5129 | Py_ssize_t len; |
| 5130 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5131 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5132 | 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] | 5133 | goto failed; |
| 5134 | } |
| 5135 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5136 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5137 | if (body == NULL) goto failed; |
| 5138 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5139 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5140 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5141 | Py_INCREF(tmp2); |
| 5142 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5143 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5144 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5145 | if (len != PyList_GET_SIZE(tmp)) { |
| 5146 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5147 | goto failed; |
| 5148 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5149 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5150 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5151 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5152 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5153 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5154 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5155 | return 1; |
| 5156 | } |
| 5157 | if (tmp == NULL) { |
| 5158 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5159 | return 1; |
| 5160 | } |
| 5161 | else { |
| 5162 | int res; |
| 5163 | Py_ssize_t len; |
| 5164 | Py_ssize_t i; |
| 5165 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5166 | 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] | 5167 | goto failed; |
| 5168 | } |
| 5169 | len = PyList_GET_SIZE(tmp); |
| 5170 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5171 | if (type_ignores == NULL) goto failed; |
| 5172 | for (i = 0; i < len; i++) { |
| 5173 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5174 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5175 | Py_INCREF(tmp2); |
| 5176 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5177 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5178 | if (res != 0) goto failed; |
| 5179 | if (len != PyList_GET_SIZE(tmp)) { |
| 5180 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5181 | goto failed; |
| 5182 | } |
| 5183 | asdl_seq_SET(type_ignores, i, val); |
| 5184 | } |
| 5185 | Py_CLEAR(tmp); |
| 5186 | } |
| 5187 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5188 | if (*out == NULL) goto failed; |
| 5189 | return 0; |
| 5190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5191 | tp = astmodulestate_global->Interactive_type; |
| 5192 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5193 | if (isinstance == -1) { |
| 5194 | return 1; |
| 5195 | } |
| 5196 | if (isinstance) { |
| 5197 | asdl_seq* body; |
| 5198 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5199 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5200 | return 1; |
| 5201 | } |
| 5202 | if (tmp == NULL) { |
| 5203 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5204 | return 1; |
| 5205 | } |
| 5206 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5207 | int res; |
| 5208 | Py_ssize_t len; |
| 5209 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5210 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5211 | 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] | 5212 | goto failed; |
| 5213 | } |
| 5214 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5215 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5216 | if (body == NULL) goto failed; |
| 5217 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5218 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5219 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5220 | Py_INCREF(tmp2); |
| 5221 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5222 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5223 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5224 | if (len != PyList_GET_SIZE(tmp)) { |
| 5225 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5226 | goto failed; |
| 5227 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5228 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5229 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5230 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5231 | } |
| 5232 | *out = Interactive(body, arena); |
| 5233 | if (*out == NULL) goto failed; |
| 5234 | return 0; |
| 5235 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5236 | tp = astmodulestate_global->Expression_type; |
| 5237 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5238 | if (isinstance == -1) { |
| 5239 | return 1; |
| 5240 | } |
| 5241 | if (isinstance) { |
| 5242 | expr_ty body; |
| 5243 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5244 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5245 | return 1; |
| 5246 | } |
| 5247 | if (tmp == NULL) { |
| 5248 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5249 | return 1; |
| 5250 | } |
| 5251 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5252 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5253 | res = obj2ast_expr(tmp, &body, arena); |
| 5254 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5255 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5256 | } |
| 5257 | *out = Expression(body, arena); |
| 5258 | if (*out == NULL) goto failed; |
| 5259 | return 0; |
| 5260 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5261 | tp = astmodulestate_global->FunctionType_type; |
| 5262 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5263 | if (isinstance == -1) { |
| 5264 | return 1; |
| 5265 | } |
| 5266 | if (isinstance) { |
| 5267 | asdl_seq* argtypes; |
| 5268 | expr_ty returns; |
| 5269 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5270 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5271 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5272 | return 1; |
| 5273 | } |
| 5274 | if (tmp == NULL) { |
| 5275 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5276 | return 1; |
| 5277 | } |
| 5278 | else { |
| 5279 | int res; |
| 5280 | Py_ssize_t len; |
| 5281 | Py_ssize_t i; |
| 5282 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5283 | 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] | 5284 | goto failed; |
| 5285 | } |
| 5286 | len = PyList_GET_SIZE(tmp); |
| 5287 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5288 | if (argtypes == NULL) goto failed; |
| 5289 | for (i = 0; i < len; i++) { |
| 5290 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5291 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5292 | Py_INCREF(tmp2); |
| 5293 | res = obj2ast_expr(tmp2, &val, arena); |
| 5294 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5295 | if (res != 0) goto failed; |
| 5296 | if (len != PyList_GET_SIZE(tmp)) { |
| 5297 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5298 | goto failed; |
| 5299 | } |
| 5300 | asdl_seq_SET(argtypes, i, val); |
| 5301 | } |
| 5302 | Py_CLEAR(tmp); |
| 5303 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5304 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5305 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5306 | return 1; |
| 5307 | } |
| 5308 | if (tmp == NULL) { |
| 5309 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5310 | return 1; |
| 5311 | } |
| 5312 | else { |
| 5313 | int res; |
| 5314 | res = obj2ast_expr(tmp, &returns, arena); |
| 5315 | if (res != 0) goto failed; |
| 5316 | Py_CLEAR(tmp); |
| 5317 | } |
| 5318 | *out = FunctionType(argtypes, returns, arena); |
| 5319 | if (*out == NULL) goto failed; |
| 5320 | return 0; |
| 5321 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5322 | |
| 5323 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5324 | failed: |
| 5325 | Py_XDECREF(tmp); |
| 5326 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5327 | } |
| 5328 | |
| 5329 | int |
| 5330 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5331 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5332 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5333 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5334 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5335 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5336 | int lineno; |
| 5337 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5338 | int end_lineno; |
| 5339 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5340 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5341 | if (obj == Py_None) { |
| 5342 | *out = NULL; |
| 5343 | return 0; |
| 5344 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5345 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5346 | return 1; |
| 5347 | } |
| 5348 | if (tmp == NULL) { |
| 5349 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5350 | return 1; |
| 5351 | } |
| 5352 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5353 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5354 | res = obj2ast_int(tmp, &lineno, arena); |
| 5355 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5356 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5357 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5358 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5359 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5360 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5361 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5362 | if (tmp == NULL) { |
| 5363 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5364 | return 1; |
| 5365 | } |
| 5366 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5367 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5368 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5369 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5370 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5371 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5372 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5373 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5374 | return 1; |
| 5375 | } |
| 5376 | if (tmp == NULL || tmp == Py_None) { |
| 5377 | Py_CLEAR(tmp); |
| 5378 | end_lineno = 0; |
| 5379 | } |
| 5380 | else { |
| 5381 | int res; |
| 5382 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5383 | if (res != 0) goto failed; |
| 5384 | Py_CLEAR(tmp); |
| 5385 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5386 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5387 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5388 | return 1; |
| 5389 | } |
| 5390 | if (tmp == NULL || tmp == Py_None) { |
| 5391 | Py_CLEAR(tmp); |
| 5392 | end_col_offset = 0; |
| 5393 | } |
| 5394 | else { |
| 5395 | int res; |
| 5396 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5397 | if (res != 0) goto failed; |
| 5398 | Py_CLEAR(tmp); |
| 5399 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5400 | tp = astmodulestate_global->FunctionDef_type; |
| 5401 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5402 | if (isinstance == -1) { |
| 5403 | return 1; |
| 5404 | } |
| 5405 | if (isinstance) { |
| 5406 | identifier name; |
| 5407 | arguments_ty args; |
| 5408 | asdl_seq* body; |
| 5409 | asdl_seq* decorator_list; |
| 5410 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5411 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5412 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5413 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5414 | return 1; |
| 5415 | } |
| 5416 | if (tmp == NULL) { |
| 5417 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5418 | return 1; |
| 5419 | } |
| 5420 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5421 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5422 | res = obj2ast_identifier(tmp, &name, arena); |
| 5423 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5424 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5425 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5426 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5427 | return 1; |
| 5428 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5429 | if (tmp == NULL) { |
| 5430 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5431 | return 1; |
| 5432 | } |
| 5433 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5434 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5435 | res = obj2ast_arguments(tmp, &args, arena); |
| 5436 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5437 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5438 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5439 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5440 | return 1; |
| 5441 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5442 | if (tmp == NULL) { |
| 5443 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5444 | return 1; |
| 5445 | } |
| 5446 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5447 | int res; |
| 5448 | Py_ssize_t len; |
| 5449 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5450 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5451 | 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] | 5452 | goto failed; |
| 5453 | } |
| 5454 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5455 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5456 | if (body == NULL) goto failed; |
| 5457 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5458 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5459 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5460 | Py_INCREF(tmp2); |
| 5461 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5462 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5463 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5464 | if (len != PyList_GET_SIZE(tmp)) { |
| 5465 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5466 | goto failed; |
| 5467 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5468 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5469 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5470 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5471 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5472 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5473 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5474 | return 1; |
| 5475 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5476 | if (tmp == NULL) { |
| 5477 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5478 | return 1; |
| 5479 | } |
| 5480 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5481 | int res; |
| 5482 | Py_ssize_t len; |
| 5483 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5484 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5485 | 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] | 5486 | goto failed; |
| 5487 | } |
| 5488 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5489 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5490 | if (decorator_list == NULL) goto failed; |
| 5491 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5492 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5493 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5494 | Py_INCREF(tmp2); |
| 5495 | res = obj2ast_expr(tmp2, &val, arena); |
| 5496 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5497 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5498 | if (len != PyList_GET_SIZE(tmp)) { |
| 5499 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5500 | goto failed; |
| 5501 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5502 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5503 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 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->returns, &tmp) < |
| 5507 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5508 | return 1; |
| 5509 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5510 | if (tmp == NULL || tmp == Py_None) { |
| 5511 | Py_CLEAR(tmp); |
| 5512 | returns = NULL; |
| 5513 | } |
| 5514 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5515 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5516 | res = obj2ast_expr(tmp, &returns, arena); |
| 5517 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5518 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5519 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5520 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5521 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5522 | return 1; |
| 5523 | } |
| 5524 | if (tmp == NULL || tmp == Py_None) { |
| 5525 | Py_CLEAR(tmp); |
| 5526 | type_comment = NULL; |
| 5527 | } |
| 5528 | else { |
| 5529 | int res; |
| 5530 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5531 | if (res != 0) goto failed; |
| 5532 | Py_CLEAR(tmp); |
| 5533 | } |
| 5534 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5535 | type_comment, lineno, col_offset, end_lineno, |
| 5536 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5537 | if (*out == NULL) goto failed; |
| 5538 | return 0; |
| 5539 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5540 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5541 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5542 | if (isinstance == -1) { |
| 5543 | return 1; |
| 5544 | } |
| 5545 | if (isinstance) { |
| 5546 | identifier name; |
| 5547 | arguments_ty args; |
| 5548 | asdl_seq* body; |
| 5549 | asdl_seq* decorator_list; |
| 5550 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5551 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5552 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5553 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5554 | return 1; |
| 5555 | } |
| 5556 | if (tmp == NULL) { |
| 5557 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5558 | return 1; |
| 5559 | } |
| 5560 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5561 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5562 | res = obj2ast_identifier(tmp, &name, arena); |
| 5563 | if (res != 0) goto failed; |
| 5564 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5565 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5566 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5567 | return 1; |
| 5568 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5569 | if (tmp == NULL) { |
| 5570 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5571 | return 1; |
| 5572 | } |
| 5573 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5574 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5575 | res = obj2ast_arguments(tmp, &args, arena); |
| 5576 | if (res != 0) goto failed; |
| 5577 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5578 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5579 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5580 | return 1; |
| 5581 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5582 | if (tmp == NULL) { |
| 5583 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5584 | return 1; |
| 5585 | } |
| 5586 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5587 | int res; |
| 5588 | Py_ssize_t len; |
| 5589 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5590 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5591 | 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] | 5592 | goto failed; |
| 5593 | } |
| 5594 | len = PyList_GET_SIZE(tmp); |
| 5595 | body = _Py_asdl_seq_new(len, arena); |
| 5596 | if (body == NULL) goto failed; |
| 5597 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5598 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5599 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5600 | Py_INCREF(tmp2); |
| 5601 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5602 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5603 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5604 | if (len != PyList_GET_SIZE(tmp)) { |
| 5605 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5606 | goto failed; |
| 5607 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5608 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5609 | } |
| 5610 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5611 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5612 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5613 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5614 | return 1; |
| 5615 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5616 | if (tmp == NULL) { |
| 5617 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5618 | return 1; |
| 5619 | } |
| 5620 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5621 | int res; |
| 5622 | Py_ssize_t len; |
| 5623 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5624 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5625 | 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] | 5626 | goto failed; |
| 5627 | } |
| 5628 | len = PyList_GET_SIZE(tmp); |
| 5629 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5630 | if (decorator_list == NULL) goto failed; |
| 5631 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5632 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5633 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5634 | Py_INCREF(tmp2); |
| 5635 | res = obj2ast_expr(tmp2, &val, arena); |
| 5636 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5637 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5638 | if (len != PyList_GET_SIZE(tmp)) { |
| 5639 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5640 | goto failed; |
| 5641 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5642 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5643 | } |
| 5644 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5645 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5646 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5647 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5648 | return 1; |
| 5649 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5650 | if (tmp == NULL || tmp == Py_None) { |
| 5651 | Py_CLEAR(tmp); |
| 5652 | returns = NULL; |
| 5653 | } |
| 5654 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5655 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5656 | res = obj2ast_expr(tmp, &returns, arena); |
| 5657 | if (res != 0) goto failed; |
| 5658 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5659 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5660 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5661 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5662 | return 1; |
| 5663 | } |
| 5664 | if (tmp == NULL || tmp == Py_None) { |
| 5665 | Py_CLEAR(tmp); |
| 5666 | type_comment = NULL; |
| 5667 | } |
| 5668 | else { |
| 5669 | int res; |
| 5670 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5671 | if (res != 0) goto failed; |
| 5672 | Py_CLEAR(tmp); |
| 5673 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5674 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5675 | type_comment, lineno, col_offset, end_lineno, |
| 5676 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5677 | if (*out == NULL) goto failed; |
| 5678 | return 0; |
| 5679 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5680 | tp = astmodulestate_global->ClassDef_type; |
| 5681 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5682 | if (isinstance == -1) { |
| 5683 | return 1; |
| 5684 | } |
| 5685 | if (isinstance) { |
| 5686 | identifier name; |
| 5687 | asdl_seq* bases; |
| 5688 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5689 | asdl_seq* body; |
| 5690 | asdl_seq* decorator_list; |
| 5691 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5692 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5693 | return 1; |
| 5694 | } |
| 5695 | if (tmp == NULL) { |
| 5696 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5697 | return 1; |
| 5698 | } |
| 5699 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5700 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5701 | res = obj2ast_identifier(tmp, &name, arena); |
| 5702 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5703 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5704 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5705 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5706 | return 1; |
| 5707 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5708 | if (tmp == NULL) { |
| 5709 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5710 | return 1; |
| 5711 | } |
| 5712 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5713 | int res; |
| 5714 | Py_ssize_t len; |
| 5715 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5716 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5717 | 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] | 5718 | goto failed; |
| 5719 | } |
| 5720 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5721 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5722 | if (bases == NULL) goto failed; |
| 5723 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5724 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5725 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5726 | Py_INCREF(tmp2); |
| 5727 | res = obj2ast_expr(tmp2, &val, arena); |
| 5728 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5729 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5730 | if (len != PyList_GET_SIZE(tmp)) { |
| 5731 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5732 | goto failed; |
| 5733 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5734 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5735 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5736 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5737 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5738 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5739 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5740 | return 1; |
| 5741 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5742 | if (tmp == NULL) { |
| 5743 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5744 | return 1; |
| 5745 | } |
| 5746 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5747 | int res; |
| 5748 | Py_ssize_t len; |
| 5749 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5750 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5751 | 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] | 5752 | goto failed; |
| 5753 | } |
| 5754 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5755 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5756 | if (keywords == NULL) goto failed; |
| 5757 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5758 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5759 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5760 | Py_INCREF(tmp2); |
| 5761 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5762 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5763 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5764 | if (len != PyList_GET_SIZE(tmp)) { |
| 5765 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5766 | goto failed; |
| 5767 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5768 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5769 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5770 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5771 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5772 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5773 | return 1; |
| 5774 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5775 | if (tmp == NULL) { |
| 5776 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5777 | return 1; |
| 5778 | } |
| 5779 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5780 | int res; |
| 5781 | Py_ssize_t len; |
| 5782 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5783 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5784 | 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] | 5785 | goto failed; |
| 5786 | } |
| 5787 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5788 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5789 | if (body == NULL) goto failed; |
| 5790 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5791 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5792 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5793 | Py_INCREF(tmp2); |
| 5794 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5795 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5796 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5797 | if (len != PyList_GET_SIZE(tmp)) { |
| 5798 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5799 | goto failed; |
| 5800 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5801 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5802 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5803 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5804 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5805 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5806 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5807 | return 1; |
| 5808 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5809 | if (tmp == NULL) { |
| 5810 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 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, "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] | 5819 | goto failed; |
| 5820 | } |
| 5821 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5822 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5823 | if (decorator_list == 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, "ClassDef field \"decorator_list\" 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(decorator_list, 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); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5838 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5839 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5840 | col_offset, end_lineno, end_col_offset, 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->Return_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 | expr_ty value; |
| 5851 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5852 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5853 | return 1; |
| 5854 | } |
| 5855 | if (tmp == NULL || tmp == Py_None) { |
| 5856 | Py_CLEAR(tmp); |
| 5857 | value = NULL; |
| 5858 | } |
| 5859 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5860 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5861 | res = obj2ast_expr(tmp, &value, arena); |
| 5862 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5863 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5864 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5865 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5866 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5867 | if (*out == NULL) goto failed; |
| 5868 | return 0; |
| 5869 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5870 | tp = astmodulestate_global->Delete_type; |
| 5871 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5872 | if (isinstance == -1) { |
| 5873 | return 1; |
| 5874 | } |
| 5875 | if (isinstance) { |
| 5876 | asdl_seq* targets; |
| 5877 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5878 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5879 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5880 | return 1; |
| 5881 | } |
| 5882 | if (tmp == NULL) { |
| 5883 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5884 | return 1; |
| 5885 | } |
| 5886 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5887 | int res; |
| 5888 | Py_ssize_t len; |
| 5889 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5890 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5891 | 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] | 5892 | goto failed; |
| 5893 | } |
| 5894 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5895 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5896 | if (targets == NULL) goto failed; |
| 5897 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5898 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5899 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5900 | Py_INCREF(tmp2); |
| 5901 | res = obj2ast_expr(tmp2, &val, arena); |
| 5902 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5903 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5904 | if (len != PyList_GET_SIZE(tmp)) { |
| 5905 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5906 | goto failed; |
| 5907 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5908 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5909 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5910 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5911 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5912 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5913 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5914 | if (*out == NULL) goto failed; |
| 5915 | return 0; |
| 5916 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5917 | tp = astmodulestate_global->Assign_type; |
| 5918 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5919 | if (isinstance == -1) { |
| 5920 | return 1; |
| 5921 | } |
| 5922 | if (isinstance) { |
| 5923 | asdl_seq* targets; |
| 5924 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5925 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5926 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5927 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5928 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5929 | return 1; |
| 5930 | } |
| 5931 | if (tmp == NULL) { |
| 5932 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5933 | return 1; |
| 5934 | } |
| 5935 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5936 | int res; |
| 5937 | Py_ssize_t len; |
| 5938 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5939 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5940 | 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] | 5941 | goto failed; |
| 5942 | } |
| 5943 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5944 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5945 | if (targets == NULL) goto failed; |
| 5946 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5947 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5948 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5949 | Py_INCREF(tmp2); |
| 5950 | res = obj2ast_expr(tmp2, &val, arena); |
| 5951 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5952 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5953 | if (len != PyList_GET_SIZE(tmp)) { |
| 5954 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5955 | goto failed; |
| 5956 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5957 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5958 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5959 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5960 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5961 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5962 | return 1; |
| 5963 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5964 | if (tmp == NULL) { |
| 5965 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5966 | return 1; |
| 5967 | } |
| 5968 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5969 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5970 | res = obj2ast_expr(tmp, &value, arena); |
| 5971 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5972 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5973 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5974 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5975 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5976 | return 1; |
| 5977 | } |
| 5978 | if (tmp == NULL || tmp == Py_None) { |
| 5979 | Py_CLEAR(tmp); |
| 5980 | type_comment = NULL; |
| 5981 | } |
| 5982 | else { |
| 5983 | int res; |
| 5984 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5985 | if (res != 0) goto failed; |
| 5986 | Py_CLEAR(tmp); |
| 5987 | } |
| 5988 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5989 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5990 | if (*out == NULL) goto failed; |
| 5991 | return 0; |
| 5992 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5993 | tp = astmodulestate_global->AugAssign_type; |
| 5994 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5995 | if (isinstance == -1) { |
| 5996 | return 1; |
| 5997 | } |
| 5998 | if (isinstance) { |
| 5999 | expr_ty target; |
| 6000 | operator_ty op; |
| 6001 | expr_ty value; |
| 6002 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6003 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6004 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6005 | return 1; |
| 6006 | } |
| 6007 | if (tmp == NULL) { |
| 6008 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 6009 | return 1; |
| 6010 | } |
| 6011 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6012 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6013 | res = obj2ast_expr(tmp, &target, arena); |
| 6014 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6015 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6016 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6017 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6018 | return 1; |
| 6019 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6020 | if (tmp == NULL) { |
| 6021 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 6022 | return 1; |
| 6023 | } |
| 6024 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6025 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6026 | res = obj2ast_operator(tmp, &op, arena); |
| 6027 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6028 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6030 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6031 | return 1; |
| 6032 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6033 | if (tmp == NULL) { |
| 6034 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 6035 | return 1; |
| 6036 | } |
| 6037 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6038 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6039 | res = obj2ast_expr(tmp, &value, arena); |
| 6040 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6041 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6042 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6043 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 6044 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6045 | if (*out == NULL) goto failed; |
| 6046 | return 0; |
| 6047 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6048 | tp = astmodulestate_global->AnnAssign_type; |
| 6049 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6050 | if (isinstance == -1) { |
| 6051 | return 1; |
| 6052 | } |
| 6053 | if (isinstance) { |
| 6054 | expr_ty target; |
| 6055 | expr_ty annotation; |
| 6056 | expr_ty value; |
| 6057 | int simple; |
| 6058 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6059 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6060 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6061 | return 1; |
| 6062 | } |
| 6063 | if (tmp == NULL) { |
| 6064 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 6065 | return 1; |
| 6066 | } |
| 6067 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6068 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6069 | res = obj2ast_expr(tmp, &target, arena); |
| 6070 | if (res != 0) goto failed; |
| 6071 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6072 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6073 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 6074 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6075 | return 1; |
| 6076 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6077 | if (tmp == NULL) { |
| 6078 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 6079 | return 1; |
| 6080 | } |
| 6081 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6082 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6083 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6084 | if (res != 0) goto failed; |
| 6085 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6086 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6087 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6088 | return 1; |
| 6089 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6090 | if (tmp == NULL || tmp == Py_None) { |
| 6091 | Py_CLEAR(tmp); |
| 6092 | value = NULL; |
| 6093 | } |
| 6094 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6095 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6096 | res = obj2ast_expr(tmp, &value, arena); |
| 6097 | if (res != 0) goto failed; |
| 6098 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6099 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6100 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6101 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6102 | return 1; |
| 6103 | } |
| 6104 | if (tmp == NULL) { |
| 6105 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6106 | return 1; |
| 6107 | } |
| 6108 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6109 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6110 | res = obj2ast_int(tmp, &simple, arena); |
| 6111 | if (res != 0) goto failed; |
| 6112 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6113 | } |
| 6114 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6115 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6116 | if (*out == NULL) goto failed; |
| 6117 | return 0; |
| 6118 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6119 | tp = astmodulestate_global->For_type; |
| 6120 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6121 | if (isinstance == -1) { |
| 6122 | return 1; |
| 6123 | } |
| 6124 | if (isinstance) { |
| 6125 | expr_ty target; |
| 6126 | expr_ty iter; |
| 6127 | asdl_seq* body; |
| 6128 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6129 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6130 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6131 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6132 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6133 | return 1; |
| 6134 | } |
| 6135 | if (tmp == NULL) { |
| 6136 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6137 | return 1; |
| 6138 | } |
| 6139 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6140 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6141 | res = obj2ast_expr(tmp, &target, arena); |
| 6142 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6143 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6144 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6145 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6146 | return 1; |
| 6147 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6148 | if (tmp == NULL) { |
| 6149 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6150 | return 1; |
| 6151 | } |
| 6152 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6153 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6154 | res = obj2ast_expr(tmp, &iter, arena); |
| 6155 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6156 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6157 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6158 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6159 | return 1; |
| 6160 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6161 | if (tmp == NULL) { |
| 6162 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6163 | return 1; |
| 6164 | } |
| 6165 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6166 | int res; |
| 6167 | Py_ssize_t len; |
| 6168 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6169 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6170 | 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] | 6171 | goto failed; |
| 6172 | } |
| 6173 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6174 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6175 | if (body == NULL) goto failed; |
| 6176 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6177 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6178 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6179 | Py_INCREF(tmp2); |
| 6180 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6181 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6182 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6183 | if (len != PyList_GET_SIZE(tmp)) { |
| 6184 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6185 | goto failed; |
| 6186 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6187 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6188 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6189 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6191 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6192 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6193 | return 1; |
| 6194 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6195 | if (tmp == NULL) { |
| 6196 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6197 | return 1; |
| 6198 | } |
| 6199 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6200 | int res; |
| 6201 | Py_ssize_t len; |
| 6202 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6203 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6204 | 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] | 6205 | goto failed; |
| 6206 | } |
| 6207 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6208 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6209 | if (orelse == NULL) goto failed; |
| 6210 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6211 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6212 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6213 | Py_INCREF(tmp2); |
| 6214 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6215 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6216 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6217 | if (len != PyList_GET_SIZE(tmp)) { |
| 6218 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6219 | goto failed; |
| 6220 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6221 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6222 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6223 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6224 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6225 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6226 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6227 | return 1; |
| 6228 | } |
| 6229 | if (tmp == NULL || tmp == Py_None) { |
| 6230 | Py_CLEAR(tmp); |
| 6231 | type_comment = NULL; |
| 6232 | } |
| 6233 | else { |
| 6234 | int res; |
| 6235 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6236 | if (res != 0) goto failed; |
| 6237 | Py_CLEAR(tmp); |
| 6238 | } |
| 6239 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6240 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6241 | if (*out == NULL) goto failed; |
| 6242 | return 0; |
| 6243 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6244 | tp = astmodulestate_global->AsyncFor_type; |
| 6245 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6246 | if (isinstance == -1) { |
| 6247 | return 1; |
| 6248 | } |
| 6249 | if (isinstance) { |
| 6250 | expr_ty target; |
| 6251 | expr_ty iter; |
| 6252 | asdl_seq* body; |
| 6253 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6254 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6255 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6256 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6257 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6258 | return 1; |
| 6259 | } |
| 6260 | if (tmp == NULL) { |
| 6261 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6262 | return 1; |
| 6263 | } |
| 6264 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6265 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6266 | res = obj2ast_expr(tmp, &target, arena); |
| 6267 | if (res != 0) goto failed; |
| 6268 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6269 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6270 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6271 | return 1; |
| 6272 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6273 | if (tmp == NULL) { |
| 6274 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6275 | return 1; |
| 6276 | } |
| 6277 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6278 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6279 | res = obj2ast_expr(tmp, &iter, arena); |
| 6280 | if (res != 0) goto failed; |
| 6281 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6282 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6283 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6284 | return 1; |
| 6285 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6286 | if (tmp == NULL) { |
| 6287 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6288 | return 1; |
| 6289 | } |
| 6290 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6291 | int res; |
| 6292 | Py_ssize_t len; |
| 6293 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6294 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6295 | 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] | 6296 | goto failed; |
| 6297 | } |
| 6298 | len = PyList_GET_SIZE(tmp); |
| 6299 | body = _Py_asdl_seq_new(len, arena); |
| 6300 | if (body == NULL) goto failed; |
| 6301 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6302 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6303 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6304 | Py_INCREF(tmp2); |
| 6305 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6306 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6307 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6308 | if (len != PyList_GET_SIZE(tmp)) { |
| 6309 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6310 | goto failed; |
| 6311 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6312 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6313 | } |
| 6314 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6315 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6316 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6317 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6318 | return 1; |
| 6319 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6320 | if (tmp == NULL) { |
| 6321 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6322 | return 1; |
| 6323 | } |
| 6324 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6325 | int res; |
| 6326 | Py_ssize_t len; |
| 6327 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6328 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6329 | 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] | 6330 | goto failed; |
| 6331 | } |
| 6332 | len = PyList_GET_SIZE(tmp); |
| 6333 | orelse = _Py_asdl_seq_new(len, arena); |
| 6334 | if (orelse == NULL) goto failed; |
| 6335 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6336 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6337 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6338 | Py_INCREF(tmp2); |
| 6339 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6340 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6341 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6342 | if (len != PyList_GET_SIZE(tmp)) { |
| 6343 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6344 | goto failed; |
| 6345 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6346 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6347 | } |
| 6348 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6349 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6350 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6351 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6352 | return 1; |
| 6353 | } |
| 6354 | if (tmp == NULL || tmp == Py_None) { |
| 6355 | Py_CLEAR(tmp); |
| 6356 | type_comment = NULL; |
| 6357 | } |
| 6358 | else { |
| 6359 | int res; |
| 6360 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6361 | if (res != 0) goto failed; |
| 6362 | Py_CLEAR(tmp); |
| 6363 | } |
| 6364 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6365 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6366 | if (*out == NULL) goto failed; |
| 6367 | return 0; |
| 6368 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6369 | tp = astmodulestate_global->While_type; |
| 6370 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6371 | if (isinstance == -1) { |
| 6372 | return 1; |
| 6373 | } |
| 6374 | if (isinstance) { |
| 6375 | expr_ty test; |
| 6376 | asdl_seq* body; |
| 6377 | asdl_seq* orelse; |
| 6378 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6379 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6380 | return 1; |
| 6381 | } |
| 6382 | if (tmp == NULL) { |
| 6383 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6384 | return 1; |
| 6385 | } |
| 6386 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6387 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6388 | res = obj2ast_expr(tmp, &test, arena); |
| 6389 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6390 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6391 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6392 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6393 | return 1; |
| 6394 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6395 | if (tmp == NULL) { |
| 6396 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6397 | return 1; |
| 6398 | } |
| 6399 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6400 | int res; |
| 6401 | Py_ssize_t len; |
| 6402 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6403 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6404 | 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] | 6405 | goto failed; |
| 6406 | } |
| 6407 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6408 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6409 | if (body == NULL) goto failed; |
| 6410 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6411 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6412 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6413 | Py_INCREF(tmp2); |
| 6414 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6415 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6416 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6417 | if (len != PyList_GET_SIZE(tmp)) { |
| 6418 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6419 | goto failed; |
| 6420 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6421 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6422 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6423 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6424 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6425 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6426 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6427 | return 1; |
| 6428 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6429 | if (tmp == NULL) { |
| 6430 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6431 | return 1; |
| 6432 | } |
| 6433 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6434 | int res; |
| 6435 | Py_ssize_t len; |
| 6436 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6437 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6438 | 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] | 6439 | goto failed; |
| 6440 | } |
| 6441 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6442 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6443 | if (orelse == NULL) goto failed; |
| 6444 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6445 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6446 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6447 | Py_INCREF(tmp2); |
| 6448 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6449 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6450 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6451 | if (len != PyList_GET_SIZE(tmp)) { |
| 6452 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6453 | goto failed; |
| 6454 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6455 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6456 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6457 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6458 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6459 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6460 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6461 | if (*out == NULL) goto failed; |
| 6462 | return 0; |
| 6463 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6464 | tp = astmodulestate_global->If_type; |
| 6465 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6466 | if (isinstance == -1) { |
| 6467 | return 1; |
| 6468 | } |
| 6469 | if (isinstance) { |
| 6470 | expr_ty test; |
| 6471 | asdl_seq* body; |
| 6472 | asdl_seq* orelse; |
| 6473 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6474 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6475 | return 1; |
| 6476 | } |
| 6477 | if (tmp == NULL) { |
| 6478 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6479 | return 1; |
| 6480 | } |
| 6481 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6482 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6483 | res = obj2ast_expr(tmp, &test, arena); |
| 6484 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6485 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6486 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6487 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6488 | return 1; |
| 6489 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6490 | if (tmp == NULL) { |
| 6491 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6492 | return 1; |
| 6493 | } |
| 6494 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6495 | int res; |
| 6496 | Py_ssize_t len; |
| 6497 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6498 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6499 | 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] | 6500 | goto failed; |
| 6501 | } |
| 6502 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6503 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6504 | if (body == NULL) goto failed; |
| 6505 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6506 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6507 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6508 | Py_INCREF(tmp2); |
| 6509 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6510 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6511 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6512 | if (len != PyList_GET_SIZE(tmp)) { |
| 6513 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6514 | goto failed; |
| 6515 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6516 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6517 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6518 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6519 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6520 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6521 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6522 | return 1; |
| 6523 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6524 | if (tmp == NULL) { |
| 6525 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6526 | return 1; |
| 6527 | } |
| 6528 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6529 | int res; |
| 6530 | Py_ssize_t len; |
| 6531 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6532 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6533 | PyErr_Format(PyExc_TypeError, "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] | 6534 | goto failed; |
| 6535 | } |
| 6536 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6537 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6538 | if (orelse == NULL) goto failed; |
| 6539 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6540 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6541 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6542 | Py_INCREF(tmp2); |
| 6543 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6544 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6545 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6546 | if (len != PyList_GET_SIZE(tmp)) { |
| 6547 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6548 | goto failed; |
| 6549 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6550 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6551 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6552 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6553 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6554 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6555 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6556 | if (*out == NULL) goto failed; |
| 6557 | return 0; |
| 6558 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6559 | tp = astmodulestate_global->With_type; |
| 6560 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6561 | if (isinstance == -1) { |
| 6562 | return 1; |
| 6563 | } |
| 6564 | if (isinstance) { |
| 6565 | asdl_seq* items; |
| 6566 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6567 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6568 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6569 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6570 | return 1; |
| 6571 | } |
| 6572 | if (tmp == NULL) { |
| 6573 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6574 | return 1; |
| 6575 | } |
| 6576 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6577 | int res; |
| 6578 | Py_ssize_t len; |
| 6579 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6580 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6581 | 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] | 6582 | goto failed; |
| 6583 | } |
| 6584 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6585 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6586 | if (items == NULL) goto failed; |
| 6587 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6588 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6589 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6590 | Py_INCREF(tmp2); |
| 6591 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6592 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6593 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6594 | if (len != PyList_GET_SIZE(tmp)) { |
| 6595 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6596 | goto failed; |
| 6597 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6598 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6599 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6600 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6601 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6602 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6603 | return 1; |
| 6604 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6605 | if (tmp == NULL) { |
| 6606 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6607 | return 1; |
| 6608 | } |
| 6609 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6610 | int res; |
| 6611 | Py_ssize_t len; |
| 6612 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6613 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6614 | 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] | 6615 | goto failed; |
| 6616 | } |
| 6617 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6618 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6619 | if (body == NULL) goto failed; |
| 6620 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6621 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6622 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6623 | Py_INCREF(tmp2); |
| 6624 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6625 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6626 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6627 | if (len != PyList_GET_SIZE(tmp)) { |
| 6628 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6629 | goto failed; |
| 6630 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6631 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6632 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6633 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6634 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6635 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6636 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6637 | return 1; |
| 6638 | } |
| 6639 | if (tmp == NULL || tmp == Py_None) { |
| 6640 | Py_CLEAR(tmp); |
| 6641 | type_comment = NULL; |
| 6642 | } |
| 6643 | else { |
| 6644 | int res; |
| 6645 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6646 | if (res != 0) goto failed; |
| 6647 | Py_CLEAR(tmp); |
| 6648 | } |
| 6649 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6650 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6651 | if (*out == NULL) goto failed; |
| 6652 | return 0; |
| 6653 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6654 | tp = astmodulestate_global->AsyncWith_type; |
| 6655 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6656 | if (isinstance == -1) { |
| 6657 | return 1; |
| 6658 | } |
| 6659 | if (isinstance) { |
| 6660 | asdl_seq* items; |
| 6661 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6662 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6663 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6664 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6665 | return 1; |
| 6666 | } |
| 6667 | if (tmp == NULL) { |
| 6668 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6669 | return 1; |
| 6670 | } |
| 6671 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6672 | int res; |
| 6673 | Py_ssize_t len; |
| 6674 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6675 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6676 | 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] | 6677 | goto failed; |
| 6678 | } |
| 6679 | len = PyList_GET_SIZE(tmp); |
| 6680 | items = _Py_asdl_seq_new(len, arena); |
| 6681 | if (items == NULL) goto failed; |
| 6682 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6683 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6684 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6685 | Py_INCREF(tmp2); |
| 6686 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6687 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6688 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6689 | if (len != PyList_GET_SIZE(tmp)) { |
| 6690 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6691 | goto failed; |
| 6692 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6693 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6694 | } |
| 6695 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6696 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6697 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6698 | return 1; |
| 6699 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6700 | if (tmp == NULL) { |
| 6701 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6702 | return 1; |
| 6703 | } |
| 6704 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6705 | int res; |
| 6706 | Py_ssize_t len; |
| 6707 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6708 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6709 | 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] | 6710 | goto failed; |
| 6711 | } |
| 6712 | len = PyList_GET_SIZE(tmp); |
| 6713 | body = _Py_asdl_seq_new(len, arena); |
| 6714 | if (body == NULL) goto failed; |
| 6715 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6716 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6717 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6718 | Py_INCREF(tmp2); |
| 6719 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6720 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6721 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6722 | if (len != PyList_GET_SIZE(tmp)) { |
| 6723 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6724 | goto failed; |
| 6725 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6726 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6727 | } |
| 6728 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6729 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6730 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6731 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6732 | return 1; |
| 6733 | } |
| 6734 | if (tmp == NULL || tmp == Py_None) { |
| 6735 | Py_CLEAR(tmp); |
| 6736 | type_comment = NULL; |
| 6737 | } |
| 6738 | else { |
| 6739 | int res; |
| 6740 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6741 | if (res != 0) goto failed; |
| 6742 | Py_CLEAR(tmp); |
| 6743 | } |
| 6744 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6745 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6746 | if (*out == NULL) goto failed; |
| 6747 | return 0; |
| 6748 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6749 | tp = astmodulestate_global->Raise_type; |
| 6750 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6751 | if (isinstance == -1) { |
| 6752 | return 1; |
| 6753 | } |
| 6754 | if (isinstance) { |
| 6755 | expr_ty exc; |
| 6756 | expr_ty cause; |
| 6757 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6758 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6759 | return 1; |
| 6760 | } |
| 6761 | if (tmp == NULL || tmp == Py_None) { |
| 6762 | Py_CLEAR(tmp); |
| 6763 | exc = NULL; |
| 6764 | } |
| 6765 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6766 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6767 | res = obj2ast_expr(tmp, &exc, arena); |
| 6768 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6769 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6770 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6771 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6772 | return 1; |
| 6773 | } |
| 6774 | if (tmp == NULL || tmp == Py_None) { |
| 6775 | Py_CLEAR(tmp); |
| 6776 | cause = NULL; |
| 6777 | } |
| 6778 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6779 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6780 | res = obj2ast_expr(tmp, &cause, arena); |
| 6781 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6782 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6783 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6784 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6785 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6786 | if (*out == NULL) goto failed; |
| 6787 | return 0; |
| 6788 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6789 | tp = astmodulestate_global->Try_type; |
| 6790 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6791 | if (isinstance == -1) { |
| 6792 | return 1; |
| 6793 | } |
| 6794 | if (isinstance) { |
| 6795 | asdl_seq* body; |
| 6796 | asdl_seq* handlers; |
| 6797 | asdl_seq* orelse; |
| 6798 | asdl_seq* finalbody; |
| 6799 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6800 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6801 | return 1; |
| 6802 | } |
| 6803 | if (tmp == NULL) { |
| 6804 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6805 | return 1; |
| 6806 | } |
| 6807 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6808 | int res; |
| 6809 | Py_ssize_t len; |
| 6810 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6811 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6812 | 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] | 6813 | goto failed; |
| 6814 | } |
| 6815 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6816 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6817 | if (body == NULL) goto failed; |
| 6818 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6819 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6820 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6821 | Py_INCREF(tmp2); |
| 6822 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6823 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6824 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6825 | if (len != PyList_GET_SIZE(tmp)) { |
| 6826 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6827 | goto failed; |
| 6828 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6829 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6830 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6831 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6832 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6833 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6834 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6835 | return 1; |
| 6836 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6837 | if (tmp == NULL) { |
| 6838 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6839 | return 1; |
| 6840 | } |
| 6841 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6842 | int res; |
| 6843 | Py_ssize_t len; |
| 6844 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6845 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6846 | 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] | 6847 | goto failed; |
| 6848 | } |
| 6849 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6850 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6851 | if (handlers == NULL) goto failed; |
| 6852 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6853 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6854 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6855 | Py_INCREF(tmp2); |
| 6856 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6857 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6858 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6859 | if (len != PyList_GET_SIZE(tmp)) { |
| 6860 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6861 | goto failed; |
| 6862 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6863 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6864 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6865 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6866 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6867 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6868 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6869 | return 1; |
| 6870 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6871 | if (tmp == NULL) { |
| 6872 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6873 | return 1; |
| 6874 | } |
| 6875 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6876 | int res; |
| 6877 | Py_ssize_t len; |
| 6878 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6879 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6880 | 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] | 6881 | goto failed; |
| 6882 | } |
| 6883 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6884 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6885 | if (orelse == NULL) goto failed; |
| 6886 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6887 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6888 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6889 | Py_INCREF(tmp2); |
| 6890 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6891 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6892 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6893 | if (len != PyList_GET_SIZE(tmp)) { |
| 6894 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6895 | goto failed; |
| 6896 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6897 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6898 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6899 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6900 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6901 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6902 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6903 | return 1; |
| 6904 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6905 | if (tmp == NULL) { |
| 6906 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6907 | return 1; |
| 6908 | } |
| 6909 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6910 | int res; |
| 6911 | Py_ssize_t len; |
| 6912 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6913 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6914 | 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] | 6915 | goto failed; |
| 6916 | } |
| 6917 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6918 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6919 | if (finalbody == NULL) goto failed; |
| 6920 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6921 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6922 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6923 | Py_INCREF(tmp2); |
| 6924 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6925 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6926 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6927 | if (len != PyList_GET_SIZE(tmp)) { |
| 6928 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6929 | goto failed; |
| 6930 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6931 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6932 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6933 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6934 | } |
| 6935 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6936 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6937 | if (*out == NULL) goto failed; |
| 6938 | return 0; |
| 6939 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6940 | tp = astmodulestate_global->Assert_type; |
| 6941 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6942 | if (isinstance == -1) { |
| 6943 | return 1; |
| 6944 | } |
| 6945 | if (isinstance) { |
| 6946 | expr_ty test; |
| 6947 | expr_ty msg; |
| 6948 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6949 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6950 | return 1; |
| 6951 | } |
| 6952 | if (tmp == NULL) { |
| 6953 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6954 | return 1; |
| 6955 | } |
| 6956 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6957 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6958 | res = obj2ast_expr(tmp, &test, arena); |
| 6959 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6960 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6961 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6962 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6963 | return 1; |
| 6964 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6965 | if (tmp == NULL || tmp == Py_None) { |
| 6966 | Py_CLEAR(tmp); |
| 6967 | msg = NULL; |
| 6968 | } |
| 6969 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6970 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6971 | res = obj2ast_expr(tmp, &msg, arena); |
| 6972 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6973 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6974 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6975 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6976 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6977 | if (*out == NULL) goto failed; |
| 6978 | return 0; |
| 6979 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6980 | tp = astmodulestate_global->Import_type; |
| 6981 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6982 | if (isinstance == -1) { |
| 6983 | return 1; |
| 6984 | } |
| 6985 | if (isinstance) { |
| 6986 | asdl_seq* names; |
| 6987 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6988 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6989 | return 1; |
| 6990 | } |
| 6991 | if (tmp == NULL) { |
| 6992 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6993 | return 1; |
| 6994 | } |
| 6995 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6996 | int res; |
| 6997 | Py_ssize_t len; |
| 6998 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6999 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7000 | 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] | 7001 | goto failed; |
| 7002 | } |
| 7003 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7004 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7005 | if (names == NULL) goto failed; |
| 7006 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7007 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7008 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7009 | Py_INCREF(tmp2); |
| 7010 | res = obj2ast_alias(tmp2, &val, arena); |
| 7011 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7012 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7013 | if (len != PyList_GET_SIZE(tmp)) { |
| 7014 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 7015 | goto failed; |
| 7016 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7017 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7018 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7019 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7020 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7021 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7022 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7023 | if (*out == NULL) goto failed; |
| 7024 | return 0; |
| 7025 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7026 | tp = astmodulestate_global->ImportFrom_type; |
| 7027 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7028 | if (isinstance == -1) { |
| 7029 | return 1; |
| 7030 | } |
| 7031 | if (isinstance) { |
| 7032 | identifier module; |
| 7033 | asdl_seq* names; |
| 7034 | int level; |
| 7035 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7036 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 7037 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7038 | return 1; |
| 7039 | } |
| 7040 | if (tmp == NULL || tmp == Py_None) { |
| 7041 | Py_CLEAR(tmp); |
| 7042 | module = NULL; |
| 7043 | } |
| 7044 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7045 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7046 | res = obj2ast_identifier(tmp, &module, arena); |
| 7047 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7048 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7049 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7050 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7051 | return 1; |
| 7052 | } |
| 7053 | if (tmp == NULL) { |
| 7054 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 7055 | return 1; |
| 7056 | } |
| 7057 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7058 | int res; |
| 7059 | Py_ssize_t len; |
| 7060 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7061 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7062 | 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] | 7063 | goto failed; |
| 7064 | } |
| 7065 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7066 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7067 | if (names == NULL) goto failed; |
| 7068 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7069 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7070 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7071 | Py_INCREF(tmp2); |
| 7072 | res = obj2ast_alias(tmp2, &val, arena); |
| 7073 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7074 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7075 | if (len != PyList_GET_SIZE(tmp)) { |
| 7076 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 7077 | goto failed; |
| 7078 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7079 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7080 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7081 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7082 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7083 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7084 | return 1; |
| 7085 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7086 | if (tmp == NULL || tmp == Py_None) { |
| 7087 | Py_CLEAR(tmp); |
| 7088 | level = 0; |
| 7089 | } |
| 7090 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7091 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7092 | res = obj2ast_int(tmp, &level, arena); |
| 7093 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7094 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7095 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7096 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7097 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7098 | if (*out == NULL) goto failed; |
| 7099 | return 0; |
| 7100 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7101 | tp = astmodulestate_global->Global_type; |
| 7102 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7103 | if (isinstance == -1) { |
| 7104 | return 1; |
| 7105 | } |
| 7106 | if (isinstance) { |
| 7107 | asdl_seq* names; |
| 7108 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7109 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7110 | return 1; |
| 7111 | } |
| 7112 | if (tmp == NULL) { |
| 7113 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7114 | return 1; |
| 7115 | } |
| 7116 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7117 | int res; |
| 7118 | Py_ssize_t len; |
| 7119 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7120 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7121 | 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] | 7122 | goto failed; |
| 7123 | } |
| 7124 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7125 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7126 | if (names == NULL) goto failed; |
| 7127 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7128 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7129 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7130 | Py_INCREF(tmp2); |
| 7131 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7132 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7133 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7134 | if (len != PyList_GET_SIZE(tmp)) { |
| 7135 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7136 | goto failed; |
| 7137 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7138 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7139 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7140 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7141 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7142 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7143 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7144 | if (*out == NULL) goto failed; |
| 7145 | return 0; |
| 7146 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7147 | tp = astmodulestate_global->Nonlocal_type; |
| 7148 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7149 | if (isinstance == -1) { |
| 7150 | return 1; |
| 7151 | } |
| 7152 | if (isinstance) { |
| 7153 | asdl_seq* names; |
| 7154 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7155 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7156 | return 1; |
| 7157 | } |
| 7158 | if (tmp == NULL) { |
| 7159 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7160 | return 1; |
| 7161 | } |
| 7162 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7163 | int res; |
| 7164 | Py_ssize_t len; |
| 7165 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7166 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7167 | 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] | 7168 | goto failed; |
| 7169 | } |
| 7170 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7171 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7172 | if (names == NULL) goto failed; |
| 7173 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7174 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7175 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7176 | Py_INCREF(tmp2); |
| 7177 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7178 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7179 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7180 | if (len != PyList_GET_SIZE(tmp)) { |
| 7181 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7182 | goto failed; |
| 7183 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7184 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7185 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7186 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7187 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7188 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7189 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7190 | if (*out == NULL) goto failed; |
| 7191 | return 0; |
| 7192 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7193 | tp = astmodulestate_global->Expr_type; |
| 7194 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7195 | if (isinstance == -1) { |
| 7196 | return 1; |
| 7197 | } |
| 7198 | if (isinstance) { |
| 7199 | expr_ty value; |
| 7200 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7201 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7202 | return 1; |
| 7203 | } |
| 7204 | if (tmp == NULL) { |
| 7205 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7206 | return 1; |
| 7207 | } |
| 7208 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7209 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7210 | res = obj2ast_expr(tmp, &value, arena); |
| 7211 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7212 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7213 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7214 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7215 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7216 | if (*out == NULL) goto failed; |
| 7217 | return 0; |
| 7218 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7219 | tp = astmodulestate_global->Pass_type; |
| 7220 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7221 | if (isinstance == -1) { |
| 7222 | return 1; |
| 7223 | } |
| 7224 | if (isinstance) { |
| 7225 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7226 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7227 | if (*out == NULL) goto failed; |
| 7228 | return 0; |
| 7229 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7230 | tp = astmodulestate_global->Break_type; |
| 7231 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7232 | if (isinstance == -1) { |
| 7233 | return 1; |
| 7234 | } |
| 7235 | if (isinstance) { |
| 7236 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7237 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7238 | if (*out == NULL) goto failed; |
| 7239 | return 0; |
| 7240 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7241 | tp = astmodulestate_global->Continue_type; |
| 7242 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7243 | if (isinstance == -1) { |
| 7244 | return 1; |
| 7245 | } |
| 7246 | if (isinstance) { |
| 7247 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7248 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7249 | if (*out == NULL) goto failed; |
| 7250 | return 0; |
| 7251 | } |
| 7252 | |
| 7253 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7254 | failed: |
| 7255 | Py_XDECREF(tmp); |
| 7256 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7257 | } |
| 7258 | |
| 7259 | int |
| 7260 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7261 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7262 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7263 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7264 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7265 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7266 | int lineno; |
| 7267 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7268 | int end_lineno; |
| 7269 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7270 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7271 | if (obj == Py_None) { |
| 7272 | *out = NULL; |
| 7273 | return 0; |
| 7274 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7275 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7276 | return 1; |
| 7277 | } |
| 7278 | if (tmp == NULL) { |
| 7279 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7280 | return 1; |
| 7281 | } |
| 7282 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7283 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7284 | res = obj2ast_int(tmp, &lineno, arena); |
| 7285 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7286 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7287 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7288 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7289 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7290 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7291 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7292 | if (tmp == NULL) { |
| 7293 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7294 | return 1; |
| 7295 | } |
| 7296 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7297 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7298 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7299 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7300 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7301 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7302 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7303 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7304 | return 1; |
| 7305 | } |
| 7306 | if (tmp == NULL || tmp == Py_None) { |
| 7307 | Py_CLEAR(tmp); |
| 7308 | end_lineno = 0; |
| 7309 | } |
| 7310 | else { |
| 7311 | int res; |
| 7312 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7313 | if (res != 0) goto failed; |
| 7314 | Py_CLEAR(tmp); |
| 7315 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7316 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7317 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7318 | return 1; |
| 7319 | } |
| 7320 | if (tmp == NULL || tmp == Py_None) { |
| 7321 | Py_CLEAR(tmp); |
| 7322 | end_col_offset = 0; |
| 7323 | } |
| 7324 | else { |
| 7325 | int res; |
| 7326 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7327 | if (res != 0) goto failed; |
| 7328 | Py_CLEAR(tmp); |
| 7329 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7330 | tp = astmodulestate_global->BoolOp_type; |
| 7331 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7332 | if (isinstance == -1) { |
| 7333 | return 1; |
| 7334 | } |
| 7335 | if (isinstance) { |
| 7336 | boolop_ty op; |
| 7337 | asdl_seq* values; |
| 7338 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7339 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7340 | return 1; |
| 7341 | } |
| 7342 | if (tmp == NULL) { |
| 7343 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7344 | return 1; |
| 7345 | } |
| 7346 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7347 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7348 | res = obj2ast_boolop(tmp, &op, arena); |
| 7349 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7350 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7351 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7352 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7353 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7354 | return 1; |
| 7355 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7356 | if (tmp == NULL) { |
| 7357 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7358 | return 1; |
| 7359 | } |
| 7360 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7361 | int res; |
| 7362 | Py_ssize_t len; |
| 7363 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7364 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7365 | 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] | 7366 | goto failed; |
| 7367 | } |
| 7368 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7369 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7370 | if (values == NULL) goto failed; |
| 7371 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7372 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7373 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7374 | Py_INCREF(tmp2); |
| 7375 | res = obj2ast_expr(tmp2, &val, arena); |
| 7376 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7377 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7378 | if (len != PyList_GET_SIZE(tmp)) { |
| 7379 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7380 | goto failed; |
| 7381 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7382 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7383 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7384 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7385 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7386 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7387 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7388 | if (*out == NULL) goto failed; |
| 7389 | return 0; |
| 7390 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7391 | tp = astmodulestate_global->NamedExpr_type; |
| 7392 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7393 | if (isinstance == -1) { |
| 7394 | return 1; |
| 7395 | } |
| 7396 | if (isinstance) { |
| 7397 | expr_ty target; |
| 7398 | expr_ty value; |
| 7399 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7400 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7401 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7402 | return 1; |
| 7403 | } |
| 7404 | if (tmp == NULL) { |
| 7405 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7406 | return 1; |
| 7407 | } |
| 7408 | else { |
| 7409 | int res; |
| 7410 | res = obj2ast_expr(tmp, &target, arena); |
| 7411 | if (res != 0) goto failed; |
| 7412 | Py_CLEAR(tmp); |
| 7413 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7414 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7415 | return 1; |
| 7416 | } |
| 7417 | if (tmp == NULL) { |
| 7418 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7419 | return 1; |
| 7420 | } |
| 7421 | else { |
| 7422 | int res; |
| 7423 | res = obj2ast_expr(tmp, &value, arena); |
| 7424 | if (res != 0) goto failed; |
| 7425 | Py_CLEAR(tmp); |
| 7426 | } |
| 7427 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7428 | end_col_offset, arena); |
| 7429 | if (*out == NULL) goto failed; |
| 7430 | return 0; |
| 7431 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7432 | tp = astmodulestate_global->BinOp_type; |
| 7433 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7434 | if (isinstance == -1) { |
| 7435 | return 1; |
| 7436 | } |
| 7437 | if (isinstance) { |
| 7438 | expr_ty left; |
| 7439 | operator_ty op; |
| 7440 | expr_ty right; |
| 7441 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7442 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7443 | return 1; |
| 7444 | } |
| 7445 | if (tmp == NULL) { |
| 7446 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7447 | return 1; |
| 7448 | } |
| 7449 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7450 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7451 | res = obj2ast_expr(tmp, &left, arena); |
| 7452 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7453 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7454 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7455 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7456 | return 1; |
| 7457 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7458 | if (tmp == NULL) { |
| 7459 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7460 | return 1; |
| 7461 | } |
| 7462 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7463 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7464 | res = obj2ast_operator(tmp, &op, arena); |
| 7465 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7466 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7467 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7468 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7469 | return 1; |
| 7470 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7471 | if (tmp == NULL) { |
| 7472 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7473 | return 1; |
| 7474 | } |
| 7475 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7476 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7477 | res = obj2ast_expr(tmp, &right, arena); |
| 7478 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7479 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7480 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7481 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7482 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7483 | if (*out == NULL) goto failed; |
| 7484 | return 0; |
| 7485 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7486 | tp = astmodulestate_global->UnaryOp_type; |
| 7487 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7488 | if (isinstance == -1) { |
| 7489 | return 1; |
| 7490 | } |
| 7491 | if (isinstance) { |
| 7492 | unaryop_ty op; |
| 7493 | expr_ty operand; |
| 7494 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7495 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7496 | return 1; |
| 7497 | } |
| 7498 | if (tmp == NULL) { |
| 7499 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7500 | return 1; |
| 7501 | } |
| 7502 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7503 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7504 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7505 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7506 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7507 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7508 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7509 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7510 | return 1; |
| 7511 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7512 | if (tmp == NULL) { |
| 7513 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7514 | return 1; |
| 7515 | } |
| 7516 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7517 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7518 | res = obj2ast_expr(tmp, &operand, arena); |
| 7519 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7520 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7521 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7522 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7523 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7524 | if (*out == NULL) goto failed; |
| 7525 | return 0; |
| 7526 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7527 | tp = astmodulestate_global->Lambda_type; |
| 7528 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7529 | if (isinstance == -1) { |
| 7530 | return 1; |
| 7531 | } |
| 7532 | if (isinstance) { |
| 7533 | arguments_ty args; |
| 7534 | expr_ty body; |
| 7535 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7536 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7537 | return 1; |
| 7538 | } |
| 7539 | if (tmp == NULL) { |
| 7540 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7541 | return 1; |
| 7542 | } |
| 7543 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7544 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7545 | res = obj2ast_arguments(tmp, &args, arena); |
| 7546 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7547 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7548 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7549 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7550 | return 1; |
| 7551 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7552 | if (tmp == NULL) { |
| 7553 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7554 | return 1; |
| 7555 | } |
| 7556 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7557 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7558 | res = obj2ast_expr(tmp, &body, arena); |
| 7559 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7560 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7561 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7562 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7563 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7564 | if (*out == NULL) goto failed; |
| 7565 | return 0; |
| 7566 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7567 | tp = astmodulestate_global->IfExp_type; |
| 7568 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7569 | if (isinstance == -1) { |
| 7570 | return 1; |
| 7571 | } |
| 7572 | if (isinstance) { |
| 7573 | expr_ty test; |
| 7574 | expr_ty body; |
| 7575 | expr_ty orelse; |
| 7576 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7577 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7578 | return 1; |
| 7579 | } |
| 7580 | if (tmp == NULL) { |
| 7581 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7582 | return 1; |
| 7583 | } |
| 7584 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7585 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7586 | res = obj2ast_expr(tmp, &test, arena); |
| 7587 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7588 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7589 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7590 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7591 | return 1; |
| 7592 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7593 | if (tmp == NULL) { |
| 7594 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7595 | return 1; |
| 7596 | } |
| 7597 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7598 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7599 | res = obj2ast_expr(tmp, &body, arena); |
| 7600 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7601 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7602 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7603 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7604 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7605 | return 1; |
| 7606 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7607 | if (tmp == NULL) { |
| 7608 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7609 | return 1; |
| 7610 | } |
| 7611 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7612 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7613 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7614 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7615 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7616 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7617 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7618 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7619 | if (*out == NULL) goto failed; |
| 7620 | return 0; |
| 7621 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7622 | tp = astmodulestate_global->Dict_type; |
| 7623 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7624 | if (isinstance == -1) { |
| 7625 | return 1; |
| 7626 | } |
| 7627 | if (isinstance) { |
| 7628 | asdl_seq* keys; |
| 7629 | asdl_seq* values; |
| 7630 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7631 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7632 | return 1; |
| 7633 | } |
| 7634 | if (tmp == NULL) { |
| 7635 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7636 | return 1; |
| 7637 | } |
| 7638 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7639 | int res; |
| 7640 | Py_ssize_t len; |
| 7641 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7642 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7643 | 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] | 7644 | goto failed; |
| 7645 | } |
| 7646 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7647 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7648 | if (keys == NULL) goto failed; |
| 7649 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7650 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7651 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7652 | Py_INCREF(tmp2); |
| 7653 | res = obj2ast_expr(tmp2, &val, arena); |
| 7654 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7655 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7656 | if (len != PyList_GET_SIZE(tmp)) { |
| 7657 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7658 | goto failed; |
| 7659 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7660 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7661 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7662 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7663 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7664 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7665 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7666 | return 1; |
| 7667 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7668 | if (tmp == NULL) { |
| 7669 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7670 | return 1; |
| 7671 | } |
| 7672 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7673 | int res; |
| 7674 | Py_ssize_t len; |
| 7675 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7676 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7677 | 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] | 7678 | goto failed; |
| 7679 | } |
| 7680 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7681 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7682 | if (values == NULL) goto failed; |
| 7683 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7684 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7685 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7686 | Py_INCREF(tmp2); |
| 7687 | res = obj2ast_expr(tmp2, &val, arena); |
| 7688 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7689 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7690 | if (len != PyList_GET_SIZE(tmp)) { |
| 7691 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7692 | goto failed; |
| 7693 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7694 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7695 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7696 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7697 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7698 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7699 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7700 | if (*out == NULL) goto failed; |
| 7701 | return 0; |
| 7702 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7703 | tp = astmodulestate_global->Set_type; |
| 7704 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7705 | if (isinstance == -1) { |
| 7706 | return 1; |
| 7707 | } |
| 7708 | if (isinstance) { |
| 7709 | asdl_seq* elts; |
| 7710 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7711 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7712 | return 1; |
| 7713 | } |
| 7714 | if (tmp == NULL) { |
| 7715 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7716 | return 1; |
| 7717 | } |
| 7718 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7719 | int res; |
| 7720 | Py_ssize_t len; |
| 7721 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7722 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7723 | 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] | 7724 | goto failed; |
| 7725 | } |
| 7726 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7727 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7728 | if (elts == NULL) goto failed; |
| 7729 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7730 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7731 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7732 | Py_INCREF(tmp2); |
| 7733 | res = obj2ast_expr(tmp2, &val, arena); |
| 7734 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7735 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7736 | if (len != PyList_GET_SIZE(tmp)) { |
| 7737 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7738 | goto failed; |
| 7739 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7740 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7741 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7742 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7743 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7744 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7745 | if (*out == NULL) goto failed; |
| 7746 | return 0; |
| 7747 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7748 | tp = astmodulestate_global->ListComp_type; |
| 7749 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7750 | if (isinstance == -1) { |
| 7751 | return 1; |
| 7752 | } |
| 7753 | if (isinstance) { |
| 7754 | expr_ty elt; |
| 7755 | asdl_seq* generators; |
| 7756 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7757 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7758 | return 1; |
| 7759 | } |
| 7760 | if (tmp == NULL) { |
| 7761 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7762 | return 1; |
| 7763 | } |
| 7764 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7765 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7766 | res = obj2ast_expr(tmp, &elt, arena); |
| 7767 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7768 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7769 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7770 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7771 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7772 | return 1; |
| 7773 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7774 | if (tmp == NULL) { |
| 7775 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7776 | return 1; |
| 7777 | } |
| 7778 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7779 | int res; |
| 7780 | Py_ssize_t len; |
| 7781 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7782 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7783 | 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] | 7784 | goto failed; |
| 7785 | } |
| 7786 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7787 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7788 | if (generators == NULL) goto failed; |
| 7789 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7790 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7791 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7792 | Py_INCREF(tmp2); |
| 7793 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7794 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7795 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7796 | if (len != PyList_GET_SIZE(tmp)) { |
| 7797 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7798 | goto failed; |
| 7799 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7800 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7801 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7802 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7803 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7804 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7805 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7806 | if (*out == NULL) goto failed; |
| 7807 | return 0; |
| 7808 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7809 | tp = astmodulestate_global->SetComp_type; |
| 7810 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7811 | if (isinstance == -1) { |
| 7812 | return 1; |
| 7813 | } |
| 7814 | if (isinstance) { |
| 7815 | expr_ty elt; |
| 7816 | asdl_seq* generators; |
| 7817 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7818 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7819 | return 1; |
| 7820 | } |
| 7821 | if (tmp == NULL) { |
| 7822 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7823 | return 1; |
| 7824 | } |
| 7825 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7826 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7827 | res = obj2ast_expr(tmp, &elt, arena); |
| 7828 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7829 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7830 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7831 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7832 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7833 | return 1; |
| 7834 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7835 | if (tmp == NULL) { |
| 7836 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7837 | return 1; |
| 7838 | } |
| 7839 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7840 | int res; |
| 7841 | Py_ssize_t len; |
| 7842 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7843 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7844 | 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] | 7845 | goto failed; |
| 7846 | } |
| 7847 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7848 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7849 | if (generators == NULL) goto failed; |
| 7850 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7851 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7852 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7853 | Py_INCREF(tmp2); |
| 7854 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7855 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7856 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7857 | if (len != PyList_GET_SIZE(tmp)) { |
| 7858 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7859 | goto failed; |
| 7860 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7861 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7862 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7863 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7864 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7865 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7866 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7867 | if (*out == NULL) goto failed; |
| 7868 | return 0; |
| 7869 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7870 | tp = astmodulestate_global->DictComp_type; |
| 7871 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7872 | if (isinstance == -1) { |
| 7873 | return 1; |
| 7874 | } |
| 7875 | if (isinstance) { |
| 7876 | expr_ty key; |
| 7877 | expr_ty value; |
| 7878 | asdl_seq* generators; |
| 7879 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7880 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7881 | return 1; |
| 7882 | } |
| 7883 | if (tmp == NULL) { |
| 7884 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7885 | return 1; |
| 7886 | } |
| 7887 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7888 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7889 | res = obj2ast_expr(tmp, &key, arena); |
| 7890 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7891 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7892 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7893 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7894 | return 1; |
| 7895 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7896 | if (tmp == NULL) { |
| 7897 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7898 | return 1; |
| 7899 | } |
| 7900 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7901 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7902 | res = obj2ast_expr(tmp, &value, arena); |
| 7903 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7904 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7905 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7906 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7907 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7908 | return 1; |
| 7909 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7910 | if (tmp == NULL) { |
| 7911 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7912 | return 1; |
| 7913 | } |
| 7914 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7915 | int res; |
| 7916 | Py_ssize_t len; |
| 7917 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7918 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7919 | 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] | 7920 | goto failed; |
| 7921 | } |
| 7922 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7923 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7924 | if (generators == NULL) goto failed; |
| 7925 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7926 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7927 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7928 | Py_INCREF(tmp2); |
| 7929 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7930 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7931 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7932 | if (len != PyList_GET_SIZE(tmp)) { |
| 7933 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7934 | goto failed; |
| 7935 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7936 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7937 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7938 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7939 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7940 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7941 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7942 | if (*out == NULL) goto failed; |
| 7943 | return 0; |
| 7944 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7945 | tp = astmodulestate_global->GeneratorExp_type; |
| 7946 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7947 | if (isinstance == -1) { |
| 7948 | return 1; |
| 7949 | } |
| 7950 | if (isinstance) { |
| 7951 | expr_ty elt; |
| 7952 | asdl_seq* generators; |
| 7953 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7954 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7955 | return 1; |
| 7956 | } |
| 7957 | if (tmp == NULL) { |
| 7958 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7959 | return 1; |
| 7960 | } |
| 7961 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7962 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7963 | res = obj2ast_expr(tmp, &elt, arena); |
| 7964 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7965 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7966 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7967 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7968 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7969 | return 1; |
| 7970 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7971 | if (tmp == NULL) { |
| 7972 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7973 | return 1; |
| 7974 | } |
| 7975 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7976 | int res; |
| 7977 | Py_ssize_t len; |
| 7978 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7979 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7980 | 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] | 7981 | goto failed; |
| 7982 | } |
| 7983 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7984 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7985 | if (generators == NULL) goto failed; |
| 7986 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7987 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7988 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7989 | Py_INCREF(tmp2); |
| 7990 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7991 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7992 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7993 | if (len != PyList_GET_SIZE(tmp)) { |
| 7994 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7995 | goto failed; |
| 7996 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7997 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7998 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7999 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8000 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8001 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 8002 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8003 | if (*out == NULL) goto failed; |
| 8004 | return 0; |
| 8005 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8006 | tp = astmodulestate_global->Await_type; |
| 8007 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8008 | if (isinstance == -1) { |
| 8009 | return 1; |
| 8010 | } |
| 8011 | if (isinstance) { |
| 8012 | expr_ty value; |
| 8013 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8014 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8015 | return 1; |
| 8016 | } |
| 8017 | if (tmp == NULL) { |
| 8018 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 8019 | return 1; |
| 8020 | } |
| 8021 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8022 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8023 | res = obj2ast_expr(tmp, &value, arena); |
| 8024 | if (res != 0) goto failed; |
| 8025 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8026 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8027 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8028 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8029 | if (*out == NULL) goto failed; |
| 8030 | return 0; |
| 8031 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8032 | tp = astmodulestate_global->Yield_type; |
| 8033 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8034 | if (isinstance == -1) { |
| 8035 | return 1; |
| 8036 | } |
| 8037 | if (isinstance) { |
| 8038 | expr_ty value; |
| 8039 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8040 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8041 | return 1; |
| 8042 | } |
| 8043 | if (tmp == NULL || tmp == Py_None) { |
| 8044 | Py_CLEAR(tmp); |
| 8045 | value = NULL; |
| 8046 | } |
| 8047 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8048 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8049 | res = obj2ast_expr(tmp, &value, arena); |
| 8050 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8051 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8052 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8053 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8054 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8055 | if (*out == NULL) goto failed; |
| 8056 | return 0; |
| 8057 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8058 | tp = astmodulestate_global->YieldFrom_type; |
| 8059 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8060 | if (isinstance == -1) { |
| 8061 | return 1; |
| 8062 | } |
| 8063 | if (isinstance) { |
| 8064 | expr_ty value; |
| 8065 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8066 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8067 | return 1; |
| 8068 | } |
| 8069 | if (tmp == NULL) { |
| 8070 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 8071 | return 1; |
| 8072 | } |
| 8073 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8074 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8075 | res = obj2ast_expr(tmp, &value, arena); |
| 8076 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8077 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8078 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8079 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8080 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8081 | if (*out == NULL) goto failed; |
| 8082 | return 0; |
| 8083 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8084 | tp = astmodulestate_global->Compare_type; |
| 8085 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8086 | if (isinstance == -1) { |
| 8087 | return 1; |
| 8088 | } |
| 8089 | if (isinstance) { |
| 8090 | expr_ty left; |
| 8091 | asdl_int_seq* ops; |
| 8092 | asdl_seq* comparators; |
| 8093 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8094 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8095 | return 1; |
| 8096 | } |
| 8097 | if (tmp == NULL) { |
| 8098 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8099 | return 1; |
| 8100 | } |
| 8101 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8102 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8103 | res = obj2ast_expr(tmp, &left, arena); |
| 8104 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8105 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8106 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8107 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8108 | return 1; |
| 8109 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8110 | if (tmp == NULL) { |
| 8111 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8112 | return 1; |
| 8113 | } |
| 8114 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8115 | int res; |
| 8116 | Py_ssize_t len; |
| 8117 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8118 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8119 | 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] | 8120 | goto failed; |
| 8121 | } |
| 8122 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8123 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8124 | if (ops == NULL) goto failed; |
| 8125 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8126 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8127 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8128 | Py_INCREF(tmp2); |
| 8129 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8130 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8131 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8132 | if (len != PyList_GET_SIZE(tmp)) { |
| 8133 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8134 | goto failed; |
| 8135 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8136 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8137 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8138 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8139 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8140 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8141 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8142 | return 1; |
| 8143 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8144 | if (tmp == NULL) { |
| 8145 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8146 | return 1; |
| 8147 | } |
| 8148 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8149 | int res; |
| 8150 | Py_ssize_t len; |
| 8151 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8152 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8153 | 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] | 8154 | goto failed; |
| 8155 | } |
| 8156 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8157 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8158 | if (comparators == NULL) goto failed; |
| 8159 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8160 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8161 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8162 | Py_INCREF(tmp2); |
| 8163 | res = obj2ast_expr(tmp2, &val, arena); |
| 8164 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8165 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8166 | if (len != PyList_GET_SIZE(tmp)) { |
| 8167 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8168 | goto failed; |
| 8169 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8170 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8171 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8172 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8173 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8174 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8175 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8176 | if (*out == NULL) goto failed; |
| 8177 | return 0; |
| 8178 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8179 | tp = astmodulestate_global->Call_type; |
| 8180 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8181 | if (isinstance == -1) { |
| 8182 | return 1; |
| 8183 | } |
| 8184 | if (isinstance) { |
| 8185 | expr_ty func; |
| 8186 | asdl_seq* args; |
| 8187 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8188 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8189 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8190 | return 1; |
| 8191 | } |
| 8192 | if (tmp == NULL) { |
| 8193 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8194 | return 1; |
| 8195 | } |
| 8196 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8197 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8198 | res = obj2ast_expr(tmp, &func, arena); |
| 8199 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8200 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8201 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8202 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8203 | return 1; |
| 8204 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8205 | if (tmp == NULL) { |
| 8206 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8207 | return 1; |
| 8208 | } |
| 8209 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8210 | int res; |
| 8211 | Py_ssize_t len; |
| 8212 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8213 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8214 | 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] | 8215 | goto failed; |
| 8216 | } |
| 8217 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8218 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8219 | if (args == NULL) goto failed; |
| 8220 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8221 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8222 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8223 | Py_INCREF(tmp2); |
| 8224 | res = obj2ast_expr(tmp2, &val, arena); |
| 8225 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8226 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8227 | if (len != PyList_GET_SIZE(tmp)) { |
| 8228 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8229 | goto failed; |
| 8230 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8231 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8232 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8233 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8234 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8235 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8236 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8237 | return 1; |
| 8238 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8239 | if (tmp == NULL) { |
| 8240 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8241 | return 1; |
| 8242 | } |
| 8243 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8244 | int res; |
| 8245 | Py_ssize_t len; |
| 8246 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8247 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8248 | 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] | 8249 | goto failed; |
| 8250 | } |
| 8251 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8252 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8253 | if (keywords == NULL) goto failed; |
| 8254 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8255 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8256 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8257 | Py_INCREF(tmp2); |
| 8258 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8259 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8260 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8261 | if (len != PyList_GET_SIZE(tmp)) { |
| 8262 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8263 | goto failed; |
| 8264 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8265 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8266 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8267 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8268 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8269 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8270 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8271 | if (*out == NULL) goto failed; |
| 8272 | return 0; |
| 8273 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8274 | tp = astmodulestate_global->FormattedValue_type; |
| 8275 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8276 | if (isinstance == -1) { |
| 8277 | return 1; |
| 8278 | } |
| 8279 | if (isinstance) { |
| 8280 | expr_ty value; |
| 8281 | int conversion; |
| 8282 | expr_ty format_spec; |
| 8283 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8284 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8285 | return 1; |
| 8286 | } |
| 8287 | if (tmp == NULL) { |
| 8288 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8289 | return 1; |
| 8290 | } |
| 8291 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8292 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8293 | res = obj2ast_expr(tmp, &value, arena); |
| 8294 | if (res != 0) goto failed; |
| 8295 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8296 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8297 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8298 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8299 | return 1; |
| 8300 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8301 | if (tmp == NULL || tmp == Py_None) { |
| 8302 | Py_CLEAR(tmp); |
| 8303 | conversion = 0; |
| 8304 | } |
| 8305 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8306 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8307 | res = obj2ast_int(tmp, &conversion, arena); |
| 8308 | if (res != 0) goto failed; |
| 8309 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8310 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8311 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8312 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8313 | return 1; |
| 8314 | } |
| 8315 | if (tmp == NULL || tmp == Py_None) { |
| 8316 | Py_CLEAR(tmp); |
| 8317 | format_spec = NULL; |
| 8318 | } |
| 8319 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8320 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8321 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8322 | if (res != 0) goto failed; |
| 8323 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8324 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8325 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8326 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8327 | if (*out == NULL) goto failed; |
| 8328 | return 0; |
| 8329 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8330 | tp = astmodulestate_global->JoinedStr_type; |
| 8331 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8332 | if (isinstance == -1) { |
| 8333 | return 1; |
| 8334 | } |
| 8335 | if (isinstance) { |
| 8336 | asdl_seq* values; |
| 8337 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8338 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8339 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8340 | return 1; |
| 8341 | } |
| 8342 | if (tmp == NULL) { |
| 8343 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8344 | return 1; |
| 8345 | } |
| 8346 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8347 | int res; |
| 8348 | Py_ssize_t len; |
| 8349 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8350 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8351 | 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] | 8352 | goto failed; |
| 8353 | } |
| 8354 | len = PyList_GET_SIZE(tmp); |
| 8355 | values = _Py_asdl_seq_new(len, arena); |
| 8356 | if (values == NULL) goto failed; |
| 8357 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8358 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8359 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8360 | Py_INCREF(tmp2); |
| 8361 | res = obj2ast_expr(tmp2, &val, arena); |
| 8362 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8363 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8364 | if (len != PyList_GET_SIZE(tmp)) { |
| 8365 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8366 | goto failed; |
| 8367 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8368 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8369 | } |
| 8370 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8371 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8372 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8373 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8374 | if (*out == NULL) goto failed; |
| 8375 | return 0; |
| 8376 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8377 | tp = astmodulestate_global->Constant_type; |
| 8378 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8379 | if (isinstance == -1) { |
| 8380 | return 1; |
| 8381 | } |
| 8382 | if (isinstance) { |
| 8383 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8384 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8385 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8386 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8387 | return 1; |
| 8388 | } |
| 8389 | if (tmp == NULL) { |
| 8390 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8391 | return 1; |
| 8392 | } |
| 8393 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8394 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8395 | res = obj2ast_constant(tmp, &value, arena); |
| 8396 | if (res != 0) goto failed; |
| 8397 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8398 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8399 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8400 | return 1; |
| 8401 | } |
| 8402 | if (tmp == NULL || tmp == Py_None) { |
| 8403 | Py_CLEAR(tmp); |
| 8404 | kind = NULL; |
| 8405 | } |
| 8406 | else { |
| 8407 | int res; |
| 8408 | res = obj2ast_string(tmp, &kind, arena); |
| 8409 | if (res != 0) goto failed; |
| 8410 | Py_CLEAR(tmp); |
| 8411 | } |
| 8412 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8413 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8414 | if (*out == NULL) goto failed; |
| 8415 | return 0; |
| 8416 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8417 | tp = astmodulestate_global->Attribute_type; |
| 8418 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8419 | if (isinstance == -1) { |
| 8420 | return 1; |
| 8421 | } |
| 8422 | if (isinstance) { |
| 8423 | expr_ty value; |
| 8424 | identifier attr; |
| 8425 | expr_context_ty ctx; |
| 8426 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8427 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8428 | return 1; |
| 8429 | } |
| 8430 | if (tmp == NULL) { |
| 8431 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8432 | return 1; |
| 8433 | } |
| 8434 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8435 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8436 | res = obj2ast_expr(tmp, &value, arena); |
| 8437 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8438 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8439 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8440 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8441 | return 1; |
| 8442 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8443 | if (tmp == NULL) { |
| 8444 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8445 | return 1; |
| 8446 | } |
| 8447 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8448 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8449 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8450 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8451 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8452 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8453 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8454 | return 1; |
| 8455 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8456 | if (tmp == NULL) { |
| 8457 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8458 | return 1; |
| 8459 | } |
| 8460 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8461 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8462 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8463 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8464 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8465 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8466 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8467 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8468 | if (*out == NULL) goto failed; |
| 8469 | return 0; |
| 8470 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8471 | tp = astmodulestate_global->Subscript_type; |
| 8472 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8473 | if (isinstance == -1) { |
| 8474 | return 1; |
| 8475 | } |
| 8476 | if (isinstance) { |
| 8477 | expr_ty value; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8478 | expr_ty slice; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8479 | expr_context_ty ctx; |
| 8480 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8481 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8482 | return 1; |
| 8483 | } |
| 8484 | if (tmp == NULL) { |
| 8485 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8486 | return 1; |
| 8487 | } |
| 8488 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8489 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8490 | res = obj2ast_expr(tmp, &value, arena); |
| 8491 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8492 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8493 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8494 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8495 | return 1; |
| 8496 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8497 | if (tmp == NULL) { |
| 8498 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8499 | return 1; |
| 8500 | } |
| 8501 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8502 | int res; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8503 | res = obj2ast_expr(tmp, &slice, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8504 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8505 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8506 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8507 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8508 | return 1; |
| 8509 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8510 | if (tmp == NULL) { |
| 8511 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8512 | return 1; |
| 8513 | } |
| 8514 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8515 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8516 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8517 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8518 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8519 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8520 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8521 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8522 | if (*out == NULL) goto failed; |
| 8523 | return 0; |
| 8524 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8525 | tp = astmodulestate_global->Starred_type; |
| 8526 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8527 | if (isinstance == -1) { |
| 8528 | return 1; |
| 8529 | } |
| 8530 | if (isinstance) { |
| 8531 | expr_ty value; |
| 8532 | expr_context_ty ctx; |
| 8533 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8534 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8535 | return 1; |
| 8536 | } |
| 8537 | if (tmp == NULL) { |
| 8538 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8539 | return 1; |
| 8540 | } |
| 8541 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8542 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8543 | res = obj2ast_expr(tmp, &value, arena); |
| 8544 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8545 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8546 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8547 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8548 | return 1; |
| 8549 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8550 | if (tmp == NULL) { |
| 8551 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8552 | return 1; |
| 8553 | } |
| 8554 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8555 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8556 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8557 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8558 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8559 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8560 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8561 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8562 | if (*out == NULL) goto failed; |
| 8563 | return 0; |
| 8564 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8565 | tp = astmodulestate_global->Name_type; |
| 8566 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8567 | if (isinstance == -1) { |
| 8568 | return 1; |
| 8569 | } |
| 8570 | if (isinstance) { |
| 8571 | identifier id; |
| 8572 | expr_context_ty ctx; |
| 8573 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8574 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8575 | return 1; |
| 8576 | } |
| 8577 | if (tmp == NULL) { |
| 8578 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 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_identifier(tmp, &id, arena); |
| 8584 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8585 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8586 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8587 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8588 | return 1; |
| 8589 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8590 | if (tmp == NULL) { |
| 8591 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8592 | return 1; |
| 8593 | } |
| 8594 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8595 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8596 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8597 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8598 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8599 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8600 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8601 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8602 | if (*out == NULL) goto failed; |
| 8603 | return 0; |
| 8604 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8605 | tp = astmodulestate_global->List_type; |
| 8606 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8607 | if (isinstance == -1) { |
| 8608 | return 1; |
| 8609 | } |
| 8610 | if (isinstance) { |
| 8611 | asdl_seq* elts; |
| 8612 | expr_context_ty ctx; |
| 8613 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8614 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8615 | return 1; |
| 8616 | } |
| 8617 | if (tmp == NULL) { |
| 8618 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8619 | return 1; |
| 8620 | } |
| 8621 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8622 | int res; |
| 8623 | Py_ssize_t len; |
| 8624 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8625 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8626 | 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] | 8627 | goto failed; |
| 8628 | } |
| 8629 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8630 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8631 | if (elts == NULL) goto failed; |
| 8632 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8633 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8634 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8635 | Py_INCREF(tmp2); |
| 8636 | res = obj2ast_expr(tmp2, &val, arena); |
| 8637 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8638 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8639 | if (len != PyList_GET_SIZE(tmp)) { |
| 8640 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8641 | goto failed; |
| 8642 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8643 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8644 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8645 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8646 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8647 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8648 | return 1; |
| 8649 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8650 | if (tmp == NULL) { |
| 8651 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8652 | return 1; |
| 8653 | } |
| 8654 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8655 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8656 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8657 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8658 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8659 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8660 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8661 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8662 | if (*out == NULL) goto failed; |
| 8663 | return 0; |
| 8664 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8665 | tp = astmodulestate_global->Tuple_type; |
| 8666 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8667 | if (isinstance == -1) { |
| 8668 | return 1; |
| 8669 | } |
| 8670 | if (isinstance) { |
| 8671 | asdl_seq* elts; |
| 8672 | expr_context_ty ctx; |
| 8673 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8674 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8675 | return 1; |
| 8676 | } |
| 8677 | if (tmp == NULL) { |
| 8678 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8679 | return 1; |
| 8680 | } |
| 8681 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8682 | int res; |
| 8683 | Py_ssize_t len; |
| 8684 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8685 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8686 | 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] | 8687 | goto failed; |
| 8688 | } |
| 8689 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8690 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8691 | if (elts == NULL) goto failed; |
| 8692 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8693 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8694 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8695 | Py_INCREF(tmp2); |
| 8696 | res = obj2ast_expr(tmp2, &val, arena); |
| 8697 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8698 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8699 | if (len != PyList_GET_SIZE(tmp)) { |
| 8700 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8701 | goto failed; |
| 8702 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8703 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8704 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8705 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8706 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8707 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8708 | return 1; |
| 8709 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8710 | if (tmp == NULL) { |
| 8711 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8712 | return 1; |
| 8713 | } |
| 8714 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8715 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8716 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8717 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8718 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8719 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8720 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8721 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8722 | if (*out == NULL) goto failed; |
| 8723 | return 0; |
| 8724 | } |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8725 | tp = astmodulestate_global->Slice_type; |
| 8726 | isinstance = PyObject_IsInstance(obj, tp); |
| 8727 | if (isinstance == -1) { |
| 8728 | return 1; |
| 8729 | } |
| 8730 | if (isinstance) { |
| 8731 | expr_ty lower; |
| 8732 | expr_ty upper; |
| 8733 | expr_ty step; |
| 8734 | |
| 8735 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
| 8736 | return 1; |
| 8737 | } |
| 8738 | if (tmp == NULL || tmp == Py_None) { |
| 8739 | Py_CLEAR(tmp); |
| 8740 | lower = NULL; |
| 8741 | } |
| 8742 | else { |
| 8743 | int res; |
| 8744 | res = obj2ast_expr(tmp, &lower, arena); |
| 8745 | if (res != 0) goto failed; |
| 8746 | Py_CLEAR(tmp); |
| 8747 | } |
| 8748 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
| 8749 | return 1; |
| 8750 | } |
| 8751 | if (tmp == NULL || tmp == Py_None) { |
| 8752 | Py_CLEAR(tmp); |
| 8753 | upper = NULL; |
| 8754 | } |
| 8755 | else { |
| 8756 | int res; |
| 8757 | res = obj2ast_expr(tmp, &upper, arena); |
| 8758 | if (res != 0) goto failed; |
| 8759 | Py_CLEAR(tmp); |
| 8760 | } |
| 8761 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
| 8762 | return 1; |
| 8763 | } |
| 8764 | if (tmp == NULL || tmp == Py_None) { |
| 8765 | Py_CLEAR(tmp); |
| 8766 | step = NULL; |
| 8767 | } |
| 8768 | else { |
| 8769 | int res; |
| 8770 | res = obj2ast_expr(tmp, &step, arena); |
| 8771 | if (res != 0) goto failed; |
| 8772 | Py_CLEAR(tmp); |
| 8773 | } |
| 8774 | *out = Slice(lower, upper, step, lineno, col_offset, end_lineno, |
| 8775 | end_col_offset, arena); |
| 8776 | if (*out == NULL) goto failed; |
| 8777 | return 0; |
| 8778 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8779 | |
| 8780 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8781 | failed: |
| 8782 | Py_XDECREF(tmp); |
| 8783 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8784 | } |
| 8785 | |
| 8786 | int |
| 8787 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8788 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8789 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8790 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8791 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8792 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8793 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8794 | } |
| 8795 | if (isinstance) { |
| 8796 | *out = Load; |
| 8797 | return 0; |
| 8798 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8799 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8800 | if (isinstance == -1) { |
| 8801 | return 1; |
| 8802 | } |
| 8803 | if (isinstance) { |
| 8804 | *out = Store; |
| 8805 | return 0; |
| 8806 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8807 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8808 | if (isinstance == -1) { |
| 8809 | return 1; |
| 8810 | } |
| 8811 | if (isinstance) { |
| 8812 | *out = Del; |
| 8813 | return 0; |
| 8814 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8815 | |
| 8816 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8817 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8818 | } |
| 8819 | |
| 8820 | int |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8821 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8822 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8823 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8824 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8825 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8826 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8827 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8828 | } |
| 8829 | if (isinstance) { |
| 8830 | *out = And; |
| 8831 | return 0; |
| 8832 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8833 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8834 | if (isinstance == -1) { |
| 8835 | return 1; |
| 8836 | } |
| 8837 | if (isinstance) { |
| 8838 | *out = Or; |
| 8839 | return 0; |
| 8840 | } |
| 8841 | |
| 8842 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8843 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8844 | } |
| 8845 | |
| 8846 | int |
| 8847 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8848 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8849 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8850 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8851 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8852 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8853 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8854 | } |
| 8855 | if (isinstance) { |
| 8856 | *out = Add; |
| 8857 | return 0; |
| 8858 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8859 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8860 | if (isinstance == -1) { |
| 8861 | return 1; |
| 8862 | } |
| 8863 | if (isinstance) { |
| 8864 | *out = Sub; |
| 8865 | return 0; |
| 8866 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8867 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8868 | if (isinstance == -1) { |
| 8869 | return 1; |
| 8870 | } |
| 8871 | if (isinstance) { |
| 8872 | *out = Mult; |
| 8873 | return 0; |
| 8874 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8875 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8876 | if (isinstance == -1) { |
| 8877 | return 1; |
| 8878 | } |
| 8879 | if (isinstance) { |
| 8880 | *out = MatMult; |
| 8881 | return 0; |
| 8882 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8883 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8884 | if (isinstance == -1) { |
| 8885 | return 1; |
| 8886 | } |
| 8887 | if (isinstance) { |
| 8888 | *out = Div; |
| 8889 | return 0; |
| 8890 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8891 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8892 | if (isinstance == -1) { |
| 8893 | return 1; |
| 8894 | } |
| 8895 | if (isinstance) { |
| 8896 | *out = Mod; |
| 8897 | return 0; |
| 8898 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8899 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8900 | if (isinstance == -1) { |
| 8901 | return 1; |
| 8902 | } |
| 8903 | if (isinstance) { |
| 8904 | *out = Pow; |
| 8905 | return 0; |
| 8906 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8907 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8908 | if (isinstance == -1) { |
| 8909 | return 1; |
| 8910 | } |
| 8911 | if (isinstance) { |
| 8912 | *out = LShift; |
| 8913 | return 0; |
| 8914 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8915 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8916 | if (isinstance == -1) { |
| 8917 | return 1; |
| 8918 | } |
| 8919 | if (isinstance) { |
| 8920 | *out = RShift; |
| 8921 | return 0; |
| 8922 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8923 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8924 | if (isinstance == -1) { |
| 8925 | return 1; |
| 8926 | } |
| 8927 | if (isinstance) { |
| 8928 | *out = BitOr; |
| 8929 | return 0; |
| 8930 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8931 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8932 | if (isinstance == -1) { |
| 8933 | return 1; |
| 8934 | } |
| 8935 | if (isinstance) { |
| 8936 | *out = BitXor; |
| 8937 | return 0; |
| 8938 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8939 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8940 | if (isinstance == -1) { |
| 8941 | return 1; |
| 8942 | } |
| 8943 | if (isinstance) { |
| 8944 | *out = BitAnd; |
| 8945 | return 0; |
| 8946 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8947 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8948 | if (isinstance == -1) { |
| 8949 | return 1; |
| 8950 | } |
| 8951 | if (isinstance) { |
| 8952 | *out = FloorDiv; |
| 8953 | return 0; |
| 8954 | } |
| 8955 | |
| 8956 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8957 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8958 | } |
| 8959 | |
| 8960 | int |
| 8961 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8962 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8963 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8964 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8965 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8966 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8967 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8968 | } |
| 8969 | if (isinstance) { |
| 8970 | *out = Invert; |
| 8971 | return 0; |
| 8972 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8973 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8974 | if (isinstance == -1) { |
| 8975 | return 1; |
| 8976 | } |
| 8977 | if (isinstance) { |
| 8978 | *out = Not; |
| 8979 | return 0; |
| 8980 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8981 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8982 | if (isinstance == -1) { |
| 8983 | return 1; |
| 8984 | } |
| 8985 | if (isinstance) { |
| 8986 | *out = UAdd; |
| 8987 | return 0; |
| 8988 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8989 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8990 | if (isinstance == -1) { |
| 8991 | return 1; |
| 8992 | } |
| 8993 | if (isinstance) { |
| 8994 | *out = USub; |
| 8995 | return 0; |
| 8996 | } |
| 8997 | |
| 8998 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 8999 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9000 | } |
| 9001 | |
| 9002 | int |
| 9003 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 9004 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9005 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9006 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9007 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9008 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9009 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9010 | } |
| 9011 | if (isinstance) { |
| 9012 | *out = Eq; |
| 9013 | return 0; |
| 9014 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9015 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9016 | if (isinstance == -1) { |
| 9017 | return 1; |
| 9018 | } |
| 9019 | if (isinstance) { |
| 9020 | *out = NotEq; |
| 9021 | return 0; |
| 9022 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9023 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9024 | if (isinstance == -1) { |
| 9025 | return 1; |
| 9026 | } |
| 9027 | if (isinstance) { |
| 9028 | *out = Lt; |
| 9029 | return 0; |
| 9030 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9031 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9032 | if (isinstance == -1) { |
| 9033 | return 1; |
| 9034 | } |
| 9035 | if (isinstance) { |
| 9036 | *out = LtE; |
| 9037 | return 0; |
| 9038 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9039 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9040 | if (isinstance == -1) { |
| 9041 | return 1; |
| 9042 | } |
| 9043 | if (isinstance) { |
| 9044 | *out = Gt; |
| 9045 | return 0; |
| 9046 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9047 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9048 | if (isinstance == -1) { |
| 9049 | return 1; |
| 9050 | } |
| 9051 | if (isinstance) { |
| 9052 | *out = GtE; |
| 9053 | return 0; |
| 9054 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9055 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9056 | if (isinstance == -1) { |
| 9057 | return 1; |
| 9058 | } |
| 9059 | if (isinstance) { |
| 9060 | *out = Is; |
| 9061 | return 0; |
| 9062 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9063 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9064 | if (isinstance == -1) { |
| 9065 | return 1; |
| 9066 | } |
| 9067 | if (isinstance) { |
| 9068 | *out = IsNot; |
| 9069 | return 0; |
| 9070 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9071 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9072 | if (isinstance == -1) { |
| 9073 | return 1; |
| 9074 | } |
| 9075 | if (isinstance) { |
| 9076 | *out = In; |
| 9077 | return 0; |
| 9078 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9079 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9080 | if (isinstance == -1) { |
| 9081 | return 1; |
| 9082 | } |
| 9083 | if (isinstance) { |
| 9084 | *out = NotIn; |
| 9085 | return 0; |
| 9086 | } |
| 9087 | |
| 9088 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9089 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9090 | } |
| 9091 | |
| 9092 | int |
| 9093 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9094 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9095 | PyObject* tmp = NULL; |
| 9096 | expr_ty target; |
| 9097 | expr_ty iter; |
| 9098 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9099 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9100 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9101 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9102 | return 1; |
| 9103 | } |
| 9104 | if (tmp == NULL) { |
| 9105 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9106 | return 1; |
| 9107 | } |
| 9108 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9109 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9110 | res = obj2ast_expr(tmp, &target, arena); |
| 9111 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9112 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9113 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9114 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9115 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9116 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9117 | if (tmp == NULL) { |
| 9118 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9119 | return 1; |
| 9120 | } |
| 9121 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9122 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9123 | res = obj2ast_expr(tmp, &iter, arena); |
| 9124 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9125 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9126 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9127 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9128 | return 1; |
| 9129 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9130 | if (tmp == NULL) { |
| 9131 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9132 | return 1; |
| 9133 | } |
| 9134 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9135 | int res; |
| 9136 | Py_ssize_t len; |
| 9137 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9138 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9139 | 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] | 9140 | goto failed; |
| 9141 | } |
| 9142 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9143 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9144 | if (ifs == NULL) goto failed; |
| 9145 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9146 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9147 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9148 | Py_INCREF(tmp2); |
| 9149 | res = obj2ast_expr(tmp2, &val, arena); |
| 9150 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9151 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9152 | if (len != PyList_GET_SIZE(tmp)) { |
| 9153 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9154 | goto failed; |
| 9155 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9156 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9157 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9158 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9159 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9160 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9161 | return 1; |
| 9162 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9163 | if (tmp == NULL) { |
| 9164 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9165 | return 1; |
| 9166 | } |
| 9167 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9168 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9169 | res = obj2ast_int(tmp, &is_async, arena); |
| 9170 | if (res != 0) goto failed; |
| 9171 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9172 | } |
| 9173 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9174 | return 0; |
| 9175 | failed: |
| 9176 | Py_XDECREF(tmp); |
| 9177 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9178 | } |
| 9179 | |
| 9180 | int |
| 9181 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9182 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9183 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9184 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9185 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9186 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9187 | int lineno; |
| 9188 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9189 | int end_lineno; |
| 9190 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9191 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9192 | if (obj == Py_None) { |
| 9193 | *out = NULL; |
| 9194 | return 0; |
| 9195 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9196 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9197 | return 1; |
| 9198 | } |
| 9199 | if (tmp == NULL) { |
| 9200 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9201 | return 1; |
| 9202 | } |
| 9203 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9204 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9205 | res = obj2ast_int(tmp, &lineno, arena); |
| 9206 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9207 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9208 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9209 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9210 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9211 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9212 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9213 | if (tmp == NULL) { |
| 9214 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9215 | return 1; |
| 9216 | } |
| 9217 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9218 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9219 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9220 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9221 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9222 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9223 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9224 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9225 | return 1; |
| 9226 | } |
| 9227 | if (tmp == NULL || tmp == Py_None) { |
| 9228 | Py_CLEAR(tmp); |
| 9229 | end_lineno = 0; |
| 9230 | } |
| 9231 | else { |
| 9232 | int res; |
| 9233 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9234 | if (res != 0) goto failed; |
| 9235 | Py_CLEAR(tmp); |
| 9236 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9237 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9238 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9239 | return 1; |
| 9240 | } |
| 9241 | if (tmp == NULL || tmp == Py_None) { |
| 9242 | Py_CLEAR(tmp); |
| 9243 | end_col_offset = 0; |
| 9244 | } |
| 9245 | else { |
| 9246 | int res; |
| 9247 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9248 | if (res != 0) goto failed; |
| 9249 | Py_CLEAR(tmp); |
| 9250 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9251 | tp = astmodulestate_global->ExceptHandler_type; |
| 9252 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9253 | if (isinstance == -1) { |
| 9254 | return 1; |
| 9255 | } |
| 9256 | if (isinstance) { |
| 9257 | expr_ty type; |
| 9258 | identifier name; |
| 9259 | asdl_seq* body; |
| 9260 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9261 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9262 | return 1; |
| 9263 | } |
| 9264 | if (tmp == NULL || tmp == Py_None) { |
| 9265 | Py_CLEAR(tmp); |
| 9266 | type = NULL; |
| 9267 | } |
| 9268 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9269 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9270 | res = obj2ast_expr(tmp, &type, arena); |
| 9271 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9272 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9273 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9274 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9275 | return 1; |
| 9276 | } |
| 9277 | if (tmp == NULL || tmp == Py_None) { |
| 9278 | Py_CLEAR(tmp); |
| 9279 | name = NULL; |
| 9280 | } |
| 9281 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9282 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9283 | res = obj2ast_identifier(tmp, &name, arena); |
| 9284 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9285 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9286 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9287 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9288 | return 1; |
| 9289 | } |
| 9290 | if (tmp == NULL) { |
| 9291 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9292 | return 1; |
| 9293 | } |
| 9294 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9295 | int res; |
| 9296 | Py_ssize_t len; |
| 9297 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9298 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9299 | 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] | 9300 | goto failed; |
| 9301 | } |
| 9302 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9303 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9304 | if (body == NULL) goto failed; |
| 9305 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9306 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9307 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9308 | Py_INCREF(tmp2); |
| 9309 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9310 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9311 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9312 | if (len != PyList_GET_SIZE(tmp)) { |
| 9313 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9314 | goto failed; |
| 9315 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9316 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9317 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9318 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9319 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9320 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9321 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9322 | if (*out == NULL) goto failed; |
| 9323 | return 0; |
| 9324 | } |
| 9325 | |
| 9326 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9327 | failed: |
| 9328 | Py_XDECREF(tmp); |
| 9329 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9330 | } |
| 9331 | |
| 9332 | int |
| 9333 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9334 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9335 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9336 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9337 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9338 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9339 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9340 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9341 | arg_ty kwarg; |
| 9342 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9343 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9344 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9345 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9346 | return 1; |
| 9347 | } |
| 9348 | if (tmp == NULL) { |
| 9349 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9350 | return 1; |
| 9351 | } |
| 9352 | else { |
| 9353 | int res; |
| 9354 | Py_ssize_t len; |
| 9355 | Py_ssize_t i; |
| 9356 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9357 | 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] | 9358 | goto failed; |
| 9359 | } |
| 9360 | len = PyList_GET_SIZE(tmp); |
| 9361 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9362 | if (posonlyargs == NULL) goto failed; |
| 9363 | for (i = 0; i < len; i++) { |
| 9364 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9365 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9366 | Py_INCREF(tmp2); |
| 9367 | res = obj2ast_arg(tmp2, &val, arena); |
| 9368 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9369 | if (res != 0) goto failed; |
| 9370 | if (len != PyList_GET_SIZE(tmp)) { |
| 9371 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9372 | goto failed; |
| 9373 | } |
| 9374 | asdl_seq_SET(posonlyargs, i, val); |
| 9375 | } |
| 9376 | Py_CLEAR(tmp); |
| 9377 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9378 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9379 | return 1; |
| 9380 | } |
| 9381 | if (tmp == NULL) { |
| 9382 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9383 | return 1; |
| 9384 | } |
| 9385 | else { |
| 9386 | int res; |
| 9387 | Py_ssize_t len; |
| 9388 | Py_ssize_t i; |
| 9389 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9390 | 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] | 9391 | goto failed; |
| 9392 | } |
| 9393 | len = PyList_GET_SIZE(tmp); |
| 9394 | args = _Py_asdl_seq_new(len, arena); |
| 9395 | if (args == NULL) goto failed; |
| 9396 | for (i = 0; i < len; i++) { |
| 9397 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9398 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9399 | Py_INCREF(tmp2); |
| 9400 | res = obj2ast_arg(tmp2, &val, arena); |
| 9401 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9402 | if (res != 0) goto failed; |
| 9403 | if (len != PyList_GET_SIZE(tmp)) { |
| 9404 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9405 | goto failed; |
| 9406 | } |
| 9407 | asdl_seq_SET(args, i, val); |
| 9408 | } |
| 9409 | Py_CLEAR(tmp); |
| 9410 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9411 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9412 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9413 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9414 | if (tmp == NULL || tmp == Py_None) { |
| 9415 | Py_CLEAR(tmp); |
| 9416 | vararg = NULL; |
| 9417 | } |
| 9418 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9419 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9420 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9421 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9422 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9423 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9424 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9425 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9426 | return 1; |
| 9427 | } |
| 9428 | if (tmp == NULL) { |
| 9429 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9430 | return 1; |
| 9431 | } |
| 9432 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9433 | int res; |
| 9434 | Py_ssize_t len; |
| 9435 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9436 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9437 | 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] | 9438 | goto failed; |
| 9439 | } |
| 9440 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9441 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9442 | if (kwonlyargs == NULL) goto failed; |
| 9443 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9444 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9445 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9446 | Py_INCREF(tmp2); |
| 9447 | res = obj2ast_arg(tmp2, &val, arena); |
| 9448 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9449 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9450 | if (len != PyList_GET_SIZE(tmp)) { |
| 9451 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9452 | goto failed; |
| 9453 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9454 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9455 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9456 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9457 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9458 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9459 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9460 | return 1; |
| 9461 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9462 | if (tmp == NULL) { |
| 9463 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9464 | return 1; |
| 9465 | } |
| 9466 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9467 | int res; |
| 9468 | Py_ssize_t len; |
| 9469 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9470 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9471 | 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] | 9472 | goto failed; |
| 9473 | } |
| 9474 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9475 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9476 | if (kw_defaults == NULL) goto failed; |
| 9477 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9478 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9479 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9480 | Py_INCREF(tmp2); |
| 9481 | res = obj2ast_expr(tmp2, &val, arena); |
| 9482 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9483 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9484 | if (len != PyList_GET_SIZE(tmp)) { |
| 9485 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9486 | goto failed; |
| 9487 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9488 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9489 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9490 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9491 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9492 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9493 | return 1; |
| 9494 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9495 | if (tmp == NULL || tmp == Py_None) { |
| 9496 | Py_CLEAR(tmp); |
| 9497 | kwarg = NULL; |
| 9498 | } |
| 9499 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9500 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9501 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9502 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9503 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9504 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9505 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9506 | return 1; |
| 9507 | } |
| 9508 | if (tmp == NULL) { |
| 9509 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9510 | return 1; |
| 9511 | } |
| 9512 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9513 | int res; |
| 9514 | Py_ssize_t len; |
| 9515 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9516 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9517 | 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] | 9518 | goto failed; |
| 9519 | } |
| 9520 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9521 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9522 | if (defaults == NULL) goto failed; |
| 9523 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9524 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9525 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9526 | Py_INCREF(tmp2); |
| 9527 | res = obj2ast_expr(tmp2, &val, arena); |
| 9528 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9529 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9530 | if (len != PyList_GET_SIZE(tmp)) { |
| 9531 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9532 | goto failed; |
| 9533 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9534 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9535 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9536 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9537 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9538 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9539 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9540 | return 0; |
| 9541 | failed: |
| 9542 | Py_XDECREF(tmp); |
| 9543 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9544 | } |
| 9545 | |
| 9546 | int |
| 9547 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9548 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9549 | PyObject* tmp = NULL; |
| 9550 | identifier arg; |
| 9551 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9552 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9553 | int lineno; |
| 9554 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9555 | int end_lineno; |
| 9556 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9557 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9558 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9559 | return 1; |
| 9560 | } |
| 9561 | if (tmp == NULL) { |
| 9562 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9563 | return 1; |
| 9564 | } |
| 9565 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9566 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9567 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9568 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9569 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9570 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9571 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9572 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9573 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9574 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9575 | if (tmp == NULL || tmp == Py_None) { |
| 9576 | Py_CLEAR(tmp); |
| 9577 | annotation = NULL; |
| 9578 | } |
| 9579 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9580 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9581 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9582 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9583 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9584 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9585 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9586 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9587 | return 1; |
| 9588 | } |
| 9589 | if (tmp == NULL || tmp == Py_None) { |
| 9590 | Py_CLEAR(tmp); |
| 9591 | type_comment = NULL; |
| 9592 | } |
| 9593 | else { |
| 9594 | int res; |
| 9595 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9596 | if (res != 0) goto failed; |
| 9597 | Py_CLEAR(tmp); |
| 9598 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9599 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9600 | return 1; |
| 9601 | } |
| 9602 | if (tmp == NULL) { |
| 9603 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9604 | return 1; |
| 9605 | } |
| 9606 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9607 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9608 | res = obj2ast_int(tmp, &lineno, arena); |
| 9609 | if (res != 0) goto failed; |
| 9610 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9611 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9612 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9613 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9614 | return 1; |
| 9615 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9616 | if (tmp == NULL) { |
| 9617 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9618 | return 1; |
| 9619 | } |
| 9620 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9621 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9622 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9623 | if (res != 0) goto failed; |
| 9624 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9625 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9626 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9627 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9628 | return 1; |
| 9629 | } |
| 9630 | if (tmp == NULL || tmp == Py_None) { |
| 9631 | Py_CLEAR(tmp); |
| 9632 | end_lineno = 0; |
| 9633 | } |
| 9634 | else { |
| 9635 | int res; |
| 9636 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9637 | if (res != 0) goto failed; |
| 9638 | Py_CLEAR(tmp); |
| 9639 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9640 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9641 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9642 | return 1; |
| 9643 | } |
| 9644 | if (tmp == NULL || tmp == Py_None) { |
| 9645 | Py_CLEAR(tmp); |
| 9646 | end_col_offset = 0; |
| 9647 | } |
| 9648 | else { |
| 9649 | int res; |
| 9650 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9651 | if (res != 0) goto failed; |
| 9652 | Py_CLEAR(tmp); |
| 9653 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9654 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9655 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9656 | return 0; |
| 9657 | failed: |
| 9658 | Py_XDECREF(tmp); |
| 9659 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9660 | } |
| 9661 | |
| 9662 | int |
| 9663 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9664 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9665 | PyObject* tmp = NULL; |
| 9666 | identifier arg; |
| 9667 | expr_ty value; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 9668 | int lineno; |
| 9669 | int col_offset; |
| 9670 | int end_lineno; |
| 9671 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9672 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9673 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9674 | return 1; |
| 9675 | } |
| 9676 | if (tmp == NULL || tmp == Py_None) { |
| 9677 | Py_CLEAR(tmp); |
| 9678 | arg = NULL; |
| 9679 | } |
| 9680 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9681 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9682 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9683 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9684 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9685 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9686 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9687 | return 1; |
| 9688 | } |
| 9689 | if (tmp == NULL) { |
| 9690 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9691 | return 1; |
| 9692 | } |
| 9693 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9694 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9695 | res = obj2ast_expr(tmp, &value, arena); |
| 9696 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9697 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9698 | } |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 9699 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
| 9700 | return 1; |
| 9701 | } |
| 9702 | if (tmp == NULL) { |
| 9703 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword"); |
| 9704 | return 1; |
| 9705 | } |
| 9706 | else { |
| 9707 | int res; |
| 9708 | res = obj2ast_int(tmp, &lineno, arena); |
| 9709 | if (res != 0) goto failed; |
| 9710 | Py_CLEAR(tmp); |
| 9711 | } |
| 9712 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9713 | { |
| 9714 | return 1; |
| 9715 | } |
| 9716 | if (tmp == NULL) { |
| 9717 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword"); |
| 9718 | return 1; |
| 9719 | } |
| 9720 | else { |
| 9721 | int res; |
| 9722 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9723 | if (res != 0) goto failed; |
| 9724 | Py_CLEAR(tmp); |
| 9725 | } |
| 9726 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9727 | { |
| 9728 | return 1; |
| 9729 | } |
| 9730 | if (tmp == NULL || tmp == Py_None) { |
| 9731 | Py_CLEAR(tmp); |
| 9732 | end_lineno = 0; |
| 9733 | } |
| 9734 | else { |
| 9735 | int res; |
| 9736 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9737 | if (res != 0) goto failed; |
| 9738 | Py_CLEAR(tmp); |
| 9739 | } |
| 9740 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9741 | < 0) { |
| 9742 | return 1; |
| 9743 | } |
| 9744 | if (tmp == NULL || tmp == Py_None) { |
| 9745 | Py_CLEAR(tmp); |
| 9746 | end_col_offset = 0; |
| 9747 | } |
| 9748 | else { |
| 9749 | int res; |
| 9750 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9751 | if (res != 0) goto failed; |
| 9752 | Py_CLEAR(tmp); |
| 9753 | } |
| 9754 | *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset, |
| 9755 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9756 | return 0; |
| 9757 | failed: |
| 9758 | Py_XDECREF(tmp); |
| 9759 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9760 | } |
| 9761 | |
| 9762 | int |
| 9763 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9764 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9765 | PyObject* tmp = NULL; |
| 9766 | identifier name; |
| 9767 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9768 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9769 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9770 | return 1; |
| 9771 | } |
| 9772 | if (tmp == NULL) { |
| 9773 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9774 | return 1; |
| 9775 | } |
| 9776 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9777 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9778 | res = obj2ast_identifier(tmp, &name, arena); |
| 9779 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9780 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9781 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9782 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9783 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9784 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9785 | if (tmp == NULL || tmp == Py_None) { |
| 9786 | Py_CLEAR(tmp); |
| 9787 | asname = NULL; |
| 9788 | } |
| 9789 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9790 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9791 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9792 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9793 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9794 | } |
| 9795 | *out = alias(name, asname, arena); |
| 9796 | return 0; |
| 9797 | failed: |
| 9798 | Py_XDECREF(tmp); |
| 9799 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9800 | } |
| 9801 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9802 | int |
| 9803 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9804 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9805 | PyObject* tmp = NULL; |
| 9806 | expr_ty context_expr; |
| 9807 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9808 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9809 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9810 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9811 | return 1; |
| 9812 | } |
| 9813 | if (tmp == NULL) { |
| 9814 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9815 | return 1; |
| 9816 | } |
| 9817 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9818 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9819 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9820 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9821 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9822 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9823 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9824 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9825 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9826 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9827 | if (tmp == NULL || tmp == Py_None) { |
| 9828 | Py_CLEAR(tmp); |
| 9829 | optional_vars = NULL; |
| 9830 | } |
| 9831 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9832 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9833 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9834 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9835 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9836 | } |
| 9837 | *out = withitem(context_expr, optional_vars, arena); |
| 9838 | return 0; |
| 9839 | failed: |
| 9840 | Py_XDECREF(tmp); |
| 9841 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9842 | } |
| 9843 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9844 | int |
| 9845 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9846 | { |
| 9847 | int isinstance; |
| 9848 | |
| 9849 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9850 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9851 | |
| 9852 | if (obj == Py_None) { |
| 9853 | *out = NULL; |
| 9854 | return 0; |
| 9855 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9856 | tp = astmodulestate_global->TypeIgnore_type; |
| 9857 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9858 | if (isinstance == -1) { |
| 9859 | return 1; |
| 9860 | } |
| 9861 | if (isinstance) { |
| 9862 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9863 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9864 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9865 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9866 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9867 | return 1; |
| 9868 | } |
| 9869 | if (tmp == NULL) { |
| 9870 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9871 | return 1; |
| 9872 | } |
| 9873 | else { |
| 9874 | int res; |
| 9875 | res = obj2ast_int(tmp, &lineno, arena); |
| 9876 | if (res != 0) goto failed; |
| 9877 | Py_CLEAR(tmp); |
| 9878 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9879 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9880 | return 1; |
| 9881 | } |
| 9882 | if (tmp == NULL) { |
| 9883 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9884 | return 1; |
| 9885 | } |
| 9886 | else { |
| 9887 | int res; |
| 9888 | res = obj2ast_string(tmp, &tag, arena); |
| 9889 | if (res != 0) goto failed; |
| 9890 | Py_CLEAR(tmp); |
| 9891 | } |
| 9892 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9893 | if (*out == NULL) goto failed; |
| 9894 | return 0; |
| 9895 | } |
| 9896 | |
| 9897 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9898 | failed: |
| 9899 | Py_XDECREF(tmp); |
| 9900 | return 1; |
| 9901 | } |
| 9902 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9903 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9904 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9905 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9906 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9907 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9908 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9909 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9910 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9911 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9912 | goto error; |
| 9913 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9914 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9915 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9916 | goto error; |
| 9917 | } |
| 9918 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9919 | goto error; |
| 9920 | } |
| 9921 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9922 | goto error; |
| 9923 | } |
| 9924 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9925 | goto error; |
| 9926 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9927 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9928 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9929 | 0) { |
| 9930 | goto error; |
| 9931 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9932 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9933 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9934 | astmodulestate_global->Interactive_type) < 0) { |
| 9935 | goto error; |
| 9936 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9937 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9938 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9939 | astmodulestate_global->Expression_type) < 0) { |
| 9940 | goto error; |
| 9941 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9942 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9943 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9944 | astmodulestate_global->FunctionType_type) < 0) { |
| 9945 | goto error; |
| 9946 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9947 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9948 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9949 | goto error; |
| 9950 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9951 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9952 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9953 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9954 | goto error; |
| 9955 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9956 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9957 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9958 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9959 | goto error; |
| 9960 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9961 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9962 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9963 | < 0) { |
| 9964 | goto error; |
| 9965 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9966 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9967 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9968 | 0) { |
| 9969 | goto error; |
| 9970 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9971 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9972 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9973 | 0) { |
| 9974 | goto error; |
| 9975 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9976 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9977 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9978 | 0) { |
| 9979 | goto error; |
| 9980 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9981 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9982 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9983 | astmodulestate_global->AugAssign_type) < 0) { |
| 9984 | goto error; |
| 9985 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9986 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9987 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9988 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9989 | goto error; |
| 9990 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9991 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9992 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9993 | goto error; |
| 9994 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9995 | Py_INCREF(astmodulestate(m)->For_type); |
| 9996 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9997 | < 0) { |
| 9998 | goto error; |
| 9999 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10000 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10001 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 10002 | goto error; |
| 10003 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10004 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10005 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 10006 | goto error; |
| 10007 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10008 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10009 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 10010 | goto error; |
| 10011 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10012 | Py_INCREF(astmodulestate(m)->With_type); |
| 10013 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10014 | astmodulestate_global->AsyncWith_type) < 0) { |
| 10015 | goto error; |
| 10016 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10017 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10018 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 10019 | goto error; |
| 10020 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10021 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10022 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 10023 | goto error; |
| 10024 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10025 | Py_INCREF(astmodulestate(m)->Try_type); |
| 10026 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10027 | 0) { |
| 10028 | goto error; |
| 10029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10030 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 10031 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10032 | 0) { |
| 10033 | goto error; |
| 10034 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10035 | Py_INCREF(astmodulestate(m)->Import_type); |
| 10036 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10037 | astmodulestate_global->ImportFrom_type) < 0) { |
| 10038 | goto error; |
| 10039 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10040 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 10041 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10042 | 0) { |
| 10043 | goto error; |
| 10044 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10045 | Py_INCREF(astmodulestate(m)->Global_type); |
| 10046 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_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)->Nonlocal_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); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10055 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 10056 | goto error; |
| 10057 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10058 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10059 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 10060 | goto error; |
| 10061 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10062 | Py_INCREF(astmodulestate(m)->Break_type); |
| 10063 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10064 | < 0) { |
| 10065 | goto error; |
| 10066 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10067 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10068 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 10069 | goto error; |
| 10070 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10071 | Py_INCREF(astmodulestate(m)->expr_type); |
| 10072 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10073 | 0) { |
| 10074 | goto error; |
| 10075 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10076 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 10077 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10078 | astmodulestate_global->NamedExpr_type) < 0) { |
| 10079 | goto error; |
| 10080 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10081 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10082 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 10083 | goto error; |
| 10084 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10085 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 10086 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10087 | 0) { |
| 10088 | goto error; |
| 10089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10090 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 10091 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_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)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10096 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 10097 | goto error; |
| 10098 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10099 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10100 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 10101 | goto error; |
| 10102 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10103 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10104 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 10105 | goto error; |
| 10106 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10107 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10108 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10109 | < 0) { |
| 10110 | goto error; |
| 10111 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10112 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10113 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10114 | 0) { |
| 10115 | goto error; |
| 10116 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10117 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10118 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10119 | < 0) { |
| 10120 | goto error; |
| 10121 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10122 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10123 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10124 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 10125 | goto error; |
| 10126 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10127 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10128 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 10129 | goto error; |
| 10130 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10131 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10132 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 10133 | goto error; |
| 10134 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10135 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10136 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10137 | astmodulestate_global->YieldFrom_type) < 0) { |
| 10138 | goto error; |
| 10139 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10140 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10141 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10142 | 0) { |
| 10143 | goto error; |
| 10144 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10145 | Py_INCREF(astmodulestate(m)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10146 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 10147 | goto error; |
| 10148 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10149 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10150 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10151 | astmodulestate_global->FormattedValue_type) < 0) { |
| 10152 | goto error; |
| 10153 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10154 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10155 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10156 | astmodulestate_global->JoinedStr_type) < 0) { |
| 10157 | goto error; |
| 10158 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10159 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10160 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10161 | < 0) { |
| 10162 | goto error; |
| 10163 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10164 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10165 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10166 | astmodulestate_global->Attribute_type) < 0) { |
| 10167 | goto error; |
| 10168 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10169 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10170 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10171 | astmodulestate_global->Subscript_type) < 0) { |
| 10172 | goto error; |
| 10173 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10174 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10175 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10176 | 0) { |
| 10177 | goto error; |
| 10178 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10179 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10180 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 10181 | goto error; |
| 10182 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10183 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10184 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10185 | goto error; |
| 10186 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10187 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10188 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10189 | goto error; |
| 10190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10191 | Py_INCREF(astmodulestate(m)->Tuple_type); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 10192 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10193 | goto error; |
| 10194 | } |
| 10195 | Py_INCREF(astmodulestate(m)->Slice_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10196 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10197 | astmodulestate_global->expr_context_type) < 0) { |
| 10198 | goto error; |
| 10199 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10200 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10201 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10202 | goto error; |
| 10203 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10204 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10205 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10206 | goto error; |
| 10207 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10208 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10209 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10210 | goto error; |
| 10211 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10212 | Py_INCREF(astmodulestate(m)->Del_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10213 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10214 | 0) { |
| 10215 | goto error; |
| 10216 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10217 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10218 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10219 | goto error; |
| 10220 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10221 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10222 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10223 | goto error; |
| 10224 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10225 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10226 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10227 | < 0) { |
| 10228 | goto error; |
| 10229 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10230 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10231 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10232 | goto error; |
| 10233 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10234 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10235 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10236 | goto error; |
| 10237 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10238 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10239 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10240 | goto error; |
| 10241 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10242 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10243 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10244 | 0) { |
| 10245 | goto error; |
| 10246 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10247 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10248 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10249 | goto error; |
| 10250 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10251 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10252 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10253 | goto error; |
| 10254 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10255 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10256 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10257 | goto error; |
| 10258 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10259 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10260 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10261 | 0) { |
| 10262 | goto error; |
| 10263 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10264 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10265 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10266 | 0) { |
| 10267 | goto error; |
| 10268 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10269 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10270 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10271 | goto error; |
| 10272 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10273 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10274 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10275 | 0) { |
| 10276 | goto error; |
| 10277 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10278 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10279 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10280 | 0) { |
| 10281 | goto error; |
| 10282 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10283 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10284 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_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)->FloorDiv_type); |
| 10289 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_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)->unaryop_type); |
| 10294 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_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)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10299 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10300 | goto error; |
| 10301 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10302 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10303 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10304 | goto error; |
| 10305 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10306 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10307 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10308 | goto error; |
| 10309 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10310 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10311 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10312 | goto error; |
| 10313 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10314 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10315 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10316 | goto error; |
| 10317 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10318 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10319 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10320 | goto error; |
| 10321 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10322 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10323 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10324 | goto error; |
| 10325 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10326 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10327 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10328 | goto error; |
| 10329 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10330 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10331 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10332 | goto error; |
| 10333 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10334 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10335 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10336 | goto error; |
| 10337 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10338 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10339 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10340 | goto error; |
| 10341 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10342 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10343 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10344 | goto error; |
| 10345 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10346 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10347 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10348 | goto error; |
| 10349 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10350 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10351 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10352 | goto error; |
| 10353 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10354 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10355 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10356 | astmodulestate_global->comprehension_type) < 0) { |
| 10357 | goto error; |
| 10358 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10359 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10360 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10361 | astmodulestate_global->excepthandler_type) < 0) { |
| 10362 | goto error; |
| 10363 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10364 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10365 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10366 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10367 | goto error; |
| 10368 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10369 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10370 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10371 | astmodulestate_global->arguments_type) < 0) { |
| 10372 | goto error; |
| 10373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10374 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10375 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10376 | goto error; |
| 10377 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10378 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10379 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10380 | 0) { |
| 10381 | goto error; |
| 10382 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10383 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10384 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10385 | goto error; |
| 10386 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10387 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10388 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10389 | < 0) { |
| 10390 | goto error; |
| 10391 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10392 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10393 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10394 | astmodulestate_global->type_ignore_type) < 0) { |
| 10395 | goto error; |
| 10396 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10397 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10398 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10399 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10400 | goto error; |
| 10401 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10402 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10403 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10404 | error: |
| 10405 | Py_DECREF(m); |
| 10406 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10407 | } |
| 10408 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10409 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10410 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10411 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10412 | if (!init_types()) |
| 10413 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10414 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10415 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10416 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10417 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10418 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10419 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10420 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10421 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10422 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10423 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10424 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10425 | return NULL; |
| 10426 | } |
| 10427 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10428 | req_type[0] = astmodulestate_global->Module_type; |
| 10429 | req_type[1] = astmodulestate_global->Expression_type; |
| 10430 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10431 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10432 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10433 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10434 | if (!init_types()) |
| 10435 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10436 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10437 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10438 | if (isinstance == -1) |
| 10439 | return NULL; |
| 10440 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10441 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10442 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10443 | return NULL; |
| 10444 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10445 | |
| 10446 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10447 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10448 | return NULL; |
| 10449 | else |
| 10450 | return res; |
| 10451 | } |
| 10452 | |
| 10453 | int PyAST_Check(PyObject* obj) |
| 10454 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10455 | if (!init_types()) |
| 10456 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10457 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10458 | } |
| 10459 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10460 | |