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

Method reduce_is_invalid

uncompyle6/parsers/parse3.py:1650–1773  ·  view source on GitHub ↗
(self, rule, ast, tokens, first, last)

Source from the content-addressed store, hash-verified

1648 return
1649
1650 def reduce_is_invalid(self, rule, ast, tokens, first, last):
1651 lhs = rule[0]
1652 n = len(tokens)
1653 last = min(last, n - 1)
1654 fn = self.reduce_check_table.get(lhs, None)
1655 if fn:
1656 if fn(self, lhs, n, rule, ast, tokens, first, last):
1657 return True
1658 pass
1659 # FIXME: put more in reduce_check_table
1660 if lhs in ("aug_assign1", "aug_assign2") and ast[0][0] == "and":
1661 return True
1662 elif lhs == "annotate_tuple":
1663 return not isinstance(tokens[first].attr, tuple)
1664 elif lhs == "kwarg":
1665 arg = tokens[first].attr
1666 return not (isinstance(arg, str) or isinstance(arg, unicode))
1667 elif rule == ("ifstmt", ("testexpr", "_ifstmts_jump")):
1668 # FIXME: go over what's up with 3.0. Evetually I'd like to remove RETURN_END_IF
1669 if self.version <= (3, 0) or tokens[last] == "RETURN_END_IF":
1670 return False
1671 if ifstmt(self, lhs, n, rule, ast, tokens, first, last):
1672 return True
1673 # FIXME: do we need the below or is it covered by "ifstmt" above?
1674 condition_jump = ast[0].last_child()
1675 if condition_jump.kind.startswith("POP_JUMP_IF"):
1676 condition_jump2 = tokens[min(last - 1, len(tokens) - 1)]
1677 # If there are two *distinct* condition jumps, they should not jump to the
1678 # same place. Otherwise we have some sort of "and"/"or".
1679 if (
1680 condition_jump2.kind.startswith("POP_JUMP_IF")
1681 and condition_jump != condition_jump2
1682 ):
1683 return condition_jump.attr == condition_jump2.attr
1684
1685 if (
1686 tokens[last] == "COME_FROM"
1687 and tokens[last].off2int() != condition_jump.attr
1688 ):
1689 return False
1690
1691 # if condition_jump.attr < condition_jump2.off2int():
1692 # print("XXX", first, last)
1693 # for t in range(first, last): print(tokens[t])
1694 # from trepan.api import debug; debug()
1695 return condition_jump.attr < condition_jump2.off2int()
1696 return False
1697 elif rule == ("ifstmt", ("testexpr", "\\e__ifstmts_jump")):
1698 # I am not sure what to check.
1699 # Probably needs fixing elsewhere
1700 return True
1701 elif lhs == "ifelsestmt" and rule[1][2] == "jump_forward_else":
1702 last = min(last, len(tokens) - 1)
1703 if tokens[last].off2int() == -1:
1704 last -= 1
1705 jump_forward_else = ast[2]
1706 return (
1707 tokens[first].off2int()

Callers

nothing calls this directly

Calls 6

ifstmtFunction · 0.90
while1stmtFunction · 0.90
last_childMethod · 0.80
off2intMethod · 0.80
fnFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected