OSDN Git Service

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