Correctly determine ranges for clang-format.

We have been assuming that CharSourceRange::getTokenRange() by itself
expands a range until the end of a token, but in fact it only sets
IsTokenRange to true. Thus, we have so far only considered the first
character of the last token to belong to an unwrapped line. This
did not really manifest in symptoms as all edit integrations
expand ranges to fully lines.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181778 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Jasper 2013-05-14 10:31:09 +00:00
Родитель 1fb8d8814a
Коммит 84f5ddfacc
2 изменённых файлов: 5 добавлений и 3 удалений

Просмотреть файл

@ -1473,9 +1473,9 @@ private:
bool touchesLine(const AnnotatedLine &TheLine) {
const FormatToken *First = &TheLine.First.FormatTok;
const FormatToken *Last = &TheLine.Last->FormatTok;
CharSourceRange LineRange = CharSourceRange::getTokenRange(
CharSourceRange LineRange = CharSourceRange::getCharRange(
First->WhiteSpaceStart.getLocWithOffset(First->LastNewlineOffset),
Last->Tok.getLocation());
Last->Tok.getLocation().getLocWithOffset(Last->TokenLength - 1));
return touchesRanges(LineRange);
}

Просмотреть файл

@ -218,7 +218,7 @@ TEST_F(FormatTest, ReformatsMovedLines) {
// Tests for control statements.
//===----------------------------------------------------------------------===//
TEST_F(FormatTest, FormatIfWithoutCompountStatement) {
TEST_F(FormatTest, FormatIfWithoutCompoundStatement) {
verifyFormat("if (true)\n f();\ng();");
verifyFormat("if (a)\n if (b)\n if (c)\n g();\nh();");
verifyFormat("if (a)\n if (b) {\n f();\n }\ng();");
@ -246,6 +246,8 @@ TEST_F(FormatTest, FormatIfWithoutCompountStatement) {
AllowsMergedIf);
EXPECT_EQ("if (a) return;", format("if(a)\nreturn;", 7, 1, AllowsMergedIf));
EXPECT_EQ("if (a) return; // comment",
format("if(a)\nreturn; // comment", 20, 1, AllowsMergedIf));
AllowsMergedIf.ColumnLimit = 14;
verifyFormat("if (a) return;", AllowsMergedIf);