File: class_29.f90

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (50 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download | duplicates (3)
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
program class_29
    type :: toml_val
        integer :: x
        character(len=:), allocatable :: y
    end type
    type :: toml_table
        integer :: x
        character(len=:), allocatable :: y
        class(toml_val), allocatable :: val
    end type
    class(toml_table), pointer :: temp
    class(toml_table), pointer :: temp2
    class(toml_table), allocatable :: temp3
    type(toml_table), allocatable :: temp4
    type(toml_table), target :: temp_table
    temp_table%x = 42
    temp => temp_table
    nullify(temp2)
    if (associated(temp2) .or. .not. associated(temp)) error stop
    
    if (allocated(temp3)) error stop
    allocate(temp3)
    allocate(temp4)
    if (.not. allocated(temp3)) error stop
    temp3%y = "Hello, World!"
    if (allocated(temp3%val)) error stop
    call destroy(temp3)
    if (allocated(temp3%y)) error stop
    temp3%y = "Hello, World!"
    temp4%y = "Hello, World!"
    if (allocated(temp3%y))  then
        deallocate(temp3%y)
    end if
    if (allocated(temp3%y)) error stop
    if (allocated(temp4%y))  then
        deallocate(temp4%y)
    end if
    if (allocated(temp4%y)) error stop
    allocate(temp4%val)
    temp4%val%y = "Hello"
    if (allocated(temp4%val%y))  then
        deallocate(temp4%val%y)
    end if
    if (allocated(temp4%val%y)) error stop
contains 
    subroutine destroy(shlex)
        class(toml_table), intent(inout) :: shlex
        deallocate(shlex%y)
    end subroutine destroy
end program