forked from OSchip/llvm-project
clang-format: Always align */& in multi-var DeclStmts.
Seems like the most consistent thing to do and in multi-var DeclStmts, it is especially important to point out that the */& bind to the identifier. llvm-svn: 230903
This commit is contained in:
parent
de4a0fd813
commit
bea1ab46d9
|
@ -526,8 +526,10 @@ private:
|
|||
Tok->Type = TT_ObjCForIn;
|
||||
break;
|
||||
case tok::comma:
|
||||
if (Contexts.back().FirstStartOfName)
|
||||
if (Contexts.back().FirstStartOfName && Contexts.size() == 1) {
|
||||
Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
|
||||
Line.IsMultiVariableDeclStmt = true;
|
||||
}
|
||||
if (Contexts.back().InCtorInitializer)
|
||||
Tok->Type = TT_CtorInitializerComma;
|
||||
if (Contexts.back().IsForEachMacro)
|
||||
|
@ -1671,15 +1673,19 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
TT_FunctionDeclarationName)))) &&
|
||||
(Left.Tok.isLiteral() ||
|
||||
(!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
|
||||
Style.PointerAlignment != FormatStyle::PAS_Left));
|
||||
(Style.PointerAlignment != FormatStyle::PAS_Left ||
|
||||
Line.IsMultiVariableDeclStmt)));
|
||||
if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
|
||||
(!Left.is(TT_PointerOrReference) ||
|
||||
Style.PointerAlignment != FormatStyle::PAS_Right))
|
||||
(Style.PointerAlignment != FormatStyle::PAS_Right &&
|
||||
!Line.IsMultiVariableDeclStmt)))
|
||||
return true;
|
||||
if (Left.is(TT_PointerOrReference))
|
||||
return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||
|
||||
(!Right.isOneOf(TT_PointerOrReference, tok::l_paren) &&
|
||||
Style.PointerAlignment != FormatStyle::PAS_Right && Left.Previous &&
|
||||
(Style.PointerAlignment != FormatStyle::PAS_Right &&
|
||||
!Line.IsMultiVariableDeclStmt) &&
|
||||
Left.Previous &&
|
||||
!Left.Previous->isOneOf(tok::l_paren, tok::coloncolon));
|
||||
if (Right.is(tok::star) && Left.is(tok::l_paren))
|
||||
return false;
|
||||
|
@ -2006,6 +2012,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
|
|||
return true;
|
||||
if (Right.is(TT_RangeBasedForLoopColon))
|
||||
return false;
|
||||
if (Right.is(TT_PointerOrReference) && Line.IsMultiVariableDeclStmt)
|
||||
return true;
|
||||
if (Left.isOneOf(TT_PointerOrReference, TT_TemplateCloser,
|
||||
TT_UnaryOperator) ||
|
||||
Left.is(tok::kw_operator))
|
||||
|
|
|
@ -42,8 +42,8 @@ public:
|
|||
: First(Line.Tokens.front().Tok), Level(Line.Level),
|
||||
InPPDirective(Line.InPPDirective),
|
||||
MustBeDeclaration(Line.MustBeDeclaration), MightBeFunctionDecl(false),
|
||||
Affected(false), LeadingEmptyLinesAffected(false),
|
||||
ChildrenAffected(false) {
|
||||
IsMultiVariableDeclStmt(false), Affected(false),
|
||||
LeadingEmptyLinesAffected(false), ChildrenAffected(false) {
|
||||
assert(!Line.Tokens.empty());
|
||||
|
||||
// Calculate Next and Previous for all tokens. Note that we must overwrite
|
||||
|
@ -90,6 +90,7 @@ public:
|
|||
bool InPPDirective;
|
||||
bool MustBeDeclaration;
|
||||
bool MightBeFunctionDecl;
|
||||
bool IsMultiVariableDeclStmt;
|
||||
|
||||
/// \c True if this line should be formatted, i.e. intersects directly or
|
||||
/// indirectly with one of the input ranges.
|
||||
|
|
|
@ -4495,17 +4495,18 @@ TEST_F(FormatTest, DeclarationsOfMultipleVariables) {
|
|||
" *c = ccccccccccccccccccc, *d = ddddddddddddddddddd;");
|
||||
verifyFormat("aaaaaaaaa ***a = aaaaaaaaaaaaaaaaaaa, ***b = bbbbbbbbbbbbbbb,\n"
|
||||
" ***c = ccccccccccccccccccc, ***d = ddddddddddddddd;");
|
||||
// FIXME: If multiple variables are defined, the "*" needs to move to the new
|
||||
// line. Also fix indent for breaking after the type, this looks bad.
|
||||
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*\n"
|
||||
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"
|
||||
" * b = bbbbbbbbbbbbbbbbbbb;",
|
||||
getGoogleStyle());
|
||||
|
||||
// Not ideal, but pointer-with-type does not allow much here.
|
||||
verifyGoogleFormat(
|
||||
"aaaaaaaaa* a = aaaaaaaaaaaaaaaaaaa, * b = bbbbbbbbbbbbbbbbbbb,\n"
|
||||
" * b = bbbbbbbbbbbbbbbbbbb, * d = ddddddddddddddddddd;");
|
||||
FormatStyle Style = getGoogleStyle();
|
||||
Style.PointerAlignment = FormatStyle::PAS_Left;
|
||||
Style.DerivePointerAlignment = false;
|
||||
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
|
||||
" *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"
|
||||
" *b = bbbbbbbbbbbbbbbbbbb;",
|
||||
Style);
|
||||
verifyFormat(
|
||||
"aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"
|
||||
" *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;",
|
||||
Style);
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
|
||||
|
|
Loading…
Reference in New Issue