mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Use used_names not in pgen2, but only in our parser.
This commit is contained in:
@@ -56,16 +56,22 @@ class Parser(object):
|
|||||||
# When this is True, the refactor*() methods will call write_file() for
|
# When this is True, the refactor*() methods will call write_file() for
|
||||||
# files processed even if they were not changed during refactoring. If
|
# files processed even if they were not changed during refactoring. If
|
||||||
# and only if the refactor method's write parameter was True.
|
# and only if the refactor method's write parameter was True.
|
||||||
|
self.used_names = {}
|
||||||
logger = logging.getLogger("RefactoringTool")
|
logger = logging.getLogger("RefactoringTool")
|
||||||
d = Driver(pytree.python_grammar, convert=self.convert, logger=logger)
|
d = Driver(pytree.python_grammar, convert=self.convert, logger=logger)
|
||||||
self.module = d.parse_string(source).get_parent_until()
|
self.module = d.parse_string(source).get_parent_until()
|
||||||
|
|
||||||
|
self.module.used_names = self.used_names
|
||||||
self.module.set_global_names(self.global_names)
|
self.module.set_global_names(self.global_names)
|
||||||
|
|
||||||
def convert(self, grammar, raw_node):
|
def convert(self, grammar, raw_node):
|
||||||
new_node = pytree.convert(grammar, raw_node)
|
new_node = pytree.convert(grammar, raw_node)
|
||||||
if isinstance(new_node, pr.GlobalStmt):
|
if isinstance(new_node, pr.GlobalStmt):
|
||||||
self.global_names += new_node.names()
|
self.global_names += new_node.names()
|
||||||
|
elif isinstance(new_node, pr.Name):
|
||||||
|
# Keep a listing of all used names
|
||||||
|
arr = self.used_names.setdefault(new_node.value, [])
|
||||||
|
arr.append(new_node)
|
||||||
return new_node
|
return new_node
|
||||||
|
|
||||||
def __init__old__(self, source, module_path=None, no_docstr=False,
|
def __init__old__(self, source, module_path=None, no_docstr=False,
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ class Parser(object):
|
|||||||
stackentry = (self.grammar.dfas[start], 0, newnode)
|
stackentry = (self.grammar.dfas[start], 0, newnode)
|
||||||
self.stack = [stackentry]
|
self.stack = [stackentry]
|
||||||
self.rootnode = None
|
self.rootnode = None
|
||||||
self.used_names = set() # Aliased to self.rootnode.used_names in pop()
|
|
||||||
|
|
||||||
def addtoken(self, type, value, context):
|
def addtoken(self, type, value, context):
|
||||||
"""Add a token; return True iff this is the end of the program."""
|
"""Add a token; return True iff this is the end of the program."""
|
||||||
@@ -149,8 +148,6 @@ class Parser(object):
|
|||||||
def classify(self, type, value, context):
|
def classify(self, type, value, context):
|
||||||
"""Turn a token into a label. (Internal)"""
|
"""Turn a token into a label. (Internal)"""
|
||||||
if type == token.NAME:
|
if type == token.NAME:
|
||||||
# Keep a listing of all used names
|
|
||||||
self.used_names.add(value)
|
|
||||||
# Check for reserved words
|
# Check for reserved words
|
||||||
ilabel = self.grammar.keywords.get(value)
|
ilabel = self.grammar.keywords.get(value)
|
||||||
if ilabel is not None:
|
if ilabel is not None:
|
||||||
@@ -186,7 +183,6 @@ class Parser(object):
|
|||||||
node[-1].append(newnode)
|
node[-1].append(newnode)
|
||||||
else:
|
else:
|
||||||
self.rootnode = newnode
|
self.rootnode = newnode
|
||||||
self.rootnode.used_names = self.used_names
|
|
||||||
|
|
||||||
def error_recovery(self, type, value, context):
|
def error_recovery(self, type, value, context):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -582,7 +582,7 @@ class SubModule(Scope, Module):
|
|||||||
Depending on the underlying parser this may be a full module or just a part
|
Depending on the underlying parser this may be a full module or just a part
|
||||||
of a module.
|
of a module.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('path', 'global_names', 'used_names', 'temp_used_names',
|
__slots__ = ('path', 'global_names', 'used_names',
|
||||||
'line_offset', 'use_as_parent')
|
'line_offset', 'use_as_parent')
|
||||||
|
|
||||||
def __init__(self, children):
|
def __init__(self, children):
|
||||||
@@ -596,8 +596,6 @@ class SubModule(Scope, Module):
|
|||||||
"""
|
"""
|
||||||
super(SubModule, self).__init__(children)
|
super(SubModule, self).__init__(children)
|
||||||
self.path = None # Set later.
|
self.path = None # Set later.
|
||||||
self.used_names = {}
|
|
||||||
self.temp_used_names = []
|
|
||||||
# this may be changed depending on fast_parser
|
# this may be changed depending on fast_parser
|
||||||
self.line_offset = 0
|
self.line_offset = 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user