(state: State, data: ReadBuffer)
| 1234 | |
| 1235 | |
| 1236 | def read_expression(state: State, data: ReadBuffer) -> Expression: |
| 1237 | # Branches ordered by frequency (based on mypy self-check) |
| 1238 | tag = read_tag(data) |
| 1239 | expr: Expression |
| 1240 | if tag == nodes.NAME_EXPR: |
| 1241 | s = read_str(data) |
| 1242 | ne = NameExpr(s) |
| 1243 | read_loc(data, ne) |
| 1244 | expect_end_tag(data) |
| 1245 | return ne |
| 1246 | elif tag == nodes.MEMBER_EXPR: |
| 1247 | e = read_expression(state, data) |
| 1248 | attr = read_str(data) |
| 1249 | m = MemberExpr(e, attr) |
| 1250 | # Check if this is a super() call - if so, convert to SuperExpr |
| 1251 | if isinstance(e, CallExpr) and isinstance(e.callee, NameExpr) and e.callee.name == "super": |
| 1252 | result: Expression = SuperExpr(attr, e) |
| 1253 | else: |
| 1254 | result = m |
| 1255 | read_loc(data, result) |
| 1256 | expect_end_tag(data) |
| 1257 | return result |
| 1258 | elif tag == nodes.CALL_EXPR: |
| 1259 | callee = read_expression(state, data) |
| 1260 | args = read_expression_list(state, data) |
| 1261 | # Read argument kinds |
| 1262 | expect_tag(data, LIST_INT) |
| 1263 | n_kinds = read_int_bare(data) |
| 1264 | arg_kinds = [ARG_KINDS[read_int_bare(data)] for _ in range(n_kinds)] |
| 1265 | # Read argument names |
| 1266 | expect_tag(data, LIST_GEN) |
| 1267 | n_names = read_int_bare(data) |
| 1268 | arg_names: list[str | None] = [] |
| 1269 | for _ in range(n_names): |
| 1270 | tag = read_tag(data) |
| 1271 | if tag == LITERAL_NONE: |
| 1272 | arg_names.append(None) |
| 1273 | elif tag == LITERAL_STR: |
| 1274 | arg_names.append(read_str_bare(data)) |
| 1275 | else: |
| 1276 | assert False, f"Unexpected tag for arg_name: {tag}" |
| 1277 | ce = CallExpr(callee, args, arg_kinds, arg_names) |
| 1278 | read_loc(data, ce) |
| 1279 | expect_end_tag(data) |
| 1280 | return ce |
| 1281 | elif tag == nodes.STR_EXPR: |
| 1282 | se = StrExpr(read_str(data)) |
| 1283 | read_loc(data, se) |
| 1284 | expect_end_tag(data) |
| 1285 | return se |
| 1286 | elif tag == nodes.COMPARISON_EXPR: |
| 1287 | left = read_expression(state, data) |
| 1288 | expect_tag(data, LIST_INT) |
| 1289 | n_ops = read_int_bare(data) |
| 1290 | ops = [cmp_ops[read_int_bare(data)] for _ in range(n_ops)] |
| 1291 | comparators = read_expression_list(state, data) |
| 1292 | assert len(ops) == len(comparators) |
| 1293 | expr = ComparisonExpr(ops, [left] + comparators) |
no test coverage detected
searching dependent graphs…