[cfe-commits] r171725 - in /cfe/trunk: include/clang/Format/Format.h lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Mon Jan 7 03:09:06 PST 2013


Author: djasper
Date: Mon Jan  7 05:09:06 2013
New Revision: 171725

URL: http://llvm.org/viewvc/llvm-project?rev=171725&view=rev
Log:
Add style option for number of spaces before trailing comments.

In LLVM style, a single space should be enough. In Google style, two
spaces are required.

Modified:
    cfe/trunk/include/clang/Format/Format.h
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/include/clang/Format/Format.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=171725&r1=171724&r2=171725&view=diff
==============================================================================
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Mon Jan  7 05:09:06 2013
@@ -52,6 +52,9 @@
   /// When false, use the same indentation level as for the switch statement.
   /// Switch statement body is always indented one level more than case labels.
   bool IndentCaseLabels;
+
+  /// \brief The number of spaces to before trailing line comments.
+  unsigned SpacesBeforeTrailingComments;
 };
 
 /// \brief Returns a format style complying with the LLVM coding standards:

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=171725&r1=171724&r2=171725&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Jan  7 05:09:06 2013
@@ -77,6 +77,7 @@
   LLVMStyle.AccessModifierOffset = -2;
   LLVMStyle.SplitTemplateClosingGreater = true;
   LLVMStyle.IndentCaseLabels = false;
+  LLVMStyle.SpacesBeforeTrailingComments = 1;
   return LLVMStyle;
 }
 
@@ -88,6 +89,7 @@
   GoogleStyle.AccessModifierOffset = -1;
   GoogleStyle.SplitTemplateClosingGreater = false;
   GoogleStyle.IndentCaseLabels = true;
+  GoogleStyle.SpacesBeforeTrailingComments = 2;
   return GoogleStyle;
 }
 
@@ -299,7 +301,7 @@
 
       unsigned Spaces = Annotations[Index].SpaceRequiredBefore ? 1 : 0;
       if (Annotations[Index].Type == TT_LineComment)
-        Spaces = 2;
+        Spaces = Style.SpacesBeforeTrailingComments;
 
       if (!DryRun)
         replaceWhitespace(Current, 0, Spaces);

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171725&r1=171724&r2=171725&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan  7 05:09:06 2013
@@ -278,21 +278,23 @@
                "  // Doesn't do anything\n"
                "}");
 
-  verifyFormat("int i  // This is a fancy variable\n"
+  verifyFormat("int i // This is a fancy variable\n"
                "    = 5;");
 
   verifyFormat("enum E {\n"
                "  // comment\n"
-               "  VAL_A,  // comment\n"
+               "  VAL_A, // comment\n"
                "  VAL_B\n"
                "};");
 
   verifyFormat(
       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
-      "    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;  // Trailing comment");
+      "    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; // Trailing comment");
 
-  EXPECT_EQ("int i;  // single line trailing comment",
+  EXPECT_EQ("int i; // single line trailing comment",
             format("int i;\\\n// single line trailing comment"));
+
+  verifyGoogleFormat("int a;  // Trailing comment.");
 }
 
 TEST_F(FormatTest, UnderstandsMultiLineComments) {





More information about the cfe-commits mailing list