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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [gdb.c++/] [virtfunc.cc] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
// Pls try the following program on virtual functions and try to do print on
2
//  most of the code in main().  Almost none of them works !
3
 
4
//
5
// The inheritance structure is:
6
//
7
// V : VA VB
8
// A : (V)
9
// B : A
10
// D : AD (V)
11
// C : (V)
12
// E : B (V) D C
13
//
14
 
15
class VA
16
{
17
public:
18
    int va;
19
};
20
 
21
class VB
22
{
23
public:
24
    int vb;
25
    int fvb();
26
    virtual int vvb();
27
};
28
 
29
class V : public VA, public VB
30
{
31
public:
32
    int f();
33
    virtual int vv();
34
    int w;
35
};
36
 
37
class A : virtual public V
38
{
39
public:
40
    virtual int f();
41
private:
42
    int a;
43
};
44
 
45
class B : public A
46
{
47
public:
48
    int f();
49
private:
50
    int b;
51
};
52
 
53
class C : public virtual V
54
{
55
public:
56
    int c;
57
};
58
 
59
class AD
60
{
61
public:
62
    virtual int vg() = 0;
63
};
64
 
65
class D : public AD, virtual public V
66
{
67
public:
68
    static void s();
69
    virtual int vg();
70
    virtual int vd();
71
    int fd();
72
    int d;
73
};
74
 
75
class E : public B, virtual public V, public D, public C
76
{
77
public:
78
    int f();
79
    int vg();
80
    int vv();
81
    int e;
82
};
83
 
84
D   dd;
85
D*  ppd = ⅆ
86
AD* pAd = ⅆ
87
 
88
A   a;
89
B   b;
90
C   c;
91
D   d;
92
E   e;
93
V   v;
94
VB  vb;
95
 
96
 
97
A*      pAa     =       &a;
98
A*      pAe     =       &e;
99
 
100
B*      pBe     =       &e;
101
 
102
D*      pDd     =       &d;
103
D*      pDe     =       &e;
104
 
105
V*      pVa     =       &a;
106
V*      pVv     =       &v;
107
V*      pVe     =       &e;
108
V*     pVd      =       &d;
109
 
110
AD*     pADe    =       &e;
111
 
112
E*      pEe     =       &e;
113
 
114
VB*     pVB     =       &vb;
115
 
116
void init()
117
{
118
        a.vb = 1;
119
        b.vb = 2;
120
        c.vb = 3;
121
        d.vb = 4;
122
        e.vb = 5;
123
        v.vb = 6;
124
        vb.vb = 7;
125
 
126
        d.d     = 1;
127
        e.d     =  2;
128
}
129
 
130
extern "C" int printf(const char *, ...);
131
 
132
int all_count = 0;
133
int failed_count = 0;
134
 
135
#define TEST(EXPR, EXPECTED) \
136
   ret = EXPR; \
137
   if (ret != EXPECTED) {\
138
      printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
139
      failed_count++; } \
140
   all_count++;
141
 
142
int ret;
143
 
144
void test_calls()
145
{
146
        TEST(pAe->f(), 20);
147
        TEST(pAa->f(), 1);
148
 
149
        TEST(pDe->vg(), 202);
150
        TEST(pADe->vg(), 202);
151
        TEST(pDd->vg(), 101);
152
 
153
        TEST(pEe->vvb(), 411);
154
 
155
        TEST(pVB->vvb(), 407);
156
 
157
        TEST(pBe->vvb(), 411);
158
        TEST(pDe->vvb(), 411);
159
 
160
        TEST(pEe->vd(), 282);
161
        TEST(pEe->fvb(), 311);
162
 
163
        TEST(pEe->D::vg(), 102);
164
        printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
165
}
166
#ifdef usestubs
167
extern "C" {
168
  void set_debug_traps();
169
  void breakpoint();
170
};
171
#endif
172
 
173
int main()
174
{
175
#ifdef usestubs
176
   set_debug_traps();
177
   breakpoint();
178
#endif
179
    init();
180
 
181
    e.w = 7;
182
    e.vb = 11;
183
 
184
    test_calls();
185
    return 0;
186
 
187
}
188
 
189
int A::f() {return 1;}
190
int B::f() {return 2;}
191
void D::s() {}
192
int E::f() {return 20;}
193
int D::vg() {return 100+d;}
194
int E::vg() {return 200+d;}
195
int V::f() {return 600+w;}
196
int V::vv() {return 400+w;}
197
int E::vv() {return 450+w;}
198
int D::fd() {return 250+d;}
199
int D::vd() {return 280+d;}
200
int VB::fvb() {return 300+vb;}
201
int VB::vvb() {return 400+vb;}

powered by: WebSVN 2.1.0

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