MCPcopy
hub / github.com/rocky/python-uncompyle6 / reduce_is_invalid

Method reduce_is_invalid

uncompyle6/parsers/parse27.py:284–385  ·  view source on GitHub ↗
(self, rule, ast, tokens, first, last)

Source from the content-addressed store, hash-verified

282 return
283
284 def reduce_is_invalid(self, rule, ast, tokens, first, last):
285 invalid = super(Python27Parser, self).reduce_is_invalid(
286 rule, ast, tokens, first, last
287 )
288
289 lhs = rule[0]
290 n = len(tokens)
291 fn = self.reduce_check_table.get(lhs, None)
292 if fn:
293 invalid = fn(self, lhs, n, rule, ast, tokens, first, last)
294 last = min(last, n - 1)
295 if invalid:
296 return invalid
297
298 if rule == ("comp_if", ("expr", "jmp_false", "comp_iter")):
299 jmp_false = ast[1]
300 if jmp_false[0] == "POP_JUMP_IF_FALSE":
301 return tokens[first].offset < jmp_false[0].attr < tokens[last].offset
302 pass
303 elif (rule[0], rule[1][0:5]) == (
304 "if_exp",
305 ("expr", "jmp_false", "expr", "JUMP_ABSOLUTE", "expr"),
306 ):
307 jmp_false = ast[1]
308 if jmp_false[0] == "POP_JUMP_IF_FALSE":
309 else_instr = ast[4].first_child()
310 if jmp_false[0].attr != else_instr.offset:
311 return True
312 end_offset = ast[3].attr
313 return end_offset < tokens[last].offset
314 pass
315 elif rule[0] == "raise_stmt1":
316 return ast[0] == "expr" and ast[0][0] == "or"
317 elif rule[0] in ("assert", "assert2"):
318 jump_inst = ast[1][0]
319 jump_target = jump_inst.attr
320 return not (
321 last >= len(tokens)
322 or jump_target == tokens[last].offset
323 or jump_target == next_offset(ast[-1].op, ast[-1].opc, ast[-1].offset)
324 )
325 elif rule == ("ifstmt", ("testexpr", "_ifstmts_jump")):
326 for i in range(last - 1, last - 4, -1):
327 t = tokens[i]
328 if t == "JUMP_FORWARD":
329 return t.attr > tokens[min(last, len(tokens) - 1)].off2int()
330 elif t not in ("POP_TOP", "COME_FROM"):
331 break
332 pass
333 pass
334 elif rule == ("iflaststmtl", ("testexpr", "c_stmts")):
335 testexpr = ast[0]
336 if testexpr[0] in ("testfalse", "testtrue"):
337 test = testexpr[0]
338 if len(test) > 1 and test[1].kind.startswith("jmp_"):
339 jmp_target = test[1][0].attr
340 if last == len(tokens):
341 last -= 1

Callers

nothing calls this directly

Calls 4

first_childMethod · 0.80
off2intMethod · 0.80
fnFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected