mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-19 06:13:14 +01:00
[svn r142] minor fix to dynamic casts.
added a few missed files.
This commit is contained in:
@@ -878,6 +878,9 @@ void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance)
|
||||
|
||||
DValue* DtoCastClass(DValue* val, Type* _to)
|
||||
{
|
||||
Logger::println("DtoCastClass(%s, %s)", val->getType()->toChars(), _to->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
Type* to = DtoDType(_to);
|
||||
if (to->ty == Tpointer) {
|
||||
const llvm::Type* tolltype = DtoType(_to);
|
||||
@@ -892,24 +895,31 @@ DValue* DtoCastClass(DValue* val, Type* _to)
|
||||
TypeClass* fc = (TypeClass*)from;
|
||||
|
||||
if (tc->sym->isInterfaceDeclaration()) {
|
||||
Logger::println("to interface");
|
||||
if (fc->sym->isInterfaceDeclaration()) {
|
||||
Logger::println("from interface");
|
||||
return DtoDynamicCastInterface(val, _to);
|
||||
}
|
||||
else {
|
||||
Logger::println("from object");
|
||||
return DtoDynamicCastObject(val, _to);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger::println("to object");
|
||||
int poffset;
|
||||
if (fc->sym->isInterfaceDeclaration()) {
|
||||
Logger::println("interface cast");
|
||||
return DtoCastInterfaceToObject(val, _to);
|
||||
}
|
||||
else if (tc->sym->isBaseOf(fc->sym,NULL)) {
|
||||
else if (!tc->sym->isInterfaceDeclaration() && tc->sym->isBaseOf(fc->sym,NULL)) {
|
||||
Logger::println("static down cast)");
|
||||
const llvm::Type* tolltype = DtoType(_to);
|
||||
llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype);
|
||||
return new DImValue(_to, rval);
|
||||
}
|
||||
else {
|
||||
Logger::println("dynamic up cast");
|
||||
return DtoDynamicCastObject(val, _to);
|
||||
}
|
||||
}
|
||||
|
||||
70
llvmdc-tango
Normal file
70
llvmdc-tango
Normal file
@@ -0,0 +1,70 @@
|
||||
profile=tango
|
||||
|
||||
compiler=llvmdc
|
||||
inifile=llvmdc.conf
|
||||
|
||||
exeext=
|
||||
objext=bc
|
||||
|
||||
|
||||
version=LLVMDC
|
||||
noversion=DigitalMars
|
||||
noversion=GNU
|
||||
testversion=linux
|
||||
testversion=Unix
|
||||
testversion=Posix
|
||||
testversion=Windows
|
||||
testversion=Win32
|
||||
testversion=Win64
|
||||
testversion=X86
|
||||
testversion=PPC
|
||||
testversion=X86_64
|
||||
testversion=PPC64
|
||||
testversion=D_InlineAsm
|
||||
testvestion=D_InlineAsm_X86
|
||||
testversion=D_InlineAsm_PPC
|
||||
testversion=D_InlineAsm_X86_64
|
||||
testversion=D_InlineAsm_PPC64
|
||||
testversion=LittleEndian
|
||||
testversion=BigEndian
|
||||
testversion=LLVM64
|
||||
|
||||
|
||||
[compile]
|
||||
cmd=llvmdc -version=Tango -c $i
|
||||
|
||||
flag=$i
|
||||
incdir=-I$i
|
||||
libdir=-L-L=$i
|
||||
optimize=-O3
|
||||
version=-version=$i
|
||||
|
||||
|
||||
[link]
|
||||
oneatatime=yes
|
||||
cmd=llvmdc $i -of$o
|
||||
|
||||
libdir=-L-L=$i
|
||||
lib=-L-l=$i
|
||||
flag=-L$i
|
||||
|
||||
|
||||
[liblink]
|
||||
safe=yes
|
||||
oneatatime=yes
|
||||
cmd=llvm-ar rsc $o $i
|
||||
|
||||
libdir=-L=$i
|
||||
lib=-l=$i
|
||||
flag=$i
|
||||
|
||||
|
||||
[postliblink]
|
||||
#cmd=ranlib $i
|
||||
|
||||
|
||||
[shliblink]
|
||||
shlibs=no
|
||||
|
||||
[dyliblink]
|
||||
dylibs=no
|
||||
@@ -550,7 +550,8 @@ class Buffer : IBuffer
|
||||
***********************************************************************/
|
||||
|
||||
IBuffer append (void* src, uint length)
|
||||
{
|
||||
{
|
||||
printf("Buffer.append(%p, %u)\n", src, length);
|
||||
if (length > writable)
|
||||
// can we write externally?
|
||||
if (sink)
|
||||
@@ -570,8 +571,9 @@ class Buffer : IBuffer
|
||||
}
|
||||
else
|
||||
error (overflow);
|
||||
|
||||
printf(" copying\n");
|
||||
copy (src, length);
|
||||
printf("returning\n");
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1095,6 +1097,7 @@ class Buffer : IBuffer
|
||||
|
||||
protected void copy (void *src, uint size)
|
||||
{
|
||||
printf("Buffer.copy(%p, %u)\n", src, size);
|
||||
// avoid "out of bounds" test on zero size
|
||||
if (size)
|
||||
{
|
||||
@@ -1102,6 +1105,7 @@ class Buffer : IBuffer
|
||||
memcpy (&data[extent], src, size);
|
||||
extent += size;
|
||||
}
|
||||
printf(" copy done\n");
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
85
tangotests/s.d
Normal file
85
tangotests/s.d
Normal file
@@ -0,0 +1,85 @@
|
||||
module s;
|
||||
|
||||
interface Inter
|
||||
{
|
||||
void inter();
|
||||
}
|
||||
|
||||
interface Inter2
|
||||
{
|
||||
void inter2();
|
||||
}
|
||||
|
||||
interface InterOne : Inter
|
||||
{
|
||||
void interOne();
|
||||
}
|
||||
|
||||
abstract class ClassAbstract : InterOne
|
||||
{
|
||||
abstract void inter();
|
||||
abstract void interOne();
|
||||
}
|
||||
|
||||
class TheClassOne : ClassAbstract
|
||||
{
|
||||
void inter()
|
||||
{
|
||||
}
|
||||
void interOne()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class TheClassTwo : TheClassOne, Inter2
|
||||
{
|
||||
long l;
|
||||
double d;
|
||||
|
||||
void inter2()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
|
||||
void main()
|
||||
{
|
||||
printf("classinfo test\n");
|
||||
{
|
||||
auto c = new TheClassOne;
|
||||
{
|
||||
auto ci = c.classinfo;
|
||||
printf("ci = %.*s\n", ci.name.length, ci.name.ptr);
|
||||
printf("ci.interfaces.length = %lu\n", ci.interfaces.length);
|
||||
printf("i[0] = %.*s\n", ci.interfaces[0].classinfo.name.length, ci.interfaces[0].classinfo.name.ptr);
|
||||
printf("i[1] = %.*s\n", ci.interfaces[1].classinfo.name.length, ci.interfaces[1].classinfo.name.ptr);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto c = new TheClassTwo;
|
||||
{
|
||||
auto ci = c.classinfo;
|
||||
printf("ci = %.*s\n", ci.name.length, ci.name.ptr);
|
||||
printf("ci.interfaces.length = %lu\n", ci.interfaces.length);
|
||||
printf("i[0] = %.*s\n", ci.interfaces[0].classinfo.name.length, ci.interfaces[0].classinfo.name.ptr);
|
||||
printf("i[1] = %.*s\n", ci.interfaces[1].classinfo.name.length, ci.interfaces[1].classinfo.name.ptr);
|
||||
printf("i[2] = %.*s\n", ci.interfaces[2].classinfo.name.length, ci.interfaces[2].classinfo.name.ptr);
|
||||
}
|
||||
auto i = cast(InterOne)c;
|
||||
{
|
||||
auto ci = i.classinfo;
|
||||
printf("ci = %.*s\n", ci.name.length, ci.name.ptr);
|
||||
}
|
||||
auto i2 = cast(Inter2)i;
|
||||
{
|
||||
auto ci = i2.classinfo;
|
||||
printf("ci = %.*s\n", ci.name.length, ci.name.ptr);
|
||||
}
|
||||
auto o = cast(Object)i2;
|
||||
{
|
||||
auto ci = o.classinfo;
|
||||
printf("ci = %.*s\n", ci.name.length, ci.name.ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
tangotests/t.d
Normal file
33
tangotests/t.d
Normal file
@@ -0,0 +1,33 @@
|
||||
interface MyInterface
|
||||
{
|
||||
void func();
|
||||
}
|
||||
|
||||
abstract class MyBaseClass : MyInterface
|
||||
{
|
||||
abstract void func();
|
||||
}
|
||||
|
||||
class MyClass : MyBaseClass
|
||||
{
|
||||
void func()
|
||||
{
|
||||
}
|
||||
|
||||
MyBaseClass toBase()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
printf("STARTING\n");
|
||||
auto c = new MyClass;
|
||||
printf("c = %p\n", c);
|
||||
auto b = c.toBase;
|
||||
printf("b = %p\n", b);
|
||||
printf("FINISHED\n");
|
||||
}
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
Reference in New Issue
Block a user