PR gold/14309
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.fortran / exprs.exp
1 # Copyright (C) 1994, 1997, 2005, 2007-2012 Free Software Foundation,
2 # Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was adapted from old Chill tests by Stan Shebs
18 # (shebs@cygnus.com).
19
20 load_lib "fortran.exp"
21
22 if { [skip_fortran_tests] } { continue }
23
24 proc test_integer_literals_accepted {} {
25 global gdb_prompt
26
27 # Test various decimal values.
28
29 gdb_test "p 123" " = 123"
30 gdb_test "p -123" " = -123"
31 }
32
33 proc test_character_literals_accepted {} {
34 global gdb_prompt
35
36 # Test various character values.
37
38 gdb_test "p 'a'" " = 'a'"
39
40 # Test various substring expression.
41 gdb_test "p 'abcdefg'(2:4)" " = 'bcd'"
42 gdb_test "p 'abcdefg'(:3)" " = 'abc'"
43 gdb_test "p 'abcdefg'(5:)" " = 'efg'"
44 gdb_test "p 'abcdefg'(:)" " = 'abcdefg'"
45
46 }
47
48 proc test_integer_literals_rejected {} {
49 global gdb_prompt
50
51 test_print_reject "p _"
52 }
53
54 proc test_logical_literals_accepted {} {
55 global gdb_prompt
56
57 # Test the only possible values for a logical, TRUE and FALSE.
58
59 gdb_test "p .TRUE." " = .TRUE."
60 gdb_test "p .FALSE." " = .FALSE."
61 }
62
63 proc test_float_literals_accepted {} {
64 global gdb_prompt
65
66 # Test various floating point formats
67
68 gdb_test "p .44 .LT. .45" " = .TRUE."
69 gdb_test "p .44 .GT. .45" " = .FALSE."
70 gdb_test "p 0.44 .LT. 0.45" " = .TRUE."
71 gdb_test "p 0.44 .GT. 0.45" " = .FALSE."
72 gdb_test "p 44. .LT. 45." " = .TRUE."
73 gdb_test "p 44. .GT. 45." " = .FALSE."
74 gdb_test "p 44.0 .LT. 45.0" " = .TRUE."
75 gdb_test "p 44.0 .GT. 45.0" " = .FALSE."
76 gdb_test "p 10D20 .LT. 10D21" " = .TRUE."
77 gdb_test "p 10D20 .GT. 10D21" " = .FALSE."
78 gdb_test "p 10d20 .LT. 10d21" " = .TRUE."
79 gdb_test "p 10d20 .GT. 10d21" " = .FALSE."
80 gdb_test "p 10E20 .LT. 10E21" " = .TRUE."
81 gdb_test "p 10E20 .GT. 10E21" " = .FALSE."
82 gdb_test "p 10e20 .LT. 10e21" " = .TRUE."
83 gdb_test "p 10e20 .GT. 10e21" " = .FALSE."
84 gdb_test "p 10.D20 .LT. 10.D21" " = .TRUE."
85 gdb_test "p 10.D20 .GT. 10.D21" " = .FALSE."
86 gdb_test "p 10.d20 .LT. 10.d21" " = .TRUE."
87 gdb_test "p 10.d20 .GT. 10.d21" " = .FALSE."
88 gdb_test "p 10.E20 .LT. 10.E21" " = .TRUE."
89 gdb_test "p 10.E20 .GT. 10.E21" " = .FALSE."
90 gdb_test "p 10.e20 .LT. 10.e21" " = .TRUE."
91 gdb_test "p 10.e20 .GT. 10.e21" " = .FALSE."
92 gdb_test "p 10.0D20 .LT. 10.0D21" " = .TRUE."
93 gdb_test "p 10.0D20 .GT. 10.0D21" " = .FALSE."
94 gdb_test "p 10.0d20 .LT. 10.0d21" " = .TRUE."
95 gdb_test "p 10.0d20 .GT. 10.0d21" " = .FALSE."
96 gdb_test "p 10.0E20 .LT. 10.0E21" " = .TRUE."
97 gdb_test "p 10.0E20 .GT. 10.0E21" " = .FALSE."
98 gdb_test "p 10.0e20 .LT. 10.0e21" " = .TRUE."
99 gdb_test "p 10.0e20 .GT. 10.0e21" " = .FALSE."
100 gdb_test "p 10.0D+20 .LT. 10.0D+21" " = .TRUE."
101 gdb_test "p 10.0D+20 .GT. 10.0D+21" " = .FALSE."
102 gdb_test "p 10.0d+20 .LT. 10.0d+21" " = .TRUE."
103 gdb_test "p 10.0d+20 .GT. 10.0d+21" " = .FALSE."
104 gdb_test "p 10.0E+20 .LT. 10.0E+21" " = .TRUE."
105 gdb_test "p 10.0E+20 .GT. 10.0E+21" " = .FALSE."
106 gdb_test "p 10.0e+20 .LT. 10.0e+21" " = .TRUE."
107 gdb_test "p 10.0e+20 .GT. 10.0e+21" " = .FALSE."
108 gdb_test "p 10.0D-11 .LT. 10.0D-10" " = .TRUE."
109 gdb_test "p 10.0D-11 .GT. 10.0D-10" " = .FALSE."
110 gdb_test "p 10.0d-11 .LT. 10.0d-10" " = .TRUE."
111 gdb_test "p 10.0d-11 .GT. 10.0d-10" " = .FALSE."
112 gdb_test "p 10.0E-11 .LT. 10.0E-10" " = .TRUE."
113 gdb_test "p 10.0E-11 .GT. 10.0E-10" " = .FALSE."
114 gdb_test "p 10.0e-11 .LT. 10.0e-10" " = .TRUE."
115 gdb_test "p 10.0e-11 .GT. 10.0e-10" " = .FALSE."
116 }
117
118 proc test_convenience_variables {} {
119 global gdb_prompt
120
121 gdb_test "set \$foo = 101" " = 101\[\r\n\]*" \
122 "Set a new convenience variable"
123
124 gdb_test "print \$foo" " = 101" \
125 "Print contents of new convenience variable"
126
127 gdb_test "set \$foo = 301" " = 301\[\r\n\]*" \
128 "Set convenience variable to a new value"
129
130 gdb_test "print \$foo" " = 301" \
131 "Print new contents of convenience variable"
132
133 gdb_test "set \$_ = 11" " = 11\[\r\n\]*" \
134 "Set convenience variable \$_"
135
136 gdb_test "print \$_" " = 11" \
137 "Print contents of convenience variable \$_"
138
139 gdb_test "print \$foo + 10" " = 311" \
140 "Use convenience variable in arithmetic expression"
141
142 gdb_test "print (\$foo = 32) + 4" " = 36" \
143 "Use convenience variable assignment in arithmetic expression"
144
145 gdb_test "print \$bar" " = VOID" \
146 "Print contents of uninitialized convenience variable"
147 }
148
149 proc test_value_history {} {
150 global gdb_prompt
151
152 gdb_test "print 101" "\\\$1 = 101" \
153 "Set value-history\[1\] using \$1"
154
155 gdb_test "print 102" "\\\$2 = 102" \
156 "Set value-history\[2\] using \$2"
157
158 gdb_test "print 103" "\\\$3 = 103" \
159 "Set value-history\[3\] using \$3"
160
161 gdb_test "print \$\$" "\\\$4 = 102" \
162 "Print value-history\[MAX-1\] using inplicit index \$\$"
163
164 gdb_test "print \$\$" "\\\$5 = 103" \
165 "Print value-history\[MAX-1\] again using implicit index \$\$"
166
167 gdb_test "print \$" "\\\$6 = 103" \
168 "Print value-history\[MAX\] using implicit index \$"
169
170 gdb_test "print \$\$2" "\\\$7 = 102" \
171 "Print value-history\[MAX-2\] using explicit index \$\$2"
172
173 gdb_test "print \$0" "\\\$8 = 102" \
174 "Print value-history\[MAX\] using explicit index \$0"
175
176 gdb_test "print 108" "\\\$9 = 108" ""
177
178 gdb_test "print \$\$0" "\\\$10 = 108" \
179 "Print value-history\[MAX\] using explicit index \$\$0"
180
181 gdb_test "print \$1" "\\\$11 = 101" \
182 "Print value-history\[1\] using explicit index \$1"
183
184 gdb_test "print \$2" "\\\$12 = 102" \
185 "Print value-history\[2\] using explicit index \$2"
186
187 gdb_test "print \$3" "\\\$13 = 103" \
188 "Print value-history\[3\] using explicit index \$3"
189
190 gdb_test "print \$-3" "\\\$14 = 100" \
191 "Print (value-history\[MAX\] - 3) using implicit index \$"
192
193 gdb_test "print \$1 + 3" "\\\$15 = 104" \
194 "Use value-history element in arithmetic expression"
195 }
196
197 proc test_arithmetic_expressions {} {
198 global gdb_prompt
199
200 # Test unary minus with various operands
201
202 # gdb_test "p -(TRUE)" " = -1" "unary minus applied to bool"
203 # gdb_test "p -('a')" " = xxx" "unary minus applied to char"
204 gdb_test "p -(1)" " = -1" "unary minus applied to int"
205 gdb_test "p -(1.0)" " = -1" "unary minus applied to real"
206
207 # Test addition with various operands
208
209 gdb_test "p .TRUE. + 1" " = 2" "bool plus int"
210 gdb_test "p 1 + 1" " = 2" "int plus int"
211 gdb_test "p 1.0 + 1" " = 2" "real plus int"
212 gdb_test "p 1.0 + 2.0" " = 3" "real plus real"
213
214 # Test subtraction with various operands
215
216 gdb_test "p .TRUE. - 1" " = 0" "bool minus int"
217 gdb_test "p 3 - 1" " = 2" "int minus int"
218 gdb_test "p 3.0 - 1" " = 2" "real minus int"
219 gdb_test "p 5.0 - 2.0" " = 3" "real minus real"
220
221 # Test multiplication with various operands
222
223 gdb_test "p .TRUE. * 1" " = 1" "bool times int"
224 gdb_test "p 2 * 3" " = 6" "int times int"
225 gdb_test "p 2.0 * 3" " = 6" "real times int"
226 gdb_test "p 2.0 * 3.0" " = 6" "real times real"
227
228 # Test division with various operands
229
230 gdb_test "p .TRUE. / 1" " = 1" "bool divided by int"
231 gdb_test "p 6 / 3" " = 2" "int divided by int"
232 gdb_test "p 6.0 / 3" " = 2" "real divided by int"
233 gdb_test "p 6.0 / 3.0" " = 2" "real divided by real"
234
235 # Test exponentiation with various operands
236
237 gdb_test "p 2 ** 3" " = 8" "int powered by int"
238 gdb_test "p 2 ** 2 ** 3" " = 256" "combined exponentiation expression"
239 gdb_test "p (2 ** 2) ** 3" " = 64" "combined exponentiation expression in specified order"
240 gdb_test "p 4 ** 0.5" " = 2" "int powered by real"
241 gdb_test "p 4.0 ** 0.5" " = 2" "real powered by real"
242
243 }
244
245 # Start with a fresh gdb.
246
247 gdb_exit
248 gdb_start
249 gdb_reinitialize_dir $srcdir/$subdir
250
251 gdb_test "set print sevenbit-strings" ""
252
253 if [set_lang_fortran] then {
254 test_value_history
255 test_convenience_variables
256 test_integer_literals_accepted
257 test_integer_literals_rejected
258 test_logical_literals_accepted
259 test_character_literals_accepted
260 test_float_literals_accepted
261 test_arithmetic_expressions
262 } else {
263 warning "$test_name tests suppressed." 0
264 }
This page took 0.034794 seconds and 4 git commands to generate.