loki.subroutine
Classes
|
Class to handle and manipulate a single subroutine. |
- class Subroutine(name, args=None, docstring=None, spec=None, body=None, contains=None, prefix=None, bind=None, result_name=None, is_function=False, ast=None, source=None, parent=None, symbol_attrs=None, rescope_symbols=False, incomplete=False, parser_classes=None)
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 aCONTAINS
statement declaring member proceduresprefix (iterable, optional) – Prefix specifications for the procedure
bind (optional) – Bind information (e.g., for Fortran
BIND(C)
annotation).result_name (str, optional) – The name of the result variable for functions.
is_function (bool, optional) – Flag to indicate this is a function instead of subroutine (in the Fortran sense). Defaults to False.
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 aModule
orSubroutine
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 providedSymbolTable
object instead of creating a newincomplete (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
- classmethod from_omni(ast, raw_source, definitions=None, parent=None, type_map=None)
Create
Subroutine
fromOMNI
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 declarationsparent (
Scope
, optional) – The enclosing parent scope of the subroutine, typically aModule
.type_map (dict, optional) – A mapping from type hash identifiers to type definitions, as provided in OMNI’s
typeTable
parse tree node
- classmethod from_ofp(ast, raw_source, definitions=None, pp_info=None, parent=None)
Create
Subroutine
fromOFP
parse tree- Parameters:
ast – The OFP parse tree
raw_source (str) – Fortran source string
definitions (list) – List of external
Module
to provide derived-type and procedure declarationspp_info – Preprocessing info as obtained by
sanitize_input
parent (
Scope
, optional) – The enclosing parent scope of the subroutine, typically aModule
.
- classmethod from_fparser(ast, raw_source, definitions=None, pp_info=None, parent=None)
Create
Subroutine
fromFP
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 declarationspp_info – Preprocessing info as obtained by
sanitize_input
parent (
Scope
, optional) – The enclosing parent scope of the subroutine, typically aModule
.
- classmethod from_regex(raw_source, parser_classes=None, parent=None)
Create
Subroutine
from source regex’ing
- 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:
- property procedure_symbol
Return the procedure symbol for this subroutine
- property procedure_type
Return the
ProcedureType
of this subroutine
- property return_type
Return the return_type 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 arguments in order of the defined signature (dummy list)
- 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 definitionsrecurse (bool, optional) – Enrich contained scopes