Copyright year update in most files of the GDB Project.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / userdef.cc
1 /* This test script is part of GDB, the GNU debugger.
2
3 Copyright 1999, 2002-2012 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
19 #include <iostream>
20
21 using namespace std;
22
23 void marker1()
24 {
25 return;
26 }
27
28 class A1 {
29 int x;
30 int y;
31
32 friend ostream& operator<<(ostream& outs, A1 one);
33
34 public:
35
36 A1(int a, int b)
37 {
38 x=a;
39 y=b;
40 }
41
42 A1 operator+=(int value);
43 A1 operator+(const A1&);
44 A1 operator-(const A1&);
45 A1 operator%(const A1&);
46 int operator==(const A1&);
47 int operator!=(const A1&);
48 int operator&&(const A1&);
49 int operator||(const A1&);
50 A1 operator<<(int);
51 A1 operator>>(int);
52 A1 operator|(const A1&);
53 A1 operator^(const A1&);
54 A1 operator&(const A1&);
55 int operator<(const A1&);
56 int operator<=(const A1&);
57 int operator>=(const A1&);
58 int operator>(const A1&);
59 A1 operator*(const A1&);
60 A1 operator/(const A1&);
61 A1 operator=(const A1&);
62
63 A1 operator~();
64 A1 operator+();
65 A1 operator-();
66 int operator!();
67 A1 operator++();
68 A1 operator++(int);
69 A1 operator--();
70 A1 operator--(int);
71
72 };
73
74
75 A1 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
84 A1 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
93 A1 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
102 A1 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
111 A1 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
120 int 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
128 int 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
136 int A1::operator&&(const A1& second)
137 {
138 return ( x && second.x);
139 }
140
141 int A1::operator||(const A1& second)
142 {
143 return ( x || second.x);
144 }
145
146 A1 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
155 A1 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
164 A1 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
173 A1 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
182 A1 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
191 int A1::operator<(const A1& second)
192 {
193 A1 b(0,0);
194 b.x = 3;
195 return (x < second.x);
196 }
197
198 int A1::operator<=(const A1& second)
199 {
200 return (x <= second.x);
201 }
202
203 int A1::operator>=(const A1& second)
204 {
205 return (x >= second.x);
206 }
207
208 int A1::operator>(const A1& second)
209 {
210 return (x > second.x);
211 }
212
213 int A1::operator!(void)
214 {
215 return (!x);
216 }
217
218 A1 A1::operator-(void)
219 {
220 A1 neg(0,0);
221 neg.x = -x;
222 neg.y = -y;
223
224 return (neg);
225 }
226
227 A1 A1::operator+(void)
228 {
229 A1 pos(0,0);
230 pos.x = +x;
231 pos.y = +y;
232
233 return (pos);
234 }
235
236 A1 A1::operator~(void)
237 {
238 A1 acompl(0,0);
239 acompl.x = ~x;
240 acompl.y = ~y;
241
242 return (acompl);
243 }
244
245 A1 A1::operator++() // pre increment
246 {
247 x = x +1;
248
249 return (*this);
250 }
251
252 A1 A1::operator++(int) // post increment
253 {
254 y = y +1;
255
256 return (*this);
257 }
258
259 A1 A1::operator--() // pre decrement
260 {
261 x = x -1;
262
263 return (*this);
264 }
265
266 A1 A1::operator--(int) // post decrement
267 {
268 y = y -1;
269
270 return (*this);
271 }
272
273
274 A1 A1::operator=(const A1& second)
275 {
276
277 x = second.x;
278 y = second.y;
279
280 return (*this);
281 }
282
283 A1 A1::operator+=(int value)
284 {
285
286 x += value;
287 y += value;
288
289 return (*this);
290 }
291
292 ostream& operator<<(ostream& outs, A1 one)
293 {
294 return (outs << endl << "x = " << one.x << endl << "y = " << one.y << endl << "-------" << endl);
295 }
296
297 class A2 {
298 public:
299 A2 operator+();
300 };
301
302 A2 A2::operator+()
303 {
304 return A2 ();
305 }
306
307 class Member
308 {
309 public:
310 int z;
311 };
312
313 bool operator== (const Member &m1, const Member &m2)
314 {
315 return m1.z == m2.z;
316 }
317
318 class Container
319 {
320 public:
321 Member m;
322
323 Member& operator* ();
324 };
325
326 Member& Container::operator* ()
327 {
328 return this->m;
329 }
330
331 int main (void)
332 {
333 A1 one(2,3);
334 A1 two(4,5);
335 A1 three(0,0);
336 Container c;
337 Member mem1, mem2;
338 int val;
339
340 mem1.z = 5;
341 mem2.z = 7;
342
343 marker1(); // marker1-returns-here
344 cout << one; // marker1-returns-here
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;
392 three = (+one);
393 cout << "+ " << three;
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
408 (*c).z = 1;
409
410 return 0;
411
412 }
This page took 0.038896 seconds and 5 git commands to generate.