1/* This test script is part of GDB, the GNU debugger.
2
3   Copyright 1999, 2002, 2003, 2004, 2005, 2006, 2007
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
8   the Free Software Foundation; either version 3 of the License, or
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.
15
16   You should have received a copy of the GNU General Public License
17   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19
20#include <iostream>
21
22using namespace std;
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~();
65A1 operator+();
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
228A1 A1::operator+(void)
229{
230 A1 pos(0,0);
231 pos.x = +x;
232 pos.y = +y;
233
234 return (pos);
235}
236
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
298class A2 {
299  public:
300A2 operator+();
301};
302
303A2 A2::operator+()
304{
305  return A2 ();
306}
307
308class Member
309{
310public:
311  int z;
312};
313
314class Container
315{
316public:
317  Member m;
318
319  Member& operator* ();
320};
321
322Member& Container::operator* ()
323{
324  return this->m;
325}
326
327int main (void)
328{
329 A1 one(2,3);
330 A1 two(4,5);
331 A1 three(0,0);
332 Container c;
333 int val;
334
335 marker1(); // marker1-returns-here
336 cout << one; // marker1-returns-here
337 cout << two;
338 three = one + two;
339 cout << "+ " <<  three;
340 three = one - two;
341 cout <<  "- " << three;
342 three = one * two;
343 cout <<"* " <<  three;
344 three = one / two;
345 cout << "/ " << three;
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
355 val = one && two;
356 cout << "&& " << val << endl << "-----"<<endl;
357 val = one || two;
358 cout << "|| " << val << endl << "-----"<<endl;
359 val = one == two;
360 cout << " == " << val << endl << "-----"<<endl;
361 val = one != two;
362 cout << "!= " << val << endl << "-----"<<endl;
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
372 three = one << 2;
373 cout << "lsh " << three;
374 three = one >> 2;
375 cout << "rsh " << three;
376
377 three = one;
378 cout << " = "<< three;
379 three += 5;
380 cout << " += "<< three;
381
382 val = (!one);
383 cout << "! " << val << endl << "-----"<<endl;
384 three = (+one);
385 cout << "+ " << three;
386 three = (-one);
387 cout << "- " << three;
388 three = (~one);
389 cout << " ~" << three;
390 three++;
391 cout << "postinc " << three;
392 three--;
393 cout << "postdec " << three;
394
395 --three;
396 cout << "predec " << three;
397 ++three;
398 cout << "preinc " << three;
399
400 (*c).z = 1;
401
402 return 0;
403
404}
405