xref: /openbsd-src/gnu/usr.bin/binutils/gdb/testsuite/gdb.cp/userdef.cc (revision 11efff7f3ac2b3cfeff0c0cddc14294d9b3aca4f)
1 /* This test script is part of GDB, the GNU debugger.
2 
3    Copyright 1999, 2002, 2003, 2004,
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 
marker1()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 
A1(int a,int b)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 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 acompl(0,0);
231  acompl.x = ~x;
232  acompl.y = ~y;
233 
234  return (acompl);
235 }
236 
operator ++()237 A1 A1::operator++() // pre increment
238 {
239  x = x +1;
240 
241  return (*this);
242 }
243 
operator ++(int)244 A1 A1::operator++(int) // post increment
245 {
246  y = y +1;
247 
248  return (*this);
249 }
250 
operator --()251 A1 A1::operator--() // pre decrement
252 {
253  x = x -1;
254 
255  return (*this);
256 }
257 
operator --(int)258 A1 A1::operator--(int) // post decrement
259 {
260  y = y -1;
261 
262  return (*this);
263 }
264 
265 
operator =(const A1 & second)266 A1 A1::operator=(const A1& second)
267 {
268 
269  x = second.x;
270  y = second.y;
271 
272  return (*this);
273 }
274 
operator +=(int value)275 A1 A1::operator+=(int value)
276 {
277 
278  x += value;
279  y += value;
280 
281  return (*this);
282 }
283 
operator <<(ostream & outs,A1 one)284 ostream& operator<<(ostream& outs, A1 one)
285 {
286  return (outs << endl << "x = " << one.x << endl << "y = " << one.y << endl << "-------" << endl);
287 }
288 
main(void)289 int main (void)
290 {
291  A1 one(2,3);
292  A1 two(4,5);
293  A1 three(0,0);
294  int val;
295 
296  marker1(); // marker1-returns-here
297  cout << one; // marker1-returns-here
298  cout << two;
299  three = one + two;
300  cout << "+ " <<  three;
301  three = one - two;
302  cout <<  "- " << three;
303  three = one * two;
304  cout <<"* " <<  three;
305  three = one / two;
306  cout << "/ " << three;
307  three = one % two;
308  cout << "% " << three;
309  three = one | two;
310  cout << "| " <<three;
311  three = one ^ two;
312  cout << "^ " <<three;
313  three = one & two;
314  cout << "& "<< three;
315 
316  val = one && two;
317  cout << "&& " << val << endl << "-----"<<endl;
318  val = one || two;
319  cout << "|| " << val << endl << "-----"<<endl;
320  val = one == two;
321  cout << " == " << val << endl << "-----"<<endl;
322  val = one != two;
323  cout << "!= " << val << endl << "-----"<<endl;
324  val = one >= two;
325  cout << ">= " << val << endl << "-----"<<endl;
326  val = one <= two;
327  cout << "<= " << val << endl << "-----"<<endl;
328  val = one < two;
329  cout << "< " << val << endl << "-----"<<endl;
330  val = one > two;
331  cout << "> " << val << endl << "-----"<<endl;
332 
333  three = one << 2;
334  cout << "lsh " << three;
335  three = one >> 2;
336  cout << "rsh " << three;
337 
338  three = one;
339  cout << " = "<< three;
340  three += 5;
341  cout << " += "<< three;
342 
343  val = (!one);
344  cout << "! " << val << endl << "-----"<<endl;
345  three = (-one);
346  cout << "- " << three;
347  three = (~one);
348  cout << " ~" << three;
349  three++;
350  cout << "postinc " << three;
351  three--;
352  cout << "postdec " << three;
353 
354  --three;
355  cout << "predec " << three;
356  ++three;
357  cout << "preinc " << three;
358 
359  return 0;
360 
361 }
362