hyklv updated this revision to Diff 186315.
hyklv marked an inline comment as done.
hyklv added a comment.
I removed accidental changes in the copyright notice, updated the code to
insert one space instead of one tab. Added a test case for the alignment.
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57655/new/
https://reviews.llvm.org/D57655
Files:
D:/Format/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
D:/Format/llvm/tools/clang/unittests/Format/FormatTest.cpp
Index: D:/Format/llvm/tools/clang/unittests/Format/FormatTest.cpp
===================================================================
--- D:/Format/llvm/tools/clang/unittests/Format/FormatTest.cpp
+++ D:/Format/llvm/tools/clang/unittests/Format/FormatTest.cpp
@@ -8739,6 +8739,9 @@
"\t\t parameter2); \\\n"
"\t}",
Tab);
+ verifyFormat("int a;\t // x\n"
+ "int bbbbbbbb; // x\n",
+ Tab);
Tab.TabWidth = 4;
Tab.IndentWidth = 8;
Index: D:/Format/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- D:/Format/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
+++ D:/Format/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
@@ -679,13 +679,17 @@
case FormatStyle::UT_Always: {
unsigned FirstTabWidth =
Style.TabWidth - WhitespaceStartColumn % Style.TabWidth;
- // Indent with tabs only when there's at least one full tab.
- if (FirstTabWidth + Style.TabWidth <= Spaces) {
+ // Insert only spaces when we want to end up before the next tab.
+ if (Spaces < FirstTabWidth || Spaces == 1) {
+ Text.append(Spaces, ' ');
+ } else {
+ // Align to next tab.
Spaces -= FirstTabWidth;
Text.append("\t");
+
+ Text.append(Spaces / Style.TabWidth, '\t');
+ Text.append(Spaces % Style.TabWidth, ' ');
}
- Text.append(Spaces / Style.TabWidth, '\t');
- Text.append(Spaces % Style.TabWidth, ' ');
break;
}
case FormatStyle::UT_ForIndentation:
Index: D:/Format/llvm/tools/clang/unittests/Format/FormatTest.cpp
===================================================================
--- D:/Format/llvm/tools/clang/unittests/Format/FormatTest.cpp
+++ D:/Format/llvm/tools/clang/unittests/Format/FormatTest.cpp
@@ -8739,6 +8739,9 @@
"\t\t parameter2); \\\n"
"\t}",
Tab);
+ verifyFormat("int a;\t // x\n"
+ "int bbbbbbbb; // x\n",
+ Tab);
Tab.TabWidth = 4;
Tab.IndentWidth = 8;
Index: D:/Format/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- D:/Format/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
+++ D:/Format/llvm/tools/clang/lib/Format/WhitespaceManager.cpp
@@ -679,13 +679,17 @@
case FormatStyle::UT_Always: {
unsigned FirstTabWidth =
Style.TabWidth - WhitespaceStartColumn % Style.TabWidth;
- // Indent with tabs only when there's at least one full tab.
- if (FirstTabWidth + Style.TabWidth <= Spaces) {
+ // Insert only spaces when we want to end up before the next tab.
+ if (Spaces < FirstTabWidth || Spaces == 1) {
+ Text.append(Spaces, ' ');
+ } else {
+ // Align to next tab.
Spaces -= FirstTabWidth;
Text.append("\t");
+
+ Text.append(Spaces / Style.TabWidth, '\t');
+ Text.append(Spaces % Style.TabWidth, ' ');
}
- Text.append(Spaces / Style.TabWidth, '\t');
- Text.append(Spaces % Style.TabWidth, ' ');
break;
}
case FormatStyle::UT_ForIndentation:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits