psyclone.psyir.frontend.fortran#
This module provides the PSyIR Fortran front-end.
Classes#
FortranReader: PSyIR Fortran frontend. This frontend translates Fortran from a string
- class psyclone.psyir.frontend.fortran.FortranReader(free_form=True, ignore_comments=True, ignore_directives=True, last_comments_as_codeblocks=False, resolve_modules=False)[source]#
PSyIR Fortran frontend. This frontend translates Fortran from a string or a file into PSyIR using the fparser2 utilities.
- Parameters:
free_form (
bool) – If parsing free-form code or not (default True).ignore_comments (
bool) – If comments should be ignored or not (default True).ignore_directives (
bool) – If directives should be ignored or not (default True). Only has an effect if ignore_comments is False.last_comments_as_codeblocks (
bool) – If the last comments in the a given block (e.g. subroutine, do, if-then body, etc.) should be kept as code blocks or lost (default False). Only has an effect if ignore_comments is False.resolve_modules (
Union[bool,List[str]]) – Whether to resolve modules while parsing a file, for more precise control it also accepts a list of module names. Defaults to False.
- Raises:
ValueError – If ignore_directives is set to False but ignore_comments is set to True.
Inheritance

- psyir_from_expression(source_code, symbol_table=None)[source]#
Generate the PSyIR tree for the supplied Fortran statement. The symbol table is expected to provide all symbols found in the expression.
- Parameters:
source_code (
str) – text of the expression to be parsed.symbol_table (
Optional[SymbolTable]) – the SymbolTable in which to search for any symbols that are encountered.
- Returns:
PSyIR representing the provided Fortran expression.
- Return type:
- Raises:
TypeError – if no valid SymbolTable is supplied.
ValueError – if the supplied source does not represent a Fortran expression.
- psyir_from_file(file_path)[source]#
Generate the PSyIR tree representing the given Fortran file.
- Parameters:
file_path (str or any Python Path format.) – path of the file to be read and parsed.
- Returns:
PSyIR representing the provided Fortran file.
- Return type:
- Raises:
ValueError – if the parser fails to parse the contents of the supplied file.
- psyir_from_source(source_code)[source]#
Generate the PSyIR tree for the given Fortran source code.
- Parameters:
source_code (
str) – text representation of the code to be parsed.- Return type:
- Returns:
the PSyIR of the provided Fortran source code.
- Raises:
ValueError – if the supplied Fortran cannot be parsed.
- psyir_from_statement(source_code, symbol_table=None)[source]#
Generate the PSyIR tree for the supplied Fortran statement. The symbolt table is expected to provide all symbols found in the statement.
- Parameters:
source_code (
str) – text of the statement to be parsed.symbol_table (
Optional[SymbolTable]) – the SymbolTable in which to search for any symbols that are encountered.
- Returns:
PSyIR representing the provided Fortran statement.
- Return type:
- Raises:
TypeError – if no valid SymbolTable is supplied.
ValueError – if the supplied source does not represent a Fortran statement.