comparison gen/toir.cpp @ 1271:0686701178d3

Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp. Fixed filenames for array bounds errors and probably others, fixes #271 .
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Mon, 27 Apr 2009 13:30:48 +0200
parents dd135ff697fa
children dd4766851b37
comparison
equal deleted inserted replaced
1270:dd135ff697fa 1271:0686701178d3
1163 DValue* ThisExp::toElem(IRState* p) 1163 DValue* ThisExp::toElem(IRState* p)
1164 { 1164 {
1165 Logger::print("ThisExp::toElem: %s @ %s\n", toChars(), type->toChars()); 1165 Logger::print("ThisExp::toElem: %s @ %s\n", toChars(), type->toChars());
1166 LOG_SCOPE; 1166 LOG_SCOPE;
1167 1167
1168 // this seems to happen for dmd generated assert statements like:
1169 // assert(this, "null this");
1170 // FIXME: check for TOKthis in AssertExp instead
1171 if (!var)
1172 {
1173 LLValue* v = p->func()->thisArg;
1174 assert(v);
1175 return new DVarValue(type, v);
1176 }
1177 // regular this expr 1168 // regular this expr
1178 else if (VarDeclaration* vd = var->isVarDeclaration()) { 1169 if (VarDeclaration* vd = var->isVarDeclaration()) {
1179 LLValue* v; 1170 LLValue* v;
1180 if (vd->toParent2() != p->func()->decl) { 1171 if (vd->toParent2() != p->func()->decl) {
1181 Logger::println("nested this exp"); 1172 Logger::println("nested this exp");
1182 return DtoNestedVariable(loc, type, vd); 1173 return DtoNestedVariable(loc, type, vd);
1183 } 1174 }
1187 } 1178 }
1188 return new DVarValue(type, vd, v); 1179 return new DVarValue(type, vd, v);
1189 } 1180 }
1190 1181
1191 // anything we're not yet handling ? 1182 // anything we're not yet handling ?
1192 assert(0); 1183 assert(0 && "no var in ThisExp");
1193 return 0; 1184 return 0;
1194 } 1185 }
1195 1186
1196 ////////////////////////////////////////////////////////////////////////////////////////// 1187 //////////////////////////////////////////////////////////////////////////////////////////
1197 1188
1751 1742
1752 if(!global.params.useAssert) 1743 if(!global.params.useAssert)
1753 return NULL; 1744 return NULL;
1754 1745
1755 // condition 1746 // condition
1756 DValue* cond = e1->toElem(p); 1747 DValue* cond;
1757 Type* condty = e1->type->toBasetype(); 1748 Type* condty;
1749
1750 // special case assert(this);
1751 if (e1->op == TOKthis)
1752 {
1753 LLValue* thisarg = p->func()->thisArg;
1754 assert(thisarg && "null thisarg, but we're in assert(this) exp;");
1755 LLValue* thisptr = DtoLoad(p->func()->thisArg);
1756 LLValue* thisnotnull = p->ir->CreateIsNotNull(thisptr);
1757 cond = new DImValue(Type::tbool, thisnotnull);
1758 condty = Type::tbool;
1759 }
1760 else
1761 {
1762 cond = e1->toElem(p);
1763 condty = e1->type->toBasetype();
1764 }
1758 1765
1759 InvariantDeclaration* invdecl; 1766 InvariantDeclaration* invdecl;
1760 1767
1761 // class invariants 1768 // class invariants
1762 if( 1769 if(