mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-07 00:23:43 +00:00
Revert "[clang-format] Fix AlignConsecutive on PP blocks"
This reverts commit b2eb439317
.
Caused the regression:
https://bugs.llvm.org/show_bug.cgi?id=47589
Reviewed By: MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D89464
This commit is contained in:
parent
53e92b4c0e
commit
b9e789447f
@ -206,12 +206,11 @@ class AnnotatedLine;
|
|||||||
struct FormatToken {
|
struct FormatToken {
|
||||||
FormatToken()
|
FormatToken()
|
||||||
: HasUnescapedNewline(false), IsMultiline(false), IsFirst(false),
|
: HasUnescapedNewline(false), IsMultiline(false), IsFirst(false),
|
||||||
MustBreakBefore(false), MustBreakAlignBefore(false),
|
MustBreakBefore(false), IsUnterminatedLiteral(false),
|
||||||
IsUnterminatedLiteral(false), CanBreakBefore(false),
|
CanBreakBefore(false), ClosesTemplateDeclaration(false),
|
||||||
ClosesTemplateDeclaration(false), StartsBinaryExpression(false),
|
StartsBinaryExpression(false), EndsBinaryExpression(false),
|
||||||
EndsBinaryExpression(false), PartOfMultiVariableDeclStmt(false),
|
PartOfMultiVariableDeclStmt(false), ContinuesLineCommentSection(false),
|
||||||
ContinuesLineCommentSection(false), Finalized(false),
|
Finalized(false), BlockKind(BK_Unknown), Decision(FD_Unformatted),
|
||||||
BlockKind(BK_Unknown), Decision(FD_Unformatted),
|
|
||||||
PackingKind(PPK_Inconclusive), Type(TT_Unknown) {}
|
PackingKind(PPK_Inconclusive), Type(TT_Unknown) {}
|
||||||
|
|
||||||
/// The \c Token.
|
/// The \c Token.
|
||||||
@ -248,12 +247,6 @@ struct FormatToken {
|
|||||||
/// before the token.
|
/// before the token.
|
||||||
unsigned MustBreakBefore : 1;
|
unsigned MustBreakBefore : 1;
|
||||||
|
|
||||||
/// Whether to not align across this token
|
|
||||||
///
|
|
||||||
/// This happens for example when a preprocessor directive ended directly
|
|
||||||
/// before the token, but very rarely otherwise.
|
|
||||||
unsigned MustBreakAlignBefore : 1;
|
|
||||||
|
|
||||||
/// Set to \c true if this token is an unterminated literal.
|
/// Set to \c true if this token is an unterminated literal.
|
||||||
unsigned IsUnterminatedLiteral : 1;
|
unsigned IsUnterminatedLiteral : 1;
|
||||||
|
|
||||||
|
@ -3046,7 +3046,6 @@ void UnwrappedLineParser::readToken(int LevelDifference) {
|
|||||||
}
|
}
|
||||||
FormatTok = Tokens->getNextToken();
|
FormatTok = Tokens->getNextToken();
|
||||||
FormatTok->MustBreakBefore = true;
|
FormatTok->MustBreakBefore = true;
|
||||||
FormatTok->MustBreakAlignBefore = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PPStack.empty() && (PPStack.back().Kind == PP_Unreachable) &&
|
if (!PPStack.empty() && (PPStack.back().Kind == PP_Unreachable) &&
|
||||||
@ -3071,7 +3070,6 @@ void UnwrappedLineParser::pushToken(FormatToken *Tok) {
|
|||||||
Line->Tokens.push_back(UnwrappedLineNode(Tok));
|
Line->Tokens.push_back(UnwrappedLineNode(Tok));
|
||||||
if (MustBreakBeforeNextToken) {
|
if (MustBreakBeforeNextToken) {
|
||||||
Line->Tokens.back().Tok->MustBreakBefore = true;
|
Line->Tokens.back().Tok->MustBreakBefore = true;
|
||||||
Line->Tokens.back().Tok->MustBreakAlignBefore = true;
|
|
||||||
MustBreakBeforeNextToken = false;
|
MustBreakBeforeNextToken = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,11 +411,9 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
|
|||||||
if (Changes[i].NewlinesBefore != 0) {
|
if (Changes[i].NewlinesBefore != 0) {
|
||||||
CommasBeforeMatch = 0;
|
CommasBeforeMatch = 0;
|
||||||
EndOfSequence = i;
|
EndOfSequence = i;
|
||||||
// If there is a blank line, there is a forced-align-break (eg,
|
// If there is a blank line, or if the last line didn't contain any
|
||||||
// preprocessor), or if the last line didn't contain any matching token,
|
// matching token, the sequence ends here.
|
||||||
// the sequence ends here.
|
if (Changes[i].NewlinesBefore > 1 || !FoundMatchOnLine)
|
||||||
if (Changes[i].NewlinesBefore > 1 ||
|
|
||||||
Changes[i].Tok->MustBreakAlignBefore || !FoundMatchOnLine)
|
|
||||||
AlignCurrentSequence();
|
AlignCurrentSequence();
|
||||||
|
|
||||||
FoundMatchOnLine = false;
|
FoundMatchOnLine = false;
|
||||||
@ -726,8 +724,6 @@ void WhitespaceManager::alignTrailingComments() {
|
|||||||
if (Changes[i].StartOfBlockComment)
|
if (Changes[i].StartOfBlockComment)
|
||||||
continue;
|
continue;
|
||||||
Newlines += Changes[i].NewlinesBefore;
|
Newlines += Changes[i].NewlinesBefore;
|
||||||
if (Changes[i].Tok->MustBreakAlignBefore)
|
|
||||||
BreakBeforeNext = true;
|
|
||||||
if (!Changes[i].IsTrailingComment)
|
if (!Changes[i].IsTrailingComment)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -12254,26 +12254,28 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
|
|||||||
Alignment);
|
Alignment);
|
||||||
|
|
||||||
// Bug 25167
|
// Bug 25167
|
||||||
verifyFormat("#if A\n"
|
/* Uncomment when fixed
|
||||||
"#else\n"
|
verifyFormat("#if A\n"
|
||||||
"int aaaaaaaa = 12;\n"
|
"#else\n"
|
||||||
"#endif\n"
|
"int aaaaaaaa = 12;\n"
|
||||||
"#if B\n"
|
"#endif\n"
|
||||||
"#else\n"
|
"#if B\n"
|
||||||
"int a = 12;\n"
|
"#else\n"
|
||||||
"#endif\n",
|
"int a = 12;\n"
|
||||||
Alignment);
|
"#endif\n",
|
||||||
verifyFormat("enum foo {\n"
|
Alignment);
|
||||||
"#if A\n"
|
verifyFormat("enum foo {\n"
|
||||||
"#else\n"
|
"#if A\n"
|
||||||
" aaaaaaaa = 12;\n"
|
"#else\n"
|
||||||
"#endif\n"
|
" aaaaaaaa = 12;\n"
|
||||||
"#if B\n"
|
"#endif\n"
|
||||||
"#else\n"
|
"#if B\n"
|
||||||
" a = 12;\n"
|
"#else\n"
|
||||||
"#endif\n"
|
" a = 12;\n"
|
||||||
"};\n",
|
"#endif\n"
|
||||||
Alignment);
|
"};\n",
|
||||||
|
Alignment);
|
||||||
|
*/
|
||||||
|
|
||||||
EXPECT_EQ("int a = 5;\n"
|
EXPECT_EQ("int a = 5;\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -2783,7 +2783,7 @@ TEST_F(FormatTestComments, AlignTrailingComments) {
|
|||||||
|
|
||||||
// Checks an edge case in preprocessor handling.
|
// Checks an edge case in preprocessor handling.
|
||||||
// These comments should *not* be aligned
|
// These comments should *not* be aligned
|
||||||
EXPECT_EQ(
|
EXPECT_NE( // change for EQ when fixed
|
||||||
"#if FOO\n"
|
"#if FOO\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"long a; // Line about a\n"
|
"long a; // Line about a\n"
|
||||||
@ -2801,6 +2801,24 @@ TEST_F(FormatTestComments, AlignTrailingComments) {
|
|||||||
"long b_long_name; // Line about b\n"
|
"long b_long_name; // Line about b\n"
|
||||||
"#endif\n",
|
"#endif\n",
|
||||||
getLLVMStyleWithColumns(80)));
|
getLLVMStyleWithColumns(80)));
|
||||||
|
|
||||||
|
// bug 47589
|
||||||
|
EXPECT_EQ(
|
||||||
|
"namespace m {\n\n"
|
||||||
|
"#define FOO_GLOBAL 0 // Global scope.\n"
|
||||||
|
"#define FOO_LINKLOCAL 1 // Link-local scope.\n"
|
||||||
|
"#define FOO_SITELOCAL 2 // Site-local scope (deprecated).\n"
|
||||||
|
"#define FOO_UNIQUELOCAL 3 // Unique local\n"
|
||||||
|
"#define FOO_NODELOCAL 4 // Loopback\n\n"
|
||||||
|
"} // namespace m\n",
|
||||||
|
format("namespace m {\n\n"
|
||||||
|
"#define FOO_GLOBAL 0 // Global scope.\n"
|
||||||
|
"#define FOO_LINKLOCAL 1 // Link-local scope.\n"
|
||||||
|
"#define FOO_SITELOCAL 2 // Site-local scope (deprecated).\n"
|
||||||
|
"#define FOO_UNIQUELOCAL 3 // Unique local\n"
|
||||||
|
"#define FOO_NODELOCAL 4 // Loopback\n\n"
|
||||||
|
"} // namespace m\n",
|
||||||
|
getLLVMStyleWithColumns(80)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {
|
TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {
|
||||||
|
Loading…
Reference in New Issue
Block a user