summaryrefslogtreecommitdiffstats
path: root/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-07 01:10:31 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-07 01:10:31 +0000
commit288c421b3d9a9c84b310088ce54c11c050775b9f (patch)
tree22f81731b5b482ce8024786e62d937056908feab /clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
parent161d5bb6f7c958738a9809efe408fb74f7adcafe (diff)
downloadbcm5719-llvm-288c421b3d9a9c84b310088ce54c11c050775b9f.tar.gz
bcm5719-llvm-288c421b3d9a9c84b310088ce54c11c050775b9f.zip
Insert a space if necessary when suggesting CFBridgingRetain/Release.
This was a problem for people who write 'return(result);' Also fix ARCMT's corresponding code, though there's no test case for this because implicit casts like this are rejected by the migrator for being ambiguous, and explicit casts have no problem. <rdar://problem/11577346> llvm-svn: 158130
Diffstat (limited to 'clang/lib/ARCMigrate/TransUnbridgedCasts.cpp')
-rw-r--r--clang/lib/ARCMigrate/TransUnbridgedCasts.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp b/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
index 72c0d8e7de3..f8bc5cf932c 100644
--- a/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
+++ b/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
@@ -37,6 +37,7 @@
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "clang/AST/ParentMap.h"
+#include "clang/Lex/Lexer.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
@@ -229,20 +230,26 @@ private:
}
} else {
assert(Kind == OBC_BridgeTransfer || Kind == OBC_BridgeRetained);
- StringRef cfBridging;
+ SmallString<32> BridgeCall;
+
+ Expr *WrapE = E->getSubExpr();
+ SourceLocation InsertLoc = WrapE->getLocStart();
+
+ SourceManager &SM = Pass.Ctx.getSourceManager();
+ char PrevChar = *SM.getCharacterData(InsertLoc.getLocWithOffset(-1));
+ if (Lexer::isIdentifierBodyChar(PrevChar, Pass.Ctx.getLangOpts()))
+ BridgeCall += ' ';
+
if (Kind == OBC_BridgeTransfer)
- cfBridging = "CFBridgingRelease";
+ BridgeCall += "CFBridgingRelease";
else
- cfBridging = "CFBridgingRetain";
+ BridgeCall += "CFBridgingRetain";
- Expr *WrapE = E->getSubExpr();
- SourceLocation insertLoc = WrapE->getLocStart();
if (isa<ParenExpr>(WrapE)) {
- TA.insert(insertLoc, cfBridging);
+ TA.insert(InsertLoc, BridgeCall);
} else {
- std::string withParens = cfBridging;
- withParens += '(';
- TA.insert(insertLoc, withParens);
+ BridgeCall += '(';
+ TA.insert(InsertLoc, BridgeCall);
TA.insertAfterToken(WrapE->getLocEnd(), ")");
}
}
OpenPOWER on IntegriCloud