Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.cp / userdef.cc
blob7e045e46b3baf8b2fd6cc6a8be9124da78be59f7
1 /* This test script is part of GDB, the GNU debugger.
3 Copyright 1999-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #include <iostream>
20 using namespace std;
22 void marker1()
24 return;
27 class A1 {
28 int x;
29 int y;
31 friend ostream& operator<<(ostream& outs, A1 one);
33 public:
35 A1(int a, int b)
37 x=a;
38 y=b;
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&);
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);
74 A1 A1::operator+(const A1& second)
76 A1 sum(0,0);
77 sum.x = x + second.x;
78 sum.y = y + second.y;
80 return (sum);
83 A1 A1::operator*(const A1& second)
85 A1 product(0,0);
86 product.x = this->x * second.x;
87 product.y = this->y * second.y;
89 return product;
92 A1 A1::operator-(const A1& second)
94 A1 diff(0,0);
95 diff.x = x - second.x;
96 diff.y = y - second.y;
98 return diff;
101 A1 A1::operator/(const A1& second)
103 A1 div(0,0);
104 div.x = x / second.x;
105 div.y = y / second.y;
107 return div;
110 A1 A1::operator%(const A1& second)
112 A1 rem(0,0);
113 rem.x = x % second.x;
114 rem.y = y % second.y;
116 return rem;
119 int A1::operator==(const A1& second)
121 int a = (x == second.x);
122 int b = (y == second.y);
124 return (a && b);
127 int A1::operator!=(const A1& second)
129 int a = (x != second.x);
130 int b = (y != second.y);
132 return (a || b);
135 int A1::operator&&(const A1& second)
137 return ( x && second.x);
140 int A1::operator||(const A1& second)
142 return ( x || second.x);
145 A1 A1::operator<<(int value)
147 A1 lshft(0,0);
148 lshft.x = x << value;
149 lshft.y = y << value;
151 return lshft;
154 A1 A1::operator>>(int value)
156 A1 rshft(0,0);
157 rshft.x = x >> value;
158 rshft.y = y >> value;
160 return rshft;
163 A1 A1::operator|(const A1& second)
165 A1 abitor(0,0);
166 abitor.x = x | second.x;
167 abitor.y = y | second.y;
169 return abitor;
172 A1 A1::operator^(const A1& second)
174 A1 axor(0,0);
175 axor.x = x ^ second.x;
176 axor.y = y ^ second.y;
178 return axor;
181 A1 A1::operator&(const A1& second)
183 A1 abitand(0,0);
184 abitand.x = x & second.x;
185 abitand.y = y & second.y;
187 return abitand;
190 int A1::operator<(const A1& second)
192 A1 b(0,0);
193 b.x = 3;
194 return (x < second.x);
197 int A1::operator<=(const A1& second)
199 return (x <= second.x);
202 int A1::operator>=(const A1& second)
204 return (x >= second.x);
207 int A1::operator>(const A1& second)
209 return (x > second.x);
212 int A1::operator!(void)
214 return (!x);
217 A1 A1::operator-(void)
219 A1 neg(0,0);
220 neg.x = -x;
221 neg.y = -y;
223 return (neg);
226 A1 A1::operator+(void)
228 A1 pos(0,0);
229 pos.x = +x;
230 pos.y = +y;
232 return (pos);
235 A1 A1::operator~(void)
237 A1 acompl(0,0);
238 acompl.x = ~x;
239 acompl.y = ~y;
241 return (acompl);
244 A1 A1::operator++() // pre increment
246 x = x +1;
248 return (*this);
251 A1 A1::operator++(int) // post increment
253 y = y +1;
255 return (*this);
258 A1 A1::operator--() // pre decrement
260 x = x -1;
262 return (*this);
265 A1 A1::operator--(int) // post decrement
267 y = y -1;
269 return (*this);
273 A1 A1::operator=(const A1& second)
276 x = second.x;
277 y = second.y;
279 return (*this);
282 A1 A1::operator+=(int value)
285 x += value;
286 y += value;
288 return (*this);
291 ostream& operator<<(ostream& outs, A1 one)
293 return (outs << endl << "x = " << one.x << endl << "y = " << one.y << endl << "-------" << endl);
296 class A2 {
297 public:
298 A2 operator+();
301 A2 A2::operator+()
303 return A2 ();
306 class Member
308 public:
309 int z;
311 int operator() ();
312 int operator() (int);
315 int Member::operator() ()
317 return z;
320 int Member::operator() (int value)
322 return value * z;
325 bool operator== (const Member &m1, const Member &m2)
327 return m1.z == m2.z;
330 class Container
332 public:
333 Member m;
335 Member& operator* ();
338 Member& Container::operator* ()
340 return this->m;
343 int main (void)
345 A1 one(2,3);
346 A1 two(4,5);
347 A1 three(0,0);
348 Container c;
349 Member mem1, mem2;
350 int val;
351 Member Container::* mptr = &Container::m;
353 mem1.z = 5;
354 mem2.z = 7;
355 c.m.z = 8;
357 marker1(); // marker1-returns-here
358 cout << one; // marker1-returns-here
359 cout << two;
360 three = one + two;
361 cout << "+ " << three;
362 three = one - two;
363 cout << "- " << three;
364 three = one * two;
365 cout <<"* " << three;
366 three = one / two;
367 cout << "/ " << three;
368 three = one % two;
369 cout << "% " << three;
370 three = one | two;
371 cout << "| " <<three;
372 three = one ^ two;
373 cout << "^ " <<three;
374 three = one & two;
375 cout << "& "<< three;
377 val = one && two;
378 cout << "&& " << val << endl << "-----"<<endl;
379 val = one || two;
380 cout << "|| " << val << endl << "-----"<<endl;
381 val = one == two;
382 cout << " == " << val << endl << "-----"<<endl;
383 val = one != two;
384 cout << "!= " << val << endl << "-----"<<endl;
385 val = one >= two;
386 cout << ">= " << val << endl << "-----"<<endl;
387 val = one <= two;
388 cout << "<= " << val << endl << "-----"<<endl;
389 val = one < two;
390 cout << "< " << val << endl << "-----"<<endl;
391 val = one > two;
392 cout << "> " << val << endl << "-----"<<endl;
394 three = one << 2;
395 cout << "lsh " << three;
396 three = one >> 2;
397 cout << "rsh " << three;
399 three = one;
400 cout << " = "<< three;
401 three += 5;
402 cout << " += "<< three;
404 val = (!one);
405 cout << "! " << val << endl << "-----"<<endl;
406 three = (+one);
407 cout << "+ " << three;
408 three = (-one);
409 cout << "- " << three;
410 three = (~one);
411 cout << " ~" << three;
412 three++;
413 cout << "postinc " << three;
414 three--;
415 cout << "postdec " << three;
417 --three;
418 cout << "predec " << three;
419 ++three;
420 cout << "preinc " << three;
422 val = mem1 ();
423 cout << "funcall " << val << endl;
424 val = mem1 (10);
425 cout << "funcall 2 " << val << endl;
426 val = (c.*mptr) (11);
427 cout << "funcall 3 " << val << endl;
429 (*c).z = 1;
431 return 0;