The formatted text of source, from its structure (analyze_structure), the gaps
(compute_gaps) and the letter case (compute_case) wanted.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(source_t), | intent(in) | :: | source |
the source |
||
| type(structure_t), | intent(in) | :: | st |
its block structure |
||
| integer, | intent(in) | :: | gap(:) |
blanks wanted before each token |
||
| type(case_marks_t), | intent(in) | :: | cases |
letter case wanted for each token |
||
| type(format_options_t), | intent(in) | :: | opts |
the formatting options |
||
| integer, | intent(out), | optional, | allocatable | :: | long_lines(:) |
input lines that kept their indentation
because the new one would make them longer
than |
function layout(source, st, gap, cases, opts, long_lines) result(out) !! The formatted text of `source`, from its structure ([[analyze_structure]]), the gaps !! ([[compute_gaps]]) and the letter case ([[compute_case]]) wanted. type(source_t), intent(in) :: source !! the source type(structure_t), intent(in) :: st !! its block structure integer, intent(in) :: gap(:) !! blanks wanted before each token type(case_marks_t), intent(in) :: cases !! letter case wanted for each token type(format_options_t), intent(in) :: opts !! the formatting options integer, allocatable, intent(out), optional :: long_lines(:) !! input lines that kept their indentation !! because the new one would make them longer !! than `opts%line_length` character(len=:), allocatable :: out type(writer_t) :: w integer :: k, level, ind w%line_length = opts%line_length w%keep_original = .not. opts%split_lines w%gap = gap w%cases = cases allocate (w%long_lines(0)) associate (src => source%text, tokens => source%tokens) do k = 1, source%stmts%n level = st%depth(k) if (.not. opts%indent_units) level = level - st%units(k) if (.not. opts%indent_procedures) level = level - st%procedures(k) if (opts%indent_fypp) level = level + st%fypp(k) ind = opts%base_indent + max(level, 0)*opts%indent associate (s => source%stmts%s(k)) if (source%keep(k)) then ! a formatter directive: written as it is call emit_range(w, src, tokens, s%first, s%last) w%comment_in = -1 w%stmt_in = -1 cycle end if select case (s%kind) case (SK_BLANK) call emit_blank(w, src, tokens, s) w%comment_in = -1 w%stmt_in = -1 case (SK_PREPROC) if (opts%indent_fypp) then call emit_fypp_line(w, src, tokens, s, ind) else call emit_range(w, src, tokens, s%first, s%last) end if w%comment_in = -1 case (SK_COMMENT) call emit_comment_line(w, src, tokens, s, ind, opts) case (SK_CODE) call emit_statement(w, src, tokens, s, st%info(k)%label > 0, ind, opts) end select end associate end do end associate out = w%buf%get() if (present(long_lines)) long_lines = w%long_lines end function layout