removed complexity of builtin scope

This commit is contained in:
David Halter
2012-09-03 16:20:20 +02:00
parent 1775843e23
commit 663d808f9f
3 changed files with 9 additions and 17 deletions

View File

@@ -379,7 +379,7 @@ def parse_function_doc(func):
param_str = '' param_str = ''
if doc is not None: if doc is not None:
r = re.search('-[>-]* ', doc[end:end+7]) r = re.search('-[>-]* ', doc[end:end + 7])
if doc is None or r is None: if doc is None or r is None:
ret = 'pass' ret = 'pass'
else: else:
@@ -407,12 +407,4 @@ class _Builtin(object):
name = '__builtin__' name = '__builtin__'
_builtins = Parser(name=name) _builtins = Parser(name=name)
@property builtin_scope = _Builtin()._builtins.parser.module
def scope(self):
return self._builtins.parser.module
def get_defined_names(self):
return self.scope.get_defined_names()
Builtin = _Builtin()

View File

@@ -146,7 +146,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
def __init__(self, base, var_args=parsing.Array(None, None)): def __init__(self, base, var_args=parsing.Array(None, None)):
super(Instance, self).__init__(base, var_args) super(Instance, self).__init__(base, var_args)
if str(base.name) in ['list', 'set'] \ if str(base.name) in ['list', 'set'] \
and builtin.Builtin.scope == base.get_parent_until(): and builtin.builtin_scope == base.get_parent_until():
# compare the module path with the builtin name. # compare the module path with the builtin name.
self.var_args = dynamic.check_array_instances(self) self.var_args = dynamic.check_array_instances(self)
else: else:
@@ -802,7 +802,7 @@ class Array(use_metaclass(CachedMetaClass, parsing.Base)):
It returns e.g. for a list: append, pop, ... It returns e.g. for a list: append, pop, ...
""" """
# `array.type` is a string with the type, e.g. 'list'. # `array.type` is a string with the type, e.g. 'list'.
scope = get_scopes_for_name(builtin.Builtin.scope, self._array.type)[0] scope = get_scopes_for_name(builtin.builtin_scope, self._array.type)[0]
names = scope.get_defined_names() names = scope.get_defined_names()
return [ArrayElement(n) for n in names] return [ArrayElement(n) for n in names]
@@ -813,7 +813,7 @@ class Array(use_metaclass(CachedMetaClass, parsing.Base)):
""" """
Return the builtin scope as parent, because the arrays are builtins Return the builtin scope as parent, because the arrays are builtins
""" """
return builtin.Builtin.scope return builtin.builtin_scope
def __getattr__(self, name): def __getattr__(self, name):
if name not in ['type', 'start_pos']: if name not in ['type', 'start_pos']:
@@ -900,7 +900,7 @@ def get_names_for_scope(scope, position=None, star_search=True,
# Add builtins to the global scope. # Add builtins to the global scope.
if include_builtin: if include_builtin:
builtin_scope = builtin.Builtin.scope builtin_scope = builtin.builtin_scope
yield builtin_scope, builtin_scope.get_defined_names() yield builtin_scope, builtin_scope.get_defined_names()
@@ -1305,7 +1305,7 @@ def follow_call_path(path, scope, position):
if not isinstance(current, parsing.NamePart): if not isinstance(current, parsing.NamePart):
if current.type in (parsing.Call.STRING, parsing.Call.NUMBER): if current.type in (parsing.Call.STRING, parsing.Call.NUMBER):
t = type(current.name).__name__ t = type(current.name).__name__
scopes = get_scopes_for_name(builtin.Builtin.scope, t) scopes = get_scopes_for_name(builtin.builtin_scope, t)
else: else:
debug.warning('unknown type:', current.type, current) debug.warning('unknown type:', current.type, current)
scopes = [] scopes = []

View File

@@ -72,7 +72,7 @@ class RecursionNode(object):
# The same's true for the builtins, because the builtins are really # The same's true for the builtins, because the builtins are really
# simple. # simple.
self.is_ignored = isinstance(stmt, parsing.Param) \ self.is_ignored = isinstance(stmt, parsing.Param) \
or (self.script == builtin.Builtin.scope) or (self.script == builtin.builtin_scope)
def __eq__(self, other): def __eq__(self, other):
if not other: if not other:
@@ -117,7 +117,7 @@ class ExecutionRecursionDecorator(object):
if isinstance(execution.base, (evaluate.Generator, evaluate.Array)): if isinstance(execution.base, (evaluate.Generator, evaluate.Array)):
return False return False
module = execution.get_parent_until() module = execution.get_parent_until()
if evaluate_generator or module == builtin.Builtin.scope: if evaluate_generator or module == builtin.builtin_scope:
return False return False
if in_par_execution_funcs: if in_par_execution_funcs: