forked from VimPlug/jedi
globals
This commit is contained in:
13
evaluate.py
13
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
|
`get_names_for_scope` and `get_scopes_for_name` are search functions
|
||||||
|
|
||||||
TODO include super classes
|
TODO include super classes
|
||||||
|
TOOD nonlocal statement
|
||||||
"""
|
"""
|
||||||
from _compatibility import next
|
from _compatibility import next
|
||||||
|
|
||||||
@@ -123,7 +124,6 @@ class Execution(Exec):
|
|||||||
|
|
||||||
debug.dbg('exec stmts=', stmts, self.base, repr(self))
|
debug.dbg('exec stmts=', stmts, self.base, repr(self))
|
||||||
|
|
||||||
#print stmts
|
|
||||||
return stmts
|
return stmts
|
||||||
|
|
||||||
@memoize(default=[])
|
@memoize(default=[])
|
||||||
@@ -249,6 +249,13 @@ def get_scopes_for_name(scope, name, search_global=False):
|
|||||||
res_new = []
|
res_new = []
|
||||||
for r in result:
|
for r in result:
|
||||||
if isinstance(r, parsing.Statement):
|
if isinstance(r, parsing.Statement):
|
||||||
|
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)
|
scopes = follow_statement(r, seek_name=name)
|
||||||
res_new += remove_statements(scopes)
|
res_new += remove_statements(scopes)
|
||||||
else:
|
else:
|
||||||
@@ -266,13 +273,12 @@ def get_scopes_for_name(scope, name, search_global=False):
|
|||||||
else:
|
else:
|
||||||
par = scope.parent
|
par = scope.parent
|
||||||
if isinstance(par, parsing.Flow):
|
if isinstance(par, parsing.Flow):
|
||||||
# TODO get Flow data, which is defined by the loop
|
|
||||||
# (or with)
|
|
||||||
if par.command == 'for':
|
if par.command == 'for':
|
||||||
# take the first statement (for has always only
|
# take the first statement (for has always only
|
||||||
# one, remember `in`). And follow it. After that,
|
# one, remember `in`). And follow it. After that,
|
||||||
# get the types which are in the array
|
# get the types which are in the array
|
||||||
arrays = follow_statement(par.inits[0])
|
arrays = follow_statement(par.inits[0])
|
||||||
|
# TODO for loops can have tuples as set_vars
|
||||||
for array in arrays:
|
for array in arrays:
|
||||||
result += array.get_index_types()
|
result += array.get_index_types()
|
||||||
else:
|
else:
|
||||||
@@ -465,7 +471,6 @@ def follow_path(path, scope):
|
|||||||
debug.warning('strange function call with {}', current, scope)
|
debug.warning('strange function call with {}', current, scope)
|
||||||
else:
|
else:
|
||||||
if isinstance(scope, parsing.Function):
|
if isinstance(scope, parsing.Function):
|
||||||
# TODO this is never reached, just remove it?
|
|
||||||
# TODO check default function methods and return them
|
# TODO check default function methods and return them
|
||||||
result = []
|
result = []
|
||||||
else:
|
else:
|
||||||
|
|||||||
4
ftest.py
4
ftest.py
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import functions
|
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']
|
||||||
#functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules']
|
#functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules']
|
||||||
functions.modules.module_find_path.insert(0, '.')
|
functions.modules.module_find_path.insert(0, '.')
|
||||||
@@ -14,7 +14,7 @@ path = os.path.join(os.getcwd(), f_name)
|
|||||||
f = open(path)
|
f = open(path)
|
||||||
code = f.read()
|
code = f.read()
|
||||||
for i in range(1):
|
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', ', '.join(sorted(str(c) for c in completions))
|
||||||
#print [n.name for n in completions]
|
#print [n.name for n in completions]
|
||||||
|
|||||||
12
parsetest.py
12
parsetest.py
@@ -124,7 +124,6 @@ def flow_test(a):
|
|||||||
|
|
||||||
if True or a:
|
if True or a:
|
||||||
print a
|
print a
|
||||||
|
|
||||||
# completion
|
# completion
|
||||||
import time
|
import time
|
||||||
class c1():
|
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].
|
abc = [1,2+3]; abc[0].
|
||||||
import pylab; def add(a1,b1): nana = 1; return a1+b1
|
import pylab; def add(a1,b1): nana = 1; return a1+b1
|
||||||
flow_test.; a12, (b12, c12) = (1,(list, "")); b12.
|
flow_test.; a12, (b12, c12) = (1,(list, "")); b12.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def globalfunc():
|
||||||
|
global globalvar, globalvar2
|
||||||
|
globalvar = 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
globalvar.
|
||||||
|
|||||||
@@ -543,6 +543,10 @@ class Statement(Simple):
|
|||||||
# array
|
# array
|
||||||
return self._assignment_details or []
|
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):
|
def get_assignment_calls(self):
|
||||||
"""
|
"""
|
||||||
This is not done in the main parser, because it might be slow and
|
This is not done in the main parser, because it might be slow and
|
||||||
|
|||||||
@@ -1,7 +1,31 @@
|
|||||||
|
# -----------------
|
||||||
|
# for loops
|
||||||
|
# -----------------
|
||||||
|
|
||||||
for a in [1,2]:
|
for a in [1,2]:
|
||||||
#? ['real']
|
#? ['real']
|
||||||
a.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:
|
with open('') as f:
|
||||||
#? ['closed']
|
#? ['closed']
|
||||||
f.closed
|
f.closed
|
||||||
@@ -13,6 +37,10 @@ with open('') as f1, open('') as f2:
|
|||||||
f2.closed
|
f2.closed
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# global vars
|
||||||
|
# -----------------
|
||||||
|
|
||||||
def global_define():
|
def global_define():
|
||||||
global glob
|
global glob
|
||||||
glob = 3
|
glob = 3
|
||||||
|
|||||||
Reference in New Issue
Block a user