]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-xmethods.cc
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-xmethods.cc
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2014-2016 Free Software Foundation, Inc.
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 namespace dop
19 {
20
21 class A
22 {
23 public:
24 int a;
25 int array [10];
26 virtual ~A ();
27 int operator+ (const A &obj);
28 int operator- (const A &obj);
29 virtual int geta (void);
30 };
31
32 A::~A () { }
33
34 int a_plus_a = 0;
35
36 int
37 A::operator+ (const A &obj)
38 {
39 a_plus_a++;
40 return a + obj.a;
41 }
42
43 int a_minus_a = 0;
44
45 int
46 A::operator- (const A &obj)
47 {
48 a_minus_a++;
49 return a - obj.a;
50 }
51
52 int a_geta = 0;
53
54 int
55 A::geta (void)
56 {
57 a_geta++;
58 return a;
59 }
60
61 class B : public A
62 {
63 public:
64 virtual int geta (void);
65 };
66
67 int b_geta = 0;
68
69 int
70 B::geta (void)
71 {
72 b_geta++;
73 return 2 * a;
74 }
75
76 typedef B Bt;
77
78 typedef Bt Btt;
79
80 class E : public A
81 {
82 public:
83 /* This class has a member named 'a', while the base class also has a
84 member named 'a'. When one invokes A::geta(), A::a should be
85 returned and not E::a as the 'geta' method is defined on class 'A'.
86 This class tests this aspect of debug methods. */
87 int a;
88 };
89
90 template <typename T>
91 class G
92 {
93 public:
94 template <typename T1>
95 int size_diff ();
96
97 template <int M>
98 int size_mul ();
99
100 template <typename T1>
101 T mul(const T1 t1);
102
103 public:
104 T t;
105 };
106
107 int g_size_diff = 0;
108
109 template <typename T>
110 template <typename T1>
111 int
112 G<T>::size_diff ()
113 {
114 g_size_diff++;
115 return sizeof (T1) - sizeof (T);
116 }
117
118 int g_size_mul = 0;
119
120 template <typename T>
121 template <int M>
122 int
123 G<T>::size_mul ()
124 {
125 g_size_mul++;
126 return M * sizeof (T);
127 }
128
129 int g_mul = 0;
130
131 template <typename T>
132 template <typename T1>
133 T
134 G<T>::mul (const T1 t1)
135 {
136 g_mul++;
137 return t1 * t;
138 }
139
140 } // namespaxe dop
141
142 using namespace dop;
143
144 int main(void)
145 {
146 A a1, a2;
147 a1.a = 5;
148 a2.a = 10;
149
150 B b1;
151 b1.a = 30;
152 A *a_ptr = &b1;
153
154 Bt bt;
155 bt.a = 40;
156
157 Btt btt;
158 btt.a = -5;
159
160 G<int> g, *g_ptr;
161 g.t = 5;
162 g_ptr = &g;
163
164 E e;
165 E &e_ref = e;
166 E *e_ptr = &e;
167 e.a = 1000;
168 e.A::a = 100;
169
170 int diff = g.size_diff<float> ();
171 int smul = g.size_mul<2> ();
172 int mul = g.mul (1.0);
173
174 for (int i = 0; i < 10; i++)
175 {
176 a1.array[i] = a2.array[i] = b1.array[i] = i;
177 }
178
179 return 0; /* Break here. */
180 }