Hi djasper, kcc,
LessLess and GreaterGreater are turned into two tokens via the stashed token
approach. The location of the stashed token (the second Less or Greater) was
assumed to be one past the first Less or Greater. This does not hold in cases
such as
printf "\\\\\x0a<<<" | clang-format
Where LessLess is considered a token of length 4 and the second Less (post
splitting) starts at an offset of 3 and not 1 from the first one. This results
in an error when attempting to insert a space between the first and second Less.
http://reviews.llvm.org/D7871
Files:
lib/Format/Format.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -940,11 +940,13 @@
FormatTok = new (Allocator.Allocate()) FormatToken;
FormatTok->Tok = Tok;
SourceLocation TokLocation =
- FormatTok->Tok.getLocation().getLocWithOffset(1);
+ FormatTok->Tok.getLocation().getLocWithOffset(Tok.getLength() - 1);
+ FormatTok->Tok.setLocation(TokLocation);
FormatTok->WhitespaceRange = SourceRange(TokLocation, TokLocation);
FormatTok->TokenText = TokenText;
FormatTok->ColumnWidth = 1;
- FormatTok->OriginalColumn = OriginalColumn;
+ FormatTok->OriginalColumn = OriginalColumn + 1;
+
return FormatTok;
}
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9753,6 +9753,7 @@
TEST_F(FormatTest, MergeLessLessAtEnd) {
verifyFormat("<<");
+ EXPECT_EQ("< < <", format("\\\n<<<"));
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaallvm::outs() <<");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -940,11 +940,13 @@
FormatTok = new (Allocator.Allocate()) FormatToken;
FormatTok->Tok = Tok;
SourceLocation TokLocation =
- FormatTok->Tok.getLocation().getLocWithOffset(1);
+ FormatTok->Tok.getLocation().getLocWithOffset(Tok.getLength() - 1);
+ FormatTok->Tok.setLocation(TokLocation);
FormatTok->WhitespaceRange = SourceRange(TokLocation, TokLocation);
FormatTok->TokenText = TokenText;
FormatTok->ColumnWidth = 1;
- FormatTok->OriginalColumn = OriginalColumn;
+ FormatTok->OriginalColumn = OriginalColumn + 1;
+
return FormatTok;
}
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9753,6 +9753,7 @@
TEST_F(FormatTest, MergeLessLessAtEnd) {
verifyFormat("<<");
+ EXPECT_EQ("< < <", format("\\\n<<<"));
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaallvm::outs() <<");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits