File: nested_23.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (87 lines) | stat: -rw-r--r-- 2,486 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
module nested_23_mod
    implicit none

    type :: build_target
        character(len=:), allocatable :: name
        character(len=:), allocatable :: names(:)
    end type build_target

contains

    subroutine prune_build_targets(targets)
        type(build_target), allocatable, intent(inout) :: targets(:)
        integer :: i

        ! ---- Basic sanity checks ----
        if (.not. allocated(targets)) error stop "targets not allocated"
        if (size(targets) == 0) error stop "targets is empty"

        do i = 1, size(targets)
            associate(target => targets(i))

                if (.not. allocated(target%name)) then
                    error stop "target name not allocated"
                end if

                if (temp_call(targets)) then
                    call collect_used_modules(target)
                end if

            end associate
        end do

    contains

        subroutine collect_used_modules(target)
            type(build_target), intent(inout) :: target

            ! ---- Validate access to host-associated variable ----
            if (.not. allocated(targets)) then
                error stop "host variable 'targets' unexpectedly unallocated"
            end if

            if (.not. allocated(target%name)) then
                error stop "collect_used_modules: target%name not allocated"
            end if

            ! Dummy logic: attach a single "used module"
            allocate(character(len=len_trim(target%name)) :: target%names(1))
            target%names(1) = target%name

        end subroutine collect_used_modules

    end subroutine prune_build_targets


    logical function temp_call(targets)
        type(build_target), allocatable, intent(in) :: targets(:)

        if (.not. allocated(targets)) error stop "temp_call: targets not allocated"

        ! Simple logic: trigger processing only if >1 target exists
        temp_call = size(targets) > 1
    end function temp_call

end module nested_23_mod


program nested_23
    use nested_23_mod
    implicit none

    type(build_target), allocatable :: targets(:)

    allocate(targets(2))

    targets(1)%name = "core_lib"
    targets(2)%name = "util_lib"

    call prune_build_targets(targets)

    ! ---- Post-condition check ----
    if (.not. allocated(targets(1)%names)) error stop "names not populated"
    if (targets(1)%names(1) /= "core_lib") error stop "unexpected module name"

    print *, "MRE completed successfully"

end program nested_23