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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.cp/] [templates.cc] - Blame information for rev 157

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* This test code is from Wendell Baker (wbaker@comet.berkeley.edu) */
2
 
3
#include <stddef.h>
4
 
5
int a_i;
6
char a_c;
7
double a_d;
8
 
9
typedef void *Pix;
10
 
11
int
12
f(int i)
13
{ return 0; }
14
 
15
int
16
f(int i, char c)
17
{ return 0; }
18
 
19
int
20
f(int i, char c, double d)
21
{ return 0; }
22
 
23
int
24
f(int i, char c, double d, char *cs)
25
{ return 0; }
26
 
27
int
28
f(int i, char c, double d, char *cs, void (*fig)(int, char))
29
{ return 0; }
30
 
31
int
32
f(int i, char c, double d, char *cs, void (*fig)(char, int))
33
{ return 0; }
34
 
35
class R {
36
public:
37
    int i;
38
};
39
class S {
40
public:
41
    int i;
42
};
43
class T {
44
public:
45
    int i;
46
};
47
 
48
char g(char, const char, volatile char)
49
{ return 'c'; }
50
char g(R, char&, const char&, volatile char&)
51
{ return 'c'; }
52
char g(char*, const char*, volatile char*)
53
{ return 'c'; }
54
char g(S, char*&, const char*&, volatile char*&)
55
{ return 'c'; }
56
 
57
signed char g(T,signed char, const signed char, volatile signed char)
58
{ return 'c'; }
59
signed char g(T, R, signed char&, const signed char&, volatile signed char&)
60
{ return 'c'; }
61
signed char g(T, signed char*, const signed char*, volatile signed char*)
62
{ return 'c'; }
63
signed char g(T, S, signed char*&, const signed char*&, volatile signed char*&)
64
{ return 'c'; }
65
 
66
unsigned char g(unsigned char, const unsigned char, volatile unsigned char)
67
{ return 'c'; }
68
unsigned char g(R, unsigned char&, const unsigned char&, volatile unsigned char&)
69
{ return 'c'; }
70
unsigned char g(unsigned char*, const unsigned char*, volatile unsigned char*)
71
{ return 'c'; }
72
unsigned char g(S, unsigned char*&, const unsigned char*&, volatile unsigned char*&)
73
{ return 'c'; }
74
 
75
short g(short, const short, volatile short)
76
{ return 0; }
77
short g(R, short&, const short&, volatile short&)
78
{ return 0; }
79
short g(short*, const short*, volatile short*)
80
{ return 0; }
81
short g(S, short*&, const short*&, volatile short*&)
82
{ return 0; }
83
 
84
signed short g(T, signed short, const signed short, volatile signed short)
85
{ return 0; }
86
signed short g(T, R, signed short&, const signed short&, volatile signed short&)
87
{ return 0; }
88
signed short g(T, signed short*, const signed short*, volatile signed short*)
89
{ return 0; }
90
signed short g(T, S, double, signed short*&, const signed short*&, volatile signed short*&)
91
{ return 0; }
92
 
93
unsigned short g(unsigned short, const unsigned short, volatile unsigned short)
94
{ return 0; }
95
unsigned short g(R, unsigned short&, const unsigned short&, volatile unsigned short&)
96
{ return 0; }
97
unsigned short g(unsigned short*, const unsigned short*, volatile unsigned short*)
98
{ return 0; }
99
unsigned short g(S, unsigned short*&, const unsigned short*&, volatile unsigned short*&)
100
{ return 0; }
101
 
102
int g(int, const int, volatile int)
103
{ return 0; }
104
int g(R, int&, const int&, volatile int&)
105
{ return 0; }
106
int g(int*, const int*, volatile int*)
107
{ return 0; }
108
int g(S, int*&, const int*&, volatile int*&)
109
{ return 0; }
110
 
