Improve formatting of trailing annotations.

Before:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((
    unused));

After:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    __attribute__((unused));

llvm-svn: 177034
This commit is contained in:
Daniel Jasper 2013-03-14 09:50:46 +00:00
parent 7118befdb5
commit bf4755bb28
2 changed files with 15 additions and 7 deletions

View File

@ -1111,12 +1111,12 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
Left.Parent->is(tok::r_paren))
return !Right.isOneOf(tok::l_brace, tok::semi, tok::equal);
if (Right.is(tok::kw___attribute))
return true;
// We only break before r_brace if there was a corresponding break before
// the l_brace, which is tracked by BreakBeforeClosingBrace.
if (Right.is(tok::r_brace))
return false;
if (Right.isOneOf(tok::r_paren, tok::greater))
if (Right.isOneOf(tok::r_brace, tok::r_paren, tok::greater))
return false;
if (Left.is(tok::identifier) && Right.is(tok::string_literal))
return true;

View File

@ -1387,15 +1387,23 @@ TEST_F(FormatTest, FormatsBuilderPattern) {
TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) {
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" GUARDED_BY(aaaaaaaaaaaaa);");
" LOCKS_EXCLUDED(aaaaaaaaaaaaa);");
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"
" GUARDED_BY(aaaaaaaaaaaaa);");
" LOCKS_EXCLUDED(aaaaaaaaaaaaa);");
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"
" GUARDED_BY(aaaaaaaaaaaaa) {}");
" LOCKS_EXCLUDED(aaaaaaaaaaaaa) {}");
verifyFormat(
"void aaaaaaaaaaaaaaaaaa()\n"
" __attribute__((aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa));");
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" __attribute__((unused));");
// FIXME: This is bad indentation, but generally hard to distinguish from a
// function declaration.
verifyFormat(
"bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
"GUARDED_BY(aaaaaaaaaaaa);");
}
TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {