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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.old-deja/] [g++.mike/] [p1989.C] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
// { dg-do assemble  }
2
// prms-id: 1989
3
 
4
#define TRUE true
5
#define FALSE false
6
typedef void *Pix;
7
 
8
template
9
struct link {
10
    T item;
11
    link *next;
12
    link *prev;
13
 
14
    link(const T& t): item(t), prev(0), next(0)
15
        { };
16
    link(const T& t, link *p, link *n): item(t), prev(p), next(n)
17
        { };
18
};
19
 
20
template
21
class List_DL {
22
public:
23
    List_DL();
24
    List_DL(const List_DL&);
25
    ~List_DL();
26
 
27
    void append(const T& item);
28
    void prepend(const T& item);
29
    void insert(const T& item, Pix x, bool before);
30
 
31
    void remove(Pix& x)
32
        { T tmp; remove(x, tmp); }
33
    void remove(Pix& x, T& item);
34
 
35
    void clear();
36
 
37
    unsigned length() const
38
        { return count; }
39
 
40
private:
41
 
42
    unsigned count;
43
    link *head;
44
    link *tail;
45
 
46
public:
47
    Pix first() const
48
        { return Pix(head); }
49
    Pix last() const
50
        { return Pix(tail); }
51
    void next(Pix& x) const
52
        { if (0 != x) x = ((link *) x)->next; }
53
    void prev(Pix& x) const
54
        { if (0 != x) x = ((link *) x)->prev; }
55
    T& operator()(Pix x) const
56
        { return ((link *) x)->item; }
57
};
58
 
59
template
60
List_DL::List_DL():
61
count(0),
62
head(0)
63
{ }
64
 
65
template
66
List_DL::List_DL(const List_DL& other):
67
count(0),
68
head(0)
69
{
70
    for (Pix x=other.first(); 0 != x; other.next(x))
71
        append(other(x));
72
}
73
 
74
template
75
List_DL::~List_DL()
76
{
77
    clear();
78
}
79
 
80
template
81
void
82
List_DL::append(const T& item)
83
{
84
    count++;
85
    if (0 == head) {
86
        head = new link(item);
87
        tail = head;
88
    } else {
89
        tail->next = new link(item, tail, 0);
90
        tail = tail->next;
91
    }
92
}
93
 
94
template
95
void
96
List_DL::prepend(const T& item)
97
{
98
    count++;
99
    if (0 == head) {
100
        head = new link(item);
101
        tail = head;
102
    } else {
103
        head = new link(item, 0, head);
104
        if (tail == head)
105
            tail = tail->next;
106
    }
107
}
108
 
109
template
110
void
111
List_DL::insert(const T& item, Pix x, bool before = TRUE)
112
{
113
    link *l = (link *) x;
114
 
115
    if (before) {
116
        if (0 == l || l == head) {
117
            prepend(item);
118
        } else {
119
            link *n = new link(item, l->prev, l);
120
            l->prev->next = n;
121
            l->prev = n;
122
        }
123
    } else {
124
        if (0 == l || l == tail) {
125
            append(item);
126
        } else {
127
            link *n = new link(item, l, l->next);
128
            l->next->prev = n;
129
            l->prev = n;
130
        }
131
    }
132
}
133
 
134
template
135
void
136
List_DL::remove(Pix& x, T& item)
137
{
138
    link *l = (link *) x;
139
 
140
    if (0 == l)
141
        return;
142
 
143
    item = l->item;
144
    if (1 == count) {
145
        delete head;
146
        head = 0;
147
        tail = 0;
148
    } else {
149
        // more than one item in the list
150
        if (l == head) {
151
            link *old = head;
152
            head = head->next;
153
            head->prev = 0;
154
            delete old;
155
        } else if (l == tail) {
156
            link *old = tail;
157
            tail = tail->prev;
158
            tail->next = 0;
159
            delete old;
160
        } else {
161
            l->next->prev = l->prev;
162
            l->prev->next = l->next;
163
            delete l;
164
        }
165
    }
166
}
167
 
168
template
169
void
170
List_DL::clear()
171
{
172
    link *l, *succ;
173
    for (l=head; 0 != l; l=succ) {
174
        succ = l->next;
175
        delete l;
176
    }
177
    head = 0;
178
    tail = 0;
179
}
180
 
