Skip to content

Commit

Permalink
ofs_parse: look for call nodes in ast
Browse files Browse the repository at this point in the history
Instead of looking for only one call node in the current ast node, walk
down the tree returning a list of all call nodes.
For each call now found, turn any ofs calls into correct C call.
  • Loading branch information
r-rojo committed Mar 12, 2021
1 parent 049e00a commit f552e4d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions scripts/ofs_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,18 @@ def write_structures(self, fp, tmpl):

def find_call(self, node):
if isinstance(node, ast.Call):
return node
return [node]
if isinstance(node, ast.Return) or isinstance(node, ast.Expr):
if isinstance(node.value, ast.Call):
return node.value
return self.find_call(node.value)
if isinstance(node, ast.Compare) or isinstance(node, ast.BinOp):
calls = self.find_call(node.left)
if isinstance(node, ast.Compare):
for c in node.comparators:
calls.extend(self.find_call(c))
else:
calls.extend(self.find_call(node.right))
return calls
return []

def annotation_to_c(self, node):
if isinstance(node, ast.Subscript):
Expand All @@ -213,8 +221,7 @@ def arg_repl(m):
# lines = body.split('\n')
line = ast.get_source_segment(body, node)

call_node = self.find_call(node)
if call_node:
for call_node in self.find_call(node):
fn_name = call_node.func.id
if fn_name in self.functions:
line = re.sub(f'({fn_name})\\((.*?)\\)', arg_repl, line)
Expand Down

0 comments on commit f552e4d

Please sign in to comment.