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