181
template
182
class List_DLS: public List_DL {
183
public:
184
    List_DLS(): List_DL()
185
        { };
186
    List_DLS(const List_DLS& other): List_DL(other)
187
        { };
188
 
189
    bool contains(const T& item) const
190
        { return search(item) != 0 ? TRUE: FALSE; }
191
    Pix search(const T&) const;
192
};
193
 
194
template
195
Pix
196
List_DLS::search(const T& item) const
197
{
198
    for (Pix x=this->first(); 0 != x; this->next(x)) {
199
        if (item == this->operator()(x)) // { dg-error "" } const subversion
200
            return x;
201
    }
202
    return 0;
203
}
204
 
205
template
206
class List_DLSp: public List_DL {
207
public:
208
    List_DLSp(): List_DL()
209
        { };
210
    List_DLSp(const List_DLSp& other): List_DL(other)
211
        { };
212
 
213
    bool contains(const T& item) const
214
#ifndef INTERNAL_ERROR
215
        ;
216
#else
217
        { return search(item) != 0 ? TRUE: FALSE; }
218
#endif
219
    Pix search(const T&) const;
220
};
221
 
222
template
223
bool
224
List_DLSp::contains(const T& item) const
225
{
226
    for (Pix x=this->first(); 0 != x; this->next(x)) {
227
        if (*item == *(this->operator()(x)))
228
            return TRUE;
229
    }
230
    return FALSE;
231
}
232
 
233
template
234
class Set {
235
public:
236
    Set();
237
    Set(const Set& other);
238
 
239
    virtual void add(const T& item);
240
 
241
    void remove(const T& item)
242
        { Pix x = search(item); remove(x); }
243
    void remove(Pix& x)
244
        { T tmp; remove(x, tmp); }
245
    virtual void remove(Pix& x, T& item);
246
 
247
    virtual void clear();
248
 
249
    virtual bool contains(const T&) const;
250
    virtual Pix search(const T&) const;
251
 
252
    virtual unsigned length() const;
253
 
254
    virtual Pix first() const;
255
    virtual void next(Pix& x) const;
256
    virtual T& operator()(Pix x) const;
257
};
258
 
259
template
260
Set::Set()
261
{ }
262
 
263
template
264
Set::Set(const Set& other)
265
{ }
266
 
267
 
268
template
269
class Set_DL: public List_DLS {
270
public:
271
    Set_DL();
272
    Set_DL(const Set_DL& other);
273
 
274
    void add(const T& item)
275
        { list.append(item); }
276
    void remove(Pix& x, T& item)
277
        { list.remove(x, item); }
278
 
279
    void clear()
280
        { list.clear(); }
281
 
282
    bool contains(const T& item) const
283
        { return list.contains(item); }
284
    Pix search(const T& item) const
285
        { return list.search(item); }
286
 
287
    unsigned length() const
288
        { return list.length(); }
289
 
290
    Pix first() const
291
        { return list.first(); }
292
    void next(Pix& x) const
293
        { list.next(x); }
294
    T& operator()(Pix x) const
295
        { return list(x); }
296
private:
297
    List_DLS list;
298
};
299
 
300
template
301
class Set_DLp: public List_DLSp {
302
public:
303
    Set_DLp();
304
    Set_DLp(const Set_DLp& other);
305
 
306
    void add(const T& item)
307
        { list.append(item); }
308
    void remove(Pix& x, T& item)
309
        { list.remove(x, item); }
310
 
311
    void clear()
312
        { list.clear(); }
313
 
314
    bool contains(const T& item) const
315
        { return list.contains(item); }
316
    Pix search(const T& item) const
317
        { return list.search(item); }
318
 
319
    unsigned length() const
320
        { return list.length(); }
321
 
322
    Pix first() const
323
        { return list.first(); }
324
    void next(Pix& x) const
325
        { list.next(x); }
326
    T& operator()(Pix x) const
327
        { return list(x); }
328
private:
329
    List_DLSp list;
330
};
331
 
332
template
333
struct vertex {
334
    T item;
335
    List_DL *> fanout;
336
 
337
    vertex(): item(), fanout()  // { dg-bogus "" }
338
      { };
339
    vertex(const T& i): item(), fanout() // { dg-bogus "" }
340
      { };
341
};
342
 
