[cfe-commits] r156873 - /cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue May 15 15:59:54 PDT 2012
Author: akirtzidis
Date: Tue May 15 17:59:54 2012
New Revision: 156873
URL: http://llvm.org/viewvc/llvm-project?rev=156873&view=rev
Log:
[objcmt] When using NSNumber numberWithInteger:/numberWithUnsignedInteger: be
more liberal in rewriting when the parameter is an enum constant.
Part of rdar://11438360
Modified:
cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
Modified: cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp?rev=156873&r1=156872&r2=156873&view=diff
==============================================================================
--- cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp (original)
+++ cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp Tue May 15 17:59:54 2012
@@ -684,6 +684,14 @@
// 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 @@
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))
More information about the cfe-commits
mailing list