conditional_kind Function

private pure function conditional_kind(text) result(kind)

Kind of a preprocessor line (lowercase text): PP_IF, PP_ELSE (#elif, #else), PP_ENDIF or PP_OTHER.

Arguments

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

text of the preprocessor token, in lowercase

Return Value integer


Called by

proc~~conditional_kind~~CalledByGraph proc~conditional_kind conditional_kind proc~analyze_structure analyze_structure proc~analyze_structure->proc~conditional_kind proc~format_pass format_pass proc~format_pass->proc~analyze_structure 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

pure integer function conditional_kind(text) result(kind)
    !! Kind of a preprocessor line (lowercase text): `PP_IF`, `PP_ELSE` (`#elif`, `#else`), `PP_ENDIF`
    !! or `PP_OTHER`.
    character(len=*), intent(in) :: text   !! text of the preprocessor token, in lowercase
    character(len=:), allocatable :: directive
    integer :: i, j

    kind = PP_OTHER
    i = 2                                   ! after '#'
    if (len(text) < 2 .or. text(1:1) /= '#') return
    if (text(2:2) == ':') i = 3             ! fypp
    do while (i <= len(text))
        if (text(i:i) /= ' ' .and. text(i:i) /= achar(9)) exit
        i = i + 1
    end do
    j = i
    do while (j <= len(text))
        if (text(j:j) < 'a' .or. text(j:j) > 'z') exit
        j = j + 1
    end do
    directive = text(i:j - 1)
    select case (directive)
    case ('if', 'ifdef', 'ifndef')
        kind = PP_IF
    case ('elif', 'else')
        kind = PP_ELSE
    case ('endif')
        kind = PP_ENDIF
    end select
end function conditional_kind