forked from OSchip/llvm-project
Type-cast RHS of assignment to prevent warning compiling rewritten foreach code.
llvm-svn: 45777
This commit is contained in:
parent
22f2347791
commit
6fa7516bc9
|
@ -808,7 +808,7 @@ void RewriteTest::SynthCountByEnumWithState(std::string &buf) {
|
||||||
/// do {
|
/// do {
|
||||||
/// if (startMutations != *enumState.mutationsPtr)
|
/// if (startMutations != *enumState.mutationsPtr)
|
||||||
/// objc_enumerationMutation(l_collection);
|
/// objc_enumerationMutation(l_collection);
|
||||||
/// elem = enumState.itemsPtr[counter++];
|
/// elem = (type)enumState.itemsPtr[counter++];
|
||||||
/// stmts;
|
/// stmts;
|
||||||
/// } while (counter < limit);
|
/// } while (counter < limit);
|
||||||
/// } while (limit = [l_collection countByEnumeratingWithState:&enumState
|
/// } while (limit = [l_collection countByEnumeratingWithState:&enumState
|
||||||
|
@ -826,19 +826,23 @@ Stmt *RewriteTest::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S) {
|
||||||
const char *startBuf = SM->getCharacterData(startLoc);
|
const char *startBuf = SM->getCharacterData(startLoc);
|
||||||
const char *startCollectionBuf = SM->getCharacterData(collectionLoc);
|
const char *startCollectionBuf = SM->getCharacterData(collectionLoc);
|
||||||
const char *elementName;
|
const char *elementName;
|
||||||
|
std::string elementTypeAsString;
|
||||||
std::string buf;
|
std::string buf;
|
||||||
buf = "\n{\n\t";
|
buf = "\n{\n\t";
|
||||||
if (DeclStmt *DS = dyn_cast<DeclStmt>(S->getElement())) {
|
if (DeclStmt *DS = dyn_cast<DeclStmt>(S->getElement())) {
|
||||||
// type elem;
|
// type elem;
|
||||||
QualType ElementType = cast<ValueDecl>(DS->getDecl())->getType();
|
QualType ElementType = cast<ValueDecl>(DS->getDecl())->getType();
|
||||||
buf += ElementType.getAsString();
|
elementTypeAsString = ElementType.getAsString();
|
||||||
|
buf += elementTypeAsString;
|
||||||
buf += " ";
|
buf += " ";
|
||||||
elementName = DS->getDecl()->getName();
|
elementName = DS->getDecl()->getName();
|
||||||
buf += elementName;
|
buf += elementName;
|
||||||
buf += ";\n\t";
|
buf += ";\n\t";
|
||||||
}
|
}
|
||||||
else if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(S->getElement()))
|
else if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(S->getElement())) {
|
||||||
elementName = DR->getDecl()->getName();
|
elementName = DR->getDecl()->getName();
|
||||||
|
elementTypeAsString = DR->getDecl()->getType().getAsString();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
assert(false && "RewriteObjCForCollectionStmt - bad element kind");
|
assert(false && "RewriteObjCForCollectionStmt - bad element kind");
|
||||||
|
|
||||||
|
@ -879,7 +883,7 @@ Stmt *RewriteTest::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S) {
|
||||||
/// do {
|
/// do {
|
||||||
/// if (startMutations != *enumState.mutationsPtr)
|
/// if (startMutations != *enumState.mutationsPtr)
|
||||||
/// objc_enumerationMutation(l_collection);
|
/// objc_enumerationMutation(l_collection);
|
||||||
/// elem = enumState.itemsPtr[counter++];
|
/// elem = (type)enumState.itemsPtr[counter++];
|
||||||
buf += "if (limit) {\n\t";
|
buf += "if (limit) {\n\t";
|
||||||
buf += "unsigned long startMutations = *enumState.mutationsPtr;\n\t";
|
buf += "unsigned long startMutations = *enumState.mutationsPtr;\n\t";
|
||||||
buf += "do {\n\t\t";
|
buf += "do {\n\t\t";
|
||||||
|
@ -888,7 +892,9 @@ Stmt *RewriteTest::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S) {
|
||||||
buf += "if (startMutations != *enumState.mutationsPtr)\n\t\t\t\t";
|
buf += "if (startMutations != *enumState.mutationsPtr)\n\t\t\t\t";
|
||||||
buf += "objc_enumerationMutation(l_collection);\n\t\t\t";
|
buf += "objc_enumerationMutation(l_collection);\n\t\t\t";
|
||||||
buf += elementName;
|
buf += elementName;
|
||||||
buf += " = enumState.itemsPtr[counter++];";
|
buf += " = (";
|
||||||
|
buf += elementTypeAsString;
|
||||||
|
buf += ")enumState.itemsPtr[counter++];";
|
||||||
// Replace ')' in for '(' type elem in collection ')' with all of these.
|
// Replace ')' in for '(' type elem in collection ')' with all of these.
|
||||||
Rewrite.ReplaceText(lparenLoc, 1, buf.c_str(), buf.size());
|
Rewrite.ReplaceText(lparenLoc, 1, buf.c_str(), buf.size());
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
// RUN: clang -rewrite-test %s
|
||||||
|
|
||||||
|
@protocol P @end
|
||||||
|
|
||||||
|
@interface MyList
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MyList
|
||||||
|
- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MyList (BasicTest)
|
||||||
|
- (void)compilerTestAgainst;
|
||||||
|
@end
|
||||||
|
|
||||||
|
int LOOP();
|
||||||
|
@implementation MyList (BasicTest)
|
||||||
|
- (void)compilerTestAgainst {
|
||||||
|
MyList * el;
|
||||||
|
for (el in self)
|
||||||
|
{ LOOP(); }
|
||||||
|
for (MyList * el1 in self)
|
||||||
|
LOOP();
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
Loading…
Reference in New Issue