[PATCH] Added an option to allow short function bodies be placed on a single line.

Alexander Kornienko alexfh at google.com
Wed Nov 20 08:16:09 PST 2013



================
Comment at: lib/Format/UnwrappedLineParser.cpp:684
@@ -683,2 +683,3 @@
           addUnwrappedLine();
+        FormatTok->Type = TT_FunctionRBrace;
         parseBlock(/*MustBeDeclaration=*/false);
----------------
Daniel Jasper wrote:
> Isn't this an l_brace?
Yep, thanks for spotting this.

================
Comment at: lib/Format/Format.cpp:421
@@ +420,3 @@
+        Style.BreakBeforeBraces != FormatStyle::BS_Attach) {
+      Limit = Limit > 3 ? Limit - 3 : 0;
+      unsigned MergedLines = 0;
----------------
Manuel Klimek wrote:
> Why 3? (please add a comment).
Done.

================
Comment at: lib/Format/Format.cpp:426
@@ +425,3 @@
+        if (MergedLines > 0)
+          ++MergedLines;
+      }
----------------
Manuel Klimek wrote:
> I assume this is because we also slurp in the { on the single line?
We try to merge the block starting from the next line (which contains the opening brace), and if we succeed, we need to count the line containing the function header. Added a comment.

================
Comment at: lib/Format/Format.cpp:439
@@ +438,3 @@
+                 : 0;
+    }
+    if (TheLine->InPPDirective &&
----------------
Manuel Klimek wrote:
> Which test breaks that needed the change from an if () {} else if () {} ... return 0; to doing the check within each if?
I didn't intend to change the behavior, only to make the control flow more clear. And added code is laid out the same way.


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



More information about the cfe-commits mailing list