[PATCH] [ClangFormat] Add ConstructorInitializerOffset to control initializer list indentation

Daniel Jasper djasper at google.com
Mon Aug 12 03:13:47 PDT 2013



================
Comment at: include/clang/Format/Format.h:65
@@ +64,3 @@
+  /// \brief The extra indent or outdent of constructor initializer lists.
+  int ConstructorInitializerOffset;
+
----------------
The reason that we have an offset for access modifiers is more or less purely historic. Please change this parameter to be an absolute indent used for constructor initializers.

================
Comment at: unittests/Format/FormatTest.cpp:5856
@@ +5855,3 @@
+
+  verifyFormat("struct foo\n"
+               "{\n"
----------------
Is the surrounding struct necessary? I'd try to make these tests as concise as possible.

================
Comment at: unittests/Format/FormatTest.cpp:5868
@@ +5867,3 @@
+
+  FormatStyle BreakAt80Chars = getLLVMStyle();
+  verifyFormat(
----------------
Unused.

================
Comment at: lib/Format/Format.cpp:658
@@ -653,1 +657,3 @@
           State.Column += 4;
+        if (Current.Type == TT_CtorInitializerColon ||
+            (Style.BreakConstructorInitializersBeforeComma ? Current : Previous)
----------------
Once this is an absolute indent, this should be merged in with the rest of the if-else-chain.

================
Comment at: lib/Format/Format.cpp:659
@@ +658,3 @@
+        if (Current.Type == TT_CtorInitializerColon ||
+            (Style.BreakConstructorInitializersBeforeComma ? Current : Previous)
+                    .Type == TT_CtorInitializerComma) {
----------------
I think the second part here might not be necessary as we fix State.Stack.back().Indent upon encountering a CtorInitializerColon. If that alone does not work, I am happy to look into what is missing.


http://llvm-reviews.chandlerc.com/D1360



More information about the cfe-commits mailing list