[PATCH] Better block comment formatting.

Alexander Kornienko alexfh at google.com
Thu Mar 21 05:40:20 PDT 2013



================
Comment at: lib/Format/Format.cpp:169-172
@@ -166,4 +168,6 @@
                            unsigned Spaces, unsigned WhitespaceStartColumn) {
-    if (Tok.Type == TT_BlockComment)
-      indentBlockComment(Tok, Spaces, true);
+    if (Tok.Type == TT_BlockComment) {
+      int StartColumn = NewLines > 0 ? Spaces : WhitespaceStartColumn + Spaces;
+      indentBlockComment(Tok, Spaces, StartColumn, true);
+    }
 
----------------
Daniel Jasper wrote:
> It seems a bit weird to have the exact same block of code twice (only with s/true/false/). Probably not a big problem now, but if it grows any further, we should pull out a method.
> 
> Ideas:
> - You could pass WhitespaceStartColumn and NewLines into indentBlockComment and calculate StartColumn there
> - You could check for TT_BlockComment in indentBlockComment ("if (Tok.Type != TT_BlockComment) return")
> 
> Not sure that these make it better, but I hat duplication ;-)
Got rid of the StartColumn calculation here. Left TT_BlockComment check, as it seems to be clearer that indentBlockComment should be called only for block comments.


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

COMMIT
  http://llvm-reviews.chandlerc.com/rL177635



More information about the cfe-commits mailing list