Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(hasattr(node, 'transfer_out') and arg.name in node.transfer_out)):
name += '_ptr%p'
if 'super-type' in arg.doc:
name += '%items'
return name
if node.mod_name is not None:
# use keyword arguments if subroutine is in a module and we have an explicit interface
arg_names = ['%s=%s' % (dummy_arg_name(arg), actual_arg_name(arg))
for arg in arg_node.arguments
if 'intent(hide)' not in arg.attributes]
else:
arg_names = [actual_arg_name(arg) for arg in arg_node.arguments
if 'intent(hide)' not in arg.attributes]
if isinstance(orig_node, ft.Function):
self.write('%(ret_val)s = %(func_name)s(%(arg_names)s)' %
{'ret_val': actual_arg_name(orig_node.ret_val),
'func_name': func_name,
'arg_names': ', '.join(arg_names)})
else:
if func_name == 'assignment(=)':
if len(arg_names) != 2:
raise RuntimeError("assignment(=) interface with len(arg_names) != 2")
arg_names = [arg_name.split('=')[1] for arg_name in arg_names]
self.write('%(lhs)s = %(rhs)s' %
{'lhs': arg_names[0],
'rhs': arg_names[1]})
else:
self.write('call %(sub_name)s(%(arg_names)s)' %
{'sub_name': func_name,
'arg_names': ', '.join(arg_names)})
def combine_elements(elements):
element_dict = {}
func_args = []
i = 0 # counter for appearance order of args
for a in elements:
if isinstance(a, ft.Subroutine) or isinstance(a, ft.Function):
func_args.append(a)
continue
i = i + 1
element_dict[a.name] = (a, i)
# Combine names with the same type, attributes and doc string
rev_dict = {}
for type, name in zip([ x[0].type.lower() + str([y.lower for y in x[0].attributes]) + str(x[0].doc) \
for x in element_dict.values() ], element_dict.keys()):
if rev_dict.has_key(type):
rev_dict[type].append(element_dict[name])
else:
rev_dict[type] = [element_dict[name]]
for k in rev_dict:
names = [x[0].name for x in rev_dict[k]]
def visit_Procedure(self, node):
if 'constructor' in node.attributes:
node.arguments[0].attributes = set_intent(node.arguments[0].attributes,
'intent(out)')
ret_val = []
ret_val_doc = None
if isinstance(node, ft.Function) and node.ret_val is not None:
ret_val.append(node.ret_val)
if node.ret_val_doc is not None:
ret_val_doc = node.ret_val_doc
arguments = []
for arg in node.arguments:
if 'intent(out)' in arg.attributes:
ret_val.append(arg)
else:
arguments.append(arg)
if ret_val == []:
new_node = node # no changes needed
else:
new_node = ft.Function(node.name,
node.filename,
node.doc,
ret_val_doc = None
if isinstance(node, ft.Function) and node.ret_val is not None:
ret_val.append(node.ret_val)
if node.ret_val_doc is not None:
ret_val_doc = node.ret_val_doc
arguments = []
for arg in node.arguments:
if 'intent(out)' in arg.attributes:
ret_val.append(arg)
else:
arguments.append(arg)
if ret_val == []:
new_node = node # no changes needed
else:
new_node = ft.Function(node.name,
node.filename,
node.doc,
node.lineno,
arguments,
node.uses,
node.attributes,
ret_val,
ret_val_doc,
mod_name=node.mod_name,
type_name=node.type_name)
new_node.orig_node = node
if hasattr(node, 'method_name'):
new_node.method_name = node.method_name
return new_node
def format_call_signature(node):
if isinstance(node, ft.Procedure):
sig = ''
if isinstance(node, ft.Function):
sig += ', '.join(ret_val.py_name for ret_val in node.ret_val)
sig += ' = '
if 'constructor' in node.attributes:
sig += node.type_name.title()
elif 'destructor' in node.attributes:
return 'Destructor for class %s' % node.type_name.title()
else:
if hasattr(node, 'method_name'):
sig += node.method_name
else:
sig += node.name
sig += '('
had_optional = False
for i, arg in enumerate(node.arguments):
if not had_optional and 'optional' in arg.attributes:
sig += '['
def walk_procedures(tree, include_ret_val=True):
"""
Walk over all nodes in tree and yield tuples
(module, procedure, arguments).
If `include_ret_val` is true then Function return values are
inserted after last non-optional argument.
"""
for node in walk(tree):
if not isinstance(node, Procedure):
continue
arguments = node.arguments[:]
if include_ret_val and isinstance(node, Function):
arguments.append(node.ret_val)
mod = find_procedure_module(tree, node)
yield (mod, node, arguments)