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; \ }) llvm-svn: 237108
This commit is contained in:
parent
6f30dc18d3
commit
5fc133e71e
|
@ -39,7 +39,7 @@ public:
|
||||||
LevelIndentTracker(const FormatStyle &Style,
|
LevelIndentTracker(const FormatStyle &Style,
|
||||||
const AdditionalKeywords &Keywords, unsigned StartLevel,
|
const AdditionalKeywords &Keywords, unsigned StartLevel,
|
||||||
int AdditionalIndent)
|
int AdditionalIndent)
|
||||||
: Style(Style), Keywords(Keywords) {
|
: Style(Style), Keywords(Keywords), AdditionalIndent(AdditionalIndent) {
|
||||||
for (unsigned i = 0; i != StartLevel; ++i)
|
for (unsigned i = 0; i != StartLevel; ++i)
|
||||||
IndentForLevel.push_back(Style.IndentWidth * i + AdditionalIndent);
|
IndentForLevel.push_back(Style.IndentWidth * i + AdditionalIndent);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public:
|
||||||
void nextLine(const AnnotatedLine &Line) {
|
void nextLine(const AnnotatedLine &Line) {
|
||||||
Offset = getIndentOffset(*Line.First);
|
Offset = getIndentOffset(*Line.First);
|
||||||
if (Line.InPPDirective) {
|
if (Line.InPPDirective) {
|
||||||
Indent = Line.Level * Style.IndentWidth;
|
Indent = Line.Level * Style.IndentWidth + AdditionalIndent;
|
||||||
} else {
|
} else {
|
||||||
while (IndentForLevel.size() <= Line.Level)
|
while (IndentForLevel.size() <= Line.Level)
|
||||||
IndentForLevel.push_back(-1);
|
IndentForLevel.push_back(-1);
|
||||||
|
@ -110,6 +110,8 @@ private:
|
||||||
const FormatStyle &Style;
|
const FormatStyle &Style;
|
||||||
const AdditionalKeywords &Keywords;
|
const AdditionalKeywords &Keywords;
|
||||||
|
|
||||||
|
unsigned AdditionalIndent;
|
||||||
|
|
||||||
/// \brief The indent in characters for each level.
|
/// \brief The indent in characters for each level.
|
||||||
std::vector<int> IndentForLevel;
|
std::vector<int> IndentForLevel;
|
||||||
|
|
||||||
|
|
|
@ -3284,6 +3284,18 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
|
||||||
verifyNoCrash("^{v^{a}}");
|
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) {
|
TEST_F(FormatTest, IndividualStatementsOfNestedBlocks) {
|
||||||
EXPECT_EQ("DEBUG({\n"
|
EXPECT_EQ("DEBUG({\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
|
|
Loading…
Reference in New Issue