Initial creation of sourceware repository
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.c++ / userdef.cc
CommitLineData
c906108c
SS
1#include <iostream.h>
2
3void marker1()
4{
5 return;
6}
7
8class A1 {
9 int x;
10 int y;
11
12friend ostream& operator<<(ostream& outs, A1 one);
13
14public:
15
16 A1(int a, int b)
17 {
18 x=a;
19 y=b;
20 }
21
22A1 operator+=(int value);
23A1 operator+(const A1&);
24A1 operator-(const A1&);
25A1 operator%(const A1&);
26int operator==(const A1&);
27int operator!=(const A1&);
28int operator&&(const A1&);
29int operator||(const A1&);
30A1 operator<<(int);
31A1 operator>>(int);
32A1 operator|(const A1&);
33A1 operator^(const A1&);
34A1 operator&(const A1&);
35int operator<(const A1&);
36int operator<=(const A1&);
37int operator>=(const A1&);
38int operator>(const A1&);
39A1 operator*(const A1&);
40A1 operator/(const A1&);
41A1 operator=(const A1&);
42
43A1 operator~();
44A1 operator-();
45int operator!();
46A1 operator++();
47A1 operator++(int);
48A1 operator--();
49A1 operator--(int);
50
51};
52
53
54A1 A1::operator+(const A1& second)
55{
56 A1 sum(0,0);
57 sum.x = x + second.x;
58 sum.y = y + second.y;
59
60 return (sum);
61}
62
63A1 A1::operator*(const A1& second)
64{
65 A1 product(0,0);
66 product.x = this->x * second.x;
67 product.y = this->y * second.y;
68
69 return product;
70}
71
72A1 A1::operator-(const A1& second)
73{
74 A1 diff(0,0);
75 diff.x = x - second.x;
76 diff.y = y - second.y;
77
78 return diff;
79}
80
81A1 A1::operator/(const A1& second)
82{
83 A1 div(0,0);
84 div.x = x / second.x;
85 div.y = y / second.y;
86
87 return div;
88}
89
90A1 A1::operator%(const A1& second)
91{
92 A1 rem(0,0);
93 rem.x = x % second.x;
94 rem.y = y % second.y;
95
96 return rem;
97}
98
99int A1::operator==(const A1& second)
100{
101 int a = (x == second.x);
102 int b = (y == second.y);
103
104 return (a && b);
105}
106
107int A1::operator!=(const A1& second)
108{
109 int a = (x != second.x);
110 int b = (y != second.y);
111
112 return (a || b);
113}
114
115int A1::operator&&(const A1& second)
116{
117 return ( x && second.x);
118}
119
120int A1::operator||(const A1& second)
121{
122 return ( x || second.x);
123}
124
125A1 A1::operator<<(int value)
126{
127 A1 lshft(0,0);
128 lshft.x = x << value;
129 lshft.y = y << value;
130
131 return lshft;
132}
133
134A1 A1::operator>>(int value)
135{
136 A1 rshft(0,0);
137 rshft.x = x >> value;
138 rshft.y = y >> value;
139
140 return rshft;
141}
142
143A1 A1::operator|(const A1& second)
144{
145 A1 abitor(0,0);
146 abitor.x = x | second.x;
147 abitor.y = y | second.y;
148
149 return abitor;
150}
151
152A1 A1::operator^(const A1& second)
153{
154 A1 axor(0,0);
155 axor.x = x ^ second.x;
156 axor.y = y ^ second.y;
157
158 return axor;
159}
160
161A1 A1::operator&(const A1& second)
162{
163 A1 abitand(0,0);
164 abitand.x = x & second.x;
165 abitand.y = y & second.y;
166
167 return abitand;
168}
169
170int A1::operator<(const A1& second)
171{
172 A1 b(0,0);
173 b.x = 3;
174 return (x < second.x);
175}
176
177int A1::operator<=(const A1& second)
178{
179 return (x <= second.x);
180}
181
182int A1::operator>=(const A1& second)
183{
184 return (x >= second.x);
185}
186
187int A1::operator>(const A1& second)
188{
189 return (x > second.x);
190}
191
192int A1::operator!(void)
193{
194 return (!x);
195}
196
197A1 A1::operator-(void)
198{
199 A1 neg(0,0);
200 neg.x = -x;
201 neg.y = -y;
202
203 return (neg);
204}
205
206A1 A1::operator~(void)
207{
208 A1 acompl(0,0);
209 acompl.x = ~x;
210 acompl.y = ~y;
211
212 return (acompl);
213}
214
215A1 A1::operator++() // pre increment
216{
217 x = x +1;
218
219 return (*this);
220}
221
222A1 A1::operator++(int) // post increment
223{
224 y = y +1;
225
226 return (*this);
227}
228
229A1 A1::operator--() // pre decrement
230{
231 x = x -1;
232
233 return (*this);
234}
235
236A1 A1::operator--(int) // post decrement
237{
238 y = y -1;
239
240 return (*this);
241}
242
243
244A1 A1::operator=(const A1& second)
245{
246
247 x = second.x;
248 y = second.y;
249
250 return (*this);
251}
252
253A1 A1::operator+=(int value)
254{
255
256 x += value;
257 y += value;
258
259 return (*this);
260}
261
262ostream& operator<<(ostream& outs, A1 one)
263{
264 return (outs << endl << "x = " << one.x << endl << "y = " << one.y << endl << "-------" << endl);
265}
266
267int main (void)
268{
269 A1 one(2,3);
270 A1 two(4,5);
271 A1 three(0,0);
272 int val;
273
274 marker1();
275 cout << one;
276 cout << two;
277 three = one + two;
278 cout << "+ " << three;
279 three = one - two;
280 cout << "- " << three;
281 three = one * two;
282 cout <<"* " << three;
283 three = one / two;
284 cout << "/ " << three;
285 three = one % two;
286 cout << "% " << three;
287 three = one | two;
288 cout << "| " <<three;
289 three = one ^ two;
290 cout << "^ " <<three;
291 three = one & two;
292 cout << "& "<< three;
293
294 val = one && two;
295 cout << "&& " << val << endl << "-----"<<endl;
296 val = one || two;
297 cout << "|| " << val << endl << "-----"<<endl;
298 val = one == two;
299 cout << " == " << val << endl << "-----"<<endl;
300 val = one != two;
301 cout << "!= " << val << endl << "-----"<<endl;
302 val = one >= two;
303 cout << ">= " << val << endl << "-----"<<endl;
304 val = one <= two;
305 cout << "<= " << val << endl << "-----"<<endl;
306 val = one < two;
307 cout << "< " << val << endl << "-----"<<endl;
308 val = one > two;
309 cout << "> " << val << endl << "-----"<<endl;
310
311 three = one << 2;
312 cout << "lsh " << three;
313 three = one >> 2;
314 cout << "rsh " << three;
315
316 three = one;
317 cout << " = "<< three;
318 three += 5;
319 cout << " += "<< three;
320
321 val = (!one);
322 cout << "! " << val << endl << "-----"<<endl;
323 three = (-one);
324 cout << "- " << three;
325 three = (~one);
326 cout << " ~" << three;
327 three++;
328 cout << "postinc " << three;
329 three--;
330 cout << "postdec " << three;
331
332 --three;
333 cout << "predec " << three;
334 ++three;
335 cout << "preinc " << three;
336
337 return 0;
338
339}
This page took 0.065948 seconds and 4 git commands to generate.