1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
use core;
use core:debug;
// Test some object cloning!
value CloneVal {
Dbg z;
init() {
init() {
z(8);
}
}
}
// Base class for cloning.
class CloneBase {
Int a;
Dbg b;
CloneVal v;
init() {
init() {
a = 2;
b(3);
}
}
}
// Derived class for cloning.
class CloneDerived extends CloneBase {
Int c;
init() {
init() {
c = 4;
}
}
init(CloneDerived o) {
init(o) {
c = o.c + 1;
}
}
void deepCopy(CloneEnv e) {
super:deepCopy(e);
c++;
}
}
Bool testClone() {
CloneBase a;
CloneBase c = clone(a);
disjoint(a, c);
}
Bool testCloneDerived() {
CloneDerived a;
CloneDerived c = a.clone;
disjoint(a, c) & (c.c == 6);
}
Bool testCloneValue() {
CloneVal a;
CloneVal b = a.clone;
disjoint(a.z, b.z);
}
Int testCloneArray() {
Dbg[] array = Dbg:[Dbg(1), Dbg(2), Dbg(3), Dbg(4)];
Dbg[] c = array.clone;
Int sum = 0;
for (Nat i = 0; i < c.count; i++) {
if (disjoint(array[i], c[i])) {
sum = sum + c[i].get;
}
}
sum;
}
|