111
signed int g(T, signed int, const signed int, volatile signed int)
112
{ return 0; }
113
signed int g(T, R, signed int&, const signed int&, volatile signed int&)
114
{ return 0; }
115
signed int g(T, signed int*, const signed int*, volatile signed int*)
116
{ return 0; }
117
signed int g(T, S, signed int*&, const signed int*&, volatile signed int*&)
118
{ return 0; }
119
 
120
unsigned int g(unsigned int, const unsigned int, volatile unsigned int)
121
{ return 0; }
122
unsigned int g(R, unsigned int&, const unsigned int&, volatile unsigned int&)
123
{ return 0; }
124
unsigned int g(unsigned int*, const unsigned int*, volatile unsigned int*)
125
{ return 0; }
126
unsigned int g(S, unsigned int*&, const unsigned int*&, volatile unsigned int*&)
127
{ return 0; }
128
 
129
long g(long, const long, volatile long)
130
{ return 0; }
131
long g(R, long&, const long&, volatile long&)
132
{ return 0; }
133
long g(long*, const long*, volatile long*)
134
{ return 0; }
135
long g(S, long*&, const long*&, volatile long*&)
136
{ return 0; }
137
 
138
signed long g(T, signed long, const signed long, volatile signed long)
139
{ return 0; }
140
signed long g(T, R, signed long&, const signed long&, volatile signed long&)
141
{ return 0; }
142
signed long g(T, signed long*, const signed long*, volatile signed long*)
143
{ return 0; }
144
signed long g(T, S, signed long*&, const signed long*&, volatile signed long*&)
145
{ return 0; }
146
 
147
unsigned long g(unsigned long, const unsigned long, volatile unsigned long)
148
{ return 0; }
149
unsigned long g(S, unsigned long&, const unsigned long&, volatile unsigned long&)
150
{ return 0; }
151
unsigned long g(unsigned long*, const unsigned long*, volatile unsigned long*)
152
{ return 0; }
153
unsigned long g(S, unsigned long*&, const unsigned long*&, volatile unsigned long*&)
154
{ return 0; }
155
 
156
#ifdef __GNUC__
157
long long g(long long, const long long, volatile long long)
158
{ return 0; }
159
long long g(S, long long&, const long long&, volatile long long&)
160
{ return 0; }
161
long long g(long long*, const long long*, volatile long long*)
162
{ return 0; }
163
long long g(R, long long*&, const long long*&, volatile long long*&)
164
{ return 0; }
165
 
166
signed long long g(T, signed long long, const signed long long, volatile signed long long)
167
{ return 0; }
168
signed long long g(T, R, signed long long&, const signed long long&, volatile signed long long&)
169
{ return 0; }
170
signed long long g(T, signed long long*, const signed long long*, volatile signed long long*)
171
{ return 0; }
172
signed long long g(T, S, signed long long*&, const signed long long*&, volatile signed long long*&)
173
{ return 0; }
174
 
175
unsigned long long g(unsigned long long, const unsigned long long, volatile unsigned long long)
176
{ return 0; }
177
unsigned long long g(R, unsigned long long*, const unsigned long long*, volatile unsigned long long*)
178
{ return 0; }
179
unsigned long long g(unsigned long long&, const unsigned long long&, volatile unsigned long long&)
180
{ return 0; }
181
unsigned long long g(S, unsigned long long*&, const unsigned long long*&, volatile unsigned long long*&)
182
{ return 0; }
183
#endif
184
 
185
float g(float, const float, volatile float)
186
{ return 0; }
187
float g(char, float&, const float&, volatile float&)
188
{ return 0; }
189
float g(float*, const float*, volatile float*)
190
{ return 0; }
191
float g(char, float*&, const float*&, volatile float*&)
192
{ return 0; }
193
 
194
double g(double, const double, volatile double)
195
{ return 0; }
196
double g(char, double&, const double&, volatile double&)
197
{ return 0; }
198
double g(double*, const double*, volatile double*)
199
{ return 0; }
200
double g(char, double*&, const double*&, volatile double*&)
201
{ return 0; }
202
 
