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/] [virtfunc.cc] - Blame information for rev 157

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* This test script is part of GDB, the GNU debugger.
2
 
3
   Copyright 1993, 1994, 1997, 1998, 1999, 2003, 2004,
4
   Free Software Foundation, Inc.
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3 of the License, or
9
   (at your option) any later version.
10
 
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
   */
19
 
20
// Pls try the following program on virtual functions and try to do print on
21
//  most of the code in main().  Almost none of them works !
22
 
23
//
24
// The inheritance structure is:
25
//
26
// V : VA VB
27
// A : (V)
28
// B : A
29
// D : AD (V)
30
// C : (V)
31
// E : B (V) D C
32
//
33
 
34
class VA
35
{
36
public:
37
    int va;
38
};
39
 
40
class VB
41
{
42
public:
43
    int vb;
44
    int fvb();
45
    virtual int vvb();
46
};
47
 
48
class V : public VA, public VB
49
{
50
public:
51
    int f();
52
    virtual int vv();
53
    int w;
54
};
55
 
56
class A : virtual public V
57
{
58
public:
59
    virtual int f();
60
private:
61
    int a;
62
};
63
 
64
class B : public A
65
{
66
public:
67
    int f();
68
private:
69
    int b;
70
};
71
 
72
class C : public virtual V
73
{
74
public:
75
    int c;
76
};
77
 
78
class AD
79
{
80
public:
81
    virtual int vg() = 0;
82
};
83
 
84
class D : public AD, virtual public V
85
{
86
public:
87
    static void s();
88
    virtual int vg();
89
    virtual int vd();
90
    int fd();
91
    int d;
92
};
93
 
94
class E : public B, virtual public V, public D, public C
95
{
96
public:
97
    int f();
98
    int vg();
99
    int vv();
100
    int e;
101
};
102
 
103
D   dd;
104
D*  ppd = &dd;
105
AD* pAd = &dd;
106
 
107
A   a;
108
B   b;
109
C   c;
110
D   d;
111
E   e;
112
V   v;
113
VB  vb;
114
 
115
 
116
A*      pAa     =       &a;
117
A*      pAe     =       &e;
118
 
119
B*      pBe     =       &e;
120
 
121
D*      pDd     =       &d;
122
D*      pDe     =       &e;
123
 
124
V*      pVa     =       &a;
125
V*      pVv     =       &v;
126
V*      pVe     =       &e;
127
V*     pVd      =       &d;
128
 
129
AD*     pADe    =       &e;
130
 
131
E*      pEe     =       &e;
132
 
133
VB*     pVB     =       &vb;
134
 
135
void init()
136
{
137
        a.vb = 1;
138
        b.vb = 2;
139
        c.vb = 3;
140
        d.vb = 4;
141
        e.vb = 5;
142
        v.vb = 6;
143
        vb.vb = 7;
144
 
145
        d.d     = 1;
146
        e.d     =  2;
147
}
148
 
149
extern "C" int printf(const char *, ...);
150
 
151
int all_count = 0;
152
int failed_count = 0;
153
 
154
#define TEST(EXPR, EXPECTED) \
155
   ret = EXPR; \
156
   if (ret != EXPECTED) {\
157
      printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
158
      failed_count++; } \
159
   all_count++;
160
 
161
int ret;
162
 
163
void test_calls()
164
{
165
        TEST(pAe->f(), 20);
166
        TEST(pAa->f(), 1);
167
 
168
        TEST(pDe->vg(), 202);
169
        TEST(pADe->vg(), 202);
170
        TEST(pDd->vg(), 101);
171
 
172
        TEST(pEe->vvb(), 411);
173
 
174
        TEST(pVB->vvb(), 407);
175
 
176
        TEST(pBe->vvb(), 411);
177
        TEST(pDe->vvb(), 411);
178
 
179
        TEST(pEe->vd(), 282);
180
        TEST(pEe->fvb(), 311);
181
 
182
        TEST(pEe->D::vg(), 102);
183
        printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
184
}
185
#ifdef usestubs
186
extern "C" {
187
  void set_debug_traps();
188
  void breakpoint();
189
};
190
#endif
191
 
192
int main()
193
{
194
#ifdef usestubs
195
   set_debug_traps();
196
   breakpoint();
197
#endif
198
    init();
199
 
200
    e.w = 7;
201
    e.vb = 11;
202
 
203
    test_calls();
204
    return 0;
205
 
206
}
207
 
208
int A::f() {return 1;}
209
int B::f() {return 2;}
210
void D::s() {}
211
int E::f() {return 20;}
212
int D::vg() {return 100+d;}
213
int E::vg() {return 200+d;}
214
int V::f() {return 600+w;}
215
int V::vv() {return 400+w;}
216
int E::vv() {return 450+w;}
217
int D::fd() {return 250+d;}
218
int D::vd() {return 280+d;}
219
int VB::fvb() {return 300+vb;}
220
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.