Use a SourceRange for the whitespace location in FormatToken.
Replaces the use of WhitespaceStart + WhitspaceLength.
This made a bug in the formatter obvous where we would incorrectly
calculate the next column.
FIXME: There's a similar bug left regarding TokenLength. We should
probably also move to have a TokenRange instead.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182572 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp
index d1a925c..a75514f 100644
--- a/lib/Format/WhitespaceManager.cpp
+++ b/lib/Format/WhitespaceManager.cpp
@@ -43,9 +43,7 @@
unsigned StartOfTokenColumn,
bool InPPDirective) {
Changes.push_back(Change(
- true, SourceRange(Tok.FormatTok.WhiteSpaceStart,
- Tok.FormatTok.WhiteSpaceStart.getLocWithOffset(
- Tok.FormatTok.WhiteSpaceLength)),
+ true, Tok.FormatTok.WhitespaceRange,
Spaces, StartOfTokenColumn, Newlines, "", "", Tok.FormatTok.Tok.getKind(),
InPPDirective && !Tok.FormatTok.IsFirst));
@@ -65,14 +63,11 @@
void WhitespaceManager::addUntouchableToken(const FormatToken &Tok,
bool InPPDirective) {
- Changes.push_back(Change(
- false,
- SourceRange(Tok.WhiteSpaceStart,
- Tok.WhiteSpaceStart.getLocWithOffset(Tok.WhiteSpaceLength)),
- Tok.WhiteSpaceLength - Tok.NewlinesBefore,
- SourceMgr.getSpellingColumnNumber(Tok.Tok.getLocation()) - 1,
- Tok.NewlinesBefore, "", "", Tok.Tok.getKind(),
- InPPDirective && !Tok.IsFirst));
+ Changes.push_back(
+ Change(false, Tok.WhitespaceRange, /*Spaces=*/0,
+ SourceMgr.getSpellingColumnNumber(Tok.Tok.getLocation()) - 1,
+ Tok.NewlinesBefore, "", "", Tok.Tok.getKind(),
+ InPPDirective && !Tok.IsFirst));
}
void WhitespaceManager::breakToken(const FormatToken &Tok, unsigned Offset,