203
#ifdef __GNUC__
204
long double g(long double, const long double, volatile long double)
205
{ return 0; }
206
long double g(char, long double&, const long double&, volatile long double&)
207
{ return 0; }
208
long double g(long double*, const long double*, volatile long double*)
209
{ return 0; }
210
long double g(char, long double*&, const long double*&, volatile long double*&)
211
{ return 0; }
212
#endif
213
 
214
class c {
215
public:
216
    c(int) {};
217
    int i;
218
};
219
 
220
class c g(c, const c, volatile c)
221
{ return 0; }
222
c g(char, c&, const c&, volatile c&)
223
{ return 0; }
224
c g(c*, const c*, volatile c*)
225
{ return 0; }
226
c g(char, c*&, const c*&, volatile c*&)
227
{ return 0; }
228
 
229
/*
230
void h(char = 'a')
231
{ }
232
void h(char, signed char = 'a')
233
{ }
234
void h(unsigned char = 'a')
235
{ }
236
*/
237
/*
238
void h(char = (char)'a')
239
{ }
240
void h(char, signed char = (signed char)'a')
241
{ }
242
void h(unsigned char = (unsigned char)'a')
243
{ }
244
 
245
 
246
void h(short = (short)43)
247
{ }
248
void h(char, signed short = (signed short)43)
249
{ }
250
void h(unsigned short = (unsigned short)43)
251
{ }
252
 
253
void h(int = (int)43)
254
{ }
255
void h(char, signed int = (signed int)43)
256
{ }
257
void h(unsigned int = (unsigned int)43)
258
{ }
259
 
260
 
261
void h(long = (long)43)
262
{ }
263
void h(char, signed long = (signed long)43)
264
{ }
265
void h(unsigned long = (unsigned long)43)
266
{ }
267
 
268
#ifdef __GNUC__
269
void h(long long = 43)
270
{ }
271
void h(char, signed long long = 43)
272
{ }
273
void h(unsigned long long = 43)
274
{ }
275
#endif
276
 
277
void h(float = 4.3e-10)
278
{ }
279
void h(double = 4.3)
280
{ }
281
#ifdef __GNUC__
282
void h(long double = 4.33e33)
283
{ }
284
#endif
285
*/
286
 
287
/* An unneeded printf() definition - actually, just a stub - used to occupy
288
   this space.  It has been removed and replaced with this comment which
289
   exists to occupy some lines so that templates.exp won't need adjustment.  */
290
 
291
class T1 {
292
public:
293
    static void* operator new(size_t) throw ();
294
    static void operator delete(void *pointer);
295
 
296
    void operator=(const T1&);
297
    T1& operator=(int);
298
 
299
    int operator==(int) const;
300
    int operator==(const T1&) const;
301
    int operator!=(int) const;
302
    int operator!=(const T1&) const;
303
 
304
    int operator<=(int) const;
305
    int operator<=(const T1&) const;
306
    int operator<(int) const;
307
    int operator<(const T1&) const;
308
    int operator>=(int) const;
309
    int operator>=(const T1&) const;
310
    int operator>(int) const;
311
    int operator>(const T1&) const;
312
 
313
    void operator+(int) const;
314
    T1& operator+(const T1&) const;
315
    void operator+=(int) const;
316
    T1& operator+=(const T1&) const;
317
 
318
    T1& operator++() const;
319
 
320
    void operator-(int) const;
321
    T1& operator-(const T1&) const;
322
    void operator-=(int) const;
323
    T1& operator-=(const T1&) const;
324
 
325
    T1& operator--() const;
326
 
327
    void operator*(int) const;
328
    T1& operator*(const T1&) const;
329
    void operator*=(int) const;
330
    T1& operator*=(const T1&) const;
331
 
332
    void operator/(int) const;
333
    T1& operator/(const T1&) const;
334
    void operator/=(int) const;
335
    T1& operator/=(const T1&) const;
336
 
337
    void operator%(int) const;
338
    T1& operator%(const T1&) const;
339
    void operator%=(int) const;
340
    T1& operator%=(const T1&) const;
341
 
342
    void operator&&(int) const;
343
    T1& operator&&(const T1&) const;
344
 
345
    void operator||(int) const;
346
    T1& operator||(const T1&) const;
347
 
348
    void operator&(int) const;
349
    T1& operator&(const T1&) const;
350
    void operator&=(int) const;
351
    T1& operator&=(const T1&) const;
352
 
353
    void operator|(int) const;
354
    T1& operator|(const T1&) const;
355
    void operator|=(int) const;
356
    T1& operator|=(const T1&) const;
357
 
358
    void operator^(int) const;
359
    T1& operator^(const T1&) const;
360
    void operator^=(int) const;
361
    T1& operator^=(const T1&) const;
362
 
363
    T1& operator!() const;
364
    T1& operator~() const;
365
};
366
 
