summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.fortran/ptype-on-functions.f90
blob: 6ce91c6787aba89b6df25a67a7bf1df52a9f97f6 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
! Copyright 2019-2022 Free Software Foundation, Inc.
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program.  If not, see <http://www.gnu.org/licenses/>.

module some_module
  implicit none

  type, public :: Number
     integer :: a
   contains
     procedure :: get => get_number
     procedure :: set => set_number
  end type Number

contains

  function get_number (this) result (val)
    class (Number), intent (in) :: this
    integer :: val
    val = this%a
  end function get_number

  subroutine set_number (this, val)
    class (Number), intent (inout) :: this
    integer :: val
    this%a = val
  end subroutine set_number

end module some_module

logical function is_bigger (a,b)
  integer, intent(in) :: a
  integer, intent(in) :: b
  is_bigger = a > b
end function is_bigger

subroutine say_numbers (v1,v2,v3)
  integer,intent(in) :: v1
  integer,intent(in) :: v2
  integer,intent(in) :: v3
  print *, v1,v2,v3
end subroutine say_numbers

program test
  use some_module

  interface
     integer function fun1 (x)
       integer :: x
     end function fun1

     integer function fun2 (x)
       integer :: x
     end function fun2

     subroutine say_array (arr)
       integer, dimension (:,:) :: arr
     end subroutine say_array
  end interface

  type (Number) :: n1
  type (Number) :: n2

  procedure(fun1), pointer:: fun_ptr => NULL()

  integer, dimension (5,5) :: array
  array = 0

  call say_numbers (1,2,3)	! stop here
  call say_string ('hello world')
  call say_array (array (2:3, 2:4))
  print *, fun_ptr (3)

end program test

integer function fun1 (x)
  implicit none
  integer :: x
  fun1 = x + 1
end function fun1

integer function fun2 (x)
  implicit none
  integer :: x
  fun2 = x + 2
end function fun2

subroutine say_string (str)
  character(len=*) :: str
  print *, str
end subroutine say_string

subroutine say_array (arr)
  integer, dimension (:,:) :: arr
  do i=LBOUND (arr, 2), UBOUND (arr, 2), 1
     do j=LBOUND (arr, 1), UBOUND (arr, 1), 1
        write(*, fmt="(i4)", advance="no") arr (j, i)
     end do
     print *, ""
  end do
end subroutine say_array