Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# no derived types apart from those in self.types
if arg.type.startswith('type') and ft.split_type(arg.type) not in self.types:
warnings.warn('removing routine %s due to unsupported derived type %s' %
(node.name, arg.type))
return None
# no arrays of derived types of assumed shape, or more than one dimension
# Yann - EXPERIMENTAL !!
if arg.type.startswith('type') and len(dims) != 0:
# warnings.warn('removing routine %s due to unsupported arrays of derived types %s' %
# (node.name, arg.type))
# return none
if len(dims) > 1:
raise ValueError('more than one dimension attribute found for arg %s' % arg.name)
dimensions_list = ArrayDimensionConverter.split_dimensions(dims[0])
if len(dimensions_list) > 1 or ':' in dimensions_list:
warnings.warn('removing routine %s due to derived type array argument : %s -- currently, only '
'fixed-lengh one-dimensional arrays of derived type are supported'
% (node.name, arg.name))
return None
return self.generic_visit(node)
def transform_to_f90_wrapper(tree, types, callbacks, constructors,
destructors, short_names, init_lines,
string_lengths, default_string_length,
sizeof_fortran_t, kind_map):
"""
Additional Fortran-specific transformations:
* Conversion of derived type arguments to opaque integer arrays
via Fortran transfer() intrinsic.
* Normalise type declarations
"""
FunctionToSubroutineConverter().visit(tree)
tree = convert_derived_type_arguments(tree, init_lines, sizeof_fortran_t)
StringLengthConverter(string_lengths, default_string_length).visit(tree)
ArrayDimensionConverter().visit(tree)
NormaliseTypes(kind_map).visit(tree)
return tree
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.',
Parameters
----------
t : `fortran.Type` node
Derived-type node of the parse tree.
el : `fortran.Element` node
An element of a module which is derived-type array
dims : `tuple` of `int`s
The dimensions of the element
sizeof_fortan_t : `int`
The size, in bytes, of a pointer to a fortran derived type ??
"""
if element.type.startswith('type') and len(ArrayDimensionConverter.split_dimensions(dims)) != 1:
return
self._write_array_getset_item(t, element, sizeof_fortran_t, 'get')
self._write_array_getset_item(t, element, sizeof_fortran_t, 'set')
self._write_array_len(t, element, sizeof_fortran_t)
def visit_Procedure(self, node):
n_dummy = 0
for arg in node.arguments:
dims = [attr for attr in arg.attributes if attr.startswith('dimension')]
if dims == []:
continue
if len(dims) != 1:
raise ValueError('more than one dimension attribute found for arg %s' % arg.name)
ds = ArrayDimensionConverter.split_dimensions(dims[0])
new_dummy_args = []
new_ds = []
for i, d in enumerate(ds):
if ArrayDimensionConverter.valid_dim_re.match(d):
if d.startswith('len'):
arg.f2py_line = ('!f2py %s %s, dimension(%s) :: %s' % \
(arg.type,
','.join(
[attr for attr in arg.attributes if not attr.startswith('dimension')]),
d.replace('len', 'slen'), arg.name))
new_ds.append(d)
continue
dummy_arg = ft.Argument(name='n%d' % n_dummy, type='integer', attributes=['intent(hide)'])
if 'intent(out)' not in arg.attributes:
dummy_arg.f2py_line = ('!f2py intent(hide), depend(%s) :: %s = shape(%s,%d)' %
(arg.name, dummy_arg.name, arg.name, i))
new_dummy_args.append(dummy_arg)
new_ds.append(dummy_arg.name)
n_dummy += 1