OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [testsuite/] [gdb.c++/] [userdef.cc] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#include <iostream.h>
2
 
3
void marker1()
4
{
5
  return;
6
}
7
 
8
class A1 {
9
  int x;
10
  int y;
11
 
12
friend ostream& operator<<(ostream& outs, A1 one);
13
 
14
public:
15
 
16
  A1(int a, int b)
17
  {
18
   x=a;
19
   y=b;
20
  }
21
 
22
A1 operator+=(int value);
23
A1 operator+(const A1&);
24
A1 operator-(const A1&);
25
A1 operator%(const A1&);
26
int operator==(const A1&);
27
int operator!=(const A1&);
28
int operator&&(const A1&);
29
int operator||(const A1&);
30
A1 operator<<(int);
31
A1 operator>>(int);
32
A1 operator|(const A1&);
33
A1 operator^(const A1&);
34
A1 operator&(const A1&);
35
int operator<(const A1&);
36
int operator<=(const A1&);
37
int operator>=(const A1&);
38
int operator>(const A1&);
39
A1 operator*(const A1&);
40
A1 operator/(const A1&);
41
A1 operator=(const A1&);
42
 
43
A1 operator~();
44
A1 operator-();
45
int operator!();
46
A1 operator++();
47
A1 operator++(int);
48
A1 operator--();
49
A1 operator--(int);
50
 
51
};
52
 
53
 
54
A1 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
 
63
A1 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
 
72
A1 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
 
81
A1 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
 
90
A1 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
 
99
int 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
 
107
int 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
 
115
int A1::operator&&(const A1& second)
116
{
117
 return ( x && second.x);
118
}
119
 
120
int A1::operator||(const A1& second)
121
{
122
 return ( x || second.x);
123
}
124
 
125
A1 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
 
134
A1 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
 
143
A1 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
 
152
A1 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
 
161
A1 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
 
170
int A1::operator<(const A1& second)
171
{
172
 A1 b(0,0);
173
 b.x = 3;
174
 return (x < second.x);
175
}
176
 
177
int A1::operator<=(const A1& second)
178
{
179
 return (x <= second.x);
180
}
181
 
182
int A1::operator>=(const A1& second)
183
{
184
 return (x >= second.x);
185
}
186
 
187
int A1::operator>(const A1& second)
188
{
189
 return (x > second.x);
190
}
191
 
192
int A1::operator!(void)
193
{
194
 return (!x);
195
}
196
 
197
A1 A1::operator-(void)
198
{
199
 A1 neg(0,0);
200
 neg.x = -x;
201
 neg.y = -y;
202
 
203
 return (neg);
204
}
205
 
206
A1 A1::operator~(void)
207
{
208
 A1 acompl(0,0);
209
 acompl.x = ~x;
210
 acompl.y = ~y;
211
 
212
 return (acompl);
213
}
214
 
215
A1 A1::operator++() // pre increment
216
{
217
 x = x +1;
218
 
219
 return (*this);
220
}
221
 
222
A1 A1::operator++(int) // post increment
223
{
224
 y = y +1;
225
 
226
 return (*this);
227
}
228
 
229
A1 A1::operator--() // pre decrement
230
{
231
 x = x -1;
232
 
233
 return (*this);
234
}
235
 
236
A1 A1::operator--(int) // post decrement
237
{
238
 y = y -1;
239
 
240
 return (*this);
241
}
242
 
243
 
244
A1 A1::operator=(const A1& second)
245
{
246
 
247
 x = second.x;
248
 y = second.y;
249
 
250
 return (*this);
251
}
252
 
253
A1 A1::operator+=(int value)
254
{
255
 
256
 x += value;
257
 y += value;
258
 
259
 return (*this);
260
}
261
 
262
ostream& operator<<(ostream& outs, A1 one)
263
{
264
 return (outs << endl << "x = " << one.x << endl << "y = " << one.y << endl << "-------" << endl);
265
}
266
 
267
int 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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.