forked from VimPlug/jedi
globals are more or less ready.
This commit is contained in:
@@ -130,6 +130,7 @@ class Evaluator(object):
|
|||||||
if isinstance(stmt, FakeStatement):
|
if isinstance(stmt, FakeStatement):
|
||||||
return stmt.children # Already contains the results.
|
return stmt.children # Already contains the results.
|
||||||
|
|
||||||
|
print('X', stmt.get_rhs())
|
||||||
result = self.eval_element(stmt.get_rhs())
|
result = self.eval_element(stmt.get_rhs())
|
||||||
|
|
||||||
ass_details = stmt.assignment_details
|
ass_details = stmt.assignment_details
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class NameFinder(object):
|
|||||||
defined.
|
defined.
|
||||||
"""
|
"""
|
||||||
if isinstance(scope, pr.Flow) \
|
if isinstance(scope, pr.Flow) \
|
||||||
or isinstance(scope, pr.KeywordStatement) and scope.name == 'global':
|
or isinstance(scope, pr.GlobalStmt):
|
||||||
|
|
||||||
if isinstance(name_list_scope, er.Class):
|
if isinstance(name_list_scope, er.Class):
|
||||||
name_list_scope = name_list_scope.base
|
name_list_scope = name_list_scope.base
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ class Parser(object):
|
|||||||
print(repr(source))
|
print(repr(source))
|
||||||
self.module = d.parse_string(source).get_parent_until()
|
self.module = d.parse_string(source).get_parent_until()
|
||||||
|
|
||||||
|
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):
|
||||||
|
|||||||
@@ -540,7 +540,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_vars', 'used_names', 'temp_used_names',
|
__slots__ = ('path', 'global_names', 'used_names', 'temp_used_names',
|
||||||
'line_offset', 'use_as_parent')
|
'line_offset', 'use_as_parent')
|
||||||
|
|
||||||
def __init__(self, children):
|
def __init__(self, children):
|
||||||
@@ -554,7 +554,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.global_vars = []
|
|
||||||
self.used_names = {}
|
self.used_names = {}
|
||||||
self.temp_used_names = []
|
self.temp_used_names = []
|
||||||
# this may be changed depending on fast_parser
|
# this may be changed depending on fast_parser
|
||||||
@@ -563,21 +562,25 @@ class SubModule(Scope, Module):
|
|||||||
if 0:
|
if 0:
|
||||||
self.use_as_parent = top_module or self
|
self.use_as_parent = top_module or self
|
||||||
|
|
||||||
def add_global(self, name):
|
def set_global_names(self, names):
|
||||||
"""
|
"""
|
||||||
Global means in these context a function (subscope) which has a global
|
Global means in these context a function (subscope) which has a global
|
||||||
statement.
|
statement.
|
||||||
This is only relevant for the top scope.
|
This is only relevant for the top scope.
|
||||||
|
|
||||||
:param name: The name of the global.
|
:param names: names of the global.
|
||||||
:type name: Name
|
:type names: list of Name
|
||||||
"""
|
"""
|
||||||
|
self.global_names = names
|
||||||
|
|
||||||
|
def add_global(self, name):
|
||||||
# set no parent here, because globals are not defined in this scope.
|
# set no parent here, because globals are not defined in this scope.
|
||||||
self.global_vars.append(name)
|
self.global_vars.append(name)
|
||||||
|
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
n = super(SubModule, self).get_defined_names()
|
n = super(SubModule, self).get_defined_names()
|
||||||
n += self.global_vars
|
# TODO uncomment
|
||||||
|
#n += self.global_names
|
||||||
return n
|
return n
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -1038,11 +1041,7 @@ class Statement(Simple, DocstringMixin):
|
|||||||
|
|
||||||
def get_rhs(self):
|
def get_rhs(self):
|
||||||
"""Returns the right-hand-side of the equals."""
|
"""Returns the right-hand-side of the equals."""
|
||||||
# TODO remove expr_stmt?
|
return self.children[-1]
|
||||||
if is_node(self.children[0], 'expr_stmt'):
|
|
||||||
return self.children[0].children[-1]
|
|
||||||
else:
|
|
||||||
return self.children[0]
|
|
||||||
|
|
||||||
def get_names_dict(self):
|
def get_names_dict(self):
|
||||||
"""The future of name resolution. Returns a dict(str -> Call)."""
|
"""The future of name resolution. Returns a dict(str -> Call)."""
|
||||||
|
|||||||
Reference in New Issue
Block a user