Mercurial > projects > ldc
comparison gen/classes.cpp @ 138:aeddd4d533b3 trunk
[svn r142] minor fix to dynamic casts.
added a few missed files.
author | lindquist |
---|---|
date | Fri, 18 Jan 2008 20:13:19 +0100 |
parents | ce7b81fb957f |
children | a123dca8349b |
comparison
equal
deleted
inserted
replaced
137:ce7b81fb957f | 138:aeddd4d533b3 |
---|---|
876 | 876 |
877 ////////////////////////////////////////////////////////////////////////////////////////// | 877 ////////////////////////////////////////////////////////////////////////////////////////// |
878 | 878 |
879 DValue* DtoCastClass(DValue* val, Type* _to) | 879 DValue* DtoCastClass(DValue* val, Type* _to) |
880 { | 880 { |
881 Logger::println("DtoCastClass(%s, %s)", val->getType()->toChars(), _to->toChars()); | |
882 LOG_SCOPE; | |
883 | |
881 Type* to = DtoDType(_to); | 884 Type* to = DtoDType(_to); |
882 if (to->ty == Tpointer) { | 885 if (to->ty == Tpointer) { |
883 const llvm::Type* tolltype = DtoType(_to); | 886 const llvm::Type* tolltype = DtoType(_to); |
884 llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype); | 887 llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype); |
885 return new DImValue(_to, rval); | 888 return new DImValue(_to, rval); |
890 | 893 |
891 Type* from = DtoDType(val->getType()); | 894 Type* from = DtoDType(val->getType()); |
892 TypeClass* fc = (TypeClass*)from; | 895 TypeClass* fc = (TypeClass*)from; |
893 | 896 |
894 if (tc->sym->isInterfaceDeclaration()) { | 897 if (tc->sym->isInterfaceDeclaration()) { |
898 Logger::println("to interface"); | |
895 if (fc->sym->isInterfaceDeclaration()) { | 899 if (fc->sym->isInterfaceDeclaration()) { |
900 Logger::println("from interface"); | |
896 return DtoDynamicCastInterface(val, _to); | 901 return DtoDynamicCastInterface(val, _to); |
897 } | 902 } |
898 else { | 903 else { |
904 Logger::println("from object"); | |
899 return DtoDynamicCastObject(val, _to); | 905 return DtoDynamicCastObject(val, _to); |
900 } | 906 } |
901 } | 907 } |
902 else { | 908 else { |
909 Logger::println("to object"); | |
903 int poffset; | 910 int poffset; |
904 if (fc->sym->isInterfaceDeclaration()) { | 911 if (fc->sym->isInterfaceDeclaration()) { |
912 Logger::println("interface cast"); | |
905 return DtoCastInterfaceToObject(val, _to); | 913 return DtoCastInterfaceToObject(val, _to); |
906 } | 914 } |
907 else if (tc->sym->isBaseOf(fc->sym,NULL)) { | 915 else if (!tc->sym->isInterfaceDeclaration() && tc->sym->isBaseOf(fc->sym,NULL)) { |
916 Logger::println("static down cast)"); | |
908 const llvm::Type* tolltype = DtoType(_to); | 917 const llvm::Type* tolltype = DtoType(_to); |
909 llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype); | 918 llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype); |
910 return new DImValue(_to, rval); | 919 return new DImValue(_to, rval); |
911 } | 920 } |
912 else { | 921 else { |
922 Logger::println("dynamic up cast"); | |
913 return DtoDynamicCastObject(val, _to); | 923 return DtoDynamicCastObject(val, _to); |
914 } | 924 } |
915 } | 925 } |
916 } | 926 } |
917 | 927 |