Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def write_dt_array_wrapper(self, node, el, dims):
if el.type.startswith('type') and len(ArrayDimensionConverter.split_dimensions(dims)) != 1:
return
func_name = 'init_array_%s' % el.name
node.dt_array_initialisers.append(func_name)
cls_name = normalise_class_name(ft.strip_type(el.type), self.class_names)
mod_name = self.types[ft.strip_type(el.type)].mod_name
cls_mod_name = self.py_mod_names.get(mod_name, mod_name)
dct = dict(el_name=el.name,
func_name=func_name,
mod_name=node.name,
type_name=ft.strip_type(el.type).lower(),
f90_mod_name=self.f90_mod_name,
prefix=self.prefix,
self='self',
selfdot='self.',
parent='self',
doc=format_doc_string(el),
cls_name=cls_name,
cls_mod_name=cls_mod_name.title() + '.')
if isinstance(node, ft.Module):
dct['parent'] = 'f90wrap.runtime.empty_type'
if self.make_package:
dct['selfdot'] = ''
dct['self'] = ''
if self.make_package:
dct['cls_mod_name'] = ''
if isinstance(t, ft.Type):
this = 'this, '
elif isinstance(t, ft.Module):
this = ''
else:
raise ValueError("Don't know how to write scalar wrappers for %s type %s"(t, type(t)))
# Get appropriate use statements
extra_uses = {}
if isinstance(t, ft.Module):
extra_uses[t.name] = ['%s_%s => %s' % (t.name, el.orig_name, el.orig_name)]
elif isinstance(t, ft.Type):
extra_uses[self.types[t.name].mod_name] = [t.name]
# Check if the type has recursive definition:
same_type = (ft.strip_type(t.name) == ft.strip_type(el.type))
if el.type.startswith('type') and not same_type:
mod = self.types[el.type].mod_name
el_tname = ft.strip_type(el.type)
if mod in extra_uses:
extra_uses[mod].append(el_tname)
else:
extra_uses[mod] = [el_tname]
# Prepend prefix to element name
# -- Since some cases require a safer localvar name, we always transform it
localvar = self.prefix + el.orig_name
self.write('subroutine %s%s__%s__%s(%s%s)' % (self.prefix, t.name,
getset, el.orig_name, this, localvar))
self.indent()
def write_dt_wrappers(self, node, el, properties):
cls_name = normalise_class_name(ft.strip_type(el.type), self.class_names)
mod_name = self.types[ft.strip_type(el.type)].mod_name
cls_mod_name = self.py_mod_names.get(mod_name, mod_name)
dct = dict(el_name=el.name,
el_name_get=el.name,
el_name_set=el.name,
mod_name=self.f90_mod_name,
prefix=self.prefix, type_name=node.name,
cls_name=cls_name,
cls_mod_name=cls_mod_name + '.',
self='self',
selfdot='self.',
selfcomma='self, ',
handle=isinstance(node, ft.Type) and 'self._handle' or '')
if isinstance(node, ft.Type):
dct['set_args'] = '%(handle)s, %(el_name)s' % dct
else:
def write_type_lines(self, tname):
"""
Write a pointer type for a given type name
Parameters
----------
tname : `str`
Should be the name of a derived type in the wrapped code.
"""
tname = ft.strip_type(tname)
self.write("""type %(typename)s_ptr_type
type(%(typename)s), pointer :: p => NULL()
end type %(typename)s_ptr_type""" % {'typename': tname})
def write_dt_wrappers(self, node, el, properties):
cls_name = normalise_class_name(ft.strip_type(el.type), self.class_names)
mod_name = self.types[ft.strip_type(el.type)].mod_name
cls_mod_name = self.py_mod_names.get(mod_name, mod_name)
dct = dict(el_name=el.name,
el_name_get=el.name,
el_name_set=el.name,
mod_name=self.f90_mod_name,
prefix=self.prefix, type_name=node.name,
cls_name=cls_name,
cls_mod_name=cls_mod_name + '.',
self='self',
selfdot='self.',
selfcomma='self, ',
handle=isinstance(node, ft.Type) and 'self._handle' or '')
if isinstance(node, ft.Type):
dct['set_args'] = '%(handle)s, %(el_name)s' % dct
else:
dct['set_args'] = '%(el_name)s' % dct
def write_dt_array_wrapper(self, node, el, dims):
if el.type.startswith('type') and len(ArrayDimensionConverter.split_dimensions(dims)) != 1:
return
func_name = 'init_array_%s' % el.name
node.dt_array_initialisers.append(func_name)
cls_name = normalise_class_name(ft.strip_type(el.type), self.class_names)
mod_name = self.types[ft.strip_type(el.type)].mod_name
cls_mod_name = self.py_mod_names.get(mod_name, mod_name)
dct = dict(el_name=el.name,
func_name=func_name,
mod_name=node.name,
type_name=ft.strip_type(el.type).lower(),
f90_mod_name=self.f90_mod_name,
prefix=self.prefix,
self='self',
selfdot='self.',
parent='self',
doc=format_doc_string(el),
cls_name=cls_name,
cls_mod_name=cls_mod_name.title() + '.')
if isinstance(node, ft.Module):
Also rename any arguments that clash with module names.
"""
for mod, sub, arguments in ft.walk_procedures(tree):
sub.uses = set()
if mod is not None:
sub_name = sub.name
if hasattr(sub, 'call_name'):
sub_name = sub.call_name
if sub.mod_name is None:
sub.mod_name = mod.name
sub.uses.add((sub.mod_name, (sub_name,)))
for arg in arguments:
if arg.type.startswith('type') and ft.strip_type(arg.type) in types:
sub.uses.add((types[ft.strip_type(arg.type)].mod_name, (ft.strip_type(arg.type),)))
for mod, sub, arguments in ft.walk_procedures(tree):
for arg in arguments:
for (mod_name, type_name) in sub.uses:
if arg.name == mod_name:
arg.name += '_'
return tree