NameFinder.filter_name is simpler now.

This commit is contained in:
Dave Halter
2014-04-14 13:45:31 +02:00
parent 6a40c9b671
commit b81eb9f8b3
2 changed files with 24 additions and 16 deletions

View File

@@ -69,24 +69,29 @@ class NameFinder(object):
# reference.
name_list = sorted(name_list, key=lambda n: n.start_pos, reverse=True)
for name in name_list:
if self.name_str != name.get_code():
continue
parpar = name.parent.parent
if self.name_str == name.get_code() and parpar not in break_scopes:
if not self._name_is_array_assignment(name):
result.append(name) # `arr[1] =` is not the definition
# for comparison we need the raw class
# this means that a definition was found and is not e.g.
# in if/else.
if result and self._name_is_break_scope(name):
#print result, name.parent, parpar, s
if isinstance(parpar, pr.Flow) \
or isinstance(parpar, pr.KeywordStatement) \
and parpar.name == 'global':
s = nscope.base if isinstance(nscope, er.Class) else nscope
if parpar == s:
break
else:
if name.parent.parent in break_scopes:
continue
if not self._name_is_array_assignment(name):
result.append(name) # `arr[1] =` is not the definition
# for comparison we need the raw class
# this means that a definition was found and is not e.g.
# in if/else.
if result and self._name_is_break_scope(name):
#print result, name.parent, parpar, s
if isinstance(parpar, pr.Flow) \
or isinstance(parpar, pr.KeywordStatement) \
and parpar.name == 'global':
s = nscope.base if isinstance(nscope, er.Class) else nscope
if parpar == s:
break
break_scopes.append(parpar)
else:
break
break_scopes.append(parpar)
if result:
break

View File

@@ -1387,6 +1387,9 @@ class NamePart(object):
def __eq__(self, other):
return self.string == other
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash(self.string)