ffmt_statements Module

Groups tokens into statements and standalone lines.

A code statement runs from its first token to the line break that ends it, including any continuation lines and the comment, blank and preprocessor lines between them. Statements separated by ; on one line are split after the ;. Lines outside statements that hold only blanks, a comment or a preprocessor directive become items of their own. Together the items cover every token exactly once, in order.


Uses

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

Used by

  • module~~ffmt_statements~~UsedByGraph module~ffmt_statements ffmt_statements module~ffmt_case ffmt_case module~ffmt_case->module~ffmt_statements module~ffmt_source ffmt_source module~ffmt_case->module~ffmt_source module~ffmt_constructs ffmt_constructs module~ffmt_constructs->module~ffmt_statements module~ffmt_directives ffmt_directives module~ffmt_directives->module~ffmt_statements module~ffmt_format ffmt_format module~ffmt_format->module~ffmt_statements module~ffmt_format->module~ffmt_case module~ffmt_layout ffmt_layout module~ffmt_format->module~ffmt_layout module~ffmt_linebreak ffmt_linebreak module~ffmt_format->module~ffmt_linebreak module~ffmt_relational ffmt_relational module~ffmt_format->module~ffmt_relational module~ffmt_format->module~ffmt_source module~ffmt_structure ffmt_structure module~ffmt_format->module~ffmt_structure module~ffmt_use_sort ffmt_use_sort module~ffmt_format->module~ffmt_use_sort module~ffmt_whitespace ffmt_whitespace module~ffmt_format->module~ffmt_whitespace module~ffmt_layout->module~ffmt_statements module~ffmt_layout->module~ffmt_case module~ffmt_layout->module~ffmt_source module~ffmt_layout->module~ffmt_structure module~ffmt_layout->module~ffmt_whitespace module~ffmt_linebreak->module~ffmt_statements module~ffmt_linebreak->module~ffmt_source module~ffmt_relational->module~ffmt_statements module~ffmt_relational->module~ffmt_source module~ffmt_source->module~ffmt_statements module~ffmt_source->module~ffmt_directives module~ffmt_structure->module~ffmt_statements module~ffmt_structure->module~ffmt_constructs module~ffmt_structure->module~ffmt_source module~ffmt_use_sort->module~ffmt_statements module~ffmt_use_sort->module~ffmt_source module~ffmt_whitespace->module~ffmt_statements module~ffmt_whitespace->module~ffmt_source module~ffmt_cli ffmt_cli module~ffmt_cli->module~ffmt_format

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: SK_BLANK = 2

a line with only blanks

integer, public, parameter :: SK_CODE = 1

a code statement

integer, public, parameter :: SK_COMMENT = 3

a line with only a comment

integer, public, parameter :: SK_PREPROC = 4

a preprocessor directive line


Derived Types

type, public ::  statement_list_t

The items of a source text, in order.

Components

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

number of items

type(statement_t), public, allocatable :: s(:)

storage; only s(1:n) is in use

Type-Bound Procedures

procedure, public :: push

append an item

type, public ::  statement_t

An item: a code statement or a standalone line, as a range of the token list.

Components

Type Visibility Attributes Name Initial
integer, public :: first = 1

first token

integer, public :: kind = SK_CODE

one of the SK_* constants

integer, public :: last = 0

last token

type, public ::  statement_view_t

The code tokens of one statement, with their lowercase text and bracket depth: what the rules that read a statement word by word need. The procedures take an index j into code(:); outside 1:n a word is '' and its kind 0, so a rule can look before and after a token without checking the bounds.

Components

Type Visibility Attributes Name Initial
integer, public, allocatable :: code(:)

indices into the token list of the code tokens (see code_tokens)

integer, public, allocatable :: depth(:)

