Handle BUILD_CONST_KEY_MAP as a varargs

custom rules with BUILD_CONST_KEY_MAP are pinned to the specific number
of args seen.
This commit is contained in:
rocky
2017-01-20 20:41:10 -05:00
parent e9057f378a
commit 8333e4ae93
3 changed files with 5 additions and 2 deletions

View File

@@ -617,7 +617,7 @@ class Python3Parser(PythonParser):
self.add_unique_rule(rule, opname, token.attr, customize)
rule = "mapexpr ::= %s %s" % (opname, kvlist_n)
self.add_unique_rule(rule, opname, token.attr, customize)
elif opname == 'BUILD_CONST_KEY_MAP':
elif opname_base == 'BUILD_CONST_KEY_MAP':
# This is in 3.6+
kvlist_n = 'expr ' * (token.attr)
rule = "mapexpr ::= %sLOAD_CONST %s" % (kvlist_n, opname)

View File

@@ -126,6 +126,9 @@ class Scanner3(Scanner):
if is_pypy:
varargs_ops.add(self.opc.CALL_METHOD)
if self.version >= 3.6:
varargs_ops.add(self.opc.BUILD_CONST_KEY_MAP)
self.varargs_ops = frozenset(varargs_ops)
# FIXME: remove the above in favor of:
# self.varargs_ops = frozenset(self.opc.hasvargs)

View File

@@ -1426,7 +1426,7 @@ class SourceWalker(GenericASTTraversal, object):
i += 3
pass
pass
elif node[-1].type == 'BUILD_CONST_KEY_MAP':
elif node[-1].type.startswith('BUILD_CONST_KEY_MAP'):
# Python 3.6+ style const map
keys = node[-2].pattr
values = node[:-2]