diff options
author | Manuel Klimek <klimek@google.com> | 2014-03-27 19:00:52 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2014-03-27 19:00:52 +0000 |
commit | 1f9d80ac666e3e96540871070fbe20758a73c708 (patch) | |
tree | 6831dc6eae1a82d172b0c621dc0c0a53123c2cfa /clang/lib | |
parent | 8018e414bbc497c1b5c7ab0ea7b4699cbe647cfc (diff) | |
download | bcm5719-llvm-1f9d80ac666e3e96540871070fbe20758a73c708.tar.gz bcm5719-llvm-1f9d80ac666e3e96540871070fbe20758a73c708.zip |
Improve handling of bool expressions in template arguments.
Now correctly formats:
foo<true && false>();
llvm-svn: 204950
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Format/FormatToken.h | 4 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 10 |
2 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 42d4a8dc249..b7262f396d5 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -282,6 +282,10 @@ struct FormatToken { (!ColonRequired || (Next && Next->is(tok::colon))); } + bool isLiteral() const { + return Tok.isLiteral() || isOneOf(tok::kw_true, tok::kw_false); + } + /// \brief Determine whether the token is a simple-type-specifier. bool isSimpleTypeSpecifier() const; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ee68afe7dcc..c3312cc66bd 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -67,7 +67,11 @@ private: // parameters. // FIXME: This is getting out of hand, write a decent parser. if (CurrentToken->Previous->isOneOf(tok::pipepipe, tok::ampamp) && - (CurrentToken->Previous->Type == TT_BinaryOperator || + ((CurrentToken->Previous->Type == TT_BinaryOperator && + // Toplevel bool expressions do not make lots of sense; + // If we're on the top level, it contains only the base context and + // the context for the current opening angle bracket. + Contexts.size() > 2) || Contexts[Contexts.size() - 2].IsExpression) && Line.First->isNot(tok::kw_template)) return false; @@ -858,9 +862,9 @@ private: PrevToken->MatchingParen->Previous->is(tok::kw_typeof)) return TT_PointerOrReference; - if (PrevToken->Tok.isLiteral() || + if (PrevToken->isLiteral() || PrevToken->isOneOf(tok::r_paren, tok::r_square) || - NextToken->Tok.isLiteral() || NextToken->isUnaryOperator() || + NextToken->isLiteral() || NextToken->isUnaryOperator() || // If we know we're in a template argument, there are no named // declarations. Thus, having an identifier on the right-hand side // indicates a binary operator. |