Reduce penalty for splitting after "{" in static initializers.

This fixes llvm.org/PR15379.

Before:
const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = { 0x00, 0x00, 0x00, 0x00, 0x00,
                                            0x00,                  // comment
                                            0x00, 0x00, 0x00, 0x00, 0x00,
                                            0x00,                  // comment
                                            0x00, 0x00, 0x00, 0x00 // comment
};

After:
const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment
  0x00, 0x00, 0x00, 0x00              // comment
};

llvm-svn: 176262
This commit is contained in:
Daniel Jasper 2013-02-28 15:04:12 +00:00
parent ce17020c97
commit a400cab43a
2 changed files with 6 additions and 3 deletions

View File

@ -880,8 +880,6 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
else
return 100;
}
if (Left.is(tok::l_brace) && Right.isNot(tok::l_brace))
return 50;
if (Left.is(tok::equal) && Right.is(tok::l_brace))
return 150;
if (Left.is(tok::coloncolon))
@ -917,7 +915,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
return 20;
if (Left.is(tok::l_paren) || Left.is(tok::l_square) ||
Left.Type == TT_TemplateOpener)
Left.is(tok::l_brace) || Left.Type == TT_TemplateOpener)
return 20;
if (Right.is(tok::lessless)) {

View File

@ -612,6 +612,11 @@ TEST_F(FormatTest, CommentsInStaticInitializers) {
"\n"
" b\n"
"};"));
verifyFormat("const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {\n"
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
" 0x00, 0x00, 0x00, 0x00 // comment\n"
"};");
}
//===----------------------------------------------------------------------===//