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