Merge remote branch 'master'
[prop.git] / tests / prop2.pcc
blob6e017fc2179ff88a421c417b357f03a4a860122f
1 //  Test datatype inheritance
3 #include <iostream.h>
4 #include <AD/gc/gcobject.h>
6 int created = 0;
7 int destroyed = 0;
8 int traced = 0;
10 class C1 : public GCObject 
11
12 public:
13    C1() { ++created; }
14   ~C1() { ++destroyed; }
15    virtual void trace(GC *) { ++traced; }
18 template <class T>
19 class C2 : public C1 
20
21 public:
22    C2() {}
23   ~C2() {}
26 datatype TYPE1 : collectable public C1 :: collectable rewrite printable =
27      CON1();
29 datatype TYPE2 : collectable public C1 :: collectable rewrite printable =
30      CON2a()
31    | CON2b()
32    ;
34 datatype TYPE3<T> : collectable public C1 :: collectable rewrite printable =
35      CON3a(T)
36      ;
38 datatype TYPE4<T> : collectable public C1 :: collectable rewrite printable =
39      CON4a(T)
40    | CON4b(T)
41    ;
43 datatype TYPE5<T> : collectable public C2<T> :: collectable rewrite printable =
44      CON5a(T, TYPE1)
45      ;
47 datatype TYPE6<T> : collectable public C2<T> :: collectable rewrite printable =
48      CON6a(T, TYPE1)
49    | CON6b(T)
50    ;
52 instantiate datatype TYPE1, TYPE2, TYPE3<int>, 
53                      TYPE4<int>, TYPE5<int>, TYPE6<int>,
54                      TYPE5<TYPE1>, TYPE6<TYPE1>,
55                      TYPE5<TYPE5<TYPE1> >, TYPE6<TYPE6<TYPE1> >
58 int main()
59 {  GC::get_default_gc().set_finalization(true);
60    for (int i = 0; i < 10000; i++)
61    {  TYPE1         t1 = CON1();
62       TYPE2         t2 = CON2a();
63       TYPE3<int>    t3 = CON3a(1);
64       TYPE4<int>    t4 = CON4a(0);
65       TYPE5<int>    t5 = CON5a(1,t1);
66       TYPE6<int>    t6 = CON6a(1,t1);
67       TYPE5<TYPE1>  t7 = CON5a(t1,t1);
68       TYPE6<TYPE1>  t8 = CON6a(t1,t1);
70       if (i % 1000 == 0) 
71           cout << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8 << '\n';
72    }
73    cout << "Created   = " << created << endl
74         << "Destroyed = " << destroyed << endl
75         << "Traced    = " << traced << endl
76    ;
77    return 0;