summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-03-13 15:53:12 +0000
committerDaniel Jasper <djasper@google.com>2013-03-13 15:53:12 +0000
commit0f8ed9e4e117e5e65c01e5a07d50655798fd78d5 (patch)
tree0784838d59db26c7433418a11a88b0361b10fbe1
parent8f6ae1912924dadac827462099e05d82b2a4bace (diff)
downloadbcm5719-llvm-0f8ed9e4e117e5e65c01e5a07d50655798fd78d5.tar.gz
bcm5719-llvm-0f8ed9e4e117e5e65c01e5a07d50655798fd78d5.zip
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(); } llvm-svn: 176953
-rw-r--r--clang/lib/Format/Format.cpp7
-rw-r--r--clang/unittests/Format/FormatTest.cpp5
2 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 67ca928a1ad..63edc6e23ee 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -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;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 79163a68183..17aeacae5c8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -427,6 +427,11 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
"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"
OpenPOWER on IntegriCloud