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

Method make_nodes

code2flow/php.py:299–334  ·  view source on GitHub ↗

Given a tree element of all the lines in a function, create the node along with the calls and variables internal to it. Also make the nested subnodes :param tree ast: :param parent Group: :rtype: list[Node]

(tree, parent)

Source from the content-addressed store, hash-verified

297
298 @staticmethod
299 def make_nodes(tree, parent):
300 """
301 Given a tree element of all the lines in a function, create the node along
302 with the calls and variables internal to it.
303 Also make the nested subnodes
304
305 :param tree ast:
306 :param parent Group:
307 :rtype: list[Node]
308 """
309 assert tree['nodeType'] in ('Stmt_Function', 'Stmt_ClassMethod', 'Expr_Closure')
310
311 if tree['nodeType'] == 'Expr_Closure':
312 token = '(Closure)'
313 else:
314 token = tree['name']['name']
315 is_constructor = token == '__construct' and parent.group_type == GROUP_TYPE.CLASS
316
317 tree_body = tree['stmts']
318 subgroup_trees, subnode_trees, this_scope_body = PHP.separate_namespaces(tree_body)
319 assert not subgroup_trees
320 calls = make_calls(this_scope_body)
321 variables = make_local_variables(this_scope_body, parent)
322
323 if parent.group_type == GROUP_TYPE.CLASS and parent.parent.group_type == GROUP_TYPE.NAMESPACE:
324 import_tokens = [djoin(parent.parent.token, parent.token, token)]
325 if parent.group_type in (GROUP_TYPE.NAMESPACE, GROUP_TYPE.CLASS):
326 import_tokens = [djoin(parent.token, token)]
327 else:
328 import_tokens = [token]
329
330 node = Node(token, calls, variables, parent, import_tokens=import_tokens,
331 is_constructor=is_constructor, line_number=lineno(tree))
332
333 subnodes = flatten([PHP.make_nodes(t, parent) for t in subnode_trees])
334 return [node] + subnodes
335
336 @staticmethod
337 def make_root_node(lines, parent):

Callers 2

make_class_groupMethod · 0.45
make_file_groupFunction · 0.45

Calls 7

djoinFunction · 0.85
NodeClass · 0.85
flattenFunction · 0.85
make_callsFunction · 0.70
make_local_variablesFunction · 0.70
linenoFunction · 0.70
separate_namespacesMethod · 0.45

Tested by

no test coverage detected