names_case Subroutine

private subroutine names_case(v, opts, mode)

Mark the intrinsic procedures, the constants of the intrinsic modules and the kinds named in one code statement.

Arguments

Type IntentOptional Attributes Name
type(statement_view_t), intent(in) :: v

the statement

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

the case wanted for each category

integer, intent(inout) :: mode(:)

case mode of each token, set for the names


Calls

proc~~names_case~~CallsGraph proc~names_case names_case proc~view_kind_of statement_view_t%view_kind_of proc~names_case->proc~view_kind_of proc~view_word statement_view_t%view_word proc~names_case->proc~view_word

Called by

proc~~names_case~~CalledByGraph proc~names_case names_case proc~compute_case compute_case proc~compute_case->proc~names_case proc~format_pass format_pass proc~format_pass->proc~compute_case 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 names_case(v, opts, mode)
    !! Mark the intrinsic procedures, the constants of the intrinsic modules and the kinds named in
    !! one code statement.
    type(statement_view_t), intent(in) :: v      !! the statement
    type(case_options_t), intent(in) :: opts     !! the case wanted for each category
    integer, intent(inout) :: mode(:)            !! case mode of each token, set for the names
    integer :: j, first
    logical :: decl, use_stmt, entity

    if (v%n == 0) return
    first = v%first
    if (first + 1 < v%n) then
        if (v%kind_of(first) == TK_NAME .and. v%is(first + 1, ':')) first = first + 2   ! construct name
    end if
    use_stmt = v%is(first, 'use')
    decl = .false.
    if (.not. use_stmt) decl = any([(v%is(j, '::') .and. v%depth(j) == 0, j=1, v%n)])
    entity = .false.             ! after `::`, the next top-level name is an entity being declared
    do j = first, v%n
        if (decl .and. v%depth(j) == 0) then
            if (v%is(j, '::') .or. (entity .and. v%is(j, ','))) then
                entity = .true.
                cycle
            end if
        end if
        if (v%kinds(j) /= TK_NAME) cycle
        if (j == first) cycle
        if (v%is(j - 1, '%')) cycle
        if (decl .and. entity .and. v%depth(j) == 0 .and. (v%is(j - 1, '::') .or. v%is(j - 1, ','))) cycle
        select case (v%word(j - 1))
        case ('function', 'subroutine', 'procedure', 'entry', 'program', 'module', 'submodule', 'interface')
            cycle
        end select
        if (opts%procedures /= CASE_KEEP .and. (v%is(j + 1, '(') .or. v%is(j - 1, 'call'))) then
            if (any(INTRINSIC_PROCEDURES == v%word(j))) mode(v%code(j)) = opts%procedures
        end if
        if (opts%constants /= CASE_KEEP .and. .not. v%is(j + 1, '=')) then
            if (any(INTRINSIC_CONSTANTS == v%word(j))) mode(v%code(j)) = opts%constants
        end if
        if (opts%types /= CASE_KEEP .and. is_kind(j)) mode(v%code(j)) = opts%types
    end do

contains

    logical function is_kind(j)
        !! True if name `j` is a kind: the value of `kind=`, or the kind of the type that starts a
        !! declaration (`real(dp) :: x`, `integer(int64), parameter :: n = 1`).
        integer, intent(in) :: j   !! index into `v%code(:)`
        is_kind = v%is(j - 1, '=') .and. v%is(j - 2, 'kind')
        if (is_kind .or. .not. decl) return
        if (j - 2 /= first .or. .not. v%is(j - 1, '(') .or. .not. v%is(j + 1, ')')) return
        select case (v%word(first))
        case ('integer', 'real', 'complex', 'logical', 'character')
            is_kind = .true.
        end select
    end function is_kind

end subroutine names_case