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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.old-deja/] [g++.jason/] [2371.C] - Blame information for rev 699

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 699 jeremybenn
// { dg-do run  }
2
// { dg-options "" }
3
# 1 "SetLS.cc"
4
// GROUPS passed templates nested-classes
5
//
6
// The SetLS template test
7
//
8
// Wendell Baker, Berkeley CAD Group, 1993 (wbaker@ic.Berkeley.EDU)
9
//
10
 
11
#pragma implementation "ListS.h"
12
#pragma implementation "SetLS.h"
13
 
14
#include 
15
#include 
16
using namespace std;
17
 
18
# 1 "../../templates/SetLS.h" 1
19
// -*- C++ -*-
20
 
21
 
22
 
23
//
24
// A Set Template - implemented with an ListS
25
//
26
// Wendell Baker, Berkeley CAD Group, 1993 (wbaker@ic.Berkeley.EDU)
27
//
28
 
29
 
30
 
31
 
32
 
33
#pragma interface
34
 
35
 
36
 
37
 
38
 
39
#define XTRUE true
40
#define XFALSE false
41
 
42
# 37 "../../templates/SetLS.h"
43
 
44
 
45
# 1 "../../templates/ListS.h" 1
46
// -*- C++ -*-
47
 
48
 
49
 
50
//
51
// A List Template - providing a singly linked capability
52
//
53
// Wendell Baker, Berkeley CAD Group, 1993 (wbaker@ic.Berkeley.EDU)
54
//
55
 
56
 
57
 
58
 
59
 
60
#pragma interface
61
 
62
 
63
 
64
 
65
 
66
 
67
# 1 "/projects/gnu-cygnus/gnu-cygnus-14/mips/lib/gcc-lib/decstation/cygnus-reno-1/g++-include/bool.h" 1 3
68
// Defining XTRUE and XFALSE is usually a Bad Idea,
69
// because you will probably be inconsistent with anyone
70
// else who had the same clever idea.
71
// Therefore:  DON'T USE THIS FILE.
72
 
73
 
74
 
75
 
76
 
77
 
78
 
79
 
80
 
81
# 23 "../../templates/ListS.h" 2
82
 
83
# 37 "../../templates/ListS.h"
84
 
85
 
86
 
87
// g++ reno-1 is not yet capable of creating templates with nested
88
// classes which instantiate the template arguments.
89
template
90
struct ListS_link {
91
    T item;
92
    ListS_link *next;
93
 
94
    ListS_link(const T& i, ListS_link *n = 0): item(i), next(n)
95
        { }
96
};
97
 
98
 
99
//
100
// For now, errors are raised by ::abort() because exceptions
101
// are not well implemented in cxx or at all in CC 3.0.1
102
//
103
template
104
class ListS {
105
public:
106
    ListS();
107
    ListS(const ListS&);
108
    ~ListS();
109
 
110
    void operator=(const ListS&);
111
 
112
    unsigned length() const
113
        { return count; }
114
 
115
    void prepend(const T& item);
116
    void append(const T& item);
117
    void clear();
118
 
119
    const T& head() const
120
        { ensure_1();
121
          return head_link->item; }
122
    T& head()
123
        { ensure_1();
124
          return head_link->item; }
125
    void head(T& fill) const
126
        { ensure_1();
127
          fill = head_link->item; }
128
    void remove_head()
129
        { remove_head_filling(0); }
130
    void remove_head(T& fill)
131
        { remove_head_filling(&fill); }
132
 
133
    const T& tail() const
134
        { ensure_1();
135
          return tail_link->item; }
136
    T& tail()
137
        { ensure_1();
138
          return tail_link->item; }
139
    void tail(T& fill) const
140
        { ensure_1();
141
          fill = tail_link->item; }
142
 
143
    class Vix {
144
    public:
145
        Vix(): owner(0), index(0)
146
            { }
147
 
148
        // These are friend functions so that v == x is the same as x == v
149
        friend int operator==(void *v, const Vix& x)
150
            { return v == x.index; }
151
        friend int operator==(const Vix& x, void *v)
152
            { return v == x.index; }
153
        friend int operator!=(void *v, const Vix& x)
154
            { return v != x.index; }
155
        friend int operator!=(const Vix& x, void *v)
156
            { return v != x.index; }
157
        friend int operator==(const Vix& x1, const Vix& x2)
158
            { return x1.owner == x2.owner && x1.index == x2.index; }
159
        friend int operator!=(const Vix& x1, const Vix& x2)
160
            { return x1.owner != x2.owner || x1.index != x2.index; }
161
    private:
162
        friend class ListS;
163
 
164
 
165
        Vix(const ListS *o, ListS_link *i): owner(o), index(i)
166
            { }
167
 
168
 
169
 
170
 
171
 
172
        const ListS *owner;
173
 
174
        ListS_link *index;
175
 
176
 
177
 
178
    };
179
 
180
    Vix first() const
181
        { return Vix(this, head_link); }
182
    void next(Vix& x) const
183
        { check(x);
184
          if (x.index != 0)
185
              x.index = x.index->next; }
186
    T& operator()(const Vix& x)
187
        { check(x);
188
          return x.index->item; }
189
    const T& operator()(const Vix& x) const
190
        { check(x);
191
          return x.index->item; }
192
protected:
193
# 154 "../../templates/ListS.h"
194
 
195
 
196
    unsigned count;
197
 
198
    ListS_link *head_link;      // 0 for a zero-length list
199
    ListS_link *tail_link;      // 0 for a zero-length list
200
 
201
 
202
 
203
 
204
 
205
private:
206
    // fill may be 0 (then don't fill)
207
    void remove_head_filling(T *fill);
208
 
209
    void ensure_1() const
210
        { if (0 == head_link)
211
              ::abort(); }
212
    void check(const Vix& x) const
213
        { if (this != x.owner)
214
              ::abort();
215
          if (0 == x.index)
216
              ::abort(); }
217
};
218
 
