Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def visit_Function(self, node):
# insert ret_val after last non-optional argument
arguments = node.arguments[:]
i = 0
for i, arg in enumerate(arguments):
if 'optional' in arg.attributes:
break
arguments.insert(i, node.ret_val)
arguments[i].name = 'ret_' + arguments[i].name
arguments[i].attributes.append('intent(out)')
new_node = ft.Subroutine(node.name,
node.filename,
node.doc,
node.lineno,
arguments,
node.uses,
node.attributes,
mod_name=node.mod_name)
if hasattr(node, 'call_name'):
new_node.call_name = node.call_name
if hasattr(node, 'type'):
new_node.type = node.type
new_node.orig_name = node.orig_name
new_node.orig_node = node # keep a reference to the original node
return new_node
def add_missing_constructors(tree):
for node in ft.walk(tree):
if not isinstance(node, ft.Type):
continue
for child in ft.iter_child_nodes(node):
if isinstance(child, ft.Procedure):
if 'constructor' in child.attributes:
logging.info('found constructor %s' % child.name)
break
else:
logging.info('adding missing constructor for %s' % node.name)
new_node = ft.Subroutine('%s_initialise' % node.name,
node.filename,
['Automatically generated constructor for %s' % node.name],
node.lineno,
[ft.Argument(name='this', # self.prefix + 'this' would probably be safer
filename=node.filename,
doc=['Object to be constructed'],
lineno=node.lineno,
attributes=['intent(out)'],
type='type(%s)' % node.name)],
node.uses,
['constructor', 'skip_call'],
mod_name=node.mod_name,
type_name=node.name)
new_node.method_name = '__init__'
node.procedures.append(new_node)
return tree
for a in sub.doc:
self.print_line(a)
self.print_line('\n\n')
got_args = (is_sub and sum([len(x.arguments) for x in node.procedures]) != 0) or not is_sub
func_args = []
if got_args:
self.print_line(r'\begin{description}')
arg_dict = {}
i = 0 # counter for appearance order of args
for sub in node.procedures:
for a in sub.arguments:
if isinstance(a, ft.Subroutine) or isinstance(a, Function):
func_args.append(a)
continue
i = i + 1
if arg_dict.has_key(a.name):
if a.type.lower() + str(sorted(map(string.lower, a.attributes))) in \
[x[0].type.lower() + str(sorted(map(string.lower, x[0].attributes))) for x in arg_dict[a.name]]:
pass # already got this name/type/attribute combo
else:
arg_dict[a.name].append((a, i))
else:
arg_dict[a.name] = [(a, i)]
# Combine multiple types with the same name
for name in arg_dict:
types = [x[0].type for x in arg_dict[name]]
def add_missing_destructors(tree):
for node in ft.walk(tree):
if not isinstance(node, ft.Type):
continue
for child in ft.iter_child_nodes(node):
if isinstance(child, ft.Procedure):
if 'destructor' in child.attributes:
logging.info('found destructor %s' % child.name)
break
else:
logging.info('adding missing destructor for %s' % node.name)
new_node = ft.Subroutine('%s_finalise' % node.name,
node.filename,
['Automatically generated destructor for %s' % node.name],
node.lineno,
[ft.Argument(name='this', # self.prefix + 'this' would probably be safer
filename=node.filename,
doc=['Object to be destructed'],
lineno=node.lineno,
attributes=['intent(inout)'],
type='type(%s)' % node.name)],
node.uses,
['destructor', 'skip_call'],
mod_name=node.mod_name,
type_name=node.name)
new_node.method_name = '__del__'
node.procedures.append(new_node)
return tree