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

Function _find_link_for_call

code2flow/engine.py:366–410  ·  view source on GitHub ↗

Given a call that happened on a node (node_a), return the node that the call links to and the call itself if >1 node matched. :param call Call: :param node_a Node: :param all_nodes list[Node]: :returns: The node it links to and the call if >1 node matched. :rtype: (Nod

(call, node_a, all_nodes)

Source from the content-addressed store, hash-verified

364
365
366def _find_link_for_call(call, node_a, all_nodes):
367 """
368 Given a call that happened on a node (node_a), return the node
369 that the call links to and the call itself if >1 node matched.
370
371 :param call Call:
372 :param node_a Node:
373 :param all_nodes list[Node]:
374
375 :returns: The node it links to and the call if >1 node matched.
376 :rtype: (Node|None, Call|None)
377 """
378
379 all_vars = node_a.get_variables(call.line_number)
380
381 for var in all_vars:
382 var_match = call.matches_variable(var)
383 if var_match:
384 # Unknown modules (e.g. third party) we don't want to match)
385 if var_match == OWNER_CONST.UNKNOWN_MODULE:
386 return None, None
387 assert isinstance(var_match, Node)
388 return var_match, None
389
390 possible_nodes = []
391 if call.is_attr():
392 for node in all_nodes:
393 # checking node.parent != node_a.file_group() prevents self linkage in cases like
394 # function a() {b = Obj(); b.a()}
395 if call.token == node.token and node.parent != node_a.file_group():
396 possible_nodes.append(node)
397 else:
398 for node in all_nodes:
399 if call.token == node.token \
400 and isinstance(node.parent, Group) \
401 and node.parent.group_type == GROUP_TYPE.FILE:
402 possible_nodes.append(node)
403 elif call.token == node.parent.token and node.is_constructor:
404 possible_nodes.append(node)
405
406 if len(possible_nodes) == 1:
407 return possible_nodes[0], None
408 if len(possible_nodes) > 1:
409 return None, call
410 return None, None
411
412
413def _find_links(node_a, all_nodes):

Callers 1

_find_linksFunction · 0.85

Calls 4

matches_variableMethod · 0.80
file_groupMethod · 0.80
get_variablesMethod · 0.45
is_attrMethod · 0.45

Tested by

no test coverage detected