diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2008-01-10 00:24:29 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2008-01-10 00:24:29 +0000 |
commit | 82ae0152a7ab97745af28d777cc612f0e702b06a (patch) | |
tree | 651d00ec0bbe880d19699999e2e71d38ce6b4654 /clang/Driver/RewriteTest.cpp | |
parent | 73d1017871ec6b8024964e7379e1ef22ea111b72 (diff) | |
download | bcm5719-llvm-82ae0152a7ab97745af28d777cc612f0e702b06a.tar.gz bcm5719-llvm-82ae0152a7ab97745af28d777cc612f0e702b06a.zip |
Allow messaging expression as foreach's collection expression.
llvm-svn: 45793
Diffstat (limited to 'clang/Driver/RewriteTest.cpp')
-rw-r--r-- | clang/Driver/RewriteTest.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp index 81f818a67b4..0384c44670d 100644 --- a/clang/Driver/RewriteTest.cpp +++ b/clang/Driver/RewriteTest.cpp @@ -822,9 +822,7 @@ void RewriteTest::SynthCountByEnumWithState(std::string &buf) { /// Stmt *RewriteTest::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S) { SourceLocation startLoc = S->getLocStart(); - SourceLocation collectionLoc = S->getCollection()->getLocStart(); const char *startBuf = SM->getCharacterData(startLoc); - const char *startCollectionBuf = SM->getCharacterData(collectionLoc); const char *elementName; std::string elementTypeAsString; std::string buf; @@ -852,14 +850,26 @@ Stmt *RewriteTest::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S) { buf += "id items[16];\n\t"; // id l_collection = (id) buf += "id l_collection = (id)"; + // Find start location of 'collection' the hard way! + const char *startCollectionBuf = startBuf; + startCollectionBuf += 3; // skip 'for' + startCollectionBuf = strchr(startCollectionBuf, '('); + startCollectionBuf++; // skip '(' + // find 'in' and skip it. + while (*startCollectionBuf != ' ' || + *(startCollectionBuf+1) != 'i' || *(startCollectionBuf+2) != 'n' || + (*(startCollectionBuf+3) != ' ' && + *(startCollectionBuf+3) != '[' && *(startCollectionBuf+3) != '(')) + startCollectionBuf++; + startCollectionBuf += 3; + // Replace: "for (type element in" with string constructed thus far. Rewrite.ReplaceText(startLoc, startCollectionBuf - startBuf, buf.c_str(), buf.size()); // Replace ')' in for '(' type elem in collection ')' with ';' - SourceLocation endCollectionLoc = S->getCollection()->getLocEnd(); - const char *endCollectionBuf = SM->getCharacterData(endCollectionLoc); - const char *lparenBuf = strchr(endCollectionBuf+1, ')'); - SourceLocation lparenLoc = startLoc.getFileLocWithOffset(lparenBuf-startBuf); + SourceLocation rightParenLoc = S->getRParenLoc(); + const char *rparenBuf = SM->getCharacterData(rightParenLoc); + SourceLocation lparenLoc = startLoc.getFileLocWithOffset(rparenBuf-startBuf); buf = ";\n\t"; // unsigned long limit = [l_collection countByEnumeratingWithState:&enumState |