r245843 - clang-format: Make formatting of member function reference qualifiers

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 24 07:28:08 PDT 2015


Author: djasper
Date: Mon Aug 24 09:28:08 2015
New Revision: 245843

URL: http://llvm.org/viewvc/llvm-project?rev=245843&view=rev
Log:
clang-format: Make formatting of member function reference qualifiers
more consistent.

Before:
  SomeType MemberFunction(const Deleted &)&&;
  SomeType MemberFunction(const Deleted &) && { ... }

After:
  SomeType MemberFunction(const Deleted &)&&;
  SomeType MemberFunction(const Deleted &)&& { ... }

Modified:
    cfe/trunk/lib/Format/FormatToken.h
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=245843&r1=245842&r2=245843&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Mon Aug 24 09:28:08 2015
@@ -525,6 +525,8 @@ private:
 /// properly supported by Clang's lexer.
 struct AdditionalKeywords {
   AdditionalKeywords(IdentifierTable &IdentTable) {
+    kw_final = &IdentTable.get("final");
+    kw_override = &IdentTable.get("override");
     kw_in = &IdentTable.get("in");
     kw_CF_ENUM = &IdentTable.get("CF_ENUM");
     kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
@@ -538,7 +540,6 @@ struct AdditionalKeywords {
 
     kw_abstract = &IdentTable.get("abstract");
     kw_extends = &IdentTable.get("extends");
-    kw_final = &IdentTable.get("final");
     kw_implements = &IdentTable.get("implements");
     kw_instanceof = &IdentTable.get("instanceof");
     kw_interface = &IdentTable.get("interface");
@@ -562,6 +563,8 @@ struct AdditionalKeywords {
   }
 
   // Context sensitive keywords.
+  IdentifierInfo *kw_final;
+  IdentifierInfo *kw_override;
   IdentifierInfo *kw_in;
   IdentifierInfo *kw_CF_ENUM;
   IdentifierInfo *kw_CF_OPTIONS;
@@ -578,7 +581,6 @@ struct AdditionalKeywords {
   // Java keywords.
   IdentifierInfo *kw_abstract;
   IdentifierInfo *kw_extends;
-  IdentifierInfo *kw_final;
   IdentifierInfo *kw_implements;
   IdentifierInfo *kw_instanceof;
   IdentifierInfo *kw_interface;

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=245843&r1=245842&r2=245843&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Aug 24 09:28:08 2015
@@ -1139,9 +1139,11 @@ private:
       return TT_UnaryOperator;
 
     const FormatToken *NextToken = Tok.getNextNonComment();
-    if (!NextToken || NextToken->is(tok::arrow) ||
+    if (!NextToken ||
+        NextToken->isOneOf(tok::arrow, Keywords.kw_final,
+                           Keywords.kw_override) ||
         (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
-      return TT_Unknown;
+      return TT_PointerOrReference;
 
     if (PrevToken->is(tok::coloncolon))
       return TT_PointerOrReference;
@@ -1855,7 +1857,9 @@ bool TokenAnnotator::spaceRequiredBetwee
         !Line.IsMultiVariableDeclStmt)))
     return true;
   if (Left.is(TT_PointerOrReference))
-    return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||
+    return Right.Tok.isLiteral() ||
+           Right.isOneOf(TT_BlockComment, Keywords.kw_final,
+                         Keywords.kw_override) ||
            (Right.is(tok::l_brace) && Right.BlockKind == BK_Block) ||
            (!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
                            tok::l_paren) &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=245843&r1=245842&r2=245843&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Aug 24 09:28:08 2015
@@ -5326,6 +5326,9 @@ TEST_F(FormatTest, UnderstandsFunctionRe
   verifyFormat("Deleted &operator=(const Deleted &)&&;");
   verifyFormat("SomeType MemberFunction(const Deleted &)&;");
   verifyFormat("SomeType MemberFunction(const Deleted &)&&;");
+  verifyFormat("SomeType MemberFunction(const Deleted &)&& {}");
+  verifyFormat("SomeType MemberFunction(const Deleted &)&& final {}");
+  verifyFormat("SomeType MemberFunction(const Deleted &)&& override {}");
 
   verifyGoogleFormat("Deleted& operator=(const Deleted&)& = default;");
   verifyGoogleFormat("SomeType MemberFunction(const Deleted&)& = delete;");
@@ -5583,11 +5586,11 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
 
   // Member function reference qualifiers aren't binary operators.
   verifyFormat("string // break\n"
-               "operator()() & {}");
+               "operator()()& {}");
   verifyFormat("string // break\n"
-               "operator()() && {}");
+               "operator()()&& {}");
   verifyGoogleFormat("template <typename T>\n"
-                     "auto x() & -> int {}");
+                     "auto x()& -> int {}");
 }
 
 TEST_F(FormatTest, UnderstandsAttributes) {




More information about the cfe-commits mailing list