]>
Commit | Line | Data |
---|---|---|
c973d0aa PA |
1 | /* This test program is part of GDB, the GNU debugger. |
2 | ||
213516ef | 3 | Copyright 2017-2023 Free Software Foundation, Inc. |
c973d0aa PA |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | /* Define typedefs of different types, for testing the "whatis" and | |
19 | "ptype" commands. */ | |
20 | ||
21 | /* Helper macro used to consistently define variables/typedefs using | |
22 | the same name scheme. BASE is the shared part of the name of all | |
23 | typedefs/variables generated. Defines a variable of the given | |
24 | typedef type, and then a typedef of that typedef and a variable of | |
25 | that new typedef type. The "double typedef" is useful to checking | |
26 | that whatis only strips one typedef level. For example, if BASE is | |
27 | "int", we get: | |
28 | ||
29 | int_typedef v_int_typedef; // "v_" stands for variable of typedef type | |
30 | typedef int_typedef int_typedef2; // typedef-of-typedef | |
31 | int_typedef2 v_int_typedef2; // var of typedef-of-typedef | |
32 | */ | |
33 | #define DEF(base) \ | |
34 | base ## _typedef v_ ## base ## _typedef; \ | |
35 | \ | |
36 | typedef base ## _typedef base ## _typedef2; \ | |
37 | base ## _typedef2 v_ ## base ## _typedef2 | |
38 | ||
39 | /* Void. */ | |
40 | ||
41 | /* (Can't have variables of void type.) */ | |
42 | ||
43 | typedef void void_typedef; | |
44 | typedef void_typedef void_typedef2; | |
45 | ||
46 | void_typedef *v_void_typedef_ptr; | |
47 | void_typedef2 *v_void_typedef_ptr2; | |
48 | ||
49 | /* Integers. */ | |
50 | ||
51 | typedef int int_typedef; | |
52 | DEF (int); | |
53 | ||
54 | /* Floats. */ | |
55 | ||
56 | typedef float float_typedef; | |
57 | DEF (float); | |
58 | ||
73fcf641 PA |
59 | /* Double floats. */ |
60 | ||
61 | typedef double double_typedef; | |
62 | DEF (double); | |
63 | ||
64 | /* Long doubles. */ | |
65 | ||
66 | typedef long double long_double_typedef; | |
67 | DEF (long_double); | |
68 | ||
c973d0aa PA |
69 | /* Enums. */ |
70 | ||
71 | typedef enum colors {red, green, blue} colors_typedef; | |
72 | DEF (colors); | |
73 | ||
74 | /* Structures. */ | |
75 | ||
76 | typedef struct t_struct | |
77 | { | |
78 | int member; | |
79 | } t_struct_typedef; | |
80 | DEF (t_struct); | |
81 | ||
82 | /* Unions. */ | |
83 | ||
84 | typedef union t_union | |
85 | { | |
86 | int member; | |
87 | } t_union_typedef; | |
88 | DEF (t_union); | |
89 | ||
90 | /* Arrays. */ | |
91 | ||
92 | typedef int int_array_typedef[3]; | |
93 | DEF (int_array); | |
94 | ||
95 | /* An array the same size of t_struct_typedef, so we can test casting. */ | |
96 | typedef unsigned char uchar_array_t_struct_typedef[sizeof (t_struct_typedef)]; | |
97 | DEF (uchar_array_t_struct); | |
98 | ||
99 | /* A struct and a eunion the same size as t_struct, so we can test | |
100 | casting. */ | |
101 | ||
102 | typedef struct t_struct_wrapper | |
103 | { | |
104 | struct t_struct base; | |
105 | } t_struct_wrapper_typedef; | |
106 | DEF (t_struct_wrapper); | |
107 | ||
108 | typedef union t_struct_union_wrapper | |
109 | { | |
110 | struct t_struct base; | |
111 | } t_struct_union_wrapper_typedef; | |
112 | DEF (t_struct_union_wrapper); | |
113 | ||
114 | /* Functions / function pointers. */ | |
115 | ||
116 | typedef void func_ftype (void); | |
117 | func_ftype *v_func_ftype; | |
118 | ||
119 | typedef func_ftype func_ftype2; | |
120 | func_ftype2 *v_func_ftype2; | |
121 | ||
122 | /* C++ methods / method pointers. */ | |
123 | ||
124 | #ifdef __cplusplus | |
125 | ||
126 | namespace ns { | |
127 | ||
128 | struct Struct { void method (); }; | |
129 | void Struct::method () {} | |
130 | ||
131 | typedef Struct Struct_typedef; | |
132 | DEF (Struct); | |
133 | ||
134 | /* Typedefs/vars in a namespace. */ | |
135 | typedef void (Struct::*method_ptr_typedef) (); | |
136 | DEF (method_ptr); | |
137 | ||
138 | } | |
139 | ||
140 | /* Similar, but in the global namespace. */ | |
141 | typedef ns::Struct ns_Struct_typedef; | |
142 | DEF (ns_Struct); | |
143 | ||
144 | typedef void (ns::Struct::*ns_method_ptr_typedef) (); | |
145 | DEF (ns_method_ptr); | |
146 | ||
147 | #endif | |
148 | ||
149 | int | |
150 | main (void) | |
151 | { | |
152 | return 0; | |
153 | } |