92 lines
2.0 KiB
Common Lisp
92 lines
2.0 KiB
Common Lisp
(* The inheritance analysis has 2 stages, graph construction & cyclic checking.
|
|
it will abort if duplicate or undefined class definitions are found before do cyclic checking *)
|
|
-- uncomment the lines below to get convinced that 1st stage works
|
|
(*
|
|
class DupDef {};
|
|
|
|
class DupDef {};
|
|
|
|
class DupDef1 {};
|
|
|
|
class DupDef1 {};
|
|
|
|
class A inherits SCHEISSE{};
|
|
*)
|
|
(*
|
|
class D inherits D {};
|
|
|
|
class Cycle1 inherits Cycle2 {};
|
|
class Cycle2 inherits Cycle3 {};
|
|
class Cycle3 inherits Cycle1 {};
|
|
|
|
class Cycle4 inherits Cycle3 {};
|
|
*)
|
|
class Ok1{};
|
|
class Ok2_1 inherits Ok1 {};
|
|
class Ok2_2 inherits Ok1 {};
|
|
class Ok3 inherits Ok2_1 {};
|
|
class Ok4 inherits Ok2_2 {};
|
|
|
|
(* Cool has restrictions on inheriting from basic classes *)
|
|
|
|
(*class Err1 inherits Int {};
|
|
class Err3 inherits String {};
|
|
class Err3 inherits Bool {};
|
|
class Err4 inherits Err3 {};*)
|
|
class Err4 inherits Ok1 {
|
|
bye: Bool <- 10;
|
|
hello(a: TT) : NOEXIST { new Object };
|
|
};
|
|
|
|
(* the following case tests redefined attributes and methods *)
|
|
(*
|
|
class Err6Base {
|
|
dup_obj: Int <- 10;
|
|
dup_method1(haha: Int): Int { 10 };
|
|
dup_method2(): Int { 10 };
|
|
dup_method3(): Int { 10 };
|
|
dup_method4(a:NOEXIST, b: Bool, c: NOEXIST): Int { a };
|
|
};
|
|
class Err6Sub inherits Err6Base {
|
|
dup_obj: Bool <- 20;
|
|
dup_obj: Bool <- 20;
|
|
dup_method1(fufu: Int): Int { 20 };
|
|
dup_method2(a:Int): Bool { false };
|
|
dup_method3(a:Int): Int { a };
|
|
dup_method4(a:NOEXIST, b: String, c: Bool): Int { a };
|
|
};
|
|
*)
|
|
|
|
|
|
class DummyMain {
|
|
la: Bool <- 20;
|
|
ala: Bool;
|
|
main(): Object {
|
|
{ new DummyMain; }
|
|
};
|
|
};
|
|
|
|
class Main inherits DummyMain {
|
|
attr1: Bool <- (new Err5).hello();
|
|
attr2: Int <- (new Err5).bye();
|
|
main(): Object {
|
|
{
|
|
let x:Int in {
|
|
x1 <- x + 1;
|
|
};
|
|
(new Err4).hello(true);
|
|
(new Err4).hello();
|
|
}
|
|
};
|
|
|
|
main: Bool <- true;
|
|
};
|
|
|
|
class Err5 {
|
|
ala: Bool <- 20;
|
|
-- hello() : Object {{ala <- ala + 1;}};
|
|
hello: Int <- 20;
|
|
hello(): NOEXIST { new Object };
|
|
bye(): Bool { 10 };
|
|
-- ala: Int <- 20;
|
|
}; |