# loki.transformations.build_system.dependency module

class DependencyTransformation(suffix, module_suffix=None, include_path=None, replace_ignore_items=True, remove_inactive_items=True)

  Bases: `Transformation`

  Basic `Transformation` class that facilitates dependency injection for transformed `Module` and `Subroutine` into complex source trees

  This transformation appends a provided `suffix` argument to transformed subroutine and module objects and changes the target names of `Import` and `CallStatement` nodes on the call-site accordingly.

  For subroutines declared via an interface block, these interfaces are updated accordingly. For subroutines that are not wrapped in a module, an updated interface block is also written as a header file to `include_path`. Where interface blocks to renamed subroutines are included via C-style imports, the import name is updated accordingly.

  To ensure that every subroutine is wrapped in a module, the accompanying `ModuleWrapTransformation` should be applied first. This restores the behaviour of the `module` mode in an earlier version of this transformation.

  When applying the transformation to a source object, one of two “roles” can be specified via the `role` keyword:

  - `'driver'`: Only renames imports and calls to kernel routines

  - `'kernel'`: Renames routine or enclosing modules, as well as renaming any further imports and calls.

  Note that `routine.apply(transformation, role='driver')` entails that the `routine` still mimicks its original counterpart and can therefore be used as a drop-in replacement during compilation that then diverts the dependency tree to the modified sub-tree.

  Parameters:

    - suffix (str) – The suffix to apply during renaming

    - module_suffix (str) – Special suffix to signal module names like _MOD

    - path (include) – Directory for generating additional header files

    - replace_ignore_items (bool) – Debug flag to toggle the replacement of calls to subroutines in the `ignore`. Default is `True`.

    - remove_inactive_items (bool) – Debug flag to toggle the removal of items (modules, subroutines) in the sourcefile that are not part of the scheduler graph. Default is `True`.

  reverse_traversal = True
  traverse_file_graph = True
  recurse_to_modules = True
  recurse_to_procedures = True
  recurse_to_internal_procedures = False
  renames_items = True
  creates_items = True
  transform_file(sourcefile, **kwargs)

    Remove non-active scope nodes if `remove_inactive_items` is true

  transform_module(module, **kwargs)

    Rename kernel modules and re-point module-level imports.

  transform_subroutine(routine, **kwargs)

    Rename kernel subroutine and all imports and calls to target routines

    For subroutines that are not wrapped in a module, re-generate the interface block.

  remove_inactive_ir_nodes(body, transformed_scope_name, **kwargs)

    Utility to filter `Scope` nodes in `body` to include only those given in `kwargs['items']`.

  derive_module_name(modname)

    Utility to derive a new module name from `suffix` and `module_suffix`

    Parameters:

      modname (str) – Current module name

  rename_calls(routine, targets=None, item=None)

    Update `CallStatement` and `InlineCall` to actively transformed procedures

    Parameters:

      targets (list of str) – Optional list of subroutine names for which to modify the corresponding calls. If not provided, all calls are updated

  rename_imports(source, imports, targets=None)

    Update imports of actively transformed subroutines.

    Parameters:

      - source (`ProgramUnit`) – The IR object to transform

      - imports (list of `Import`) – The list of imports to update. This includes both, C-style header includes and Fortran import statements (`USE` and `IMPORT`)

      - targets (list of str) – Optional list of subroutine names for which to modify imports

  rename_access_spec_names(access_spec, targets=None, active_nodes=None, routines=None)

    Rename target names in an access spec

    For all names in the access spec that are contained in `targets`, rename them as `{name}{self.suffix}`. If `active_nodes` are given, then all names that are not in the list of active nodes, are being removed from the list. :param access_spec: List of names from an access spec :type access_spec: list of str :param targets: Optional list of subroutine names for which to modify access specs :type targets: list of str :param active_nodes: Optional list of active nodes :type active_nodes: list of str :param routines: Optional list of subroutines :type routines: list of `Subroutine`

  rename_interfaces(intfs, targets=None)

    Update explicit interfaces to actively transformed subroutines.

    Parameters:

      - intfs (list of `Interface`) – The list of interfaces to update.

      - targets (list of str) – Optional list of subroutine names for which to modify interfaces

  generate_interfaces(routine)

    Generate external header file with interface block for this subroutine.