fab.parse.fortran module

Fortran language handling classes.

class fab.parse.fortran.AnalysedFortran(fpath, file_hash=None, program_defs=None, module_defs=None, symbol_defs=None, module_deps=None, symbol_deps=None, mo_commented_file_deps=None, file_deps=None, psyclone_kernels=None)

Bases: AnalysedDependent

An analysis result for a single file, containing module and symbol definitions and dependencies.

The user should be unlikely to encounter this class. If the third-party fortran parser is unable to process a source file, a FortranParserWorkaround object can be provided to the Analyse step, which will be converted at runtime into an instance of this class.

Parameters:
  • fpath (Union[str, Path]) – The source file that was analysed.

  • file_hash (Optional[int]) – (default: None) The hash of the source. If omitted, Fab will evaluate lazily.

  • program_defs (Optional[Iterable[str]]) – (default: None) Set of program names defined by this source file.

  • module_defs (Optional[Iterable[str]]) – (default: None) Set of module names defined by this source file. A subset of symbol_defs

  • symbol_defs (Optional[Iterable[str]]) – (default: None) Set of symbol names defined by this source file.

  • module_deps (Optional[Iterable[str]]) – (default: None) Set of module names used by this source file.

  • symbol_deps (Optional[Iterable[str]]) – (default: None) Set of symbol names used by this source file. Can include symbols in the same file.

  • mo_commented_file_deps (Optional[Iterable[str]]) – (default: None) A set of C file names, without paths, on which this file depends. Comes from “DEPENDS ON:” comments which end in “.o”.

  • file_deps (Optional[Iterable[Path]]) – (default: None) Other files on which this source depends. Must not include itself. This attribute is calculated during symbol analysis, after everything has been parsed.

  • psyclone_kernels (Optional[Dict[str, int]]) – (default: None) The hash of any PSyclone kernel metadata found in this source file, by name.

add_program_def(name)
add_module_def(name)
add_module_dep(name)
property mod_filenames

The mod_filenames property defines which module files are expected to be created (but not where).

classmethod field_names()

Defines the order in which we want fields to appear in str or repr strings.

Calling this helps to ensure any lazy attributes are evaluated before use, e.g when constructing a string representation of the instance, or generating a hash value.

to_dict()

Create a dict representing the object.

The dict may be written to json, so can’t contain sets. Lists are sorted for reproducibility in testing.

Return type:

Dict[str, Any]

classmethod from_dict(d)
validate()
class fab.parse.fortran.FortranAnalyser(std=None, ignore_mod_deps=None)

Bases: FortranAnalyserBase

A build step which analyses a fortran file using fparser2, creating an AnalysedFortran.

Parameters:
  • std – (default: None) The Fortran standard.

  • ignore_mod_deps (Optional[Iterable[str]]) – (default: None) Module names to ignore in use statements.

walk_nodes(fpath, file_hash, node_tree)

Examine the nodes in the parse tree, recording things we’re interested in.

Return type depends on our subclass, and will be a subclass of AnalysedDependent.

Return type:

AnalysedFortran

class fab.parse.fortran.FortranParserWorkaround(fpath, module_defs=None, symbol_defs=None, module_deps=None, symbol_deps=None, mo_commented_file_deps=None)

Bases: object

Use this class to create a workaround when the third-party Fortran parser is unable to process a valid source file.

You must manually examine the source file and list:
  • module definitions

  • module dependencies

  • symbols defined outside a module

  • symbols used without a use statement

Params are as for AnalysedFortranBase.

This class is intended to be passed to the Analyse step.

Parameters:
  • fpath (Union[str, Path]) – The source file that was analysed.

  • module_defs (Optional[Iterable[str]]) – (default: None) Set of module names defined by this source file. A subset of symbol_defs

  • symbol_defs (Optional[Iterable[str]]) – (default: None) Set of symbol names defined by this source file.

  • module_deps (Optional[Iterable[str]]) – (default: None) Set of module names used by this source file.

  • symbol_deps (Optional[Iterable[str]]) – (default: None) Set of symbol names used by this source file. Can include symbols in the same file.

  • mo_commented_file_deps (Optional[Iterable[str]]) – (default: None) A set of C file names, without paths, on which this file depends. Comes from “DEPENDS ON:” comments which end in “.o”.

as_analysed_fortran()