# loki.transformations.extract.internal

Functions

`extract_contained_procedure`(procedure, name) | Extract a single internal procedure with name `name` from the parent procedure `procedure`.
`extract_contained_procedures`(procedure) | This transform creates "standalone" `Subroutine`s from the internal procedures (subroutines or functions) of ``procedure``.
`extract_internal_procedure`(procedure, name) | Extract a single internal procedure with name `name` from the parent procedure `procedure`.
`extract_internal_procedures`(procedure) | This transform creates "standalone" `Subroutine`s from the internal procedures (subroutines or functions) of ``procedure``.

extract_contained_procedures(procedure)

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

  A list of `Subroutine`s corresponding to each internal 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 internal procedures(s) are introduced as imports or dummy arguments to the modified internal procedures(s) to make them standalone. 2. all calls or invocations of the internal 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 internal 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 internal procedure are introduced as imports or dummy arguments to the modified internal procedure returned from this function. 2. all calls or invocations of the internal procedure in the parent are modified accordingly.

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

extract_internal_procedures(procedure)

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

  A list of `Subroutine`s corresponding to each internal 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 internal procedures(s) are introduced as imports or dummy arguments to the modified internal procedures(s) to make them standalone. 2. all calls or invocations of the internal 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_internal_procedure(procedure, name)

  Extract a single internal 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 internal procedure are introduced as imports or dummy arguments to the modified internal procedure returned from this function. 2. all calls or invocations of the internal procedure in the parent are modified accordingly.

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