subroutineparse_type
subroutine parse_type(line, t)
Read the type at the start of line.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| line | character(len=*) | in | the statement | |
| t | type(parsed_type_t) | out | the result |
Calls
Source
Show the code
subroutine parse_type(line, t)
character(len=*), intent(in) :: line !! the statement
type(parsed_type_t), intent(out) :: t !! the result
character(len=:), allocatable :: rest, args, word
type(string_t), allocatable :: parts(:)
integer :: n, k, at, sel
logical :: star
call type_keyword(lowercase(line), n, word)
if (n == 0) return
t%ok = .true.
t%vartype = word
rest = strip(line(n + 1:))
sel = selector_length(rest)
t%rest = strip(rest(sel + 1:))
if (sel == 0) then
if (t%vartype == 'character') t%strlen = '1'
return
end if
star = rest(1:1) == '*'
if (star) then
args = strip(rest(2:sel))
if (args(1:1) == '(') args = strip(args(2:len(args) - 1))
else
args = strip(rest(2:sel - 1))
end if
args = remove_blanks(args)
select case (t%vartype)
case ('type', 'class', 'procedure')
at = index(args, '(')
if (at > 0) then
t%proto = [string_t(args(:at - 1)), string_t(args(at + 1:len(args) - 1))]
else
t%proto = [string_t(args), string_t('')]
end if
case ('character')
if (star) then
t%strlen = args
return
end if
parts = top_split(args, ',')
do k = 1, size(parts)
associate (p => parts(k)%s)
if (.not. allocated(t%strlen) .and. starts_with(lowercase(p), 'len=')) then
t%strlen = p(5:)
else if (.not. allocated(t%kind) .and. starts_with(lowercase(p), 'kind=')) then
t%kind = p(6:)
else if (.not. allocated(t%strlen)) then
t%strlen = p
else if (.not. allocated(t%kind)) then
t%kind = p
end if
end associate
end do
if (.not. allocated(t%strlen)) t%strlen = '1'
case default
if (starts_with(lowercase(args), 'kind=')) then
t%kind = args(6:)
else
t%kind = args
end if
end select
end subroutine parse_type