ffmt_linebreak Module

Splitting code lines that are longer than the line length.

A line is split at a token boundary, preferring (in this order) after a comma, after an operator, = or ::, after an opening bracket, and anywhere between two tokens. Within the best kind of break that fits, the rightmost is used. The first part ends with & and the rest goes on a new line; the layout pass then aligns it. Only the code counts: a trailing comment may extend past the limit and moves with the last part. Lines are not split inside tokens (strings in particular), in protected code, in comment or preprocessor lines, or when a token spans lines.


Uses

  • module~~ffmt_linebreak~~UsesGraph module~ffmt_linebreak ffmt_linebreak module~ffmt_source ffmt_source module~ffmt_linebreak->module~ffmt_source module~ffmt_statements ffmt_statements module~ffmt_linebreak->module~ffmt_statements module~ffmt_strings ffmt_strings module~ffmt_linebreak->module~ffmt_strings module~ffmt_tokens ffmt_tokens module~ffmt_linebreak->module~ffmt_tokens module~ffmt_source->module~ffmt_statements module~ffmt_source->module~ffmt_tokens module~ffmt_directives ffmt_directives module~ffmt_source->module~ffmt_directives module~ffmt_lexer ffmt_lexer module~ffmt_source->module~ffmt_lexer module~ffmt_statements->module~ffmt_strings module~ffmt_statements->module~ffmt_tokens module~ffmt_tokens->module~ffmt_strings module~ffmt_directives->module~ffmt_statements module~ffmt_directives->module~ffmt_tokens module~ffmt_lexer->module~ffmt_strings module~ffmt_lexer->module~ffmt_tokens

Used by

  • module~~ffmt_linebreak~~UsedByGraph module~ffmt_linebreak ffmt_linebreak module~ffmt_format ffmt_format module~ffmt_format->module~ffmt_linebreak module~ffmt_cli ffmt_cli module~ffmt_cli->module~ffmt_format

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: MAX_CONTINUATIONS = 255

continuation lines a statement may have before Fortran 2023 (F2018 6.3.2.1); splitting stops there


Functions

private function break_point(tokens, src, a, lend, start_col, line_length) result(best)

The token after which to split tokens a:lend of a line that starts at token a in column start_col, or 0 if the code fits or cannot be split.

Arguments

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

the tokens of src

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

the source text

integer, intent(in) :: a

first token of the line

integer, intent(in) :: lend

last token of the line, its line break if it has one

integer, intent(in) :: start_col

column of token a

integer, intent(in) :: line_length

maximum line width, in characters

Return Value integer

public function long_code_lines(src, line_length) result(lines)

Line numbers of code lines whose code (without a trailing comment) is longer than line_length, outside protected code.

Arguments

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

the source text

integer, intent(in) :: line_length

maximum line width, in characters; 0 or less for no limit

Return Value integer, allocatable, (:)

private pure function priority(text, kind) result(prio)

How good a place the end of a token with this text is for a line break (1 is best).

Arguments

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

lowercase text of the token

integer, intent(in) :: kind

token kind (TK_*)

Return Value integer

public function split_long_lines(src, line_length, indent, nsplit, changed) result(out)

src with each code line longer than line_length split once. The new continuation lines are indented by indent more than the line they come from if it is the first line of a statement, and like it if it is a continuation line, which the layout pass will usually leave in place. nsplit returns the number of splits.

Arguments

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

the source text

integer, intent(in) :: line_length

maximum line width, in characters

integer, intent(in) :: indent

indentation step, in blanks

integer, intent(out) :: nsplit

number of lines split

integer, intent(out), optional, allocatable :: changed(:,:)

where the statements that were split are in out: bytes changed(1, j):changed(2, j). Not allocated if one of them cannot be laid out again on its own (see stands_alone)

Return Value character(len=:), allocatable

private pure function stands_alone(source, k)

True if statement k of source, a code statement, can be laid out again on its own after one of its lines is split, giving what laying out the whole text would: it takes up whole lines (no ; before or after it on its lines, no byte order mark), has no statement label (which stays at the start of the line), and is not followed by a comment line that may be lined up with a comment at the end of its last line.

Arguments

Type IntentOptional Attributes Name
type(source_t), intent(in) :: source

the source

integer, intent(in) :: k

index into source%stmts

Return Value logical