diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Format/Format.cpp | 6 | ||||
-rw-r--r-- | lib/Format/UnwrappedLineParser.h | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index a3c5e503b9..f7702cbd4f 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -995,6 +995,9 @@ public: // Consume and record whitespace until we find a significant token. while (FormatTok.Tok.is(tok::unknown)) { unsigned Newlines = Text.count('\n'); + if (Newlines > 0) + FormatTok.LastNewlineOffset = + FormatTok.WhiteSpaceLength + Text.rfind('\n') + 1; unsigned EscapedNewlines = Text.count("\\\n"); FormatTok.NewlinesBefore += Newlines; FormatTok.HasUnescapedNewline |= EscapedNewlines != Newlines; @@ -1371,7 +1374,8 @@ private: const FormatToken *First = &TheLine.First.FormatTok; const FormatToken *Last = &TheLine.Last->FormatTok; CharSourceRange LineRange = CharSourceRange::getTokenRange( - First->Tok.getLocation(), Last->Tok.getLocation()); + First->WhiteSpaceStart.getLocWithOffset(First->LastNewlineOffset), + Last->Tok.getLocation()); for (unsigned i = 0, e = Ranges.size(); i != e; ++i) { if (!SourceMgr.isBeforeInTranslationUnit(LineRange.getEnd(), Ranges[i].getBegin()) && diff --git a/lib/Format/UnwrappedLineParser.h b/lib/Format/UnwrappedLineParser.h index 5db5e7ba21..f4fecc5ef0 100644 --- a/lib/Format/UnwrappedLineParser.h +++ b/lib/Format/UnwrappedLineParser.h @@ -33,8 +33,8 @@ namespace format { struct FormatToken { FormatToken() : NewlinesBefore(0), HasUnescapedNewline(false), WhiteSpaceLength(0), - TokenLength(0), IsFirst(false), MustBreakBefore(false) { - } + LastNewlineOffset(0), TokenLength(0), IsFirst(false), + MustBreakBefore(false) {} /// \brief The \c Token. Token Tok; @@ -59,6 +59,10 @@ struct FormatToken { /// the \c Token. unsigned WhiteSpaceLength; + /// \brief The offset just past the last '\n' in this token's leading + /// whitespace (relative to \c WhiteSpaceStart). 0 if there is no '\n'. + unsigned LastNewlineOffset; + /// \brief The length of the non-whitespace parts of the token. This is /// necessary because we need to handle escaped newlines that are stored /// with the token. |