r176953 - Fix comment indentation before labels.
Daniel Jasper
djasper at google.com
Wed Mar 13 08:53:12 PDT 2013
Author: djasper
Date: Wed Mar 13 10:53:12 2013
New Revision: 176953
URL: http://llvm.org/viewvc/llvm-project?rev=176953&view=rev
Log:
Fix comment indentation before labels.
Before:
switch (x) {
// if 1, do f()
case 1:
f();
}
After:
switch (x) {
// if 1, do f()
case 1:
f();
}
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=176953&r1=176952&r2=176953&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Mar 13 10:53:12 2013
@@ -1135,6 +1135,13 @@ public:
deriveLocalStyle();
for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
Annotator.calculateFormattingInformation(AnnotatedLines[i]);
+
+ // Adapt level to the next line if this is a comment.
+ // FIXME: Can/should this be done in the UnwrappedLineParser?
+ if (i + 1 != e && AnnotatedLines[i].First.is(tok::comment) &&
+ AnnotatedLines[i].First.Children.empty() &&
+ AnnotatedLines[i + 1].First.isNot(tok::r_brace))
+ AnnotatedLines[i].Level = AnnotatedLines[i + 1].Level;
}
std::vector<int> IndentForLevel;
bool PreviousLineWasTouched = false;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=176953&r1=176952&r2=176953&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 13 10:53:12 2013
@@ -427,6 +427,11 @@ TEST_F(FormatTest, FormatsSwitchStatemen
"default: {\n"
" // Do nothing.\n"
"}");
+ verifyFormat("switch (x) {\n"
+ "// if 1, do f()\n"
+ "case 1:\n"
+ " f();\n"
+ "}");
verifyGoogleFormat("switch (x) {\n"
" case 1:\n"
More information about the cfe-commits
mailing list