loki.program_unit
Classes
|
Common base class for |
- class ProgramUnit(parent: dataclasses.InitVar[object] = None)
Bases:
ScopeCommon base class for
ModuleandSubroutine- Parameters:
name (str) – Name of the program unit.
docstring (tuple of
Node, optional) – The docstring in the original source.spec (
Section, optional) – The spec of the program unit.contains (
Section, optional) – The internal-subprogram part following aCONTAINSstatement declaring module or member proceduresast (optional) – Parse tree node from the frontend for this program unit
source (
Source) – Source object representing the raw source string information from the original file.parent (
Scope, optional) – The enclosing parent scope of the program unit. Declarations from the parent scope remain valid within the program unit’s scope (unless shadowed by local declarations).rescope_symbols (bool, optional) – Ensure that the type information for all
TypedSymbolin the IR exist in this program unit’s scope or the scope’s parents. Defaults to False.symbol_attrs (
SymbolTable, optional) – Use the providedSymbolTableobject 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.REGEXfrontend and a full parse using one of the other frontends is pending.
- classmethod from_source(source, definitions=None, xmods=None, parser_classes=None, frontend=Frontend.FP, parent=None)
Instantiate an object derived from
ProgramUnitfrom raw source stringThis calls the frontend-specific factory method implemented in the derived class, such as
ModuleorSubroutine- Parameters:
source (str) – Fortran source string
definitions (list, optional) – List of external
Moduleto provide derived-type and procedure declarationsxmods (list, optional) – List of locations with “xmods” module files. Only relevant for
OMNIfrontendfrontend (
Frontend, optional) – Choice of frontend to use for parsing source (defaultFrontend.FP)parent (
Scope, optional) – The parent scope this module or subroutine is nested into
- abstract classmethod from_omni(ast, raw_source, definitions=None, parent=None, type_map=None)
Create the
ProgramUnitobject from anOMNIparse tree.This method must be implemented by the derived class.
- Parameters:
ast – The OMNI parse tree
raw_source (str) – Fortran source string
definitions (list, optional) – List of external
Moduleto provide derived-type and procedure declarationsparent (
Scope, optional) – The enclosing parent scope of the moduletypetable (dict, optional) – A mapping from type hash identifiers to type definitions, as provided in OMNI’s
typeTableparse tree node
- abstract classmethod from_ofp(ast, raw_source, definitions=None, pp_info=None, parent=None)
Create the
ProgramUnitobject from anOFPparse tree.This method must be implemented by the derived class.
- Parameters:
ast – The OFP parse tree
raw_source (str) – Fortran source string
definitions (list) – List of external
Moduleto provide derived-type and procedure declarationspp_info – Preprocessing info as obtained by
sanitize_inputparent (
Scope, optional) – The enclosing parent scope of the module.
- abstract classmethod from_fparser(ast, raw_source, definitions=None, pp_info=None, parent=None)
Create the
ProgramUnitobject from anFPparse tree.This method must be implemented by the derived class.
- Parameters:
ast – The FParser parse tree
raw_source (str) – Fortran source string
definitions (list) – List of external
Moduleto provide derived-type and procedure declarationspp_info – Preprocessing info as obtained by
sanitize_inputparent (
Scope, optional) – The enclosing parent scope of the module.
- abstract classmethod from_regex(raw_source, parser_classes=None, parent=None)
Create the
ProgramUnitobject from source regex’ing.This method must be implemented by the derived class.
- abstract register_in_parent_scope()
Insert the type information for this object in the parent’s symbol table
If
parentis None, this does nothing.This method must be implemented by the derived class.
- make_complete(**frontend_args)
Trigger a re-parse of the object if incomplete to produce a full Loki IR
If the object is marked to be incomplete, i.e. when using the lazy constructor option, this triggers a new parsing of all
ProgramUnitobjects and anyRawSourcenodes in their.Existing
ModuleandSubroutineobjects continue to exist and references to them stay valid, as they will only be updated instead of replaced.
- clone(**kwargs)
Create a deep copy of the object with the option to override individual parameters
- Parameters:
**kwargs – Any parameters from the constructor of the class.
- Returns:
The cloned object.
- Return type:
Object of type
self.__class__
- property declarations
Return the declarations from the
specof this unit
- property variables
Return the variables declared in the
specof this unit
- property imported_symbols
Return the symbols imported in this unit
- property imported_symbol_map
Map of imported symbol names to objects
- property interface_symbols
Return the list of symbols declared via interfaces in this unit
- property interface_symbol_map
Map of declared interface names to symbols
- property enum_symbols
List of symbols defined via an enum
- property symbols
Return list of all symbols declared or imported in this module scope
- property symbol_map
Map of symbol names to symbols
- property subroutines
List of
Subroutineobjects that are declared in this unit
- property routines
List of
Subroutineobjects that are declared in this unit
- property subroutine_map
Map of subroutine names to
Subroutineobjects insubroutines
- property spec_parts
Return the
specsubdivided into the parts the Fortran standard describes and requires to appear in a specific orderThe parts are:
import statements (such as module imports via
USE)implicit-part (such as
IMPLICIT NONE)declaration constructs (such as access statements, variable declarations etc.)
This can be useful when adding or looking for statements that have to appear in a certain position.
Note that comments at the interface between parts may be allocated to the previous or next part.
- Returns:
The parts of the spec, with empty parts represented by empty tuples.
- Return type:
tuple of tuple of
ir.Node
- property ir
All components of the intermediate representation in this unit
- to_fortran(conservative=False, cuf=False)
Convert this unit to Fortran source representation
- apply(op, **kwargs)
Apply a given transformation to this program unit
Note that the dispatch routine
op.apply(source)will ensure that all entities of thisProgramUnitare correctly traversed.