[PATCH] D60225: [clang-format] [PR19056] Add support for indenting class members and methods one level under the modifiers

Manuel Klimek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 9 01:08:29 PDT 2019


klimek added inline comments.


================
Comment at: clang/include/clang/Format/Format.h:50
 struct FormatStyle {
+  /// Indents after access modifiers. i.e.
+  /// \code
----------------
I think we need to explain this a bit more:
What this does is:
Indent classes with access modifiers at 2x indent compared to classes without access modifiers, while keeping the access modifiers at a normal indent.


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2009
+  // classes case
+  if (Style.AccessModifierIndentation && Line->Level % 2 == 0)
+    --Line->Level;
----------------
What if the class starts at level 1? (for example, inside a function or due to namespace indentation)

namespace A {
  class B {
    public:
      ..
  };
}


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2022
+  // After we wrap for Access modifier then indent a level if desired
+  if (Style.AccessModifierIndentation && Line->Level >= 1)
+    ++Line->Level;
----------------
Similarly, I think we need to remember whether we unindented, as otherwise I think we can run into cases where this is true, but the previous was false (class declared at level > 1).


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2230
+          Next = Tokens->getNextToken();
+          if (!Next)
+            break;
----------------
We should structure this like other parse loops in this file, using switch and eof (instead of !Next). See parseParens() for a good example.



Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60225/new/

https://reviews.llvm.org/D60225





More information about the cfe-commits mailing list