219
template
220
ListS::ListS():
221
count(0),
222
head_link(0),
223
tail_link(0)
224
{ }
225
 
226
template
227
ListS::ListS(const ListS& other):
228
count(0),
229
head_link(0),
230
tail_link(0)
231
{
232
    for (Vix x=other.first(); 0 != x; other.next(x))
233
        append(other(x));
234
}
235
 
236
template
237
ListS::~ListS()
238
{
239
    clear();
240
}
241
 
242
template
243
void
244
ListS::operator=(const ListS& other)
245
{
246
    clear();
247
    for (Vix x=other.first(); 0 != x; other.next(x))
248
        append(other(x));
249
}
250
 
251
template
252
void
253
ListS::prepend(const T& item)
254
{
255
 
256
    head_link = new ListS_link(item, head_link);
257
 
258
 
259
 
260
    if (0 == tail_link)
261
        tail_link = head_link;
262
    count++;
263
}
264
 
265
template
266
void
267
ListS::append(const T& item)
268
{
269
 
270
    ListS_link *new_link = new ListS_link(item);
271
 
272
 
273
 
274
    if (0 == tail_link) {
275
        head_link = new_link;
276
        tail_link = new_link;
277
    } else {
278
        tail_link->next = new_link;
279
        tail_link = tail_link->next;
280
    }
281
    count++;
282
}
283
 
284
template
285
void
286
ListS::clear()
287
{
288
 
289
    ListS_link *next, *l;
290
 
291
 
292
 
293
    for (l=head_link; 0 != l; l=next) {
294
        next = l->next;
295
        delete l;
296
    }
297
 
298
    count = 0;
299
    head_link = 0;
300
    tail_link = 0;
301
}
302
 
303
template
304
void
305
ListS::remove_head_filling(T* fill)
306
// fill may be 0 in which case don't assign into it
307
{
308
    ensure_1();
309
 
310
    ListS_link *ohead = head_link;
311
 
312
 
313
 
314
    if (0 != fill)
315
        *fill = ohead->item;
316
    head_link = ohead->next;
317
    if (0 == head_link)
318
        tail_link = 0;
319
    count--;
320
    delete ohead;
321
}
322
 
323
 
324
# 40 "../../templates/SetLS.h" 2
325
 
326
 
327
# 62 "../../templates/SetLS.h"
328
 
329
template
330
class SetLS {
331
public:
332
    SetLS();
333
 
334
    void add(const T& item);
335
    // There is no remove(const T& item) for this set
336
    bool contains(const T& item) const;
337
 
338
    unsigned length() const
339
        { return list.length(); }
340
 
341
    void clear()
342
        { list.clear(); }
343
 
344
    class Vix {
345
    public:
346
        Vix(): owner(0), vix()
347
            { }
348
 
349
        // These are friend functions so that v == x is the same as x == v
350
        friend int operator==(void *v, const Vix& x)
351
            { return v == x.vix; }
352
        friend int operator==(const Vix& x, void *v)
353
            { return v == x.vix; }
354
        friend int operator!=(void *v, const Vix& x)
355
            { return v != x.vix; }
356
        friend int operator!=(const Vix& x, void *v)
357
            { return v != x.vix; }
358
        friend int operator==(const Vix& x1, const Vix& x2)
359
            { return x1.owner == x2.owner && x1.vix == x2.vix; }
360
        friend int operator!=(const Vix& x1, const Vix& x2)
361
            { return x1.owner != x2.owner || x1.vix != x2.vix; }
362
    private:
363
        friend class SetLS;
364
 
365
        Vix(const SetLS *o, const typename ListS::Vix& x): owner(o), vix(x)
366
            { }
367
 
368
        const SetLS *owner;
369
        typename ListS::Vix vix;
370
    };
371
    friend class Vix;
372
 
373
    Vix first() const
374
        { return Vix(this, list.first()); }
375
    void next(Vix& x) const
376
        { check(x);
377
          list.next(x.vix); }
378
    const T& operator()(const Vix& x) const
379
        { check(x);
380
          return list(x.vix); }
381
    // There is item no remove(const Vix&) for this set
382
protected:
383
    ListS list;
384
 
385
private:
386
    void check(const Vix& x) const
387
        { if (this != x.owner)
388
              ::abort(); }
389
};
390
 
