1"""transform functions such that have separate the parameters where input and output are separate"""
5from ..utils
import dprint, is_tree_type
6from ..grammar
import UnexpectedHCodeStructureError
7from .name_stub
import *
13 Traverse all usage of function calls, convert function names into stubs (for duplicating functions)
14 And add prologue and epilogue for function calls
29 proc_name = tree.children[0]
44 @current_module_function_nodes.setter
53 if f.children[0] == func_name:
58 if f.children[0][:-1] == func_name[:-1]:
60 raise ValueError(f
'Function {func_name} not found')
78 var = tree.children[0].children[0]
85 var = tree.children[0]
92 var = tree.children[0].children[0]
113 tree.func_name_stubs = []
120 tree.func_name_stubs = []
126 for ch
in tree.children:
127 if is_tree_type(ch,
'hcstmt'):
130 if len(body.children) == 0:
131 body.children.append(Tree(
'stmts', children=[]))
132 body = body.children[0]
133 for name, stub
in tree.name_stub.items():
134 blkassign = Tree(
'blkassign', children=[
138 body.children.insert(0, Tree(
'stmt', children=[blkassign]))
141 for name, stub
in tree.name_stub.items():
142 blkassign = Tree(
'blkassign', children=[
146 body.children.append(Tree(
'stmt', children=[blkassign]))
153 Tree(
'vardeclinit', children=[stub.children[0], stub.children[1]])
158 Tree(
'vardeclinit', children=[name, t])
160 tree.children.extend(stub_decl)
167 if tpe.children[0].children[0]
in [
'__func_inout',
'sc_in']:
168 t = copy.deepcopy(tpe)
169 t.children = t.children[0].children[1:]
177 Tree(
'vardecl', children=[
178 Tree(
'vardeclinit', children=[ stub.children[0], stub.children[1] ])
183 Tree(
'vardecl', children=[
184 Tree(
'vardeclinit', children=[name, t])
186 tree.children.extend(stub_decl)
190 func_name = tree.children[0]
195 for child
in tree.children[1:]:
196 if child.data ==
'hfunctionparams':
198 elif child.data ==
'hfunctionrettype':
200 elif child.data ==
'hfunctionlocalvars':
202 elif child.data ==
'hfunctionbody':
204 return func_name, ret_type, func_params, local_vars, func_body
209 if hasattr(tree,
'phantom_var'):
210 return tree.phantom_var
211 elif isinstance(tree, str):
213 elif hasattr(tree,
'original_name'):
214 return tree.original_name
215 return tree.children[0]
239 if not in_global_scope
or (in_global_scope
and in_sens_list):
252 orig_len = len(tree.children)
260 func_name = tree.children[0]
262 orig_func_name = func_name
265 func_name, ret_type, func_params, local_vars, func_body = self.
__extract_func_def(func_node)
268 func_args = tree.children[1:]
269 if func_params
is not None:
270 for idx, _
in func_params.io_params:
273 extra_args.append(Tree(
'hvarref', children=[stub.children[0]]))
274 tree.children.extend(extra_args)
276 if orig_func_name != func_name:
277 tree.children[0] = func_name
278 for idx
in range(orig_len):
279 arg = tree.children[idx]
282 if is_tree_type(arg,
'hmethodcall'):
287 tree.children[idx] = stub.children[0]
296 tree.children[1].children[0].children[0] =
'sc_in'
304 if is_tree_type(tree,
'func_param_name_stub'):
305 return tree.children[0]
309 if hasattr(tree,
'func_repl_id'):
310 tree.original_name = tree.children[0]
315 tree.original_name = tree.children[0]
316 tree.children[0] = stub.children[0]
325 tree.func_name_stubs = []
327 func_name, ret_type, func_params, local_vars, func_body = self.
__extract_func_def(tree)
330 if func_params
is not None:
331 for idx, par
in func_params.io_params:
332 tpe = func_params.children[idx].children[1]
335 extra_params.append(stub)
340 func_params.children.extend(extra_params)
341 for assignment
in tree.assignments: