<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Feb 9, 2014 at 3:19 AM, Sean Silva <span dir="ltr"><<a href="mailto:silvas@purdue.edu" target="_blank" class="cremed">silvas@purdue.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><span style="font-size:13px;font-family:arial,sans-serif">+  unsigned</span><br style="font-size:13px;font-family:arial,sans-serif">

<span style="font-size:13px;font-family:arial,sans-serif">+  LimitConsideringMacros(</span><span style="font-size:13px;font-family:arial,sans-serif">SmallVectorImpl<AnnotatedLine *>::const_iterator I,</span><br style="font-size:13px;font-family:arial,sans-serif">


<span style="font-size:13px;font-family:arial,sans-serif">+                         SmallVectorImpl<AnnotatedLine *>::const_iterator E,</span><br style="font-size:13px;font-family:arial,sans-serif">
<span style="font-size:13px;font-family:arial,sans-serif">+                         unsigned Limit) {</span><br><div><span style="font-size:13px;font-family:arial,sans-serif"><br></span></div>
</div><div><span style="font-size:13px;font-family:arial,sans-serif">Naming (do we not have a clang-tidy check for this yet?).</span></div></div></blockquote><div><br></div><div>No. Although, a check local to a single translation unit would be easy to write. However, renaming generally needs project-wide changes, which is not implemented in clang-tidy (yet).</div>
<div><br></div><div>Fixed the spelling in r201138.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><span style="font-size:13px;font-family:arial,sans-serif">Also, can this be static?</span></div>

</div></blockquote><div><br></div><div>Probably, but not worth a change at the moment as this needs some bigger refactoring anyway.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><span><font color="#888888"><div>
<span style="font-size:13px;font-family:arial,sans-serif"><br></span></div>
<div><span style="font-size:13px;font-family:arial,sans-serif">-- Sean Silva</span></div></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 7, 2014 at 8:45 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank" class="cremed">djasper@google.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: djasper<br>
Date: Fri Feb  7 07:45:27 2014<br>
New Revision: 200974<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=200974&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=200974&view=rev</a><br>
Log:<br>
clang-format: Fix column limit violation for merged lines in macros.<br>
<br>
Before (81 columns):<br>
  #define A                                                                       \<br>
    void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { return aaaaaaaa; } \<br>
    int i;<br>
<br>
After:<br>
  #define A                                                    \<br>
    void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { \<br>
      return aaaaaaaa;                                         \<br>
    }                                                          \<br>
    int i;<br>
<br>
Modified:<br>
    cfe/trunk/lib/Format/Format.cpp<br>
    cfe/trunk/unittests/Format/FormatTest.cpp<br>
<br>
Modified: cfe/trunk/lib/Format/Format.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=200974&r1=200973&r2=200974&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=200974&r1=200973&r2=200974&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Fri Feb  7 07:45:27 2014<br>
@@ -581,6 +581,7 @@ private:<br>
     if (I[1]->InPPDirective != (*I)->InPPDirective ||<br>
         (I[1]->InPPDirective && I[1]->First->HasUnescapedNewline))<br>
       return 0;<br>
+    Limit = LimitConsideringMacros(I + 1, E, Limit);<br>
     AnnotatedLine &Line = **I;<br>
     if (Line.Last->isNot(tok::r_paren))<br>
       return 0;<br>
@@ -624,6 +625,7 @@ private:<br>
       // Check that we still have three lines and they fit into the limit.<br>
       if (I + 2 == E || I[2]->Type == LT_Invalid)<br>
         return 0;<br>
+      Limit = LimitConsideringMacros(I + 2, E, Limit);<br>
<br>
       if (!nextTwoLinesFitInto(I, Limit))<br>
         return 0;<br>
@@ -649,6 +651,19 @@ private:<br>
     return 0;<br>
   }<br>
<br>
+  /// Returns the modified column limit for \p I if it is inside a macro and<br>
+  /// needs a trailing '\'.<br>
+  unsigned<br>
+  LimitConsideringMacros(SmallVectorImpl<AnnotatedLine *>::const_iterator I,<br>
+                         SmallVectorImpl<AnnotatedLine *>::const_iterator E,<br>
+                         unsigned Limit) {<br>
+    if (I[0]->InPPDirective && I + 1 != E &&<br>
+        !I[1]->First->HasUnescapedNewline && !I[1]->First->is(tok::eof)) {<br>
+      return Limit < 2 ? 0 : Limit - 2;<br>
+    }<br>
+    return Limit;<br>
+  }<br>
+<br>
   bool nextTwoLinesFitInto(SmallVectorImpl<AnnotatedLine *>::const_iterator I,<br>
                            unsigned Limit) {<br>
     return 1 + I[1]->Last->TotalLength + 1 + I[2]->Last->TotalLength <= Limit;<br>
<br>
Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=200974&r1=200973&r2=200974&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=200974&r1=200973&r2=200974&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Feb  7 07:45:27 2014<br>
@@ -5070,6 +5070,25 @@ TEST_F(FormatTest, PullTrivialFunctionDe<br>
             "    : b(0) {\n"<br>
             "}",<br>
             format("A()\n:b(0)\n{\n}", DoNotMergeNoColumnLimit));<br>
+<br>
+  verifyFormat("#define A          \\\n"<br>
+               "  void f() {       \\\n"<br>
+               "    int i;         \\\n"<br>
+               "  }",<br>
+               getLLVMStyleWithColumns(20));<br>
+  verifyFormat("#define A           \\\n"<br>
+               "  void f() { int i; }",<br>
+               getLLVMStyleWithColumns(21));<br>
+  verifyFormat("#define A            \\\n"<br>
+               "  void f() {         \\\n"<br>
+               "    int i;           \\\n"<br>
+               "  }                  \\\n"<br>
+               "  int j;",<br>
+               getLLVMStyleWithColumns(22));<br>
+  verifyFormat("#define A             \\\n"<br>
+               "  void f() { int i; } \\\n"<br>
+               "  int j;",<br>
+               getLLVMStyleWithColumns(23));<br>
 }<br>
<br>
 TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {<br>
@@ -5183,6 +5202,17 @@ TEST_F(FormatTest, MergeHandlingInTheFac<br>
                "  if (true) continue;\n"<br>
                "}",<br>
                ShortMergedIf);<br>
+  ShortMergedIf.ColumnLimit = 29;<br>
+  verifyFormat("#define A                   \\\n"<br>
+               "  if (aaaaaaaaaa) return 1; \\\n"<br>
+               "  return 2;",<br>
+               ShortMergedIf);<br>
+  ShortMergedIf.ColumnLimit = 28;<br>
+  verifyFormat("#define A         \\\n"<br>
+               "  if (aaaaaaaaaa) \\\n"<br>
+               "    return 1;     \\\n"<br>
+               "  return 2;",<br>
+               ShortMergedIf);<br>
 }<br>
<br>
 TEST_F(FormatTest, BlockCommentsInControlLoops) {<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>