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