Line numbers of code lines whose code (without a trailing comment) is longer than line_length,
outside protected code.
| Type | Intent | Optional | 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 |
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. character(len=*), intent(in) :: src !! the source text integer, intent(in) :: line_length !! maximum line width, in characters; 0 or less for no limit integer, allocatable :: lines(:) type(source_t) :: source integer :: k, t, col, last_line, line, p, q allocate (lines(0)) if (line_length <= 0) return call parse_source(src, source) last_line = 0 do k = 1, source%stmts%n if (source%keep(k) .or. source%stmts%s(k)%kind /= SK_CODE) cycle col = 0 do t = source%stmts%s(k)%first, source%stmts%s(k)%last associate (tk => source%tokens%tok(t)) if (tk%kind == TK_NEWLINE) then col = 0 cycle end if if (t == source%stmts%s(k)%first) col = start_column(t) if (tk%kind == TK_COMMENT .or. tk%kind == TK_PREPROC) cycle ! a token continued on later lines (a string) is measured line by line line = tk%line p = tk%first do q = index(src(p:tk%last), achar(10)) if (q == 0) exit q = p + q - 1 ! the line feed if (q > p) then if (src(q - 1:q - 1) == achar(13)) q = q - 1 end if call check_width(tk, col + utf8_width(src(p:q - 1)), line) col = 0 line = line + 1 p = p + index(src(p:tk%last), achar(10)) end do col = col + utf8_width(src(p:tk%last)) call check_width(tk, col, line) end associate end do end do contains subroutine check_width(tk, width, line) !! Record `line` if it holds code token `tk` and its code is `width` characters wide, too long. type(token_t), intent(in) :: tk !! the token integer, intent(in) :: width !! width of the line up to the end of `tk` on it integer, intent(in) :: line !! line number if (is_code_kind(tk%kind) .and. width > line_length .and. line /= last_line) then lines = [lines, line] last_line = line end if end subroutine check_width integer function start_column(t) !! Column of token `t`: the width of the text before it on its line. integer, intent(in) :: t !! index into the token list integer :: i i = scan(src(1:source%tokens%tok(t)%first - 1), achar(10)//achar(13), back=.true.) start_column = utf8_width(src(i + 1:source%tokens%tok(t)%first - 1)) end function start_column end function long_code_lines