Improve Python 2.6 & 2.7 verification

This commit is contained in:
rocky
2017-01-23 02:32:09 -05:00
parent cc2321f49e
commit 597d51951e
3 changed files with 32 additions and 18 deletions

View File

@@ -159,7 +159,6 @@ class Scanner2(scan.Scanner):
# we sort them). That way, specific COME_FROM tags will match up # we sort them). That way, specific COME_FROM tags will match up
# properly. For example, a "loop" with an "if" nested in it should have the # properly. For example, a "loop" with an "if" nested in it should have the
# "loop" tag last so the grammar rule matches that properly. # "loop" tag last so the grammar rule matches that properly.
# last_offset = -1
for jump_offset in sorted(jump_targets[offset], reverse=True): for jump_offset in sorted(jump_targets[offset], reverse=True):
# if jump_offset == last_offset: # if jump_offset == last_offset:
# continue # continue
@@ -265,13 +264,14 @@ class Scanner2(scan.Scanner):
# rule for that. # rule for that.
target = self.get_target(offset) target = self.get_target(offset)
if target <= offset: if target <= offset:
op_name = 'JUMP_BACK'
if (offset in self.stmts if (offset in self.stmts
and self.code[offset+3] not in (self.opc.END_FINALLY, and self.code[offset+3] not in (self.opc.END_FINALLY,
self.opc.POP_BLOCK) self.opc.POP_BLOCK)):
and offset not in self.not_continue): if ((offset in self.linestartoffsets and
op_name = 'CONTINUE' self.code[self.prev[offset]] == self.opc.JUMP_ABSOLUTE)
else: or offset not in self.not_continue):
op_name = 'JUMP_BACK' op_name = 'CONTINUE'
elif op == self.opc.LOAD_GLOBAL: elif op == self.opc.LOAD_GLOBAL:
if offset in self.load_asserts: if offset in self.load_asserts:

View File

@@ -158,12 +158,15 @@ class Scanner26(scan.Scanner2):
# we sort them). That way, specific COME_FROM tags will match up # we sort them). That way, specific COME_FROM tags will match up
# properly. For example, a "loop" with an "if" nested in it should have the # properly. For example, a "loop" with an "if" nested in it should have the
# "loop" tag last so the grammar rule matches that properly. # "loop" tag last so the grammar rule matches that properly.
last_jump_offset = -1
for jump_offset in sorted(jump_targets[offset], reverse=True): for jump_offset in sorted(jump_targets[offset], reverse=True):
tokens.append(Token( if jump_offset != last_jump_offset:
'COME_FROM', None, repr(jump_offset), tokens.append(Token(
offset="%s_%d" % (offset, jump_idx), 'COME_FROM', None, repr(jump_offset),
has_arg = True)) offset="%s_%d" % (offset, jump_idx),
jump_idx += 1 has_arg = True))
jump_idx += 1
last_jump_offset = jump_offset
elif offset in self.thens: elif offset in self.thens:
tokens.append(Token( tokens.append(Token(
'THEN', None, self.thens[offset], 'THEN', None, self.thens[offset],
@@ -242,16 +245,21 @@ class Scanner26(scan.Scanner2):
# boundaries The continue-type jumps help us get # boundaries The continue-type jumps help us get
# "continue" statements with would otherwise be turned # "continue" statements with would otherwise be turned
# into a "pass" statement because JUMPs are sometimes # into a "pass" statement because JUMPs are sometimes
# ignored in rules as just boundary overhead. # ignored in rules as just boundary overhead. In
# comprehensions we might sometimes classify JUMP_BACK
# as CONTINUE, but that's okay since we add a grammar
# rule for that.
target = self.get_target(offset) target = self.get_target(offset)
if target <= offset: if target <= offset:
op_name = 'JUMP_BACK'
if (offset in self.stmts if (offset in self.stmts
and self.code[offset+3] not in (self.opc.END_FINALLY, and self.code[offset+3] not in (self.opc.END_FINALLY,
self.opc.POP_BLOCK) self.opc.POP_BLOCK)):
and offset not in self.not_continue): if ((offset in self.linestartoffsets and
op_name = 'CONTINUE' tokens[-1].type == 'JUMP_BACK')
or offset not in self.not_continue):
op_name = 'CONTINUE'
else: else:
op_name = 'JUMP_BACK'
# FIXME: this is a hack to catch stuff like: # FIXME: this is a hack to catch stuff like:
# if x: continue # if x: continue
# the "continue" is not on a new line. # the "continue" is not on a new line.

View File

@@ -318,8 +318,14 @@ def cmp_code_objects(version, is_pypy, code_obj1, code_obj2,
elif tokens1[i1].type == 'LOAD_NAME' and tokens2[i2].type == 'LOAD_CONST' \ elif tokens1[i1].type == 'LOAD_NAME' and tokens2[i2].type == 'LOAD_CONST' \
and tokens1[i1].pattr == 'None' and tokens2[i2].pattr is None: and tokens1[i1].pattr == 'None' and tokens2[i2].pattr is None:
pass pass
elif tokens1[i1].type == 'RETURN_VALUE' and \ elif tokens1[i1].type == 'LOAD_GLOBAL' and tokens2[i2].type == 'LOAD_NAME' \
tokens2[i2].type == 'RETURN_END_IF': and tokens1[i1].pattr == tokens2[i2].pattr:
pass
elif (tokens1[i1].type == 'RETURN_VALUE' and
tokens2[i2].type == 'RETURN_END_IF'):
pass
elif (tokens1[i1].type == 'BUILD_TUPLE_0' and
tokens2[i2].pattr == ()):
pass pass
else: else:
raise CmpErrorCode(name, tokens1[i1].offset, tokens1[i1], raise CmpErrorCode(name, tokens1[i1].offset, tokens1[i1],