Commit | Line | Data |
---|---|---|
2efb12e8 MC |
1 | /* This test script is part of GDB, the GNU debugger. |
2 | ||
607fbc54 | 3 | Copyright 1999, 2002, 2003, 2004, 2005 |
2efb12e8 MC |
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 | ||
ea2119ec JM |
21 | #include <iostream> |
22 | ||
23 | using namespace std; | |
c906108c SS |
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~(); | |
36e9969c | 66 | A1 operator+(); |
c906108c SS |
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 | ||
36e9969c NS |
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 | ||
c906108c SS |
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 | ||
36e9969c NS |
299 | class A2 { |
300 | public: | |
301 | A2 operator+(); | |
302 | }; | |
303 | ||
304 | A2 A2::operator+() | |
305 | { | |
306 | return A2 (); | |
307 | } | |
308 | ||
309 | ||
c906108c SS |
310 | int main (void) |
311 | { | |
312 | A1 one(2,3); | |
313 | A1 two(4,5); | |
314 | A1 three(0,0); | |
315 | int val; | |
316 | ||
93201743 JB |
317 | marker1(); // marker1-returns-here |
318 | cout << one; // marker1-returns-here | |
c906108c SS |
319 | cout << two; |
320 | three = one + two; | |
321 | cout << "+ " << three; | |
322 | three = one - two; | |
323 | cout << "- " << three; | |
324 | three = one * two; | |
325 | cout <<"* " << three; | |
326 | three = one / two; | |
327 | cout << "/ " << three; | |
328 | three = one % two; | |
329 | cout << "% " << three; | |
330 | three = one | two; | |
331 | cout << "| " <<three; | |
332 | three = one ^ two; | |
333 | cout << "^ " <<three; | |
334 | three = one & two; | |
335 | cout << "& "<< three; | |
336 | ||
337 | val = one && two; | |
338 | cout << "&& " << val << endl << "-----"<<endl; | |
339 | val = one || two; | |
340 | cout << "|| " << val << endl << "-----"<<endl; | |
341 | val = one == two; | |
342 | cout << " == " << val << endl << "-----"<<endl; | |
343 | val = one != two; | |
344 | cout << "!= " << val << endl << "-----"<<endl; | |
345 | val = one >= two; | |
346 | cout << ">= " << val << endl << "-----"<<endl; | |
347 | val = one <= two; | |
348 | cout << "<= " << val << endl << "-----"<<endl; | |
349 | val = one < two; | |
350 | cout << "< " << val << endl << "-----"<<endl; | |
351 | val = one > two; | |
352 | cout << "> " << val << endl << "-----"<<endl; | |
353 | ||
354 | three = one << 2; | |
355 | cout << "lsh " << three; | |
356 | three = one >> 2; | |
357 | cout << "rsh " << three; | |
358 | ||
359 | three = one; | |
360 | cout << " = "<< three; | |
361 | three += 5; | |
362 | cout << " += "<< three; | |
363 | ||
364 | val = (!one); | |
365 | cout << "! " << val << endl << "-----"<<endl; | |
36e9969c NS |
366 | three = (+one); |
367 | cout << "+ " << three; | |
c906108c SS |
368 | three = (-one); |
369 | cout << "- " << three; | |
370 | three = (~one); | |
371 | cout << " ~" << three; | |
372 | three++; | |
373 | cout << "postinc " << three; | |
374 | three--; | |
375 | cout << "postdec " << three; | |
376 | ||
377 | --three; | |
378 | cout << "predec " << three; | |
379 | ++three; | |
380 | cout << "preinc " << three; | |
381 | ||
382 | return 0; | |
383 | ||
384 | } |