[svn r117] Initial working implementation of interfaces.

Groundwork for all the different types of class/interface casts laid out.
This commit is contained in:
Tomas Lindquist Olsen
2007-11-24 06:33:00 +01:00
parent 0a8ff5931a
commit b43f5729b0
18 changed files with 867 additions and 145 deletions

22
test/interface1.d Normal file
View File

@@ -0,0 +1,22 @@
module interface1;
interface Inter
{
void func();
}
class Class : Inter
{
override void func()
{
printf("hello world\n");
}
}
void main()
{
scope c = new Class;
c.func();
Inter i = c;
i.func();
}

35
test/interface2.d Normal file
View File

@@ -0,0 +1,35 @@
module interface2;
interface A
{
void a();
}
interface B
{
void b();
}
class C : A,B
{
int i = 0;
override void a()
{
printf("hello from C.a\n");
}
override void b()
{
printf("hello from C.b\n");
}
}
void main()
{
scope c = new C;
{c.a();
c.b();}
{A a = c;
a.a();}
{B b = c;
b.b();}
}

28
test/interface3.d Normal file
View File

@@ -0,0 +1,28 @@
module interface3;
interface I
{
void func();
}
class C : I
{
int i = 42;
override void func()
{
printf("hello %d\n", i);
i++;
}
}
void main()
{
scope c = new C;
{c.func();}
{
I i = c;
{i.func();}
}
{printf("final %d\n", c.i);}
{assert(c.i == 44);}
}

33
test/interface4.d Normal file
View File

@@ -0,0 +1,33 @@
module interface4;
interface I
{
void func();
}
interface I2
{
void func();
}
class C : I,I2
{
int i = 42;
override void func()
{
printf("hello %d\n", i);
i++;
}
}
void main()
{
scope c = new C;
c.func();
I i = c;
i.func();
I2 i2 = c;
i2.func();
printf("final %d\n", c.i);
assert(c.i == 45);
}