diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-06-11 16:01:49 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-06-11 16:01:49 +0000 |
commit | 555efc36d08b07e65e2aba65c91fcaec63834c29 (patch) | |
tree | 4084d1b79103bd7851ece8261c34c59ec040d62e /clang/lib/Format/WhitespaceManager.cpp | |
parent | 447d2d12f0d4a41feeb88341bddbaa79c36a5103 (diff) | |
download | llvm-555efc36d08b07e65e2aba65c91fcaec63834c29.zip llvm-555efc36d08b07e65e2aba65c91fcaec63834c29.tar.gz llvm-555efc36d08b07e65e2aba65c91fcaec63834c29.tar.bz2 |
Insert a space at the start of a line comment in case it starts with an alphanumeric character.
Summary:
"//Test" becomes "// Test". This change is aimed to improve code
readability and conformance to certain coding styles. If a comment starts with a
non-alphanumeric character, the space isn't added, e.g. "//-*-c++-*-" stays
unchanged.
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D949
llvm-svn: 183750
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index e6e4e01..e3ca32c 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -56,16 +56,15 @@ void WhitespaceManager::addUntouchableToken(const FormatToken &Tok, InPPDirective && !Tok.IsFirst)); } -void WhitespaceManager::breakToken(const FormatToken &Tok, unsigned Offset, - unsigned ReplaceChars, - StringRef PreviousPostfix, - StringRef CurrentPrefix, bool InPPDirective, - unsigned Spaces) { +void WhitespaceManager::replaceWhitespaceInToken( + const FormatToken &Tok, unsigned Offset, unsigned ReplaceChars, + StringRef PreviousPostfix, StringRef CurrentPrefix, bool InPPDirective, + unsigned Newlines, unsigned Spaces) { Changes.push_back(Change( true, SourceRange(Tok.getStartOfNonWhitespace().getLocWithOffset(Offset), Tok.getStartOfNonWhitespace().getLocWithOffset( Offset + ReplaceChars)), - Spaces, Spaces, 1, PreviousPostfix, CurrentPrefix, + Spaces, Spaces, Newlines, PreviousPostfix, CurrentPrefix, // FIXME: Unify token adjustment, so we don't split it between // BreakableToken and the WhitespaceManager. That would also allow us to // correctly store a tok::TokenKind instead of rolling our own enum. @@ -214,10 +213,10 @@ void WhitespaceManager::generateChanges() { std::string ReplacementText = C.PreviousLinePostfix + (C.ContinuesPPDirective - ? getNewLineText(C.NewlinesBefore, C.Spaces, + ? getNewlineText(C.NewlinesBefore, C.Spaces, C.PreviousEndOfTokenColumn, C.EscapedNewlineColumn) - : getNewLineText(C.NewlinesBefore, C.Spaces)) + + : getNewlineText(C.NewlinesBefore, C.Spaces)) + C.CurrentLinePrefix; storeReplacement(C.OriginalWhitespaceRange, ReplacementText); } @@ -237,26 +236,26 @@ void WhitespaceManager::storeReplacement(const SourceRange &Range, SourceMgr, CharSourceRange::getCharRange(Range), Text)); } -std::string WhitespaceManager::getNewLineText(unsigned NewLines, +std::string WhitespaceManager::getNewlineText(unsigned Newlines, unsigned Spaces) { - return std::string(NewLines, '\n') + getIndentText(Spaces); + return std::string(Newlines, '\n') + getIndentText(Spaces); } -std::string WhitespaceManager::getNewLineText(unsigned NewLines, +std::string WhitespaceManager::getNewlineText(unsigned Newlines, unsigned Spaces, unsigned PreviousEndOfTokenColumn, unsigned EscapedNewlineColumn) { - std::string NewLineText; - if (NewLines > 0) { + std::string NewlineText; + if (Newlines > 0) { unsigned Offset = std::min<int>(EscapedNewlineColumn - 1, PreviousEndOfTokenColumn); - for (unsigned i = 0; i < NewLines; ++i) { - NewLineText += std::string(EscapedNewlineColumn - Offset - 1, ' '); - NewLineText += "\\\n"; + for (unsigned i = 0; i < Newlines; ++i) { + NewlineText += std::string(EscapedNewlineColumn - Offset - 1, ' '); + NewlineText += "\\\n"; Offset = 0; } } - return NewLineText + getIndentText(Spaces); + return NewlineText + getIndentText(Spaces); } std::string WhitespaceManager::getIndentText(unsigned Spaces) { |