391
 
392
template
393
SetLS::SetLS():
394
 
395
 
396
 
397
list()
398
 
399
{ }
400
 
401
template
402
void
403
SetLS::add(const T& item)
404
{
405
    if ( ! contains(item) ) {
406
 
407
 
408
 
409
        list.append(item);
410
 
411
    }
412
}
413
 
414
template
415
bool
416
SetLS::contains(const T& item) const
417
{
418
    for (Vix x=first(); 0 != x; next(x)) {
419
        if (operator()(x) == item)
420
            return XTRUE;
421
    }
422
    return XFALSE;
423
}
424
 
425
 
426
# 17 "SetLS.cc" 2
427
 
428
 
429
 
430
// In (most versions of) g++ 2.X, this use of typedefs has the effect
431
// of causing the instantiation of the templates, thereby testing the
432
// templates
433
 
434
class test {
435
public:
436
    test(): value(0)
437
        { }
438
    test(int v): value(v)
439
        { }
440
 
441
    void print(ostream& out) const
442
        { out << value; }
443
 
444
    friend int operator==(const test& a, const test& b);
445
private:
446
    int value;
447
};
448
 
449
int
450
operator==(const test& a, const test& b)
451
{
452
    return a.value == b.value;
453
}
454
 
455
ostream&
456
operator<<(ostream& o, const test& t)
457
{
458
    t.print(o);
459
    return o;
460
}
461
 
462
typedef SetLS SLS;
463
 
464
static ostream&
465
operator<<(ostream& o, const SLS& s)
466
{
467
    o << "set of " << s.length() << " = {";
468
 
469
    bool first;
470
    SetLS::Vix x;
471
    for (first=XTRUE, x=s.first(); 0 != x; s.next(x), first=XFALSE) {
472
        if ( ! first )
473
            o << ',';
474
        o << ' ';
475
        s(x).print(o);
476
    }
477
    o << '}';
478
 
479
    return o;
480
}
481
 
482
SLS gsls;
483
const SLS gcsls;
484
 
485
void foo()
486
{
487
    const unsigned SIZE = 20;
488
 
489
    //
490
    // SetLS()
491
    // SetLS(const SetLS&)
492
    //
493
    SLS sls;
494
    {
495
        // Fill sls with some interesting values
496
        for (unsigned i=0; i
497
            test t = i;
498
            sls.add(t);
499
        }
500
    }
501
 
502
    const SLS csls(sls);
503
 
504
    //
505
    // void operator=(const SetLS&);
506
    //
507
    sls = csls;
508
 
509
    //
510
    // bool contains(const T& item) const
511
    //
512
    for (unsigned i=0; i
513
        test t = i;
514
 
515
        int contains = sls.contains(t);
516
    }
517
 
518
    //
519
    // void clear()
520
    //
521
    sls.clear();
522
    if (sls.length() != 0)
523
        ::abort();
524
 
525
    sls = csls;
526
 
527
    //
528
    // Vix first() const
529
    // void next(Vix& x) const
530
    // T& operator()(const Vix& x)
531
    // const T& operator()(const Vix& x) const
532
    //
533
    SetLS::Vix cx;
534
    for (cx=csls.first(); 0 != cx; sls.next(cx)) {
535
        if ( ! sls.contains(csls(cx)) )
536
            ::abort();
537
    }
538
 
539
    cout << "gsls:\t" << gsls << '\n';
540
    cout << "gcsls:\t" << gcsls << '\n';
541
    cout << "sls:\t" << sls << '\n';
542
    cout << "csls:\t" << csls << '\n';
543
}
544
 
545
// Dummy function so it'll run
546
int main()
547
{
548
  cout << "PASS" << endl;
549
}
550
 
551
template class ListS;

powered by: WebSVN 2.1.0

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