diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-14 23:33:49 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-14 23:33:49 +0000 |
commit | 20119a87fbb7719c161d81fc5f721f1ee6ed7e66 (patch) | |
tree | 82e78e7f9820cbe4fb2006f6c28f452b888b5268 /lib/Edit | |
parent | 0cd00be2813db976d62fb88fa26ccca8d6791823 (diff) |
[objcmt] When rewriting to subscripting syntax, make sure we put
the receiver in parentheses when necessary.
Part of rdar://11438360
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156789 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Edit')
-rw-r--r-- | lib/Edit/RewriteObjCFoundationAPI.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/Edit/RewriteObjCFoundationAPI.cpp b/lib/Edit/RewriteObjCFoundationAPI.cpp index 8c3c7a5bf3..218ef2274f 100644 --- a/lib/Edit/RewriteObjCFoundationAPI.cpp +++ b/lib/Edit/RewriteObjCFoundationAPI.cpp @@ -77,9 +77,10 @@ bool edit::rewriteObjCRedundantCallWithLiteral(const ObjCMessageExpr *Msg, // rewriteToObjCSubscriptSyntax. //===----------------------------------------------------------------------===// +static bool subscriptOperatorNeedsParens(const Expr *FullExpr); + static void maybePutParensOnReceiver(const Expr *Receiver, Commit &commit) { - Receiver = Receiver->IgnoreImpCasts(); - if (isa<BinaryOperator>(Receiver) || isa<UnaryOperator>(Receiver)) { + if (subscriptOperatorNeedsParens(Receiver)) { SourceRange RecRange = Receiver->getSourceRange(); commit.insertWrap("(", RecRange, ")"); } @@ -600,6 +601,29 @@ static bool rewriteToNumberLiteral(const ObjCMessageExpr *Msg, return true; } +// FIXME: Make determination of operator precedence more general and +// make it broadly available. +static bool subscriptOperatorNeedsParens(const Expr *FullExpr) { + const Expr* Expr = FullExpr->IgnoreImpCasts(); + if (isa<ArraySubscriptExpr>(Expr) || + isa<CallExpr>(Expr) || + isa<DeclRefExpr>(Expr) || + isa<CXXNamedCastExpr>(Expr) || + isa<CXXConstructExpr>(Expr) || + isa<CXXThisExpr>(Expr) || + isa<CXXTypeidExpr>(Expr) || + isa<CXXUnresolvedConstructExpr>(Expr) || + isa<ObjCMessageExpr>(Expr) || + isa<ObjCPropertyRefExpr>(Expr) || + isa<ObjCProtocolExpr>(Expr) || + isa<MemberExpr>(Expr) || + isa<ParenExpr>(FullExpr) || + isa<ParenListExpr>(Expr) || + isa<SizeOfPackExpr>(Expr)) + return false; + + return true; +} static bool castOperatorNeedsParens(const Expr *FullExpr) { const Expr* Expr = FullExpr->IgnoreImpCasts(); if (isa<ArraySubscriptExpr>(Expr) || |