fdoc

subroutineread_declarationprivate

subroutine read_declaration(list, unit, line, doc, s)

Read a variable declaration, adding a variable for each name.

Arguments

NameTypeIntentAttributesDescription
listtype(entity_list_t)inout

the entities

unitintegerin

the entity it is in

linecharacter(len=*)in

the statement

doctype(doc_lines_t)in

the statement's documentation

stype(settings_t)in

the settings

Calls

Source

Show the code
subroutine read_declaration(list, unit, line, doc, s)
    type(entity_list_t), intent(inout) :: list  !! the entities
    integer, intent(in) :: unit                 !! the entity it is in
    character(len=*), intent(in) :: line        !! the statement
    type(doc_lines_t), intent(in) :: doc        !! the statement's documentation
    type(settings_t), intent(in) :: s           !! the settings
    type(parsed_type_t) :: t
    type(string_t), allocatable :: attributes(:), names(:), kept(:)
    character(len=:), allocatable :: rest, low, permission, intent, name, dimension, initial
    logical :: optional, parameter, points
    integer :: k, id

    call parse_type(line, t)
    if (.not. t%ok) return
    call split_attributes(t%rest, attributes, rest)
    allocate (kept(0))
    permission = inherited_permission(list, unit)
    intent = ''
    optional = .false.
    parameter = .false.
    do k = 1, size(attributes)
        low = remove_blanks(lowercase(attributes(k)%s))
        select case (low)
        case ('public', 'private', 'protected')
            permission = low
        case ('optional')
            optional = .true.
        case ('parameter')
            parameter = .true.
        case ('intent(in)')
            intent = 'in'
        case ('intent(out)')
            intent = 'out'
        case ('intent(inout)', 'intent(in out)')
            intent = 'inout'
        case default
            call push(kept, attributes(k)%s)
        end select
    end do
    names = top_split(rest, ',')
    do k = 1, size(names)
        call parse_declarator(names(k)%s, name, dimension, initial, points)
        ! what is initialized in a declaration in a procedure is saved, even with no `save`
        if (is_procedure(list%box(unit)%e%kind) .and. .not. parameter) then
            if (allocated(initial) .or. contains_string(kept, 'save')) list%box(unit)%e%more%saved_state = .true.
        end if
        id = list%add(E_VARIABLE, unit)
        associate (v => list%box(id)%e)
            call move_alloc(name, v%name)
            if (allocated(dimension)) call move_alloc(dimension, v%dimension)
            if (allocated(initial)) call move_alloc(initial, v%initial)
            call set_type(v, t)
            v%attribs = kept
            v%permission = permission
            v%intent = intent
            v%optional = optional
            v%parameter = parameter
            v%points = points
            if (allocated(doc%lines)) then
                call set_doc(v, s, doc%lines)
            else
                call set_doc(v, s, [string_t ::])
            end if
        end associate
    end do
end subroutine read_declaration

Graphs

Calls

Called by