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

do_merge_associates(routine[, max_parents])

Moves associate mappings in Associate within a Subroutine to the outermost parent scope.

do_resolve_associates(routine[, start_depth])

Resolve Associate mappings in the body of a given routine.

Classes

AssociatesTransformation([...])

Transformation object to apply code sanitisation steps specific to Associate nodes.

MergeAssociatesTransformer([max_parents])

NestedTransformer that moves associate mappings in Associate to parent nodes.

ResolveAssociateMapper(*args[, start_depth])

Exppression mapper that will resolve symbol associations due Associate scopes.

ResolveAssociatesTransformer([start_depth])

Transformer class to resolve Associate nodes in IR trees.

class AssociatesTransformation(resolve_associates=True, merge_associates=False, start_depth=0, max_parents=None)

Bases: Transformation

Transformation object to apply code sanitisation steps specific to Associate nodes.

It allows merging in nested Associate scopes to move independent assocation pairs to the outermost scope, optionally restricted by a number of max_parents symbols.

It also provides partial or full resolution of Associate nodes by replacing identifier symbols with the corresponding selector 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 method apply().

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 a start_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 resolve Associate nodes in IR trees.

This will replace each Associate node with its own body, where all identifier symbols have been replaced with the corresponding selector expression defined in associations.

Importantly, this Transformer can also be applied over partial bodies of Associate bodies.

Optionally, partial resolution of only inner Associate mappings is supported when a start_depth is specified.

Parameters:

start_depth (int, optional) – Starting depth for partial resolution of Associate

visit_Expression(o, **kwargs)
visit_Associate(o, **kwargs)

Replaces an Associate node with its transformed body

visit_CallStatement(o, **kwargs)
do_merge_associates(routine, max_parents=None)

Moves associate mappings in Associate within a Subroutine 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.