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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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