MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / make_local_variables

Function make_local_variables

code2flow/php.py:167–192  ·  view source on GitHub ↗

Given an ast of all the lines in a function, generate a list of variables in that function. Variables are tokens and what they link to. :param tree_el ast: :param parent Group: :rtype: list[Variable]

(tree_el, parent)

Source from the content-addressed store, hash-verified

165
166
167def make_local_variables(tree_el, parent):
168 """
169 Given an ast of all the lines in a function, generate a list of
170 variables in that function. Variables are tokens and what they link to.
171
172 :param tree_el ast:
173 :param parent Group:
174 :rtype: list[Variable]
175 """
176 variables = []
177 for el in walk(tree_el):
178 if el['nodeType'] == 'Expr_Assign':
179 variables.append(process_assign(el))
180 if el['nodeType'] == 'Stmt_Use':
181 for use in el['uses']:
182 owner_token = djoin(use['name']['parts'])
183 token = use['alias']['name'] if use['alias'] else owner_token
184 variables.append(Variable(token, points_to=owner_token,
185 line_number=lineno(el)))
186
187 # Make a 'this'/'self' variable for use anywhere we need it that points to the class
188 if isinstance(parent, Group) and parent.group_type in GROUP_TYPE.CLASS:
189 variables.append(Variable('this', parent, line_number=parent.line_number))
190 variables.append(Variable('self', parent, line_number=parent.line_number))
191
192 return list(filter(None, variables))
193
194
195def get_inherits(tree):

Callers 2

make_nodesMethod · 0.70
make_root_nodeMethod · 0.70

Calls 5

djoinFunction · 0.85
VariableClass · 0.85
walkFunction · 0.70
process_assignFunction · 0.70
linenoFunction · 0.70

Tested by

no test coverage detected