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

Function walk

code2flow/php.py:81–108  ·  view source on GitHub ↗

Given an ast tree walk it to get every node. For PHP, the exception is that we return Expr_BinaryOp_Concat which has internal nodes but is important to process as a whole. :param tree_el ast: :rtype: list[ast]

(tree)

Source from the content-addressed store, hash-verified

79
80
81def walk(tree):
82 """
83 Given an ast tree walk it to get every node. For PHP, the exception
84 is that we return Expr_BinaryOp_Concat which has internal nodes but
85 is important to process as a whole.
86
87 :param tree_el ast:
88 :rtype: list[ast]
89 """
90
91 if isinstance(tree, list):
92 ret = []
93 for el in tree:
94 if isinstance(el, dict) and el.get('nodeType'):
95 ret += walk(el)
96 return ret
97
98 assert isinstance(tree, dict)
99 assert tree['nodeType']
100 ret = [tree]
101
102 if tree['nodeType'] == 'Expr_BinaryOp_Concat':
103 return ret
104
105 for v in tree.values():
106 if isinstance(v, list) or (isinstance(v, dict) and v.get('nodeType')):
107 ret += walk(v)
108 return ret
109
110
111def children(tree):

Callers 2

make_callsFunction · 0.70
make_local_variablesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected