ffmt_constructs Module

Classifies statements by their role in the block structure: opening a construct or program unit, continuing one (else, case, contains, ...), or closing one.

Classification looks only at a statement's code tokens. Keywords are not reserved in Fortran, so a keyword followed by =, => or % is treated as a variable (end = 1).


Uses

  • module~~ffmt_constructs~~UsesGraph module~ffmt_constructs ffmt_constructs module~ffmt_statements ffmt_statements module~ffmt_constructs->module~ffmt_statements module~ffmt_strings ffmt_strings module~ffmt_constructs->module~ffmt_strings module~ffmt_tokens ffmt_tokens module~ffmt_constructs->module~ffmt_tokens module~ffmt_statements->module~ffmt_strings module~ffmt_statements->module~ffmt_tokens module~ffmt_tokens->module~ffmt_strings

Used by

  • module~~ffmt_constructs~~UsedByGraph module~ffmt_constructs ffmt_constructs module~ffmt_structure ffmt_structure module~ffmt_structure->module~ffmt_constructs module~ffmt_format ffmt_format module~ffmt_format->module~ffmt_structure module~ffmt_layout ffmt_layout module~ffmt_format->module~ffmt_layout module~ffmt_layout->module~ffmt_structure module~ffmt_cli ffmt_cli module~ffmt_cli->module~ffmt_format

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: C_ANY = 1

a bare end

integer, public, parameter :: C_ASSOCIATE = 15
integer, public, parameter :: C_BLOCK = 16
integer, public, parameter :: C_BLOCK_DATA = 8
integer, public, parameter :: C_CONTAINS = 21

contains (a middle statement of program units and types)

integer, public, parameter :: C_CRITICAL = 17
integer, public, parameter :: C_DO = 13
integer, public, parameter :: C_ENUM = 11
integer, public, parameter :: C_ENUMERATION = 22

enumeration type (F2023)

integer, public, parameter :: C_FORALL = 20
integer, public, parameter :: C_FUNCTION = 6
integer, public, parameter :: C_IF = 12
integer, public, parameter :: C_INTERFACE = 9
integer, public, parameter :: C_MODULE = 3
integer, public, parameter :: C_NONE = 0

no construct

integer, public, parameter :: C_PROCEDURE = 7

separate module procedure (module procedure name in a submodule)

integer, public, parameter :: C_PROGRAM = 2
integer, public, parameter :: C_SELECT = 14
integer, public, parameter :: C_SUBMODULE = 4
integer, public, parameter :: C_SUBROUTINE = 5
integer, public, parameter :: C_TEAM = 18
integer, public, parameter :: C_TYPE = 10
integer, public, parameter :: C_WHERE = 19
character(len=*), private, parameter :: LABELS(0:NCONSTRUCTS) = [character(len=16)::'none', 'end', 'program', 'module', 'submodule', 'subroutine', 'function', 'procedure', 'block data', 'interface', 'type', 'enum', 'if', 'do', 'select', 'associate', 'block', 'critical', 'change team', 'where', 'forall', 'contains', 'enumeration type']
integer, private, parameter :: NCONSTRUCTS = 22
integer, public, parameter :: ROLE_CLOSE = 3
integer, public, parameter :: ROLE_MIDDLE = 2
integer, public, parameter :: ROLE_NONE = 0
integer, public, parameter :: ROLE_OPEN = 1
integer, private, parameter :: WORD_LEN = 32

longer than any keyword


Derived Types

type, public ::  stmt_info_t

What a statement does to the block structure, as found by classify_statement.

Components

Type Visibility Attributes Name Initial
integer, public :: construct = C_NONE

the construct opened, continued or closed: one of the C_* constants

integer, public :: do_label = 0

for do 10 ...: the label of the statement that ends the loop

integer, public :: label = 0

statement label, or 0

character(len=:), public, allocatable :: name

construct name, as in outer: do

integer, public :: role = ROLE_NONE

ROLE_OPEN, ROLE_MIDDLE, ROLE_CLOSE, or ROLE_NONE for other statements

type, private ::  words_t

The words of a statement, with combined keywords such as endif split into end, if.

Components

Type Visibility Attributes Name Initial
integer, public :: n = 0

number of words

integer, public, allocatable :: tok(:)

index into the code token list for each word

type(string_t), public, allocatable :: w(:)

the words of the first token; the others are its code tokens


Functions

public function classify_statement(src, tokens, v, in_interface) result(info)

Classify a code statement. in_interface is true directly inside an interface block, where module procedure lists procedures instead of starting one.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: src

source text

type(token_list_t), intent(in) :: tokens

tokens of src

type(statement_view_t), intent(in) :: v

the statement

logical, intent(in) :: in_interface

the innermost open construct is an interface block

Return Value type(stmt_info_t)

public pure function closed_construct(second, third) result(construct)

The construct that end second third closes (C_ANY for a bare end), or C_NONE if second names no construct, so that the end is not a closing statement.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: second

the word after end, in lowercase, or ''

character(len=*), intent(in) :: third

the word after that, or '' (data in end block data)

Return Value integer

public pure function construct_label(construct) result(label)

Name of a construct for messages ('if', 'select', 'end' for a bare end), or '?'.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: construct

one of the C_* constants

Return Value character(len=label_width)

private pure function expand_keyword(w) result(parts)

Split a keyword that may be written as one word (endif, elseif, selectcase, endblockdata, ...) into its parts. Other words are returned unchanged.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: w

the word, in lowercase

Return Value type(string_t), allocatable, (:)

private pure function label_width(construct)

Length of the text of construct_label.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: construct

one of the C_* constants

Return Value integer


Subroutines

private pure subroutine read_label(text, label)

Set label to the value of text, unless that is not a statement label. This is not an internal read, because it runs in parallel, where those take a lock in the runtime library.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text

the label

integer, intent(inout) :: label

its value, or as it was

private pure subroutine set(info, role, construct)

Set the role and construct of info.

Arguments

Type IntentOptional Attributes Name
type(stmt_info_t), intent(inout) :: info

the classification to update

integer, intent(in) :: role

one of the ROLE_* constants

integer, intent(in) :: construct

one of the C_* constants