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