Files
binutils-gdb/gdb/testsuite/gdb.dlang/expression.exp
Andrew Burgess 1d506c26d9 Update copyright year range in header of all files managed by GDB
This commit is the result of the following actions:

  - Running gdb/copyright.py to update all of the copyright headers to
    include 2024,

  - Manually updating a few files the copyright.py script told me to
    update, these files had copyright headers embedded within the
    file,

  - Regenerating gdbsupport/Makefile.in to refresh it's copyright
    date,

  - Using grep to find other files that still mentioned 2023.  If
    these files were updated last year from 2022 to 2023 then I've
    updated them this year to 2024.

I'm sure I've probably missed some dates.  Feel free to fix them up as
you spot them.
2024-01-12 15:49:57 +00:00

139 lines
4.7 KiB
Plaintext

# Copyright (C) 2014-2024 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/>.
# Test basic builtin types.
# NOTE: The tests here intentionally do not require a D compiler.
load_lib "d-support.exp"
require allow_d_tests
proc test_d_integer_literals {} {
# Test valid D integer literals are accepted.
gdb_test "print 123456" " = 123456"
gdb_test "print 123_456" " = 123456"
gdb_test "print 1_2_3_4_5_6_" " = 123456"
gdb_test "print 0x123456" " = 1193046"
gdb_test "print 0x123_456" " = 1193046"
gdb_test "print 0x1_2_3_4_5_6_" " = 1193046"
gdb_test "print 0123456" " = 42798"
gdb_test "print 0123_456" " = 42798"
gdb_test "print 01_2_3_4_5_6_" " = 42798"
gdb_test "print 0b101010" " = 42"
gdb_test "print 0b101_010" " = 42"
gdb_test "print 0b1_0_1_0_1_0_" " = 42"
# Usual decimal notation
gdb_test "ptype 0" "type = int"
gdb_test "ptype 2_147_483_647" "type = int"
gdb_test "ptype 2_147_483_648" "type = long"
gdb_test "ptype 4_294_967_296" "type = long"
# Explicit suffixes
gdb_test "ptype 0L" "type = long"
gdb_test "ptype 2_147_483_648U" "type = uint"
gdb_test "ptype 4_294_967_296U" "type = ulong"
gdb_test "ptype 0UL" "type = ulong"
gdb_test "ptype 0LU" "type = ulong"
# Hexadecimal notation
gdb_test "ptype 0x0" "type = int"
gdb_test "ptype 0x7FFF_FFFF" "type = int"
gdb_test "ptype 0x8000_0000" "type = uint"
gdb_test "ptype 0x1_0000_0000" "type = long"
# Hexadecimal notation with explicit suffixes
gdb_test "ptype 0x0L" "type = long"
gdb_test "ptype 0x7FFF_FFFFU" "type = uint"
gdb_test "ptype 0x1_0000_0000U" "type = ulong"
gdb_test "ptype 0x0UL" "type = ulong"
gdb_test "ptype 0x0LU" "type = ulong"
# Octal notation
gdb_test "ptype 00" "type = int"
gdb_test "ptype 017_777_777_777" "type = int"
gdb_test "ptype 020_000_000_000" "type = uint"
gdb_test "ptype 040_000_000_000" "type = long"
# Octal notation with explicit suffixes
gdb_test "ptype 00L" "type = long"
gdb_test "ptype 017_777_777_777U" "type = uint"
gdb_test "ptype 040_000_000_000U" "type = ulong"
gdb_test "ptype 00UL" "type = ulong"
gdb_test "ptype 00LU" "type = ulong"
# Binary notation
gdb_test "ptype 0b0" "type = int"
gdb_test "ptype 0b1111111111111111111111111111111" "type = int"
gdb_test "ptype 0b10000000000000000000000000000000" "type = uint"
gdb_test "ptype 0b100000000000000000000000000000000" "type = long"
# Binary notation with explicit suffixes
gdb_test "ptype 0b0L" "type = long"
gdb_test "ptype 0b1111111111111111111111111111111U" "type = uint"
gdb_test "ptype 0b100000000000000000000000000000000U" "type = ulong"
gdb_test "ptype 0b0UL" "type = ulong"
gdb_test "ptype 0b0LU" "type = ulong"
}
proc test_d_float_literals {} {
# Test valid D float literals are accepted.
gdb_test "ptype 123_456.567_8" "type = double"
gdb_test "ptype 1_2_3_4_5_6_._5_6_7_8" "type = double"
gdb_test "ptype 1_2_3_4_5_6_._5e-6_" "type = double"
gdb_test "ptype 0x1.FFFFFFFFFFFFFp1023" "type = double"
gdb_test "ptype 0x1p-52L" "type = real"
gdb_test "ptype 1.175494351e-38F" "type = float"
gdb_test "ptype 6.3i" "type = idouble"
gdb_test "ptype 6.3fi" "type = ifloat"
gdb_test "ptype 6.4Li" "type = ireal"
}
proc test_d_expressions {} {
# Test expression behaviour specific to D.
# Comparison and order expressions have same precedence.
gdb_test "print 1 == 2 > 0" "A syntax error in expression, near `> 0'\."
gdb_test "print (1 == 2) > 0" " = false"
# Exponent expressions
gdb_test "print 5 ^^ 5" "3125"
gdb_test "print 144 ^^ 0.5" "12"
gdb_test "print (-10 ^^ 2)" "-100"
gdb_test "print (-10) ^^ 2" "100"
gdb_test_no_output "set \$var = 144 ^^ 0.5" ""
gdb_test "print \$var ^^= 2" "144"
gdb_test "print 1 ~ \[2, 3\]" " = \\\{1, 2, 3\\\}"
gdb_test "print \[1, 2\] ~ 3" " = \\\{1, 2, 3\\\}"
gdb_test "print \[1, 2\] ~ \[2, 3\]" " = \\\{1, 2, 2, 3\\\}"
}
clean_restart
if [set_lang_d] {
test_d_integer_literals
test_d_float_literals
test_d_expressions
} else {
warning "D type tests suppressed."
}