<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 8, 2015 at 3:59 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank" class="cremed">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: klimek<br>
Date: Fri May  8 08:59:15 2015<br>
New Revision: 236854<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=236854&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=236854&view=rev</a><br>
Log:<br>
Make emacs show when clang-format encountered a syntax error.<br>
<br>
Propagate the 'incomplete-format' state back through clang-format's command<br>
line interace and adapt the emacs integration to show a better result.<br>
<br>
Added:<br>
    cfe/trunk/test/Format/incomplete.cpp<br>
      - copied, changed from r236846, cfe/trunk/test/Format/cursor.cpp<br>
Modified:<br>
    cfe/trunk/test/Format/cursor.cpp<br>
    cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
    cfe/trunk/tools/clang-format/clang-format.el<br>
<br>
Modified: cfe/trunk/test/Format/cursor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/cursor.cpp?rev=236854&r1=236853&r2=236854&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/cursor.cpp?rev=236854&r1=236853&r2=236854&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Format/cursor.cpp (original)<br>
+++ cfe/trunk/test/Format/cursor.cpp Fri May  8 08:59:15 2015<br>
@@ -1,6 +1,6 @@<br>
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp<br>
 // RUN: clang-format -style=LLVM %t2.cpp -cursor=6 > %t.cpp<br>
 // RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s<br>
-// CHECK: {{^\{ "Cursor": 4 \}$}}<br>
+// CHECK: {{^\{ "Cursor": 4, }}<br>
 // CHECK: {{^int\ \i;$}}<br>
  int    i;<br>
<br>
Copied: cfe/trunk/test/Format/incomplete.cpp (from r236846, cfe/trunk/test/Format/cursor.cpp)<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/incomplete.cpp?p2=cfe/trunk/test/Format/incomplete.cpp&p1=cfe/trunk/test/Format/cursor.cpp&r1=236846&r2=236854&rev=236854&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/incomplete.cpp?p2=cfe/trunk/test/Format/incomplete.cpp&p1=cfe/trunk/test/Format/cursor.cpp&r1=236846&r2=236854&rev=236854&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Format/cursor.cpp (original)<br>
+++ cfe/trunk/test/Format/incomplete.cpp Fri May  8 08:59:15 2015<br>
@@ -1,6 +1,8 @@<br>
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp<br>
-// RUN: clang-format -style=LLVM %t2.cpp -cursor=6 > %t.cpp<br>
+// RUN: clang-format -style=LLVM %t2.cpp > %t.cpp<br>
 // RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s<br>
-// CHECK: {{^\{ "Cursor": 4 \}$}}<br>
+// CHECK: {{^\{ "IncompleteFormat": true }}<br>
 // CHECK: {{^int\ \i;$}}<br>
  int    i;<br>
