1# Copyright (C) 2014-2020 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# Test basic builtin types. 17# NOTE: The tests here intentionally do not require a D compiler. 18 19load_lib "d-support.exp" 20 21if { [skip_d_tests] } { continue } 22 23proc test_d_integer_literals {} { 24 # Test valid D integer literals are accepted. 25 26 gdb_test "print 123456" " = 123456" 27 gdb_test "print 123_456" " = 123456" 28 gdb_test "print 1_2_3_4_5_6_" " = 123456" 29 30 gdb_test "print 0x123456" " = 1193046" 31 gdb_test "print 0x123_456" " = 1193046" 32 gdb_test "print 0x1_2_3_4_5_6_" " = 1193046" 33 34 gdb_test "print 0123456" " = 42798" 35 gdb_test "print 0123_456" " = 42798" 36 gdb_test "print 01_2_3_4_5_6_" " = 42798" 37 38 gdb_test "print 0b101010" " = 42" 39 gdb_test "print 0b101_010" " = 42" 40 gdb_test "print 0b1_0_1_0_1_0_" " = 42" 41 42 # Usual decimal notation 43 gdb_test "ptype 0" "type = int" 44 gdb_test "ptype 2_147_483_647" "type = int" 45 gdb_test "ptype 2_147_483_648" "type = long" 46 gdb_test "ptype 4_294_967_296" "type = long" 47 48 # Explicit suffixes 49 gdb_test "ptype 0L" "type = long" 50 gdb_test "ptype 2_147_483_648U" "type = uint" 51 gdb_test "ptype 4_294_967_296U" "type = ulong" 52 gdb_test "ptype 0UL" "type = ulong" 53 gdb_test "ptype 0LU" "type = ulong" 54 55 # Hexadecimal notation 56 gdb_test "ptype 0x0" "type = int" 57 gdb_test "ptype 0x7FFF_FFFF" "type = int" 58 gdb_test "ptype 0x8000_0000" "type = uint" 59 gdb_test "ptype 0x1_0000_0000" "type = long" 60 61 # Hexadecimal notation with explicit suffixes 62 gdb_test "ptype 0x0L" "type = long" 63 gdb_test "ptype 0x7FFF_FFFFU" "type = uint" 64 gdb_test "ptype 0x1_0000_0000U" "type = ulong" 65 gdb_test "ptype 0x0UL" "type = ulong" 66 gdb_test "ptype 0x0LU" "type = ulong" 67 68 # Octal notation 69 gdb_test "ptype 00" "type = int" 70 gdb_test "ptype 017_777_777_777" "type = int" 71 gdb_test "ptype 020_000_000_000" "type = uint" 72 gdb_test "ptype 040_000_000_000" "type = long" 73 74 # Octal notation with explicit suffixes 75 gdb_test "ptype 00L" "type = long" 76 gdb_test "ptype 017_777_777_777U" "type = uint" 77 gdb_test "ptype 040_000_000_000U" "type = ulong" 78 gdb_test "ptype 00UL" "type = ulong" 79 gdb_test "ptype 00LU" "type = ulong" 80 81 # Binary notation 82 gdb_test "ptype 0b0" "type = int" 83 gdb_test "ptype 0b1111111111111111111111111111111" "type = int" 84 gdb_test "ptype 0b10000000000000000000000000000000" "type = uint" 85 gdb_test "ptype 0b100000000000000000000000000000000" "type = long" 86 87 # Binary notation with explicit suffixes 88 gdb_test "ptype 0b0L" "type = long" 89 gdb_test "ptype 0b1111111111111111111111111111111U" "type = uint" 90 gdb_test "ptype 0b100000000000000000000000000000000U" "type = ulong" 91 gdb_test "ptype 0b0UL" "type = ulong" 92 gdb_test "ptype 0b0LU" "type = ulong" 93} 94 95proc test_d_float_literals {} { 96 # Test valid D float literals are accepted. 97 98 gdb_test "ptype 123_456.567_8" "type = double" 99 gdb_test "ptype 1_2_3_4_5_6_._5_6_7_8" "type = double" 100 gdb_test "ptype 1_2_3_4_5_6_._5e-6_" "type = double" 101 gdb_test "ptype 0x1.FFFFFFFFFFFFFp1023" "type = double" 102 gdb_test "ptype 0x1p-52L" "type = real" 103 gdb_test "ptype 1.175494351e-38F" "type = float" 104 gdb_test "ptype 6.3i" "type = idouble" 105 gdb_test "ptype 6.3fi" "type = ifloat" 106 gdb_test "ptype 6.4Li" "type = ireal" 107} 108 109proc test_d_expressions {} { 110 # Test expression behaviour specific to D. 111 112 # Comparison and order expressions have same precedence. 113 gdb_test "print 1 == 2 > 0" "A syntax error in expression, near `> 0'\." 114 gdb_test "print (1 == 2) > 0" " = false" 115 116 # Exponent expressions 117 gdb_test "print 5 ^^ 5" "3125" 118 gdb_test "print 144 ^^ 0.5" "12" 119 gdb_test "print (-10 ^^ 2)" "-100" 120 gdb_test "print (-10) ^^ 2" "100" 121 122 gdb_test_no_output "set \$var = 144 ^^ 0.5" "" 123 gdb_test "print \$var ^^= 2" "144" 124} 125 126# Start with a fresh gdb. 127 128gdb_exit 129gdb_start 130 131if [set_lang_d] { 132 test_d_integer_literals 133 test_d_float_literals 134 test_d_expressions 135} else { 136 warning "D type tests suppressed." 137} 138