binutils-gdb/gdb/testsuite/gdb.ada/operator_call.exp
Tom Tromey c04da66c26 Implement Ada operator overloading
In the expression rewrite, I neglected to carry over support for Ada
operator overloading.  It turns out that there were no tests for this
in-tree.

This patch adds support for operator overloading, and adds the missing
test.

gdb/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (numeric_type_p, integer_type_p): Return true for
	fixed-point.
	* ada-exp.y (maybe_overload): New function.
	(ada_wrap_overload): New function.
	(ada_un_wrap2, ada_wrap2, ada_wrap_op): Use maybe_overload.
	(exp1, simple_exp, relation, and_exp, and_then_exp, or_exp)
	(or_else_exp, xor_exp, primary): Update.

gdb/testsuite/ChangeLog
2021-03-15  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/operator_call/twovecs.ads: New file.
	* gdb.ada/operator_call/twovecs.adb: New file.
	* gdb.ada/operator_call/opcall.adb: New file.
	* gdb.ada/operator_call.exp: New file.
2021-03-15 06:23:13 -06:00

116 lines
3.3 KiB
Plaintext

# Copyright 2021 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/>.
load_lib "ada.exp"
if { [skip_ada_tests] } { return -1 }
standard_ada_testfile opcall
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
return -1
}
clean_restart ${testfile}
set bp_location [gdb_get_line_number "STOP" ${testdir}/opcall.adb]
runto "opcall.adb:$bp_location"
gdb_test "print p" " = \\(x => 4, y => 5\\)"
proc test_with_menu {command result} {
global expect_out
set rxcmd [string_to_regexp $command]
set num {}
send_gdb "$command\n"
gdb_expect 30 {
-re "^$rxcmd\r\n" {
exp_continue
}
-re "Multiple matches for \[^\r\n\]*\r\n" {
exp_continue
}
-re "^\\\[(\[0-9\]+)\\\] twovecs\\.*\[^\r\n\]*\r\n" {
set num $expect_out(1,string)
exp_continue
}
-re "^\\\[\[0-9\]+\\\] \[^\r\n\]*\r\n" {
# Any other match, we don't want.
exp_continue
}
-re "^> " {
if {$num == ""} {
fail $command
set num 0
}
send_gdb "$num\n"
exp_continue
}
-re "^\[0-9\]+\r\n" {
# The number we just sent, ignore.
exp_continue
}
-re "\\\$\[0-9\]+ = (\[^\r\n\]+)\r\n" {
if {[regexp $result $expect_out(1,string)]} {
pass $command
} else {
fail $command
}
}
timeout {
fail "$command (timeout)"
}
}
}
test_with_menu "print p + p" "\\(x => 8, y => 10\\)"
test_with_menu "print p - p" "\\(x => 0, y => 0\\)"
test_with_menu "print p * p" "\\(x => 16, y => 25\\)"
test_with_menu "print p / p" "\\(x => 1, y => 1\\)"
# See the code to understand the weird numbers here.
test_with_menu "print p mod p" "\\(x => 17, y => 18\\)"
test_with_menu "print p rem p" "\\(x => 38, y => 39\\)"
test_with_menu "print p ** p" "\\(x => 84, y => 105\\)"
test_with_menu "print p < p" "false"
test_with_menu "print p < p2" "true"
test_with_menu "print p <= p" "true"
test_with_menu "print p <= p2" "true"
test_with_menu "print p > p" "false"
test_with_menu "print p2 > p" "true"
test_with_menu "print p >= p" "true"
test_with_menu "print p2 >= p" "true"
test_with_menu "print p = p" "true"
test_with_menu "print p = p2" "false"
test_with_menu "print p /= p" "false"
test_with_menu "print p /= p2" "true"
test_with_menu "print p and p2" "\\(x => 4, y => 4\\)"
test_with_menu "print p or p2" "\\(x => 12, y => 13\\)"
test_with_menu "print p xor p2" "\\(x => 8, y => 9\\)"
# See the code to understand the weird numbers here.
test_with_menu "print p & p" "\\(x => 44, y => 55\\)"
test_with_menu "print -p" "\\(x => 65532, y => 65531\\)"
test_with_menu "print abs(-p)" "\\(x => 65532, y => 65531\\)"
test_with_menu "print not(p)" "\\(x => 65531, y => 65530\\)"
# See the code to understand the weird numbers here.
test_with_menu "print +(p)" "\\(x => 5, y => 4\\)"