A code statement, with its continuation lines and the comment, blank and preprocessor lines
between them. The first line is indented to ind; a statement label stays at the start of
the line.
| Type | Intent | Optional | 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 code statement |
||
| logical, | intent(in) | :: | labeled |
the statement has a statement label |
||
| integer, | intent(in) | :: | ind |
indentation of the statement, in blanks |
||
| type(format_options_t), | intent(in) | :: | opts |
the formatting options |
subroutine emit_statement(w, src, tokens, s, labeled, ind, opts) !! A code statement, with its continuation lines and the comment, blank and preprocessor lines !! between them. The first line is indented to `ind`; a statement label stays at the start of !! the line. 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 code statement logical, intent(in) :: labeled !! the statement has a statement label integer, intent(in) :: ind !! indentation of the statement, in blanks type(format_options_t), intent(in) :: opts !! the formatting options integer :: j, lend, f logical :: first_line, mid_line w%nbrackets = 0 w%anchor_col = -1 w%pending_anchor = 0 w%pending_bracket = .false. w%separated = .false. w%declaration = .false. w%prev = 0 ! a statement after `;` starts in the middle of a line mid_line = .false. if (s%first > 1) mid_line = tokens%tok(s%first - 1)%kind /= TK_NEWLINE .and. tokens%tok(s%first - 1)%kind /= TK_BOM first_line = .true. j = s%first do while (j <= s%last) lend = j do while (lend < s%last) if (tokens%tok(lend)%kind == TK_NEWLINE) exit lend = lend + 1 end do if (tokens%tok(j)%kind == TK_BOM) then call put(w, token_text(src, tokens%tok(j))) j = j + 1 end if f = first_non_blank(tokens, j, lend) w%line_comment = .false. if (f > lend) then continue ! nothing left on the line else if (tokens%tok(f)%kind == TK_NEWLINE) then call put(w, token_text(src, tokens%tok(f))) ! blank line else if (tokens%tok(f)%kind == TK_PREPROC) then call emit_range(w, src, tokens, j, lend) else if (tokens%tok(f)%kind == TK_COMMENT) then call put(w, repeat(' ', comment_column(w, src, tokens, f, ind + opts%continuation_indent))) call emit_body(w, src, tokens, f, lend) w%line_comment = .true. else if (first_line) then if (mid_line) then call emit_body(w, src, tokens, j, lend) else if (labeled .and. tokens%tok(f)%kind == TK_INT) then call put(w, token_text(src, tokens%tok(f))) call put(w, repeat(' ', max(1, ind - w%col))) call start_statement(first_non_blank(tokens, f + 1, lend)) ! the code after the label call emit_body(w, src, tokens, first_non_blank(tokens, f + 1, lend), lend) else call put(w, repeat(' ', fitting_column(w, src, tokens, f, lend, & [ind, input_column(src, tokens%tok(f))]))) call start_statement(f) call emit_body(w, src, tokens, f, lend) end if first_line = .false. else call emit_continuation(w, src, tokens, f, lend, continuation_target(w, ind, opts), & ind + opts%continuation_indent) end if if (.not. w%line_comment) w%comment_in = -1 w%pending_anchor = 0 w%pending_bracket = .false. j = lend + 1 end do contains subroutine start_statement(f) !! Record where the statement starting with token `f` begins, for comment lines after it. integer, intent(in) :: f !! first code token of the statement, after any label w%stmt_in = -1 if (f > s%last) return w%stmt_in = input_column(src, tokens%tok(f)) w%stmt_out = w%col w%generic = token_lower(src, tokens%tok(f)) == 'generic' end subroutine start_statement end subroutine emit_statement