Skip to content

Commit

Permalink
Transformation: Renaming recursion attributes and improve docstring
Browse files Browse the repository at this point in the history
This now resembles the more formal nomenclature of "procedures" and
"internal procedures", which we are trying to adopt throughout.
  • Loading branch information
mlange05 committed Nov 30, 2023
1 parent 99043a0 commit 0faa31d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions loki/transform/dependency_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class DependencyTransformation(Transformation):

# This transformation recurses from the Sourcefile down
recurse_to_modules = True
recurse_to_subroutines = True
recurse_to_contained_procedures = False
recurse_to_procedures = True
recurse_to_internal_procedures = False


def __init__(self, suffix, mode='module', module_suffix=None, include_path=None,
Expand Down
38 changes: 20 additions & 18 deletions loki/transform/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,32 @@ class Transformation:
traversed before standalone :any:`Subroutine` objects.
Classes inheriting from :any:`Transformation` may configure the
invocation and behaviour batch processing via a predefined set of
class attributes. These flags determine the underlying
invocation and behaviour during batch processing via a predefined
set of class attributes. These flags determine the underlying
graph traversal when processing complex call trees and determine
how the transformations are invoked for a given type of scheduler
:any:`Item`.
* ``reverse_traversal`` :
Attributes
----------
reverse_traversal : bool
Forces scheduler traversal in reverse order from the leaf
nodes upwards (default: ``False``).
* ``traverse_file_graph`` :
traverse_file_graph : bool
Apply :any:`Transformation` to the :any:`Sourcefile` object
corresponding to the :any:`Item` being processed, instead of
the program unit in question (default: ``False``).
* ``item_filter`` :
item_filter : bool
Filter by graph node types to prune the graph and change connectivity.
By default, only calls to :any:`Subroutine` items are used to construct
the graph.
* ``recurse_to_modules`` :
recurse_to_modules : bool
Apply transformation to all :any:`Module` objects when processing
a :any:`Sourcefile` (default ``False``)
* ``recurse_to_subroutines`` :
recurse_to_procedures : bool
Apply transformation to all :any:`Subroutine` objects when processing
:any:`Sourcefile` or :any:``Module`` objects (default ``False``)
* ``recurse_to_contained_procedures`` :
recurse_to_internal_procedures : bool
Apply transformation to all internal :any:`Subroutine` objects
when processing :any:`Subroutine` objects (default ``False``)
"""
Expand All @@ -77,8 +79,8 @@ class attributes. These flags determine the underlying

# Recursion behaviour when invoking transformations via ``trafo.apply()``
recurse_to_modules = False # Recurse from Sourcefile to Module
recurse_to_subroutines = False # Recurse from Sourcefile/Module to Subroutine
recurse_to_contained_procedures = False # Recurse to subroutines in ``contains`` clause
recurse_to_procedures = False # Recurse from Sourcefile/Module to subroutines and functions
recurse_to_internal_procedures = False # Recurse to subroutines in ``contains`` clause


def transform_subroutine(self, routine, **kwargs):
Expand Down Expand Up @@ -167,7 +169,7 @@ def apply_file(self, sourcefile, **kwargs):
If the :attr:`recurse_to_modules` class property is set, it
will also invoke :meth:`apply` on all :any:`Module` objects in
this :any:`Sourcefile`. Likewise, if
:attr:`recurse_to_subroutines` is set, it will invoke
:attr:`recurse_to_procedures` is set, it will invoke
:meth:`apply` on all free :any:`Subroutine` objects in this
:any:`Sourcefile`.
Expand Down Expand Up @@ -211,8 +213,8 @@ def apply_file(self, sourcefile, **kwargs):
for module in sourcefile.modules:
self.transform_module(module, item=item, role=role, targets=targets, items=items, **kwargs)

# Recurse into subroutine, if configured
if self.recurse_to_subroutines:
# Recurse into procedures, if configured
if self.recurse_to_procedures:
if items:
# Recursion into all subroutine items in the current file
for item in items:
Expand Down Expand Up @@ -250,8 +252,8 @@ def apply_subroutine(self, subroutine, **kwargs):
# Apply the actual transformation for subroutines
self.transform_subroutine(subroutine, **kwargs)

# Recurse to contained member subroutines
if self.recurse_to_contained_procedures:
# Recurse to internal procedures
if self.recurse_to_internal_procedures:
for routine in subroutine.subroutines:
self.apply_subroutine(routine, **kwargs)

Expand All @@ -261,7 +263,7 @@ def apply_module(self, module, **kwargs):
This calls :meth:`transform_module`.
If the :attr:`recurse_to_subroutines` class property is set,
If the :attr:`recurse_to_procedures` class property is set,
it will also invoke :meth:`apply` on all :any:`Subroutine`
objects in the ``contains`` clause of this :any:`Module`.
Expand All @@ -281,8 +283,8 @@ def apply_module(self, module, **kwargs):
# Apply the actual transformation for modules
self.transform_module(module, **kwargs)

# Recurse to subroutines contained in this module
if self.recurse_to_subroutines:
# Recurse to procedures contained in this module
if self.recurse_to_procedures:
for routine in module.subroutines:
self.apply_subroutine(routine, **kwargs)

Expand Down

0 comments on commit 0faa31d

Please sign in to comment.