-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcollect_variable.py
41 lines (32 loc) · 1.67 KB
/
collect_variable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import ast
from collections import OrderedDict
from PythonVoiceCodingPlugin.library import sorted_by_source_region,get_source_region,make_flat
from PythonVoiceCodingPlugin.library.info import *
from PythonVoiceCodingPlugin.library.LCA import LCA
from PythonVoiceCodingPlugin.library.level_info import LevelVisitor
from PythonVoiceCodingPlugin.library.partial import partially_parse, line_partial
from PythonVoiceCodingPlugin.library.traverse import search_upwards,search_upwards_log, find_matching,match_node, find_all_nodes,search_upwards_for_parent
from PythonVoiceCodingPlugin.queries.abstract import CollectionQuery
from PythonVoiceCodingPlugin.queries.tiebreak import tiebreak_on_lca
from PythonVoiceCodingPlugin.queries.strategies import adjective_strategy,decode_abstract_vertical,translate_adjective,obtain_result
from PythonVoiceCodingPlugin.queries.strategies import decode_item_selection
class CollectVariable(CollectionQuery):
indexable = True
label = 'Variables'
def handle_single(self,view_information,query_description,extra = {}):
build, selection, origin = self._preliminary(view_information,query_description,extra)
if not build:
return None,None
root,atok,m,r = build
definition_node = search_upwards(origin,ast.FunctionDef) if query_description["format"]!=1 else root
name_nodes = [(get_id(x),0) for x in find_all_nodes(definition_node,ast.Name) if is_store(x)]
names = list(OrderedDict(name_nodes).keys())
if query_description["format"]==1:
result = None
else:
mode = {
2:"individual",
3:"range",
}[query_description["format"]]
result = ",".join(decode_item_selection(names,query_description,mode,"item_index"))
return result, names