summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index e6e4e015f95..e3ca32c1865 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) {
OpenPOWER on IntegriCloud