367
void*
368
T1::operator new(size_t) throw ()
369
{ return 0; }
370
 
371
void
372
T1::operator delete(void *pointer)
373
{ }
374
 
375
class T2 {
376
public:
377
    T2(int i): integer(i)
378
        { }
379
    int integer;
380
};
381
 
382
int operator==(const T2&, const T2&)
383
{ return 0; }
384
int operator==(const T2&, char)
385
{ return 0; }
386
int operator!=(const T2&, const T2&)
387
{ return 0; }
388
int operator!=(const T2&, char)
389
{ return 0; }
390
 
391
int operator<=(const T2&, const T2&)
392
{ return 0; }
393
int operator<=(const T2&, char)
394
{ return 0; }
395
int operator<(const T2&, const T2&)
396
{ return 0; }
397
int operator<(const T2&, char)
398
{ return 0; }
399
int operator>=(const T2&, const T2&)
400
{ return 0; }
401
int operator>=(const T2&, char)
402
{ return 0; }
403
int operator>(const T2&, const T2&)
404
{ return 0; }
405
int operator>(const T2&, char)
406
{ return 0; }
407
 
408
T2 operator+(const T2 t, int i)
409
{ return t.integer + i; }
410
T2 operator+(const T2 a, const T2& b)
411
{ return a.integer + b.integer; }
412
T2& operator+=(T2& t, int i)
413
{ t.integer += i; return t; }
414
T2& operator+=(T2& a, const T2& b)
415
{ a.integer += b.integer; return a; }
416
 
417
T2 operator-(const T2 t, int i)
418
{ return t.integer - i; }
419
T2 operator-(const T2 a, const T2& b)
420
{ return a.integer - b.integer; }
421
T2& operator-=(T2& t, int i)
422
{ t.integer -= i; return t; }
423
T2& operator-=(T2& a, const T2& b)
424
{ a.integer -= b.integer; return a; }
425
 
426
T2 operator*(const T2 t, int i)
427
{ return t.integer * i; }
428
T2 operator*(const T2 a, const T2& b)
429
{ return a.integer * b.integer; }
430
T2& operator*=(T2& t, int i)
431
{ t.integer *= i; return t; }
432
T2& operator*=(T2& a, const T2& b)
433
{ a.integer *= b.integer; return a; }
434
 
435
T2 operator/(const T2 t, int i)
436
{ return t.integer / i; }
437
T2 operator/(const T2 a, const T2& b)
438
{ return a.integer / b.integer; }
439
T2& operator/=(T2& t, int i)
440
{ t.integer /= i; return t; }
441
T2& operator/=(T2& a, const T2& b)
442
{ a.integer /= b.integer; return a; }
443
 
444
T2 operator%(const T2 t, int i)
445
{ return t.integer % i; }
446
T2 operator%(const T2 a, const T2& b)
447
{ return a.integer % b.integer; }
448
T2& operator%=(T2& t, int i)
449
{ t.integer %= i; return t; }
450
T2& operator%=(T2& a, const T2& b)
451
{ a.integer %= b.integer; return a; }
452
 
