diff options
| author | Alexander Kornienko <alexfh@google.com> | 2013-09-27 09:45:40 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2013-09-27 09:45:40 +0000 |
| commit | db4c21f9945283f2e8d29c7a8a898512ebf37b52 (patch) | |
| tree | c97127d07f6704390ca9dd17aba464bdf12ed645 /clang/lib | |
| parent | 36c671e2c7b2eeec111cc7625b36d08f15ce4dd2 (diff) | |
| download | bcm5719-llvm-db4c21f9945283f2e8d29c7a8a898512ebf37b52.tar.gz bcm5719-llvm-db4c21f9945283f2e8d29c7a8a898512ebf37b52.zip | |
Correctly indent with tabs when whitespace starts from the column not divisible by TabWidth.
Summary:
The width of the first inserted tab character depends on the initial
column, so we need to handle the first tab in a special manner.
Reviewers: klimek, djasper
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1763
llvm-svn: 191497
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 12 | ||||
| -rw-r--r-- | clang/lib/Format/WhitespaceManager.h | 3 |
2 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index c0a3f5d60bd..50ff8582d39 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -225,7 +225,7 @@ void WhitespaceManager::generateChanges() { C.PreviousEndOfTokenColumn, C.EscapedNewlineColumn); else appendNewlineText(ReplacementText, C.NewlinesBefore); - appendIndentText(ReplacementText, C.Spaces); + appendIndentText(ReplacementText, C.Spaces, C.StartOfTokenColumn - C.Spaces); ReplacementText.append(C.CurrentLinePrefix); storeReplacement(C.OriginalWhitespaceRange, ReplacementText); } @@ -264,10 +264,18 @@ void WhitespaceManager::appendNewlineText(std::string &Text, unsigned Newlines, } } -void WhitespaceManager::appendIndentText(std::string &Text, unsigned Spaces) { +void WhitespaceManager::appendIndentText(std::string &Text, unsigned Spaces, + unsigned WhitespaceStartColumn) { if (!Style.UseTab) { Text.append(std::string(Spaces, ' ')); } else { + unsigned FirstTabWidth = + Style.TabWidth - WhitespaceStartColumn % Style.TabWidth; + // Indent with tabs only when there's at least one full tab. + if (FirstTabWidth + Style.TabWidth <= Spaces) { + Spaces -= FirstTabWidth; + Text.append("\t"); + } Text.append(std::string(Spaces / Style.TabWidth, '\t')); Text.append(std::string(Spaces % Style.TabWidth, ' ')); } diff --git a/clang/lib/Format/WhitespaceManager.h b/clang/lib/Format/WhitespaceManager.h index 2c58216d1cd..642b5b682bd 100644 --- a/clang/lib/Format/WhitespaceManager.h +++ b/clang/lib/Format/WhitespaceManager.h @@ -157,7 +157,8 @@ private: void appendNewlineText(std::string &Text, unsigned Newlines, unsigned PreviousEndOfTokenColumn, unsigned EscapedNewlineColumn); - void appendIndentText(std::string &Text, unsigned Spaces); + void appendIndentText(std::string &Text, unsigned Spaces, + unsigned WhitespaceStartColumn); SmallVector<Change, 16> Changes; SourceManager &SourceMgr; |

