diff options
author | Daniel Jasper <djasper@google.com> | 2012-12-04 13:02:32 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-12-04 13:02:32 +0000 |
commit | 8822d3a99c07c7d874f8bfd81a7fe02059b9c19e (patch) | |
tree | 0939c4db617a985804dc8ce5768331a28badd79c /lib/Format/Format.cpp | |
parent | 00a3cccb8cbd9accddfa0e77e85939e263d6a10d (diff) |
Small fixes to unary operator recognition and handling of include
directives.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169261 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r-- | lib/Format/Format.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index d11e223b53..0383d01a31 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -21,6 +21,8 @@ #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" +#include <string> + namespace clang { namespace format { @@ -486,13 +488,11 @@ public: Annotation.SpaceRequiredBefore = false; } else if (Annotation.Type == TokenAnnotation::TT_UnaryOperator) { Annotation.SpaceRequiredBefore = - Line.Tokens[i - 1].Tok.isNot(tok::l_paren); + Line.Tokens[i - 1].Tok.isNot(tok::l_paren) && + Line.Tokens[i - 1].Tok.isNot(tok::l_square); } else if (Line.Tokens[i - 1].Tok.is(tok::greater) && Line.Tokens[i].Tok.is(tok::greater)) { - if (Annotation.Type == TokenAnnotation::TT_TemplateOpener && - Annotations[i - 1].Type == TokenAnnotation::TT_TemplateOpener) - Annotation.SpaceRequiredBefore = Style.SplitTemplateClosingGreater; - else if (Annotation.Type == TokenAnnotation::TT_TemplateCloser && + if (Annotation.Type == TokenAnnotation::TT_TemplateCloser && Annotations[i - 1].Type == TokenAnnotation::TT_TemplateCloser) Annotation.SpaceRequiredBefore = Style.SplitTemplateClosingGreater; else @@ -505,6 +505,9 @@ public: Annotations[i - 1].Type == TokenAnnotation::TT_TemplateCloser && Line.Tokens[i].Tok.is(tok::l_paren)) { Annotation.SpaceRequiredBefore = false; + } else if (Line.Tokens[i].Tok.is(tok::less) && + Line.Tokens[0].Tok.is(tok::hash)) { + Annotation.SpaceRequiredBefore = true; } else { Annotation.SpaceRequiredBefore = spaceRequiredBetween(Line.Tokens[i - 1].Tok, Line.Tokens[i].Tok); @@ -533,7 +536,7 @@ private: if (Tok.Tok.is(tok::star) || Tok.Tok.is(tok::amp)) Annotation.Type = determineStarAmpUsage(i); - else if (Tok.Tok.is(tok::minus) && Line.Tokens[i - 1].Tok.is(tok::equal)) + else if (isUnaryOperator(i)) Annotation.Type = TokenAnnotation::TT_UnaryOperator; else if (isBinaryOperator(Line.Tokens[i])) Annotation.Type = TokenAnnotation::TT_BinaryOperator; @@ -548,6 +551,17 @@ private: } } + bool isUnaryOperator(unsigned Index) { + const Token &Tok = Line.Tokens[Index].Tok; + if (Tok.isNot(tok::minus) && Tok.isNot(tok::plus)) + return false; + const Token &PreviousTok = Line.Tokens[Index - 1].Tok; + if (PreviousTok.is(tok::equal) || PreviousTok.is(tok::l_paren) || + PreviousTok.is(tok::comma) || PreviousTok.is(tok::l_square)) + return true; + return Annotations[Index - 1].Type == TokenAnnotation::TT_BinaryOperator; + } + bool isBinaryOperator(const FormatToken &Tok) { switch (Tok.Tok.getKind()) { case tok::equal: |