loki.transformations.sanitise.associates
A small selection of utility transformations that resolve certain code constructs to unify code structure and make reasoning about Fortran code easier.
Functions
|
Moves associate mappings in |
|
Resolve |
Classes
|
|
|
|
|
Exppression mapper that will resolve symbol associations due |
|
|
- class AssociatesTransformation(resolve_associates=True, merge_associates=False, start_depth=0, max_parents=None)
Bases:
Transformation
Transformation
object to apply code sanitisation steps specific toAssociate
nodes.It allows merging in nested
Associate
scopes to move independent assocation pairs to the outermost scope, optionally restricted by a number ofmax_parents
symbols.It also provides partial or full resolution of
Associate
nodes by replacingidentifier
symbols with the correspondingselector
in the node’s body.- Parameters:
resolve_associates (bool, default: True) – Enable full or partial resolution of only
Associate
scopes.merge_associates (bool, default: False) – Enable merging
Associate
to the outermost possible scope in nested associate blocks.start_depth (int, optional) – Starting depth for partial resolution of
Associate
after merging.max_parents (int, optional) – Maximum number of parent symbols for valid selector to have when merging
Associate
nodes.
- transform_subroutine(routine, **kwargs)
Defines the transformation to apply to
Subroutine
items.For transformations that modify
Subroutine
objects, this method should be implemented. It gets called via the dispatch methodapply()
.- Parameters:
routine (
Subroutine
) – The subroutine to be transformed.**kwargs (optional) – Keyword arguments for the transformation.
- do_resolve_associates(routine, start_depth=0)
Resolve
Associate
mappings in the body of a given routine.Optionally, partial resolution of only inner
Associate
mappings is supported when astart_depth
is specified.- Parameters:
routine (
Subroutine
) – The subroutine for which to resolve all associate blocks.start_depth (int, optional) – Starting depth for partial resolution of
Associate
- class ResolveAssociatesTransformer(start_depth=0, **kwargs)
Bases:
Transformer
Transformer
class to resolveAssociate
nodes in IR trees.This will replace each
Associate
node with its own body, where allidentifier
symbols have been replaced with the correspondingselector
expression defined inassociations
.Importantly, this
Transformer
can also be applied over partial bodies ofAssociate
bodies.Optionally, partial resolution of only inner
Associate
mappings is supported when astart_depth
is specified.- visit_Expression(o, **kwargs)
- visit_CallStatement(o, **kwargs)
- do_merge_associates(routine, max_parents=None)
Moves associate mappings in
Associate
within aSubroutine
to the outermost parent scope.Please see
MergeAssociatesTransformer
for mode details.Note
This method can be combined with
resolve_associates
to create a more unified look-and-feel for nested ASSOCIATE blocks.- Parameters:
routine (
Subroutine
) – The subroutine for which to resolve all associate blocks.max_parents (int, optional) – Maximum number of parent symbols for valid selector to have.