aboutsummaryrefslogtreecommitdiff
path: root/lib/Edit/RewriteObjCFoundationAPI.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-05-15 22:59:54 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-05-15 22:59:54 +0000
commitc5d33e959b45987bb97a7fcf639cdf5ce55987ed (patch)
tree065da26bfde9642ec0eb6910e7a96645dab46193 /lib/Edit/RewriteObjCFoundationAPI.cpp
parent9abf88c9286d7465ce18285f87bb302f588b59fc (diff)
[objcmt] When using NSNumber numberWithInteger:/numberWithUnsignedInteger: be
more liberal in rewriting when the parameter is an enum constant. Part of rdar://11438360 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156873 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Edit/RewriteObjCFoundationAPI.cpp')
-rw-r--r--lib/Edit/RewriteObjCFoundationAPI.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Edit/RewriteObjCFoundationAPI.cpp b/lib/Edit/RewriteObjCFoundationAPI.cpp
index 38584d65ef..5f7bef6f54 100644
--- a/lib/Edit/RewriteObjCFoundationAPI.cpp
+++ b/lib/Edit/RewriteObjCFoundationAPI.cpp
@@ -684,6 +684,14 @@ static void objectifyExpr(const Expr *E, Commit &commit) {
// rewriteToNumericBoxedExpression.
//===----------------------------------------------------------------------===//
+static bool isEnumConstant(const Expr *E) {
+ if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
+ if (const ValueDecl *VD = DRE->getDecl())
+ return isa<EnumConstantDecl>(VD);
+
+ return false;
+}
+
static bool rewriteToNumericBoxedExpression(const ObjCMessageExpr *Msg,
const NSAPI &NS, Commit &commit) {
if (Msg->getNumArgs() != 1)
@@ -725,7 +733,7 @@ static bool rewriteToNumericBoxedExpression(const ObjCMessageExpr *Msg,
if ((MK == NSAPI::NSNumberWithInteger ||
MK == NSAPI::NSNumberWithUnsignedInteger) &&
!isTruncated) {
- if (OrigTy->getAs<EnumType>())
+ if (OrigTy->getAs<EnumType>() || isEnumConstant(OrigArg))
break;
if ((MK==NSAPI::NSNumberWithInteger) == OrigTy->isSignedIntegerType() &&
OrigTySize >= Ctx.getTypeSize(Ctx.IntTy))