This commit is contained in:
rocky
2023-08-09 04:48:42 -04:00
parent 3a178836a6
commit 8865599145

View File

@@ -1,13 +1,16 @@
# Copyright (c) 2020 Rocky Bernstein # Copyright (c) 2020, 2023 Rocky Bernstein
def ifstmt(self, lhs, n, rule, ast, tokens, first, last): def ifstmt(self, lhs, n, rule, ast, tokens, first, last):
first_offset = tokens[first].off2int(prefer_last=False)
if lhs == "ifstmtl": if lhs == "ifstmtl":
if last == n: if last == n:
last -= 1 last -= 1
pass pass
if tokens[last].attr and isinstance(tokens[last].attr, int): if tokens[last].attr and isinstance(tokens[last].attr, int):
if tokens[first].offset >= tokens[last].attr: if first_offset >= tokens[last].attr:
return True return True
pass pass
pass pass
@@ -36,7 +39,7 @@ def ifstmt(self, lhs, n, rule, ast, tokens, first, last):
if tokens[l] == "JUMP_FORWARD": if tokens[l] == "JUMP_FORWARD":
return tokens[l].attr != pjif_target return tokens[l].attr != pjif_target
return True return True
elif lhs == "ifstmtl" and tokens[first].off2int() > pjif_target: elif lhs == "ifstmtl" and first_offset > pjif_target:
# A conditional JUMP to the loop is expected for "ifstmtl" # A conditional JUMP to the loop is expected for "ifstmtl"
return False return False
pass pass
@@ -55,7 +58,7 @@ def ifstmt(self, lhs, n, rule, ast, tokens, first, last):
if len(test) > 1 and test[1].kind.startswith("jmp_"): if len(test) > 1 and test[1].kind.startswith("jmp_"):
jmp_target = test[1][0].attr jmp_target = test[1][0].attr
if ( if (
tokens[first].off2int(prefer_last=True) first_offset
<= jmp_target <= jmp_target
< tokens[last].off2int(prefer_last=False) < tokens[last].off2int(prefer_last=False)
): ):