[cfe-commits] r172200 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Fri Jan 11 06:23:32 PST 2013


Author: djasper
Date: Fri Jan 11 08:23:32 2013
New Revision: 172200

URL: http://llvm.org/viewvc/llvm-project?rev=172200&view=rev
Log:
Improve handling of trailing declaration annotations.

Before:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) GUARDED_BY(
    aaaaaaaaaaaaa);

After:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
    GUARDED_BY(aaaaaaaaaaaaa);

Also did some formatting cleanups with clang-format on the way.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172200&r1=172199&r2=172200&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Jan 11 08:23:32 2013
@@ -183,7 +183,7 @@
       FitsOnALine = false;
       break;
     }
-  };
+  }
   return FitsOnALine;
 }
 
@@ -274,7 +274,7 @@
 
     bool operator<(const ParenState &Other) const {
       if (Indent != Other.Indent)
-        return Indent < Other.Indent; 
+        return Indent < Other.Indent;
       if (LastSpace != Other.LastSpace)
         return LastSpace < Other.LastSpace;
       if (FirstLessLess != Other.FirstLessLess)
@@ -406,8 +406,7 @@
           (getPrecedence(Previous) == prec::Assignment ||
            Previous.is(tok::kw_return)))
         State.Stack[ParenLevel].Indent = State.Column + Spaces;
-      if (Previous.is(tok::l_paren) ||
-          Previous.is(tok::l_brace) ||
+      if (Previous.is(tok::l_paren) || Previous.is(tok::l_brace) ||
           State.NextToken->Parent->Type == TT_TemplateOpener)
         State.Stack[ParenLevel].Indent = State.Column + Spaces;
 
@@ -604,8 +603,7 @@
   TokenAnnotator(const UnwrappedLine &Line, const FormatStyle &Style,
                  SourceManager &SourceMgr, Lexer &Lex)
       : Style(Style), SourceMgr(SourceMgr), Lex(Lex),
-        RootToken(Line.RootToken) {
-  }
+        RootToken(Line.RootToken) {}
 
   /// \brief A parser that gathers additional information about tokens.
   ///
@@ -615,8 +613,7 @@
   class AnnotatingParser {
   public:
     AnnotatingParser(AnnotatedToken &RootToken)
-        : CurrentToken(&RootToken), KeywordVirtualFound(false) {
-    }
+        : CurrentToken(&RootToken), KeywordVirtualFound(false) {}
 
     bool parseAngle() {
       while (CurrentToken != NULL) {
@@ -1065,8 +1062,8 @@
     if (Right.is(tok::l_paren)) {
       return CurrentLineType == LT_ObjCDecl || Left.is(tok::kw_if) ||
              Left.is(tok::kw_for) || Left.is(tok::kw_while) ||
-             Left.is(tok::kw_switch) ||
-             Left.is(tok::kw_return) || Left.is(tok::kw_catch);
+             Left.is(tok::kw_switch) || Left.is(tok::kw_return) ||
+             Left.is(tok::kw_catch);
     }
     if (Left.is(tok::at) &&
         Right.FormatTok.Tok.getObjCKeywordID() != tok::objc_not_keyword)
@@ -1167,6 +1164,8 @@
            Right.is(tok::colon) || Left.is(tok::semi) ||
            Left.is(tok::l_brace) || Left.is(tok::question) ||
            Right.is(tok::r_brace) || Left.Type == TT_ConditionalExpr ||
+           (Left.is(tok::r_paren) && Left.Type != TT_CastRParen &&
+            Right.is(tok::identifier)) ||
            (Left.is(tok::l_paren) && !Right.is(tok::r_paren));
   }
 
@@ -1267,8 +1266,7 @@
       : Diag(Diag), Style(Style), Lex(Lex), SourceMgr(SourceMgr),
         Ranges(Ranges) {}
 
-  virtual ~Formatter() {
-  }
+  virtual ~Formatter() {}
 
   tooling::Replacements format() {
     LexerBasedFormatTokenSource Tokens(Lex, SourceMgr);
@@ -1346,7 +1344,7 @@
   unsigned formatFirstToken(const AnnotatedToken &RootToken, unsigned Level,
                             bool InPPDirective,
                             unsigned PreviousEndOfLineColumn) {
-    const FormatToken& Tok = RootToken.FormatTok;
+    const FormatToken &Tok = RootToken.FormatTok;
     if (!Tok.WhiteSpaceStart.isValid() || StructuralError)
       return SourceMgr.getSpellingColumnNumber(Tok.Tok.getLocation()) - 1;
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172200&r1=172199&r2=172200&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 11 08:23:32 2013
@@ -741,6 +741,11 @@
                "    }\n  }\n}");
 }
 
+TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) {
+  verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+               "    GUARDED_BY(aaaaaaaaaaaaa);");
+}
+
 TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
   verifyFormat(
       "if (aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"





More information about the cfe-commits mailing list