1# Copyright 2012-2023 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
16set nl		"\[\r\n\]+"
17
18if { [skip_cplus_tests] } { continue }
19
20load_lib "cp-support.exp"
21
22standard_testfile .cc
23
24if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
25    return -1
26}
27
28if {![runto_main]} {
29    return
30}
31
32if {[test_compiler_info {clang-*-*} c++]} {
33    set using_clang true
34} else {
35    set using_clang false
36}
37
38gdb_test_no_output "set language c++" ""
39gdb_test_no_output "set width 0" ""
40
41proc do_check_holder {name {flags ""} {show_typedefs 1} {show_methods 1}
42		      {raw 0}} {
43    global using_clang
44
45    set contents {
46	{ base "public Base<T>" }
47	{ field public "Simple<T> t;" }
48	{ field public "Simple<T*> tstar;" }
49    }
50
51    if {$raw} {
52	lappend contents { field public "Holder<int>::Z z;" }
53    } else {
54	lappend contents { field public "Z z;" }
55    }
56
57    if {$show_typedefs} {
58	# Clang does not add accessibility information for typedefs:
59	# https://github.com/llvm/llvm-project/issues/57608
60	if {$using_clang} {
61	    setup_xfail "clang 57608" *-*-*
62	}
63	lappend contents { typedef public "typedef Simple<Simple<T> > Z;" }
64    }
65
66    if {$show_methods} {
67	lappend contents { method public "double method();" }
68    }
69
70    if {$raw} {
71	regsub -all -- "T" $contents "int" contents
72    }
73
74    cp_test_ptype_class value $name "class" "Holder<int>" $contents \
75	"" {} $flags
76}
77
78proc do_check_typedef_holder {name {flags ""} {show_typedefs 1} {show_methods 1}
79			      {raw 0}} {
80
81    set contents {
82	{ field public "double a;" }
83	{ field public "ns::scoped_double b;" }
84	{ field public "global_double c;" }
85    }
86
87    if {$show_typedefs} {
88	lappend contents { typedef private "typedef double class_double;" }
89    }
90
91    if {$show_methods} {
92	lappend contents { method private "double method1(ns::scoped_double);" }
93	lappend contents { method private "double method2(global_double);" }
94    }
95
96    if {$raw} {
97	lappend contents { field private "TypedefHolder::class_double d;" }
98    } else {
99	lappend contents { field private "class_double d;" }
100    }
101
102    cp_test_ptype_class value2 $name "class" "TypedefHolder" $contents \
103	"" {} $flags
104}
105
106do_check_holder "basic test"
107do_check_holder "no methods" "/m" 1 0
108do_check_holder "no typedefs" "/t" 0 1
109do_check_holder "no methods or typedefs" "/mt" 0 0
110do_check_typedef_holder "typdefs class: basic test"
111do_check_typedef_holder "typdefs class: no methods" "/m" 1 0
112do_check_typedef_holder "typdefs class: no typedefs" "/t" 0 1 0
113do_check_typedef_holder "typdefs class:no methods or typedefs" "/mt" 0 0
114
115do_check_holder "raw" "/r" 1 1 1
116do_check_holder "raw no methods" "/rm" 1 0 1
117do_check_holder "raw no typedefs" "/rt" 0 1 1
118do_check_holder "raw no methods or typedefs" "/rmt" 0 0 1
119do_check_typedef_holder "typedef class: raw" "/r" 1 1 1
120do_check_typedef_holder "typedef class: raw no methods" "/rm" 1 0 1
121do_check_typedef_holder "typedef class: raw no typedefs" "/rt" 0 1 1
122do_check_typedef_holder "typedef class: raw no methods or typedefs" "/rmt" 0 0 1
123
124gdb_test_no_output "set print type methods off"
125do_check_holder "basic test, default methods off" "" 1 0
126do_check_holder "methods, default methods off" "/M" 1 1
127do_check_holder "no typedefs, default methods off" "/t" 0 0
128do_check_holder "methods, no typedefs, default methods off" "/Mt" 0 1
129do_check_typedef_holder \
130    "typedef class: basic test, default methods off" "" 1 0
131do_check_typedef_holder \
132    "typedef class: methods, default methods off" "/M" 1 1
133do_check_typedef_holder \
134    "typedef class: no typedefs, default methods off" "/t" 0 0
135do_check_typedef_holder \
136    "typedef class: methods, no typedefs, default methods off" "/Mt" 0 1
137
138gdb_test_no_output "set print type typedefs off"
139do_check_holder "basic test, default methods+typedefs off" "" 0 0
140do_check_holder "methods, default methods+typedefs off" "/M" 0 1
141do_check_holder "typedefs, default methods+typedefs off" "/T" 1 0
142do_check_holder "methods typedefs, default methods+typedefs off" "/MT" 1 1
143do_check_typedef_holder \
144    "typedef class: basic test, default methods+typedefs off" "" 0 0
145do_check_typedef_holder \
146    "typedef class: methods, default methods+typedefs off" "/M" 0 1
147do_check_typedef_holder \
148    "typedef class: typedefs, default methods+typedefs off" "/T" 1 0
149do_check_typedef_holder \
150    "typedef class: methods typedefs, default methods+typedefs off" "/MT" 1 1
151