How to use the f90wrap.fortran.walk_procedures function in f90wrap

To help you get started, we’ve selected a few f90wrap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jameskermode / f90wrap / f90wrap / transform.py View on Github external
def convert_derived_type_arguments(tree, init_lines, sizeof_fortran_t):
    for mod, sub, arguments in ft.walk_procedures(tree, include_ret_val=True):
        sub.types = set()
        sub.transfer_in = []
        sub.transfer_out = []
        sub.allocate = []
        sub.deallocate = []

        if 'constructor' in sub.attributes:
            sub.arguments[0].attributes = set_intent(sub.arguments[0].attributes, 'intent(out)')

        if 'destructor' in sub.attributes:
            logging.debug('deallocating arg "%s" in %s' % (sub.arguments[0].name, sub.name))
            sub.deallocate.append(sub.arguments[0].name)

        for arg in arguments:
            if not hasattr(arg, 'type') or not arg.type.startswith('type'):
                continue
github jameskermode / f90wrap / f90wrap / transform.py View on Github external
def convert_array_intent_out_to_intent_inout(tree):
    """
    Find all intent(out) array arguments and convert to intent(inout)
    """
    for mod, sub, arguments in ft.walk_procedures(tree, include_ret_val=True):
        for arg in 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)
            if 'intent(out)' in arg.attributes:
                arg.attributes = set_intent(arg.attributes, 'intent(inout)')
    return tree
github jameskermode / f90wrap / f90wrap / transform.py View on Github external
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
github jameskermode / f90wrap / f90wrap / transform.py View on Github external
def fix_subroutine_uses_clauses(tree, types):
    """Walk over all nodes in tree, updating subroutine uses
       clauses to include the parent module and all necessary
       modules from types

       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: