loki.transformations.extract

Functions

extract_contained_procedure(procedure, name)

Extract a single contained procedure with name name from the parent procedure procedure.

extract_contained_procedures(procedure)

This transform creates "standalone" Subroutine`s from the contained procedures (subroutines or functions) of ``procedure`.

extract_contained_procedures(procedure)

This transform creates “standalone” Subroutine`s from the contained procedures (subroutines or functions) of ``procedure`.

A list of Subroutine`s corresponding to each contained subroutine of ``procedure` is returned and procedure itself is modified (see below). This function does the following transforms: 1. all global bindings from the point of view of the contained procedures(s) are introduced as imports or dummy arguments to the modified contained procedures(s) to make them standalone. 2. all calls or invocations of the contained procedures in parent are modified accordingly. 3. All procedures are removed from the CONTAINS block of procedure.

As a basic example of this transformation, the Fortran subroutine:

subroutine outer()
    integer :: y
    integer :: o
    o = 0
    y = 1
    call inner(o)
    contains
    subroutine inner(o)
       integer, intent(inout) :: o
       integer :: x
       x = 4
       o = x + y ! Note, 'y' is "global" here!
    end subroutine inner
end subroutine outer

is modified to:

subroutine outer()
    integer :: y
    integer :: o
    o = 0
    y = 1
    call inner(o, y) ! 'y' now passed as argument.
    contains
end subroutine outer

and the (modified) child:

subroutine inner(o, y)
       integer, intent(inout) :: o
       integer, intent(inout) :: y
       integer :: x
       x = 4
       o = x + y ! Note, 'y' is no longer "global"
end subroutine inner

is returned.

extract_contained_procedure(procedure, name)

Extract a single contained procedure with name name from the parent procedure procedure.

This function does the following transforms: 1. all global bindings from the point of view of the contained procedure are introduced as imports or dummy arguments to the modified contained procedure returned from this function. 2. all calls or invocations of the contained procedure in the parent are modified accordingly.

See also the “driver” function extract_contained_procedures, which applies this function to each contained procedure of a parent procedure and additionally empties the CONTAINS section of subroutines.