343
template
344
class Graph {
345
public:
346
    Graph();
347
    Graph(const Graph&);
348
    ~Graph();
349
 
350
    void add(const T& from, const T& to);
351
    bool contains(const T& from, const T& to) const;
352
 
353
    void clear()
354
        { vertices.clear(); }
355
 
356
    unsigned lengthV() const
357
        { return vertices.length(); }
358
 
359
    Pix firstV() const
360
        { return vertices.first(); }
361
    void nextV(Pix& x) const
362
        { vertices.next(x); }
363
    T& V(Pix x) const
364
        { return vertices(x).item; }
365
 
366
    Pix firstV1(Pix vx) const;
367
    void nextV1(Pix vx, Pix& x) const;
368
    T& V1(Pix vx, Pix x) const;
369
private:
370
    vertex *lookup(const T& from) const;
371
    vertex *lookup_new(const T& from);
372
 
373
    List_DLS > vertices;
374
};
375
 
376
template
377
Graph::Graph():
378
vertices()
379
{ }
380
 
381
template
382
Graph::Graph(const Graph& other):
383
vertices()
384
{
385
    for (Pix vx=firstV(); 0 != vx; nextV(vx)) {
386
        for (Pix vx1=firstV1(vx); 0 != vx1; nextV1(vx, vx1)) {
387
            add(V(vx), V1(vx, vx1));
388
        }
389
    }
390
}
391
 
392
template
393
Graph::~Graph()
394
{
395
    clear();
396
}
397
 
398
template
399
void
400
Graph::add(const T& from, const T& to)
401
{
402
    vertex *fromv = lookup_new(from);
403
    if (from == to)
404
        return;
405
    vertex *tov = lookup_new(to);
406
    fromv->fanout.append(tov);
407
}
408
 
409
template
410
bool
411
Graph::contains(const T& from, const T& to) const
412
{
413
    vertex *fromv = lookup(from);
414
    if (0 == fromv)
415
        return FALSE;
416
 
417
    for (Pix x=fromv->fanout.first(); 0 != x; fromv->fanout.next(x)) {
418
        if (fromv->fanout(x)->item == to)
419
            return TRUE;
420
    }
421
 
422
    return FALSE;
423
}
424
 
425
template
426
vertex *
427
Graph::lookup(const T& from) const
428
{
429
    for (Pix x=vertices.first(); 0 != x; vertices.next(x)) {
430
        if (vertices(x).item == from)
431
            return &vertices(x);
432
    }
433
    return 0;
434
}
435
 
436
template
437
vertex *
438
Graph::lookup_new(const T& from)
439
{
440
    vertex *v = lookup(from);
441
    if (0 == v) {
442
        vertices.append(from);
443
        return &vertices(vertices.last());
444
    }
445
    return v;
446
}
447
 
448
template
449
Pix
450
Graph::firstV1(Pix vx) const
451
{
452
    vertex *v = (vertex *) vx;
453
    return v->fanout.first();
454
}
455
 
456
template
457
void
458
Graph::nextV1(Pix vx, Pix& x) const
459
{
460
    vertex *v = (vertex *) vx;
461
    return v->fanout.next(x);
462
}
463
 
464
template
465
T&
466
Graph::V1(Pix vx, Pix x) const
467
{
468
    vertex *v = (vertex *) vx;
469
    static T x1;
470
    return x1;
471
}
472
 
473
class STRLIdentifier;
474
 
475
extern int x(List_DL);
476
extern int x(List_DLS);
477
 
478
extern int x(Set);
479
extern int x(Set_DL);
480
extern int x(Set_DLp);
481
 
482
extern int x(Graph);
483
 
484
class STRLIdentifier {
485
    char buf[10];
486
};
487
 
488
extern int operator==(vertex&, vertex&); // { dg-error "" } const subversion
489
extern int operator==(STRLIdentifier&, STRLIdentifier&); // { dg-error "" } fn ref in err msg
490
 
491
extern int x(List_DLSp);
492
 
493
template class Graph;
494
template class List_DLS >;

powered by: WebSVN 2.1.0

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