diff --git a/evaluate.py b/evaluate.py index e81b5c17..b371adb8 100644 --- a/evaluate.py +++ b/evaluate.py @@ -5,6 +5,7 @@ follow_statement -> follow_call -> follow_paths -> follow_path `get_names_for_scope` and `get_scopes_for_name` are search functions TODO include super classes +TOOD nonlocal statement """ from _compatibility import next @@ -123,7 +124,6 @@ class Execution(Exec): debug.dbg('exec stmts=', stmts, self.base, repr(self)) - #print stmts return stmts @memoize(default=[]) @@ -249,8 +249,15 @@ def get_scopes_for_name(scope, name, search_global=False): res_new = [] for r in result: if isinstance(r, parsing.Statement): - scopes = follow_statement(r, seek_name=name) - res_new += remove_statements(scopes) + if r.is_global(): + res_new += [] + for token_name in r.token_list[1:]: + if isinstance(token_name, parsing.Name): + res_new += get_scopes_for_name(r.parent, + str(token_name)) + else: + scopes = follow_statement(r, seek_name=name) + res_new += remove_statements(scopes) else: res_new.append(r) debug.dbg('sfn remove, new: %s, old: %s' % (res_new, result)) @@ -266,13 +273,12 @@ def get_scopes_for_name(scope, name, search_global=False): else: par = scope.parent if isinstance(par, parsing.Flow): - # TODO get Flow data, which is defined by the loop - # (or with) if par.command == 'for': # take the first statement (for has always only # one, remember `in`). And follow it. After that, # get the types which are in the array arrays = follow_statement(par.inits[0]) + # TODO for loops can have tuples as set_vars for array in arrays: result += array.get_index_types() else: @@ -465,7 +471,6 @@ def follow_path(path, scope): debug.warning('strange function call with {}', current, scope) else: if isinstance(scope, parsing.Function): - # TODO this is never reached, just remove it? # TODO check default function methods and return them result = [] else: diff --git a/ftest.py b/ftest.py index 5eaaad7b..10fef9d8 100755 --- a/ftest.py +++ b/ftest.py @@ -2,7 +2,7 @@ import functions -#functions.debug.debug_function = functions.debug.print_to_stdout +functions.debug.debug_function = functions.debug.print_to_stdout functions.debug.ignored_modules = ['parsing', 'builtin'] #functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules'] functions.modules.module_find_path.insert(0, '.') @@ -14,7 +14,7 @@ path = os.path.join(os.getcwd(), f_name) f = open(path) code = f.read() for i in range(1): - completions = functions.complete(code, 150, 200, path) + completions = functions.complete(code, 160, 200, path) print '\n', ', '.join(sorted(str(c) for c in completions)) #print [n.name for n in completions] diff --git a/parsetest.py b/parsetest.py index c2dc5878..b2bafe58 100644 --- a/parsetest.py +++ b/parsetest.py @@ -124,7 +124,6 @@ def flow_test(a): if True or a: print a - # completion import time class c1(): @@ -148,3 +147,14 @@ c = b().c3(); abc = datetime; return [abc][0]. ;pylab.; add(1+2,2).; for fi in [ abc = [1,2+3]; abc[0]. import pylab; def add(a1,b1): nana = 1; return a1+b1 flow_test.; a12, (b12, c12) = (1,(list, "")); b12. + + + +def globalfunc(): + global globalvar, globalvar2 + globalvar = 3 + + + + +globalvar. diff --git a/parsing.py b/parsing.py index 8b823d2d..a98fbcbf 100644 --- a/parsing.py +++ b/parsing.py @@ -543,6 +543,10 @@ class Statement(Simple): # array return self._assignment_details or [] + def is_global(self): + # first keyword of the first token is global -> must be a global + return str(self.token_list[0]) == "global" + def get_assignment_calls(self): """ This is not done in the main parser, because it might be slow and diff --git a/test/completion/basic.py b/test/completion/basic.py index a5532b4e..02926ebe 100644 --- a/test/completion/basic.py +++ b/test/completion/basic.py @@ -1,7 +1,31 @@ +# ----------------- +# for loops +# ----------------- + for a in [1,2]: #? ['real'] a.real +for a1 in 1,"": + #? ['real'] + a1.real + #? ['upper'] + a1.upper + +for a3, b3 in (1,""), (1,""): + #? ['real'] + a3.real + #? [] + a3.upper + #? [] + b3.real + #? ['upper'] + b3.upper + +# ----------------- +# with statements +# ----------------- + with open('') as f: #? ['closed'] f.closed @@ -13,6 +37,10 @@ with open('') as f1, open('') as f2: f2.closed +# ----------------- +# global vars +# ----------------- + def global_define(): global glob glob = 3