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

Function make_local_variables

code2flow/ruby.py:108–131  ·  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. In this case, what it links to is just a string. However, that is resolved later. Also return variables for the outer scope parent :param

(tree_el, parent)

Source from the content-addressed store, hash-verified

106
107
108def make_local_variables(tree_el, parent):
109 """
110 Given an ast of all the lines in a function, generate a list of
111 variables in that function. Variables are tokens and what they link to.
112 In this case, what it links to is just a string. However, that is resolved
113 later.
114
115 Also return variables for the outer scope parent
116
117 :param tree_el ast:
118 :param parent Group:
119 :rtype: list[Variable]
120 """
121 variables = []
122 for el in tree_el:
123 if el[0] == 'lvasgn':
124 variables.append(process_assign(el))
125
126 # Make a 'self' variable for use anywhere we need it that points to the class
127 if isinstance(parent, Group) and parent.group_type == GROUP_TYPE.CLASS:
128 variables.append(Variable('self', parent))
129
130 variables = list(filter(None, variables))
131 return variables
132
133
134def as_lines(tree_el):

Callers 2

make_nodesMethod · 0.70
make_root_nodeMethod · 0.70

Calls 2

VariableClass · 0.85
process_assignFunction · 0.70

Tested by

no test coverage detected