diff options
author | Daniel Jasper <djasper@google.com> | 2013-03-13 07:49:51 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-03-13 07:49:51 +0000 |
commit | 6f21a988990ff5872822dcb049bd8fc65ce3d236 (patch) | |
tree | 3674fc64cc6a90272d87924bc2a096dcfb35f132 /lib/Format/TokenAnnotator.cpp | |
parent | e0d5c86687c4a449f5104306108aa365b20ba09d (diff) |
Fix formatting of new arrays of pointers.
Before:
A = new SomeType * [Length];
A = new SomeType *[Length]();
After:
A = new SomeType *[Length];
A = new SomeType *[Length]();
Small formatting cleanups with clang-format.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176936 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 307607aadd..72edc76d77 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -183,21 +183,22 @@ private: bool parseSquare() { if (!CurrentToken) return false; - ScopedContextCreator ContextCreator(*this, 10); // A '[' could be an index subscript (after an indentifier or after // ')' or ']'), it could be the start of an Objective-C method // expression, or it could the the start of an Objective-C array literal. AnnotatedToken *Left = CurrentToken->Parent; AnnotatedToken *Parent = getPreviousToken(*Left); - Contexts.back().IsExpression = true; bool StartsObjCMethodExpr = - !Parent || Parent->is(tok::colon) || Parent->is(tok::l_square) || - Parent->is(tok::l_paren) || Parent->is(tok::kw_return) || - Parent->is(tok::kw_throw) || isUnaryOperator(*Parent) || - Parent->Type == TT_ObjCForIn || Parent->Type == TT_CastRParen || - getBinOpPrecedence(Parent->FormatTok.Tok.getKind(), true, true) > - prec::Unknown; + Contexts.back().CanBeExpression && + (!Parent || Parent->is(tok::colon) || Parent->is(tok::l_square) || + Parent->is(tok::l_paren) || Parent->is(tok::kw_return) || + Parent->is(tok::kw_throw) || isUnaryOperator(*Parent) || + Parent->Type == TT_ObjCForIn || Parent->Type == TT_CastRParen || + getBinOpPrecedence(Parent->FormatTok.Tok.getKind(), true, true) > + prec::Unknown); + ScopedContextCreator ContextCreator(*this, 10); + Contexts.back().IsExpression = true; bool StartsObjCArrayLiteral = Parent && Parent->is(tok::at); if (StartsObjCMethodExpr) { @@ -525,7 +526,8 @@ private: Context(unsigned BindingStrength, bool IsExpression) : BindingStrength(BindingStrength), LongestObjCSelectorName(0), ColonIsForRangeExpr(false), ColonIsObjCMethodExpr(false), - FirstObjCSelectorName(NULL), IsExpression(IsExpression) {} + FirstObjCSelectorName(NULL), IsExpression(IsExpression), + CanBeExpression(true) {} unsigned BindingStrength; unsigned LongestObjCSelectorName; @@ -533,6 +535,7 @@ private: bool ColonIsObjCMethodExpr; AnnotatedToken *FirstObjCSelectorName; bool IsExpression; + bool CanBeExpression; }; /// \brief Puts a new \c Context onto the stack \c Contexts for the lifetime @@ -574,6 +577,8 @@ private: } else if (Current.Parent && Current.Parent->Type == TT_CtorInitializerColon) { Contexts.back().IsExpression = true; + } else if (Current.is(tok::kw_new)) { + Contexts.back().CanBeExpression = false; } if (Current.Type == TT_Unknown) { |