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 | 7571228ec9b31de7733ae96352ee4eaa8afcf2b5 (patch) | |
tree | 42eba1de3ba9fb960f278424bb89ff22d531d19c /Driver/RewriteTest.cpp | |
parent | 6f81811e6bf5ce6dc43c0ee0bb00087ca5ced378 (diff) |
Allow messaging expression as foreach's collection expression.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45793 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/RewriteTest.cpp')
-rw-r--r-- | Driver/RewriteTest.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 81f818a67b..0384c44670 100644 --- a/Driver/RewriteTest.cpp +++ b/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 |