453
template<class T>
454
class T5 {
455
public:
456
    T5(int);
457
    T5(const T5<T>&);
458
    ~T5();
459
    static void* operator new(size_t) throw ();
460
    static void operator delete(void *pointer);
461
    int value();
462
 
463
    static T X;
464
    T x;
465
    int val;
466
};
467
 
468
template<class T>
469
T5<T>::T5(int v)
470
{ val = v; }
471
 
472
template<class T>
473
T5<T>::T5(const T5<T>&)
474
{}
475
 
476
template<class T>
477
T5<T>::~T5()
478
{}
479
 
480
template<class T>
481
void*
482
T5<T>::operator new(size_t) throw ()
483
{ return 0; }
484
 
485
template<class T>
486
void
487
T5<T>::operator delete(void *pointer)
488
{ }
489
 
490
template<class T>
491
int
492
T5<T>::value()
493
{ return val; }
494
 
495
 
496
#if ! defined(__GNUC__) || defined(GCC_BUG)
497
template<class T>
498
T T5<T>::X;
499
#endif
500
 
501
 
502
 
503
 
504
T5<char> t5c(1);
505
T5<int> t5i(2);
506
T5<int (*)(char, void *)> t5fi1(3);
507
T5<int (*)(int, double **, void *)> t5fi2(4);
508
 
509
 
510
 
511
 
512
 
513
 
514
class x {
515
public:
516
    int (*manage[5])(double,
517
                     void *(*malloc)(unsigned size),
518
                     void (*free)(void *pointer));
519
    int (*device[5])(int open(const char *, unsigned mode, unsigned perms, int extra),
520
                     int *(*read)(int fd, void *place, unsigned size),
521
                     int *(*write)(int fd, void *place, unsigned size),
522
                     void (*close)(int fd));
523
};
524
T5<x> t5x(5);
525
 
526
#if !defined(__GNUC__) || (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)
527
template class T5<char>;
528
template class T5<int>;
529
template class T5<int (*)(char, void *)>;
530
template class T5<int (*)(int, double **, void *)>;
531
template class T5<x>;
532
#endif
533
 
534
class T7 {
535
public:
536
    static int get();
537
    static void put(int);
538
};
539
 
540
int
541
T7::get()
542
{ return 1; }
543
 
544
void
545
T7::put(int i)
546
{
547
    // nothing
548
}
549
 
550
// More template kinds.  GDB 4.16 didn't handle these, but
551
// Wildebeest does.  Note: Assuming HP aCC is used to compile
552
// this file; with g++ or HP cfront or other compilers the
553
// demangling may not get done correctly.
554
 
555
// Ordinary template, to be instantiated with different types
556
template<class T>
557
class Foo {
558
public:
559
  int x;
560
  T t;
561
  T foo (int, T);
562
};
563
 
564
 
565
template<class T> T Foo<T>::foo (int i, T tt)
566
{
567
  return tt;
568
}
569
 
570
// Template with int parameter
571
 
572
template<class T, int sz>
573
class Bar {
574
public:
575
  int x;
576
  T t;
577
  T bar (int, T);
578
};
579
 
580
 
581
template<class T, int sz> T Bar<T, sz>::bar (int i, T tt)
582
{
583
  if (i < sz)
584
    return tt;
585
  else
586
    return 0;
587
}
588
 
589
// function template with int parameter
590
template<class T> int dummy (T tt, int i)
591
{
592
  return tt;
593
}
594
 
595
// Template with partial specializations
596
template<class T1, class T2>
597
class Spec {
598
public:
599
  int x;
600
  T1 spec (T2);
601
};
602
 
603
template<class T1, class T2>
604
T1 Spec<T1, T2>::spec (T2 t2)
605
{
606
  return 0;
607
}
608
 
609
template<class T>
610
class Spec<T, T*> {
611
public:
612
  int x;
613
  T spec (T*);
614
};
615
 
616
template<class T>
617
T Spec<T, T*>::spec (T * tp)
618
{
619
  return *tp;
620
}
621
 
