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