From 7825be29ee315c8d5a2d1b1ca7083b49084539b5 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Fri, 18 Jan 2008 20:13:19 +0100 Subject: [PATCH] [svn r142] minor fix to dynamic casts. added a few missed files. --- gen/classes.cpp | 12 +++++- llvmdc-tango | 70 +++++++++++++++++++++++++++++++++ tango/tango/io/Buffer.d | 8 +++- tangotests/s.d | 85 +++++++++++++++++++++++++++++++++++++++++ tangotests/t.d | 33 ++++++++++++++++ 5 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 llvmdc-tango create mode 100644 tangotests/s.d create mode 100644 tangotests/t.d diff --git a/gen/classes.cpp b/gen/classes.cpp index 977e5bdb..23402e35 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -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); } } diff --git a/llvmdc-tango b/llvmdc-tango new file mode 100644 index 00000000..fce75875 --- /dev/null +++ b/llvmdc-tango @@ -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 diff --git a/tango/tango/io/Buffer.d b/tango/tango/io/Buffer.d index 0e540156..9d37b50c 100644 --- a/tango/tango/io/Buffer.d +++ b/tango/tango/io/Buffer.d @@ -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"); } /*********************************************************************** diff --git a/tangotests/s.d b/tangotests/s.d new file mode 100644 index 00000000..bc904e59 --- /dev/null +++ b/tangotests/s.d @@ -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); + } + } +} diff --git a/tangotests/t.d b/tangotests/t.d new file mode 100644 index 00000000..fc4d95cd --- /dev/null +++ b/tangotests/t.d @@ -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*, ...);