r237108 - clang-format: Fix hanging nested blocks in macros.
Daniel Jasper
djasper at google.com
Tue May 12 03:16:02 PDT 2015
Author: djasper
Date: Tue May 12 05:16:02 2015
New Revision: 237108
URL: http://llvm.org/viewvc/llvm-project?rev=237108&view=rev
Log:
clang-format: Fix hanging nested blocks in macros.
Before:
#define MACRO() \
Debug(aaa, /* force line break */ \
{ \
int i; \
int j; \
})
After:
#define MACRO() \
Debug(aaa, /* force line break */ \
{ \
int i; \
int j; \
})
Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=237108&r1=237107&r2=237108&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Tue May 12 05:16:02 2015
@@ -39,7 +39,7 @@ public:
LevelIndentTracker(const FormatStyle &Style,
const AdditionalKeywords &Keywords, unsigned StartLevel,
int AdditionalIndent)
- : Style(Style), Keywords(Keywords) {
+ : Style(Style), Keywords(Keywords), AdditionalIndent(AdditionalIndent) {
for (unsigned i = 0; i != StartLevel; ++i)
IndentForLevel.push_back(Style.IndentWidth * i + AdditionalIndent);
}
@@ -52,7 +52,7 @@ public:
void nextLine(const AnnotatedLine &Line) {
Offset = getIndentOffset(*Line.First);
if (Line.InPPDirective) {
- Indent = Line.Level * Style.IndentWidth;
+ Indent = Line.Level * Style.IndentWidth + AdditionalIndent;
} else {
while (IndentForLevel.size() <= Line.Level)
IndentForLevel.push_back(-1);
@@ -110,6 +110,8 @@ private:
const FormatStyle &Style;
const AdditionalKeywords &Keywords;
+ unsigned AdditionalIndent;
+
/// \brief The indent in characters for each level.
std::vector<int> IndentForLevel;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=237108&r1=237107&r2=237108&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue May 12 05:16:02 2015
@@ -3284,6 +3284,18 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
verifyNoCrash("^{v^{a}}");
}
+TEST_F(FormatTest, FormatNestedBlocksInMacros) {
+ EXPECT_EQ("#define MACRO() \\\n"
+ " Debug(aaa, /* force line break */ \\\n"
+ " { \\\n"
+ " int i; \\\n"
+ " int j; \\\n"
+ " })",
+ format("#define MACRO() Debug(aaa, /* force line break */ \\\n"
+ " { int i; int j; })",
+ getGoogleStyle()));
+}
+
TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) {
EXPECT_EQ("DEBUG({\n"
" int i;\n"
More information about the cfe-commits
mailing list