open ( and [ around each code token; a bracket is outside its own pair

integer, public :: first = 1

first code token after a statement label (10 continue)

integer, public, allocatable :: hi(:)

where it ends

integer, public, allocatable :: kinds(:)

kind of each code token (TK_*)

integer, public, allocatable :: lo(:)

where the text of each code token starts in low

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

lowercase text of the code tokens, one after another

integer, public :: n = 0

number of code tokens

Type-Bound Procedures

procedure, public :: closing => view_closing

the ) that closes a (

procedure, public :: is => view_is

whether a code token's lowercase text is a given one

procedure, public :: kind_of => view_kind_of

kind of a code token

procedure, public :: word => view_word

lowercase text of a code token


Functions

public function code_tokens(src, tokens, stmt) result(idx)

Indices of the code tokens of a statement: no blanks, line breaks, comments, continuation markers, preprocessor lines or ; separators.

Arguments

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

source text

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

tokens of src

type(statement_t), intent(in) :: stmt

the statement

Return Value integer, allocatable, (:)

private pure function ends_with_continuation(tokens, i, lend)

True if the last token of the line before any comment is a continuation &.

Arguments

Type IntentOptional Attributes Name
type(token_list_t), intent(in) :: tokens

the token list

integer, intent(in) :: i

tokens to search, up to the end of the line

integer, intent(in) :: lend

tokens to search, up to the end of the line

Return Value logical

private pure function find_semicolon(src, tokens, i, lend) result(semi)

A ; in i:lend that is followed by more code on the line, or 0.

Arguments

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

source text

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

tokens of src

integer, intent(in) :: i

tokens to search, up to the end of the line

integer, intent(in) :: lend

tokens to search, up to the end of the line

Return Value integer

private pure function line_end_token(tokens, i) result(j)

Index of the line break that ends the line containing token i, or the last token.

Arguments

Type IntentOptional Attributes Name
type(token_list_t), intent(in) :: tokens

the token list

integer, intent(in) :: i

a token at or after the start of the line

Return Value integer

private pure function line_kind(tokens, i, lend) result(kind)

Kind of the line i:lend from its first non-blank token.

Arguments

Type IntentOptional Attributes Name
type(token_list_t), intent(in) :: tokens

the token list

integer, intent(in) :: i

first and last token of the line

integer, intent(in) :: lend

first and last token of the line

Return Value integer

public function statement_view(src, tokens, stmt) result(v)

The view of code statement stmt (see set_view, which fills one in place, without a copy).

Arguments

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

source text

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

tokens of src

type(statement_t), intent(in) :: stmt

the statement

Return Value type(statement_view_t)

private pure function view_closing(v, j) result(c)

Index of the ) that closes the ( at code token j (counting only parentheses), or 0 if token j is not ( or it is not closed.

Arguments

Type IntentOptional Attributes Name
class(statement_view_t), intent(in) :: v

the statement

integer, intent(in) :: j

index into v%code(:)

Return Value integer

private pure function view_is(v, j, text)

True if the lowercase text of code token j is text, without making a copy of it. Outside the statement only '' matches.

Arguments

Type IntentOptional Attributes Name
class(statement_view_t), intent(in) :: v

the statement

integer, intent(in) :: j

index into v%code(:)

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

the text, in lowercase

Return Value logical

private pure function view_kind_of(v, j) result(kind)

Kind (TK_*) of code token j, or 0 outside the statement.

Arguments

Type IntentOptional Attributes Name
class(statement_view_t), intent(in) :: v

the statement

integer, intent(in) :: j

index into v%code(:)

Return Value integer

private pure function view_word(v, j) result(w)

Lowercase text of code token j, or '' outside the statement.

Arguments

Type IntentOptional Attributes Name
class(statement_view_t), intent(in) :: v

the statement

integer, intent(in) :: j

index into v%code(:)

Return Value character(len=:), allocatable


Subroutines

private subroutine push(self, s)

Append item s, growing the storage as needed.

Arguments

Type IntentOptional Attributes Name
class(statement_list_t), intent(inout) :: self

the item list

type(statement_t), intent(in) :: s

item to append

public subroutine set_view(src, tokens, stmt, v)

Make v the view of code statement stmt.

Arguments

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

source text

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

tokens of src

type(statement_t), intent(in) :: stmt

the statement

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

the view

public subroutine split_statements(src, tokens, stmts)

Group tokens into code statements and standalone blank, comment and preprocessor lines.

Arguments

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

source text

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

tokens of src

type(statement_list_t), intent(out) :: stmts

the items, covering every token once