Automatic Copyright Year update after running gdb/copyright.py
[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
88b9d363 3 Copyright 1999-2022 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
47d48711 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
2efb12e8 17
ea2119ec
JM
18#include <iostream>
19
20using namespace std;
c906108c
SS
21
22void marker1()
23{
24 return;
25}
26
27class A1 {
28 int x;
29 int y;
30
31friend ostream& operator<<(ostream& outs, A1 one);
32
33public:
34
35 A1(int a, int b)
36 {
37 x=a;
38 y=b;
39 }
40
41A1 operator+=(int value);
42A1 operator+(const A1&);
43A1 operator-(const A1&);
44A1 operator%(const A1&);
45int operator==(const A1&);
46int operator!=(const A1&);
47int operator&&(const A1&);
48int operator||(const A1&);
49A1 operator<<(int);
50A1 operator>>(int);
51A1 operator|(const A1&);
52A1 operator^(const A1&);
53A1 operator&(const A1&);
54int operator<(const A1&);
55int operator<=(const A1&);
56int operator>=(const A1&);
57int operator>(const A1&);
58A1 operator*(const A1&);
59A1 operator/(const A1&);
60A1 operator=(const A1&);
61
62A1 operator~();
36e9969c 63A1 operator+();
c906108c
SS
64A1 operator-();
65int operator!();
66A1 operator++();
67A1 operator++(int);
68A1 operator--();
69A1 operator--(int);
70
71};
72
73
74A1 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
83A1 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
92A1 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
101A1 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
110A1 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
119int 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
127int 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
135int A1::operator&&(const A1& second)
136{
137 return ( x && second.x);
138}
139
140int A1::operator||(const A1& second)
141{
142 return ( x || second.x);
143}
144
145A1 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
154A1 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
163A1 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
172A1 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
181A1 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
190int A1::operator<(const A1& second)
191{
192 A1 b(0,0);
193 b.x = 3;
194 return (x < second.x);
195}
196
197int A1::operator<=(const A1& second)
198{
199 return (x <= second.x);
200}
201
202int A1::operator>=(const A1& second)
203{
204 return (x >= second.x);
205}
206
207int A1::operator>(const A1& second)
208{
209 return (x > second.x);
210}
211
212int A1::operator!(void)
213{
214 return (!x);
215}
216
217A1 A1::operator-(void)
218{
219 A1 neg(0,0);
220 neg.x = -x;
221 neg.y = -y;
222
223 return (neg);
224}
225
36e9969c
NS
226A1 A1::operator+(void)
227{
228 A1 pos(0,0);
229 pos.x = +x;
230 pos.y = +y;
231
232 return (pos);
233}
234
c906108c
SS
235A1 A1::operator~(void)
236{
237 A1 acompl(0,0);
238 acompl.x = ~x;
239 acompl.y = ~y;
240
241 return (acompl);
242}
243
244A1 A1::operator++() // pre increment
245{
246 x = x +1;
247
248 return (*this);
249}
250
251A1 A1::operator++(int) // post increment
252{
253 y = y +1;
254
255 return (*this);
256}
257
258A1 A1::operator--() // pre decrement
259{
260 x = x -1;
261
262 return (*this);
263}
264
265A1 A1::operator--(int) // post decrement
266{
267 y = y -1;
268
269 return (*this);
270}
271
272
273A1 A1::operator=(const A1& second)
274{
275
276 x = second.x;
277 y = second.y;
278
279 return (*this);
280}
281
282A1 A1::operator+=(int value)
283{
284
285 x += value;
286 y += value;
287
288 return (*this);
289}
290
291ostream& operator<<(ostream& outs, A1 one)
292{
293 return (outs << endl << "x = " << one.x << endl << "y = " << one.y << endl << "-------" << endl);
294}
295
36e9969c
NS
296class A2 {
297 public:
298A2 operator+();
299};
300
301A2 A2::operator+()
302{
303 return A2 ();
304}
305
ab5c9f60
DJ
306class Member
307{
308public:
309 int z;
310};
311
6e31430b
TT
312bool operator== (const Member &m1, const Member &m2)
313{
314 return m1.z == m2.z;
315}
316
ab5c9f60
DJ
317class Container
318{
319public:
320 Member m;
321
322 Member& operator* ();
323};
324
325Member& Container::operator* ()
326{
327 return this->m;
328}
36e9969c 329
c906108c
SS
330int main (void)
331{
332 A1 one(2,3);
333 A1 two(4,5);
334 A1 three(0,0);
ab5c9f60 335 Container c;
6e31430b 336 Member mem1, mem2;
c906108c
SS
337 int val;
338
6e31430b
TT
339 mem1.z = 5;
340 mem2.z = 7;
341
93201743
JB
342 marker1(); // marker1-returns-here
343 cout << one; // marker1-returns-here
c906108c
SS
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;
36e9969c
NS
391 three = (+one);
392 cout << "+ " << three;
c906108c
SS
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
ab5c9f60
DJ
407 (*c).z = 1;
408
c906108c
SS
409 return 0;
410
411}
This page took 2.720375 seconds and 4 git commands to generate.