OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [gdb/] [testsuite/] [gdb.cp/] [virtfunc.cc] - Diff between revs 157 and 223

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 157 Rev 223
/* This test script is part of GDB, the GNU debugger.
/* This test script is part of GDB, the GNU debugger.
 
 
   Copyright 1993, 1994, 1997, 1998, 1999, 2003, 2004,
   Copyright 1993, 1994, 1997, 1998, 1999, 2003, 2004,
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
   */
 
 
// Pls try the following program on virtual functions and try to do print on
// Pls try the following program on virtual functions and try to do print on
//  most of the code in main().  Almost none of them works !
//  most of the code in main().  Almost none of them works !
 
 
//
//
// The inheritance structure is:
// The inheritance structure is:
//
//
// V : VA VB
// V : VA VB
// A : (V)
// A : (V)
// B : A
// B : A
// D : AD (V)
// D : AD (V)
// C : (V)
// C : (V)
// E : B (V) D C
// E : B (V) D C
//
//
 
 
class VA
class VA
{
{
public:
public:
    int va;
    int va;
};
};
 
 
class VB
class VB
{
{
public:
public:
    int vb;
    int vb;
    int fvb();
    int fvb();
    virtual int vvb();
    virtual int vvb();
};
};
 
 
class V : public VA, public VB
class V : public VA, public VB
{
{
public:
public:
    int f();
    int f();
    virtual int vv();
    virtual int vv();
    int w;
    int w;
};
};
 
 
class A : virtual public V
class A : virtual public V
{
{
public:
public:
    virtual int f();
    virtual int f();
private:
private:
    int a;
    int a;
};
};
 
 
class B : public A
class B : public A
{
{
public:
public:
    int f();
    int f();
private:
private:
    int b;
    int b;
};
};
 
 
class C : public virtual V
class C : public virtual V
{
{
public:
public:
    int c;
    int c;
};
};
 
 
class AD
class AD
{
{
public:
public:
    virtual int vg() = 0;
    virtual int vg() = 0;
};
};
 
 
class D : public AD, virtual public V
class D : public AD, virtual public V
{
{
public:
public:
    static void s();
    static void s();
    virtual int vg();
    virtual int vg();
    virtual int vd();
    virtual int vd();
    int fd();
    int fd();
    int d;
    int d;
};
};
 
 
class E : public B, virtual public V, public D, public C
class E : public B, virtual public V, public D, public C
{
{
public:
public:
    int f();
    int f();
    int vg();
    int vg();
    int vv();
    int vv();
    int e;
    int e;
};
};
 
 
D   dd;
D   dd;
D*  ppd = &dd;
D*  ppd = &dd;
AD* pAd = &dd;
AD* pAd = &dd;
 
 
A   a;
A   a;
B   b;
B   b;
C   c;
C   c;
D   d;
D   d;
E   e;
E   e;
V   v;
V   v;
VB  vb;
VB  vb;
 
 
 
 
A*      pAa     =       &a;
A*      pAa     =       &a;
A*      pAe     =       &e;
A*      pAe     =       &e;
 
 
B*      pBe     =       &e;
B*      pBe     =       &e;
 
 
D*      pDd     =       &d;
D*      pDd     =       &d;
D*      pDe     =       &e;
D*      pDe     =       &e;
 
 
V*      pVa     =       &a;
V*      pVa     =       &a;
V*      pVv     =       &v;
V*      pVv     =       &v;
V*      pVe     =       &e;
V*      pVe     =       &e;
V*     pVd      =       &d;
V*     pVd      =       &d;
 
 
AD*     pADe    =       &e;
AD*     pADe    =       &e;
 
 
E*      pEe     =       &e;
E*      pEe     =       &e;
 
 
VB*     pVB     =       &vb;
VB*     pVB     =       &vb;
 
 
void init()
void init()
{
{
        a.vb = 1;
        a.vb = 1;
        b.vb = 2;
        b.vb = 2;
        c.vb = 3;
        c.vb = 3;
        d.vb = 4;
        d.vb = 4;
        e.vb = 5;
        e.vb = 5;
        v.vb = 6;
        v.vb = 6;
        vb.vb = 7;
        vb.vb = 7;
 
 
        d.d     = 1;
        d.d     = 1;
        e.d     =  2;
        e.d     =  2;
}
}
 
 
extern "C" int printf(const char *, ...);
extern "C" int printf(const char *, ...);
 
 
int all_count = 0;
int all_count = 0;
int failed_count = 0;
int failed_count = 0;
 
 
#define TEST(EXPR, EXPECTED) \
#define TEST(EXPR, EXPECTED) \
   ret = EXPR; \
   ret = EXPR; \
   if (ret != EXPECTED) {\
   if (ret != EXPECTED) {\
      printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
      printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
      failed_count++; } \
      failed_count++; } \
   all_count++;
   all_count++;
 
 
int ret;
int ret;
 
 
void test_calls()
void test_calls()
{
{
        TEST(pAe->f(), 20);
        TEST(pAe->f(), 20);
        TEST(pAa->f(), 1);
        TEST(pAa->f(), 1);
 
 
        TEST(pDe->vg(), 202);
        TEST(pDe->vg(), 202);
        TEST(pADe->vg(), 202);
        TEST(pADe->vg(), 202);
        TEST(pDd->vg(), 101);
        TEST(pDd->vg(), 101);
 
 
        TEST(pEe->vvb(), 411);
        TEST(pEe->vvb(), 411);
 
 
        TEST(pVB->vvb(), 407);
        TEST(pVB->vvb(), 407);
 
 
        TEST(pBe->vvb(), 411);
        TEST(pBe->vvb(), 411);
        TEST(pDe->vvb(), 411);
        TEST(pDe->vvb(), 411);
 
 
        TEST(pEe->vd(), 282);
        TEST(pEe->vd(), 282);
        TEST(pEe->fvb(), 311);
        TEST(pEe->fvb(), 311);
 
 
        TEST(pEe->D::vg(), 102);
        TEST(pEe->D::vg(), 102);
        printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
        printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
}
}
#ifdef usestubs
#ifdef usestubs
extern "C" {
extern "C" {
  void set_debug_traps();
  void set_debug_traps();
  void breakpoint();
  void breakpoint();
};
};
#endif
#endif
 
 
int main()
int main()
{
{
#ifdef usestubs
#ifdef usestubs
   set_debug_traps();
   set_debug_traps();
   breakpoint();
   breakpoint();
#endif
#endif
    init();
    init();
 
 
    e.w = 7;
    e.w = 7;
    e.vb = 11;
    e.vb = 11;
 
 
    test_calls();
    test_calls();
    return 0;
    return 0;
 
 
}
}
 
 
int A::f() {return 1;}
int A::f() {return 1;}
int B::f() {return 2;}
int B::f() {return 2;}
void D::s() {}
void D::s() {}
int E::f() {return 20;}
int E::f() {return 20;}
int D::vg() {return 100+d;}
int D::vg() {return 100+d;}
int E::vg() {return 200+d;}
int E::vg() {return 200+d;}
int V::f() {return 600+w;}
int V::f() {return 600+w;}
int V::vv() {return 400+w;}
int V::vv() {return 400+w;}
int E::vv() {return 450+w;}
int E::vv() {return 450+w;}
int D::fd() {return 250+d;}
int D::fd() {return 250+d;}
int D::vd() {return 280+d;}
int D::vd() {return 280+d;}
int VB::fvb() {return 300+vb;}
int VB::fvb() {return 300+vb;}
int VB::vvb() {return 400+vb;}
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.