622
// Template with char parameter
623
template<class T, char sz>
624
class Baz {
625
public:
626
  int x;
627
  T t;
628
  T baz (int, T);
629
};
630
 
631
template<class T, char sz> T Baz<T, sz>::baz (int i, T tt)
632
{
633
  if (i < sz)
634
    return tt;
635
  else
636
    return 0;
637
}
638
 
639
// Template with char * parameter
640
template<class T, char * sz>
641
class Qux {
642
public:
643
  int x;
644
  T t;
645
  T qux (int, T);
646
};
647
 
648
template<class T, char * sz> T Qux<T, sz>::qux (int i, T tt)
649
{
650
  if (sz[0] == 'q')
651
    return tt;
652
  else
653
    return 0;
654
}
655
 
656
// Template with a function pointer parameter
657
template<class T, int (*f)(int) >
658
class Qux1 {
659
public:
660
  int x;
661
  T t;
662
  T qux (int, T);
663
};
664
 
665
template<class T, int (*f)(int)> T Qux1<T, f>::qux (int i, T tt)
666
{
667
  if (f != 0)
668
    return tt;
669
  else
670
    return 0;
671
}
672
 
673
// Some functions to provide as arguments to template
674
int gf1 (int a) {
675
  return a * 2 + 13;
676
}
677
int gf2 (int a) {
678
  return a * 2 + 26;
679
}
680
 
681
char string[3];
682
 
683
 
684
// Template for nested instantiations
685
 
686
template<class T>
687
class Garply {
688
public:
689
  int x;
690
  T t;
691
  T garply (int, T);
692
};
693
 
694
template<class T> T Garply<T>::garply (int i, T tt)
695
{
696
  if (i > x)
697
    return tt;
698
  else
699
    {
700
      x += i;
701
      return tt;
702
    }
703
}
704
 
705
 
706
int main()
707
{
708
    int i;
709
#ifdef usestubs
710
    set_debug_traps();
711
    breakpoint();
712
#endif
713
    i = i + 1;
714
 
715
    // New tests added here
716
 
717
  Foo<int> fint={0,0};
718
  Foo<char> fchar={0,0};
719
  Foo<volatile char *> fvpchar = {0, 0};
720
 
721
  Bar<int, 33> bint;
722
  Bar<int, (4 > 3)> bint2;
723
 
724
  Baz<int, 's'> bazint;
725
  Baz<char, 'a'> bazint2;
726
 
727
  Qux<char, string> quxint2;
728
  Qux<int, string> quxint;
729
 
730
  Qux1<int, gf1> qux11;
731
 
732
  int x = fint.foo(33, 47);
733
  char c = fchar.foo(33, 'x');
734
  volatile char * cp = fvpchar.foo(33, 0);
735
 
736
  int y = dummy<int> (400, 600);
737
 
738
  int z = bint.bar(55, 66);
739
  z += bint2.bar(55, 66);
740
 
741
  c = bazint2.baz(4, 'y');
742
  c = quxint2.qux(4, 'z');
743
 
744
  y = bazint.baz(4,3);
745
  y = quxint.qux(4, 22);
746
  y += qux11.qux(4, 22);
747
 
748
  y *= gf1(y) - gf2(y);
749
 
750
  Spec<int, char> sic;
751
  Spec<int, int *> siip;
752
 
753
  sic.spec ('c');
754
  siip.spec (&x);
755
 
756
  Garply<int> f;
757
  Garply<char> fc;
758
  f.x = 13;
759
 
760
  Garply<Garply<char> > nf;
761
  nf.x = 31;
762
 
763
  x = f.garply (3, 4);
764
 
765
  fc = nf.garply (3, fc);
766
 
767
  y = x + fc.x;
768
 
769
 
770
  return 0;
771
 
772
}
773
 
774
 
775
 
776
 
777
 
778
 
779
 
780
 
781
 
782
 
783
 
784
 
785
 

powered by: WebSVN 2.1.0

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