# loki.subroutine module

class Subroutine(*args, parent=None, symbol_attrs=None, **kwargs)

  Bases: `ProgramUnit`

  Class to handle and manipulate a single subroutine.

  Parameters:

    - name (str) – Name of the subroutine.

    - args (iterable of str, optional) – The names of the dummy args.

    - docstring (tuple of `Node`, optional) – The subroutine docstring in the original source.

    - spec (`Section`, optional) – The spec of the subroutine.

    - body (`Section`, optional) – The body of the subroutine.

    - contains (`Section`, optional) – The internal-subprogram part following a `CONTAINS` statement declaring member procedures

    - prefix (iterable, optional) – Prefix specifications for the procedure

    - bind (optional) – Bind information (e.g., for Fortran `BIND(C)` annotation).

    - ast (optional) – Frontend node for this subroutine (from parse tree of the frontend).

    - source (`Source`) – Source object representing the raw source string information from the read file.

    - parent (`Scope`, optional) – The enclosing parent scope of the subroutine, typically a `Module` or `Subroutine` object. Declarations from the parent scope remain valid within the subroutine’s scope (unless shadowed by local declarations).

    - rescope_symbols (bool, optional) – Ensure that the type information for all `TypedSymbol` in the subroutine’s IR exist in the subroutine’s scope or the scope’s parents. Defaults to False.

    - symbol_attrs (`SymbolTable`, optional) – Use the provided `SymbolTable` object instead of creating a new

    - incomplete (bool, optional) – Mark the object as incomplete, i.e. only partially parsed. This is typically the case when it was instantiated using the `Frontend.REGEX` frontend and a full parse using one of the other frontends is pending.

    - parser_classes (`RegexParserClass`, optional) – Provide the list of parser classes used during incomplete regex parsing

  is_function = False
  classmethod from_omni(ast, raw_source, definitions=None, parent=None, type_map=None)

    Create `Subroutine` from `OMNI` parse tree

    Parameters:

      - ast – The OMNI parse tree

      - raw_source (str) – Fortran source string

      - definitions (list) – List of external `Module` to provide derived-type and procedure declarations

      - parent (`Scope`, optional) – The enclosing parent scope of the subroutine, typically a `Module`.

      - type_map (dict, optional) – A mapping from type hash identifiers to type definitions, as provided in OMNI’s `typeTable` parse tree node

  classmethod from_fparser(ast, raw_source, definitions=None, pp_info=None, parent=None)

    Create `Subroutine` from `FP` parse tree

    Parameters:

      - ast – The FParser parse tree

      - raw_source (str) – Fortran source string

      - definitions (list) – List of external `Module` to provide derived-type and procedure declarations

      - pp_info – Preprocessing info as obtained by `sanitize_input`

      - parent (`Scope`, optional) – The enclosing parent scope of the subroutine, typically a `Module`.

  classmethod from_regex(raw_source, parser_classes=None, parent=None)

    Create `Subroutine` from source regex’ing

    Parameters:

      - raw_source (str) – Fortran source string

      - parent (`Scope`, optional) – The enclosing parent scope of the subroutine, typically a `Module`.

  register_in_parent_scope()

    Insert the type information for this object in the parent’s symbol table

    If `parent` is None, this does nothing.

  clone(**kwargs)

    Create a copy of the subroutine with the option to override individual parameters.

    Parameters:

      **kwargs – Any parameters from the constructor of `Subroutine`.

    Returns:

      The cloned subroutine object.

    Return type:

      `Subroutine`

  property procedure_symbol

    Return the procedure symbol for this subroutine

  property procedure_type

    Return the `ProcedureType` of this subroutine

  property variables

    Return the variables declared in the `spec` of this unit

  property arguments

    Return arguments in order of the defined signature (dummy list).

  property argnames

    Return names of dummy arguments as list of lower-case strings in order of the defined signature

  property members

    List of `Subroutine` objects that are declared in this unit

  property ir

    All components of the intermediate representation in this subroutine

  property interface

    Interface object that defines the Subroutine signature in header files.

  enrich(definitions, recurse=False)

    Apply `ProgramUnit.enrich` and expand enrichment to calls declared via interfaces

    Parameters:

      - definitions (list of `ProgramUnit`) – A list of all available definitions

      - recurse (bool, optional) – Enrich contained scopes