summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90
blob: db71692f4caca7a5466bc757636a9bb7f4a0c7dc (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
! Copyright 2018-2020 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/> .

! Source code for short-circuit-argument-list.exp.

module called_state
    implicit none
    type called_counts
	integer :: function_no_arg_called = 0
	integer :: function_no_arg_false_called = 0
	integer :: function_one_arg_called = 0
	integer :: function_two_arg_called = 0
	integer :: function_array_called = 0
    end type
    type(called_counts) :: calls
end module called_state

logical function function_no_arg()
    use called_state
    implicit none
    calls%function_no_arg_called = calls%function_no_arg_called + 1
    function_no_arg = .TRUE.
end function function_no_arg

logical function function_no_arg_false()
    use called_state
    implicit none
    calls%function_no_arg_false_called = calls%function_no_arg_false_called + 1
    function_no_arg_false = .FALSE.
end function function_no_arg_false

logical function function_one_arg(x)
    use called_state
    implicit none
    logical, intent(in) :: x
    calls%function_one_arg_called = calls%function_one_arg_called + 1
    function_one_arg = .TRUE.
end function function_one_arg

logical function function_two_arg(x, y)
    use called_state
    implicit none
    logical, intent(in) :: x, y
    calls%function_two_arg_called = calls%function_two_arg_called + 1
    function_two_arg = .TRUE.
end function function_two_arg

logical function function_array(logical_array)
    use called_state
    implicit none
    logical, dimension(4,2), target, intent(in) :: logical_array
    logical, dimension(:,:), pointer :: p
    calls%function_array_called = calls%function_array_called + 1
    function_array = .TRUE.
end function function_array

program generate_truth_table
    use called_state
    implicit none
    interface
	logical function function_no_arg()
	end function function_no_arg
	logical function function_no_arg_false()
	end function
	logical function function_one_arg(x)
	    logical, intent(in) :: x
	end function
	logical function function_two_arg(x, y)
	    logical, intent(in) :: x, y
	end function
	logical function function_array(logical_array)
	    logical, dimension(4,2), target, intent(in) :: logical_array
	end function function_array
    end interface
    logical, dimension (4,2) :: truth_table
    logical :: a, b, c, d, e
    character(2) :: binary_string
    binary_string = char(0) // char(1)
    truth_table = .FALSE.
    truth_table(3:4,1) = .TRUE.
    truth_table(2::2,2) = .TRUE.
    a = function_no_arg() ! post_truth_table_init
    b = function_no_arg_false()
    c = function_one_arg(b)
    d = function_two_arg(a, b)
    e = function_array(truth_table)
    print *, truth_table(:, 1), a, b, e
    print *, truth_table(:, 2), c, d
end program generate_truth_table