File: string_103.f90

package info (click to toggle)
lfortran 0.61.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 61,892 kB
  • sloc: cpp: 181,767; f90: 92,175; python: 17,616; ansic: 10,170; yacc: 2,377; sh: 1,444; fortran: 892; makefile: 38; javascript: 15
file content (41 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
program string_103
! Test that a temporary variable created for a function call result
! whose type depends on another variable (e.g., character(len=len(x)))
! has the correct dependency list in ASR.
implicit none
character(len=:), allocatable :: temp
character(len=:), allocatable :: rev
integer :: i
temp = "hello/world"
rev = reverse(temp)
i = find_char(rev, "/")
if (i /= 6) error stop
! The following nested call triggered an ASR verify error before the fix:
! "Variable lfortran_tmp depends on temp but isn't found in its dependency list"
i = find_char(reverse(temp), "/")
print *, "ok"
contains
    function reverse(string) result(reverse_string)
        character(len=*), intent(in) :: string
        character(len=len(string)) :: reverse_string
        integer :: i, n
        n = len(string)
        do i = 1, n
            reverse_string(n-i+1:n-i+1) = string(i:i)
        end do
    end function

    function find_char(string, pattern) result(res)
        character(len=*), intent(in) :: string
        character(len=*), intent(in) :: pattern
        integer :: res
        integer :: i
        res = 0
        do i = 1, len(string)
            if (string(i:i) == pattern(1:1)) then
                res = i
                return
            end if
        end do
    end function
end program