+// CHECK: {{^f  \( g  \(;$}}<br>
+f  ( g  (;<br>
<br>
Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=236854&r1=236853&r2=236854&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=236854&r1=236853&r2=236854&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)<br>
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Fri May  8 08:59:15 2015<br>
@@ -225,14 +225,17 @@ static bool format(StringRef FileName) {<br>
<br>
   FormatStyle FormatStyle = getStyle(<br>
       Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle);<br>
-  tooling::Replacements Replaces = reformat(FormatStyle, Sources, ID, Ranges);<br>
+  bool IncompleteFormat = false;<br>
+  tooling::Replacements Replaces = reformat(FormatStyle, Sources, ID, Ranges, &IncompleteFormat);<br></blockquote><div><br></div><div>Column limit .... Y U no clang-format ;-).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   if (OutputXML) {<br>
-    llvm::outs()<br>
-        << "<?xml version='1.0'?>\n<replacements xml:space='preserve'>\n";<br>
+    llvm::outs() << "<?xml version='1.0'?>\n<replacements "<br>
+                    "xml:space='preserve' incomplete_format='"<br>
+                 << (IncompleteFormat ? "true" : "false") << "'>\n";<br>
     if (Cursor.getNumOccurrences() != 0)<br>
       llvm::outs() << "<cursor>"<br>
                    << tooling::shiftedCodePosition(Replaces, Cursor)<br>
                    << "</cursor>\n";<br>
+<br>
     for (tooling::Replacements::const_iterator I = Replaces.begin(),<br>
                                                E = Replaces.end();<br>
          I != E; ++I) {<br>
@@ -252,9 +255,12 @@ static bool format(StringRef FileName) {<br>
       else if (Rewrite.overwriteChangedFiles())<br>
         return true;<br>
     } else {<br>
+      outs() << "{";<br>
       if (Cursor.getNumOccurrences() != 0)<br>
-        outs() << "{ \"Cursor\": "<br>
-               << tooling::shiftedCodePosition(Replaces, Cursor) << " }\n";<br>
+        outs() << " \"Cursor\": "<br>
+               << tooling::shiftedCodePosition(Replaces, Cursor) << ",";<br>
+      outs() << " \"IncompleteFormat\": "<br>
+             << (IncompleteFormat ? "true" : "false") << " }\n";<br>
       Rewrite.getEditBuffer(ID).write(outs());<br>
     }<br>
   }<br>
<br>
Modified: cfe/trunk/tools/clang-format/clang-format.el<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.el?rev=236854&r1=236853&r2=236854&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.el?rev=236854&r1=236853&r2=236854&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/clang-format/clang-format.el (original)<br>
+++ cfe/trunk/tools/clang-format/clang-format.el Fri May  8 08:59:15 2015<br>
@@ -61,6 +61,7 @@ of the buffer."<br>
   (unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements))<br>
     (error "Expected <replacements> node"))<br>
   (let ((nodes (xml-node-children xml-node))<br>
+        (incomplete-format (xml-get-attribute xml-node 'incomplete_format))<br>
         replacements<br>
         cursor)<br>
     (dolist (node nodes)<br>
@@ -89,7 +90,7 @@ of the buffer."<br>
                                    (and (= (car a) (car b))<br>
                                         (> (cadr a) (cadr b)))))))<br>
<br>
-    (cons replacements cursor)))<br>
+    (list replacements cursor (string= incomplete-format "true"))))<br>
<br>
 (defun clang-format--replace (offset length &optional text)<br>
   (let ((start (byte-to-position (1+ offset)))<br>
@@ -142,20 +143,24 @@ is no active region.  If no style is giv<br>
            ((stringp status)<br>
             (error "(clang-format killed by signal %s%s)" status stderr))<br>
            ((not (equal 0 status))<br>
-            (error "(clang-format failed with code %d%s)" status stderr))<br>
-           (t (message "(clang-format succeeded%s)" stderr)))<br>
+            (error "(clang-format failed with code %d%s)" status stderr)))<br>
<br>
           (with-current-buffer temp-buffer<br>
             (setq operations (clang-format--extract (car (xml-parse-region)))))<br>
<br>
-          (let ((replacements (car operations))<br>
-                (cursor (cdr operations)))<br>
+          (let ((replacements (nth 0 operations))<br>
+                (cursor (nth 1 operations))<br>
+                (incomplete-format (nth 2 operations)))<br>
             (save-excursion<br>
               (mapc (lambda (rpl)<br>
                       (apply #'clang-format--replace rpl))<br>
                     replacements))<br>
             (when cursor<br>
-              (goto-char (byte-to-position (1+ cursor))))))<br>
+              (goto-char (byte-to-position (1+ cursor))))<br>
+            (message "%s" incomplete-format)<br>
+            (if incomplete-format<br>
+                (message "(clang-format: incomplete (syntax errors)%s)" stderr)<br>
+              (message "(clang-format: success%s)" stderr))))<br>
       (delete-file temp-file)<br>
       (when (buffer-name temp-buffer) (kill-buffer temp-buffer)))))<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" 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>