emit_comment_line Subroutine

private subroutine emit_comment_line(w, src, tokens, s, ind, opts)

A comment line, re-indented to ind. A comment that lines up with the comment on the line above (a continued trailing comment) stays lined up with it. Comment lines directly after a statement that are indented more than it keep their extra indentation. With keep_column1_comments, a comment that starts in column 1 stays there.

Arguments

Type IntentOptional Attributes Name
type(writer_t), intent(inout) :: w

the output and the alignment state

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

the source text

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

its tokens

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

the comment line item

integer, intent(in) :: ind

indentation of the code around it, in blanks

type(format_options_t), intent(in) :: opts

the formatting options


Calls

proc~~emit_comment_line~~CallsGraph proc~emit_comment_line emit_comment_line proc~comment_column comment_column proc~emit_comment_line->proc~comment_column proc~emit_range emit_range proc~emit_comment_line->proc~emit_range proc~input_column input_column proc~emit_comment_line->proc~input_column proc~put put proc~emit_comment_line->proc~put proc~token_text token_text proc~emit_comment_line->proc~token_text proc~trim_blanks trim_blanks proc~emit_comment_line->proc~trim_blanks proc~comment_column->proc~input_column proc~fitting_column fitting_column proc~comment_column->proc~fitting_column proc~emit_range->proc~put proc~emit_range->proc~token_text proc~utf8_width utf8_width proc~input_column->proc~utf8_width proc~builder_append string_builder_t%builder_append proc~put->proc~builder_append proc~put->proc~utf8_width proc~first_piece_width first_piece_width proc~fitting_column->proc~first_piece_width proc~line_width line_width proc~fitting_column->proc~line_width proc~first_piece_width->proc~utf8_width proc~line_pieces line_pieces proc~first_piece_width->proc~line_pieces proc~line_width->proc~utf8_width proc~line_width->proc~line_pieces

Called by

proc~~emit_comment_line~~CalledByGraph proc~emit_comment_line emit_comment_line proc~layout layout proc~layout->proc~emit_comment_line proc~format_pass format_pass proc~format_pass->proc~layout proc~format_text format_text proc~format_text->proc~format_pass proc~relayout relayout proc~format_text->proc~relayout proc~relayout->proc~format_pass proc~process_text process_text proc~process_text->proc~format_text proc~process_file process_file proc~process_file->proc~process_text proc~process_stdin process_stdin proc~process_stdin->proc~process_text proc~run run proc~run->proc~process_file proc~run->proc~process_stdin

Source Code

subroutine emit_comment_line(w, src, tokens, s, ind, opts)
    !! A comment line, re-indented to `ind`. A comment that lines up with the comment on the line
    !! above (a continued trailing comment) stays lined up with it. Comment lines directly after a
    !! statement that are indented more than it keep their extra indentation. With `keep_column1_comments`, a
    !! comment that starts in column 1 stays there.
    type(writer_t), intent(inout) :: w           !! the output and the alignment state
    character(len=*), intent(in) :: src          !! the source text
    type(token_list_t), intent(in) :: tokens     !! its tokens
    type(statement_t), intent(in) :: s           !! the comment line item
    integer, intent(in) :: ind                   !! indentation of the code around it, in blanks
    type(format_options_t), intent(in) :: opts   !! the formatting options
    integer :: j, col

    if (.not. opts%indent_comments) then
        call emit_range(w, src, tokens, s%first, s%last)
        w%comment_in = -1
        return
    end if
    do j = s%first, s%last
        select case (tokens%tok(j)%kind)
        case (TK_BOM, TK_NEWLINE)
            call put(w, token_text(src, tokens%tok(j)))
        case (TK_COMMENT)
            if (opts%keep_column1_comments .and. input_column(src, tokens%tok(j)) == 0) then
                col = 0                         ! a comment in column 1 stays there
                w%comment_in = -1
            else
                col = ind
                ! comments directly after a statement and indented deeper than it (such as FORD
                ! `!!` documentation) keep their extra indentation
                if (w%stmt_in >= 0) col = max(ind, w%stmt_out + input_column(src, tokens%tok(j)) - w%stmt_in)
                col = comment_column(w, src, tokens, j, col)
            end if
            call put(w, repeat(' ', col))
            call put(w, trim_blanks(token_text(src, tokens%tok(j))))
        end select
    end do
end subroutine emit_comment_line