comparison gen/tollvm.cpp @ 114:5880c12dba83 trunk

[svn r118] Fixed dynamic casts. Fixed a few interface bugs.
author lindquist
date Sun, 25 Nov 2007 00:19:13 +0100
parents 27b9f749d9fe
children fd7ad91fd713
comparison
equal deleted inserted replaced
113:27b9f749d9fe 114:5880c12dba83
1136 } 1136 }
1137 else 1137 else
1138 assert(0); 1138 assert(0);
1139 } 1139 }
1140 1140
1141 DValue* DtoCastClass(DValue* val, Type* _to)
1142 {
1143 Type* to = DtoDType(_to);
1144 if (to->ty == Tpointer) {
1145 const llvm::Type* tolltype = DtoType(_to);
1146 llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype);
1147 return new DImValue(_to, rval);
1148 }
1149
1150 assert(to->ty == Tclass);
1151 TypeClass* tc = (TypeClass*)to;
1152
1153 Type* from = DtoDType(val->getType());
1154 TypeClass* fc = (TypeClass*)from;
1155
1156 if (tc->sym->isInterfaceDeclaration()) {
1157 assert(!fc->sym->isInterfaceDeclaration());
1158 return DtoCastObjectToInterface(val, _to);
1159 }
1160 else {
1161 if (fc->sym->isInterfaceDeclaration()) {
1162 assert(0);
1163 return DtoCastInterfaceToObject(val);
1164 }
1165 else {
1166 const llvm::Type* tolltype = DtoType(_to);
1167 assert(to->ty == Tclass);
1168 llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype);
1169 return new DImValue(_to, rval);
1170 }
1171 }
1172 }
1173
1174 DValue* DtoCast(DValue* val, Type* to) 1141 DValue* DtoCast(DValue* val, Type* to)
1175 { 1142 {
1176 Type* fromtype = DtoDType(val->getType()); 1143 Type* fromtype = DtoDType(val->getType());
1177 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars()); 1144 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars());
1178 if (fromtype->isintegral()) { 1145 if (fromtype->isintegral()) {