1
0
forked from VimPlug/jedi

parsing.set_parent -> use_as_parent

This commit is contained in:
David Halter
2013-01-09 15:21:04 +01:00
parent 232aafeb6a
commit b85c54932b

View File

@@ -64,13 +64,13 @@ class Simple(Base):
The super class for Scope, Import, Name and Statement. Every object in The super class for Scope, Import, Name and Statement. Every object in
the parser tree inherits from this class. the parser tree inherits from this class.
""" """
__slots__ = ('parent', 'module', '_start_pos', 'set_parent', '_end_pos') __slots__ = ('parent', 'module', '_start_pos', 'use_as_parent', '_end_pos')
def __init__(self, module, start_pos, end_pos=(None, None)): def __init__(self, module, start_pos, end_pos=(None, None)):
self._start_pos = start_pos self._start_pos = start_pos
self._end_pos = end_pos self._end_pos = end_pos
self.parent = None self.parent = None
# use this attribute if parent should be something else than self. # use this attribute if parent should be something else than self.
self.set_parent = self self.use_as_parent = self
self.module = module self.module = module
@Python3Method @Python3Method
@@ -132,12 +132,12 @@ class Scope(Simple):
self.asserts = [] self.asserts = []
def add_scope(self, sub, decorators): def add_scope(self, sub, decorators):
sub.parent = self.set_parent sub.parent = self.use_as_parent
sub.decorators = decorators sub.decorators = decorators
for d in decorators: for d in decorators:
# the parent is the same, because the decorator has not the scope # the parent is the same, because the decorator has not the scope
# of the function # of the function
d.parent = self.set_parent d.parent = self.use_as_parent
self.subscopes.append(sub) self.subscopes.append(sub)
return sub return sub
@@ -146,7 +146,7 @@ class Scope(Simple):
Used to add a Statement or a Scope. Used to add a Statement or a Scope.
A statement would be a normal command (Statement) or a Scope (Flow). A statement would be a normal command (Statement) or a Scope (Flow).
""" """
stmt.parent = self.set_parent stmt.parent = self.use_as_parent
self.statements.append(stmt) self.statements.append(stmt)
return stmt return stmt
@@ -156,7 +156,7 @@ class Scope(Simple):
def add_import(self, imp): def add_import(self, imp):
self.imports.append(imp) self.imports.append(imp)
imp.parent = self.set_parent imp.parent = self.use_as_parent
def get_imports(self): def get_imports(self):
""" Gets also the imports within flow statements """ """ Gets also the imports within flow statements """
@@ -283,7 +283,7 @@ class SubModule(Scope, Module):
# this may be changed depending on fast_parser # this may be changed depending on fast_parser
self.line_offset = 0 self.line_offset = 0
self.set_parent = top_module or self self.use_as_parent = top_module or self
def add_global(self, name): def add_global(self, name):
""" """
@@ -316,7 +316,7 @@ class SubModule(Scope, Module):
string = r.group(1) string = r.group(1)
names = [(string, (0, 0))] names = [(string, (0, 0))]
self._name = Name(self, names, self.start_pos, self.end_pos, self._name = Name(self, names, self.start_pos, self.end_pos,
self.set_parent) self.use_as_parent)
return self._name return self._name
def is_builtin(self): def is_builtin(self):
@@ -337,10 +337,10 @@ class Class(Scope):
def __init__(self, module, name, supers, start_pos): def __init__(self, module, name, supers, start_pos):
super(Class, self).__init__(module, start_pos) super(Class, self).__init__(module, start_pos)
self.name = name self.name = name
name.parent = self.set_parent name.parent = self.use_as_parent
self.supers = supers self.supers = supers
for s in self.supers: for s in self.supers:
s.parent = self.set_parent s.parent = self.use_as_parent
self.decorators = [] self.decorators = []
def get_code(self, first_indent=False, indention=' '): def get_code(self, first_indent=False, indention=' '):
@@ -373,18 +373,18 @@ class Function(Scope):
super(Function, self).__init__(module, start_pos) super(Function, self).__init__(module, start_pos)
self.name = name self.name = name
if name is not None: if name is not None:
name.parent = self.set_parent name.parent = self.use_as_parent
self.params = params self.params = params
for p in params: for p in params:
p.parent = self.set_parent p.parent = self.use_as_parent
p.parent_function = self.set_parent p.parent_function = self.use_as_parent
self.decorators = [] self.decorators = []
self.returns = [] self.returns = []
self.is_generator = False self.is_generator = False
self.listeners = set() # not used here, but in evaluation. self.listeners = set() # not used here, but in evaluation.
if annotation is not None: if annotation is not None:
annotation.parent = self.set_parent annotation.parent = self.use_as_parent
self.annotation = annotation self.annotation = annotation
def get_code(self, first_indent=False, indention=' '): def get_code(self, first_indent=False, indention=' '):
@@ -481,14 +481,14 @@ class Flow(Scope):
# These have to be statements, because of with, which takes multiple. # These have to be statements, because of with, which takes multiple.
self.inits = inits self.inits = inits
for s in inits: for s in inits:
s.parent = self.set_parent s.parent = self.use_as_parent
if set_vars is None: if set_vars is None:
self.set_vars = [] self.set_vars = []
else: else:
self.set_vars = set_vars self.set_vars = set_vars
for s in self.set_vars: for s in self.set_vars:
s.parent.parent = self.set_parent s.parent.parent = self.use_as_parent
s.parent = self.set_parent s.parent = self.use_as_parent
@property @property
def parent(self): def parent(self):
@@ -595,7 +595,7 @@ class Import(Simple):
self.from_ns = from_ns self.from_ns = from_ns
for n in [namespace, alias, from_ns]: for n in [namespace, alias, from_ns]:
if n: if n:
n.parent = self.set_parent n.parent = self.use_as_parent
self.star = star self.star = star
self.relative_count = relative_count self.relative_count = relative_count
@@ -682,7 +682,7 @@ class Statement(Simple):
self.used_vars = used_vars self.used_vars = used_vars
self.token_list = token_list self.token_list = token_list
for s in set_vars + used_funcs + used_vars: for s in set_vars + used_funcs + used_vars:
s.parent = self.set_parent s.parent = self.use_as_parent
self.set_vars = self._remove_executions_from_set_vars(set_vars) self.set_vars = self._remove_executions_from_set_vars(set_vars)
# cache # cache
@@ -917,7 +917,7 @@ class Param(Statement):
self.parent_function = None self.parent_function = None
def add_annotation(self, annotation_stmt): def add_annotation(self, annotation_stmt):
annotation_stmt.parent = self.set_parent annotation_stmt.parent = self.use_as_parent
self.annotation_stmt = annotation_stmt self.annotation_stmt = annotation_stmt
def get_name(self): def get_name(self):