]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/userdef.cc
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / userdef.cc
CommitLineData
2efb12e8
MC
1/* This test script is part of GDB, the GNU debugger.
2
6aba47ca 3 Copyright 1999, 2002, 2003, 2004, 2005, 2006, 2007
2efb12e8
MC
4 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
ea2119ec
JM
21#include <iostream>
22
23using namespace std;
c906108c
SS
24
25void marker1()
26{
27 return;
28}
29
30class A1 {
31 int x;
32 int y;
33
34friend ostream& operator<<(ostream& outs, A1 one);
35
36public:
37
38 A1(int a, int b)
39 {
40 x=a;
41 y=b;
42 }
43
44A1 operator+=(int value);
45A1 operator+(const A1&);
46A1 operator-(const A1&);
47A1 operator%(const A1&);
48int operator==(const A1&);
49int operator!=(const A1&);
50int operator&&(const A1&);
51int operator||(const A1&);
52A1 operator<<(int);
53A1 operator>>(int);
54A1 operator|(const A1&);
55A1 operator^(const A1&);
56A1 operator&(const A1&);
57int operator<(const A1&);
58int operator<=(const A1&);
59int operator>=(const A1&);
60int operator>(const A1&);
61A1 operator*(const A1&);
62A1 operator/(const A1&);
63A1 operator=(const A1&);
64
65A1 operator~();
36e9969c 66A1 operator+();
c906108c
SS
67A1 operator-();
68int operator!();
69A1 operator++();
70A1 operator++(int);
71A1 operator--();
72A1 operator--(int);
73
74};
75
76
77A1 A1::operator+(const A1& second)
78{
79 A1 sum(0,0);
80 sum.x = x + second.x;
81 sum.y = y + second.y;
82
83 return (sum);
84}
85
86A1 A1::operator*(const A1& second)
87{
88 A1 product(0,0);
89 product.x = this->x * second.x;
90 product.y = this->y * second.y;
91
92 return product;
93}
94
95A1 A1::operator-(const A1& second)
96{
97 A1 diff(0,0);
98 diff.x = x - second.x;
99 diff.y = y - second.y;
100
101 return diff;
102}
103
104A1 A1::operator/(const A1& second)
105{
106 A1 div(0,0);
107 div.x = x / second.x;
108 div.y = y / second.y;
109
110 return div;
111}
112
113A1 A1::operator%(const A1& second)
114{
115 A1 rem(0,0);
116 rem.x = x % second.x;
117 rem.y = y % second.y;
118
119 return rem;
120}
121
122int A1::operator==(const A1& second)
123{
124 int a = (x == second.x);
125 int b = (y == second.y);
126
127 return (a && b);
128}
129
130int A1::operator!=(const A1& second)
131{
132 int a = (x != second.x);
133 int b = (y != second.y);
134
135 return (a || b);
136}
137
138int A1::operator&&(const A1& second)
139{
140 return ( x && second.x);
141}
142
143int A1::operator||(const A1& second)
144{
145 return ( x || second.x);
146}
147
148A1 A1::operator<<(int value)
149{
150 A1 lshft(0,0);
151 lshft.x = x << value;
152 lshft.y = y << value;
153
154 return lshft;
155}
156
157A1 A1::operator>>(int value)
158{
159 A1 rshft(0,0);
160 rshft.x = x >> value;
161 rshft.y = y >> value;
162
163 return rshft;
164}
165
166A1 A1::operator|(const A1& second)
167{
168 A1 abitor(0,0);
169 abitor.x = x | second.x;
170 abitor.y = y | second.y;
171
172 return abitor;
173}
174
175A1 A1::operator^(const A1& second)
176{
177 A1 axor(0,0);
178 axor.x = x ^ second.x;
179 axor.y = y ^ second.y;
180
181 return axor;
182}
183
184A1 A1::operator&(const A1& second)
185{
186 A1 abitand(0,0);
187 abitand.x = x & second.x;
188 abitand.y = y & second.y;
189
190 return abitand;
191}
192
193int A1::operator<(const A1& second)
194{
195 A1 b(0,0);
196 b.x = 3;
197 return (x < second.x);
198}
199
200int A1::operator<=(const A1& second)
201{
202 return (x <= second.x);
203}
204
205int A1::operator>=(const A1& second)
206{
207 return (x >= second.x);
208}
209
210int A1::operator>(const A1& second)
211{
212 return (x > second.x);
213}
214
215int A1::operator!(void)
216{
217 return (!x);
218}
219
220A1 A1::operator-(void)
221{
222 A1 neg(0,0);
223 neg.x = -x;
224 neg.y = -y;
225
226 return (neg);
227}
228
36e9969c
NS
229A1 A1::operator+(void)
230{
231 A1 pos(0,0);
232 pos.x = +x;
233 pos.y = +y;
234
235 return (pos);
236}
237
c906108c
SS
238A1 A1::operator~(void)
239{
240 A1 acompl(0,0);
241 acompl.x = ~x;
242 acompl.y = ~y;
243
244 return (acompl);
245}
246
247A1 A1::operator++() // pre increment
248{
249 x = x +1;
250
251 return (*this);
252}
253
254A1 A1::operator++(int) // post increment
255{
256 y = y +1;
257
258 return (*this);
259}
260
261A1 A1::operator--() // pre decrement
262{
263 x = x -1;
264
265 return (*this);
266}
267
268A1 A1::operator--(int) // post decrement
269{
270 y = y -1;
271
272 return (*this);
273}
274
275
276A1 A1::operator=(const A1& second)
277{
278
279 x = second.x;
280 y = second.y;
281
282 return (*this);
283}
284
285A1 A1::operator+=(int value)
286{
287
288 x += value;
289 y += value;
290
291 return (*this);
292}
293
294ostream& operator<<(ostream& outs, A1 one)
295{
296 return (outs << endl << "x = " << one.x << endl << "y = " << one.y << endl << "-------" << endl);
297}
298
36e9969c
NS
299class A2 {
300 public:
301A2 operator+();
302};
303
304A2 A2::operator+()
305{
306 return A2 ();
307}
308
ab5c9f60
DJ
309class Member
310{
311public:
312 int z;
313};
314
315class Container
316{
317public:
318 Member m;
319
320 Member& operator* ();
321};
322
323Member& Container::operator* ()
324{
325 return this->m;
326}
36e9969c 327
c906108c
SS
328int main (void)
329{
330 A1 one(2,3);
331 A1 two(4,5);
332 A1 three(0,0);
ab5c9f60 333 Container c;
c906108c
SS
334 int val;
335
93201743
JB
336 marker1(); // marker1-returns-here
337 cout << one; // marker1-returns-here
c906108c
SS
338 cout << two;
339 three = one + two;
340 cout << "+ " << three;
341 three = one - two;
342 cout << "- " << three;
343 three = one * two;
344 cout <<"* " << three;
345 three = one / two;
346 cout << "/ " << three;
347 three = one % two;
348 cout << "% " << three;
349 three = one | two;
350 cout << "| " <<three;
351 three = one ^ two;
352 cout << "^ " <<three;
353 three = one & two;
354 cout << "& "<< three;
355
356 val = one && two;
357 cout << "&& " << val << endl << "-----"<<endl;
358 val = one || two;
359 cout << "|| " << val << endl << "-----"<<endl;
360 val = one == two;
361 cout << " == " << val << endl << "-----"<<endl;
362 val = one != two;
363 cout << "!= " << val << endl << "-----"<<endl;
364 val = one >= two;
365 cout << ">= " << val << endl << "-----"<<endl;
366 val = one <= two;
367 cout << "<= " << val << endl << "-----"<<endl;
368 val = one < two;
369 cout << "< " << val << endl << "-----"<<endl;
370 val = one > two;
371 cout << "> " << val << endl << "-----"<<endl;
372
373 three = one << 2;
374 cout << "lsh " << three;
375 three = one >> 2;
376 cout << "rsh " << three;
377
378 three = one;
379 cout << " = "<< three;
380 three += 5;
381 cout << " += "<< three;
382
383 val = (!one);
384 cout << "! " << val << endl << "-----"<<endl;
36e9969c
NS
385 three = (+one);
386 cout << "+ " << three;
c906108c
SS
387 three = (-one);
388 cout << "- " << three;
389 three = (~one);
390 cout << " ~" << three;
391 three++;
392 cout << "postinc " << three;
393 three--;
394 cout << "postdec " << three;
395
396 --three;
397 cout << "predec " << three;
398 ++three;
399 cout << "preinc " << three;
400
ab5c9f60
DJ
401 (*c).z = 1;
402
c906108c
SS
403 return 0;
404
405}