limit_diagnostics Function

private function limit_diagnostics(src) result(diags)

Warnings for input beyond the limits of the Fortran 2023 standard (6.3.2.1): lines longer than 10,000 characters, and statements of more than 1,000,000 characters (counted without comments and line breaks).

Arguments

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

source text

Return Value type(diagnostic_t), allocatable, (:)


Calls

proc~~limit_diagnostics~~CallsGraph proc~limit_diagnostics limit_diagnostics proc~longest_line longest_line proc~limit_diagnostics->proc~longest_line proc~parse_source parse_source proc~limit_diagnostics->proc~parse_source proc~to_s to_s proc~limit_diagnostics->proc~to_s proc~protected_items protected_items proc~parse_source->proc~protected_items proc~split_statements split_statements proc~parse_source->proc~split_statements proc~tokenize tokenize proc~parse_source->proc~tokenize proc~directive directive proc~protected_items->proc~directive proc~ends_with_continuation ends_with_continuation proc~split_statements->proc~ends_with_continuation proc~find_semicolon find_semicolon proc~split_statements->proc~find_semicolon proc~line_end_token line_end_token proc~split_statements->proc~line_end_token proc~line_kind line_kind proc~split_statements->proc~line_kind proc~push statement_list_t%push proc~split_statements->proc~push proc~add add proc~tokenize->proc~add proc~comment_kind comment_kind proc~tokenize->proc~comment_kind proc~dotop_at dotop_at proc~tokenize->proc~dotop_at proc~dotop_end dotop_end proc~tokenize->proc~dotop_end proc~fypp_inline_end fypp_inline_end proc~tokenize->proc~fypp_inline_end proc~is_blank is_blank proc~tokenize->proc~is_blank proc~is_digit is_digit proc~tokenize->proc~is_digit proc~is_preproc_start is_preproc_start proc~tokenize->proc~is_preproc_start proc~is_quote is_quote proc~tokenize->proc~is_quote proc~lex_number lex_number proc~tokenize->proc~lex_number proc~line_end line_end proc~tokenize->proc~line_end proc~name_end name_end proc~tokenize->proc~name_end proc~operator_end operator_end proc~tokenize->proc~operator_end proc~peek peek proc~tokenize->proc~peek proc~preproc_end preproc_end proc~tokenize->proc~preproc_end proc~string_end string_end proc~tokenize->proc~string_end proc~add->proc~is_blank proc~add->proc~peek proc~is_code_char is_code_char proc~add->proc~is_code_char proc~push~2 token_list_t%push proc~add->proc~push~2 proc~comment_kind->proc~peek proc~is_letter is_letter proc~comment_kind->proc~is_letter proc~lowercase lowercase proc~comment_kind->proc~lowercase proc~token_text token_text proc~directive->proc~token_text proc~dotop_at->proc~peek proc~dotop_at->proc~is_letter proc~dotop_end->proc~name_end proc~dotop_end->proc~peek proc~is_name_char is_name_char proc~dotop_end->proc~is_name_char proc~dotop_end->proc~lowercase proc~fypp_inline_end->proc~peek proc~is_preproc_start->proc~peek proc~lex_number->proc~dotop_at proc~lex_number->proc~is_digit proc~lex_number->proc~name_end proc~lex_number->proc~peek proc~digits_end digits_end proc~lex_number->proc~digits_end proc~lex_number->proc~is_name_char proc~lower_char lower_char proc~lex_number->proc~lower_char proc~name_end->proc~peek proc~name_end->proc~is_name_char proc~preproc_end->proc~line_end proc~preproc_end->proc~peek proc~last_nonblank last_nonblank proc~preproc_end->proc~last_nonblank proc~string_end->proc~is_blank proc~string_end->proc~line_end proc~string_end->proc~peek proc~only_blanks_to_eol only_blanks_to_eol proc~string_end->proc~only_blanks_to_eol proc~digits_end->proc~is_digit proc~digits_end->proc~peek proc~is_code_char->proc~is_blank proc~is_name_char->proc~is_digit proc~is_name_char->proc~is_letter proc~last_nonblank->proc~is_blank proc~lowercase->proc~lower_char proc~only_blanks_to_eol->proc~line_end proc~only_blanks_to_eol->proc~last_nonblank

Called by

proc~~limit_diagnostics~~CalledByGraph proc~limit_diagnostics limit_diagnostics proc~format_text format_text proc~format_text->proc~limit_diagnostics 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

function limit_diagnostics(src) result(diags)
    !! Warnings for input beyond the limits of the Fortran 2023 standard (6.3.2.1): lines longer than
    !! 10,000 characters, and statements of more than 1,000,000 characters (counted without comments
    !! and line breaks).
    character(len=*), intent(in) :: src      !! source text
    type(diagnostic_t), allocatable :: diags(:)
    integer, parameter :: MAX_LINE = 10000, MAX_STATEMENT = 1000000
    type(source_t) :: source
    integer :: k, j, n, line, width, c

    allocate (diags(0))
    if (longest_line(src) > MAX_LINE) then
        line = 1
        width = 0
        do k = 1, len(src)
            c = iand(ichar(src(k:k)), 255)
            if (c == 10) then
                line = line + 1
                width = 0
            else if (c < 128 .or. c >= 192) then
                width = width + 1
                if (width == MAX_LINE + 1) diags = [diags, diagnostic_t(line, 'line '//to_s(line)// &
                                                                        ' is longer than '//to_s(MAX_LINE)//' characters, '// &
                                                                        'the limit of the Fortran standard')]
            end if
        end do
    end if
    if (len(src) <= MAX_STATEMENT) return
    call parse_source(src, source)
    do k = 1, source%stmts%n
        if (source%stmts%s(k)%kind /= SK_CODE) cycle
        n = 0
        do j = source%stmts%s(k)%first, source%stmts%s(k)%last
            associate (t => source%tokens%tok(j))
                if (t%kind /= TK_COMMENT .and. t%kind /= TK_NEWLINE) n = n + t%last - t%first + 1
            end associate
        end do
        if (n > MAX_STATEMENT) then
            line = source%tokens%tok(source%stmts%s(k)%first)%line
            diags = [diags, diagnostic_t(line, 'the statement on line '//to_s(line)//' has more than '// &
                                         to_s(MAX_STATEMENT)//' characters, the limit of the Fortran standard')]
        end if
    end do
end function limit_diagnostics