loki.transform.transform_utilities
Collection of utility routines to deal with general language conversion.
Functions
|
Converts all variables and symbols in a subroutine to lower-case. |
|
Eliminate any imported symbols (or imports alltogether) that are not in the set of used symbols. |
|
Find all unused imported symbols and eliminate them from their import statements in the given routine and all contained members. |
|
Utility function to apply a substitution map for expressions to itself |
|
Replace known intrinsic functions and symbols. |
|
Find all uses of |
|
Sanitise imports by removing unused symbols and eliminating imports with empty symbol lists. |
|
Modify/extend variable declarations to |
|
Helper routine that yields the symbol names for the different types of symbols we may encounter. |
Classes
|
Mapper to convert other Fortran kind specifications to their definitions from |
- convert_to_lower_case(routine)
Converts all variables and symbols in a subroutine to lower-case.
Note, this is intended for conversion to case-sensitive languages.
TODO: Should be extended to Module objects.
- replace_intrinsics(routine, function_map=None, symbol_map=None, case_sensitive=False)
Replace known intrinsic functions and symbols.
- Parameters:
routine (
Subroutine
) – The subroutine object in which to replace intrinsic callsfunction_map (dict[str, str]) – Mapping from function names (
InlineCall
names) to their replacementsymbol_map (dict[str, str]) – Mapping from intrinsic symbol names to their replacement
case_sensitive (bool) – Match case for name lookups in
function_map
andsymbol_map
- sanitise_imports(module_or_routine)
Sanitise imports by removing unused symbols and eliminating imports with empty symbol lists.
Note that this is currently limited to imports that are identified to be
Scalar
,Array
, orProcedureSymbol
.
- replace_selected_kind(routine)
Find all uses of
selected_real_kind
orselected_int_kind
and replace them by theiriso_fortran_env
counterparts.This inserts imports for all used constants from
iso_fortran_env
.
- single_variable_declaration(routine, variables=None, group_by_shape=False)
Modify/extend variable declarations to
default: only declare one variable each time while preserving the order if
variables=None
andgroup_by_shape=False
declare variables specified in
variables``in single/unique declarations if ``variables
is a tuple of variablesvariable declarations to be grouped according to their shapes if
group_by_shape=True
- Parameters:
routine (
Subroutine
) – The subroutine in which to modify the variable declarationsvariables (tuple) – Variables to grant unique/single declaration for
group_by_shape (bool) – Whether to strictly make unique variable declarations or to only disassemble non-arrays and arrays and among arrays, arrays with differing shapes.
- recursive_expression_map_update(expr_map, max_iterations=10)
Utility function to apply a substitution map for expressions to itself
The expression substitution mechanism
SubstituteExpressions
and the underlying mapperSubstituteExpressionsMapper
replace nodes that are found in the substitution map by their corresponding replacement.However, expression nodes can be nested inside other expression nodes, e.g. via the
parent
ordimensions
properties of variables. In situations, where such expression nodes as well as expression nodes appearing inside such properties are marked for substitution, it may be necessary to apply the substitution map to itself first. This utility routine takes care of that.