Skip to content

Commit e579564

Browse files
author
hnakamura5
committed
Fixed part of the reviewed points.
- NOT fixed: Make FormatTestTableGen.cpp up to date to f8d10d5. I am planning to fix it in other pull request.
1 parent b0080a4 commit e579564

File tree

10 files changed

+556
-62
lines changed

10 files changed

+556
-62
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 447 additions & 1 deletion
Large diffs are not rendered by default.

clang/include/clang/Format/Format.h

Lines changed: 88 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,10 @@ struct FormatStyle {
396396
/// \version 17
397397
ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements;
398398

399-
/// Style of aligning consecutive TableGen cond operator colons.
400-
/// \code
401-
/// !cond(!eq(size, 1) : 1,
402-
/// !eq(size, 16): 1,
403-
/// true : 0)
404-
/// \endcode
405-
/// \version 18
406-
AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons;
407-
408399
/// Style of aligning consecutive TableGen DAGArg operator colons.
409-
/// Intended to be used with TableGenBreakInsideDAGArgList
410-
/// \code
400+
/// This works only when TableGenBreakInsideDAGArgList is true and the DAGArg
401+
/// is not excepted by TableGenBreakingDAGArgOperators's effect. Align the
402+
/// colon inside DAGArg which have line break inside. \code{tablegen}
411403
/// let dagarg = (ins
412404
/// a :$src1,
413405
/// aa :$src2,
@@ -417,14 +409,25 @@ struct FormatStyle {
417409
/// \version 18
418410
AlignConsecutiveStyle AlignConsecutiveTableGenBreakingDAGArgColons;
419411

412+
/// Style of aligning consecutive TableGen cond operator colons.
413+
/// Align the colons of each case inside !cond operators.
414+
/// \code
415+
/// !cond(!eq(size, 1) : 1,
416+
/// !eq(size, 16): 1,
417+
/// true : 0)
418+
/// \endcode
419+
/// \version 18
420+
AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons;
421+
420422
/// Style of aligning consecutive TableGen def colons.
423+
/// This aligns the inherits colons of consecutive definitions.
421424
/// \code
422425
/// def Def : Parent {}
423426
/// def DefDef : Parent {}
424427
/// def DefDefDef : Parent {}
425428
/// \endcode
426429
/// \version 18
427-
AlignConsecutiveStyle AlignConsecutiveTableGenDefinitions;
430+
AlignConsecutiveStyle AlignConsecutiveTableGenDefinitionColons;
428431

429432
/// Different styles for aligning escaped newlines.
430433
enum EscapedNewlineAlignmentStyle : int8_t {
@@ -4687,14 +4690,68 @@ struct FormatStyle {
46874690
/// \version 8
46884691
std::vector<std::string> StatementMacros;
46894692

4690-
/// Tablegen
4691-
bool TableGenAllowBreakBeforeInheritColon;
4692-
bool TableGenAllowBreakAfterInheritColon;
4693+
/// Works only when TableGenBreakInsideDAGArgList is true.
4694+
/// The list needs to be consists of identifiers in TableGen.
4695+
/// If any identifier is specified, this limits the effect of
4696+
/// TableGenBreakInsideDAGArgList only on DAGArgs beginning with the specified
4697+
/// identifiers. For example the configuration,
4698+
///
4699+
/// \code
4700+
/// TableGenBreakingDAGArgOperators: ['ins', 'outs']
4701+
/// \endcode
4702+
///
4703+
/// makes the line break only occurs inside DAGArgs beginning with the
4704+
/// specified identifiers 'ins' and 'outs'.
4705+
///
4706+
/// \code
4707+
/// let DAGArgIns = (ins
4708+
/// i32:$src1,
4709+
/// i32:$src2
4710+
/// );
4711+
/// let DAGArgOthers = (others i32:$other1, i32:$other2);
4712+
/// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
4713+
/// \endcode
4714+
/// \version 18
4715+
std::vector<std::string> TableGenBreakingDAGArgOperators;
4716+
4717+
/// Insert the line break after each case of !cond operator in TableGen.
4718+
/// \code
4719+
/// let CondOpe1 = !cond(!eq(size, 1): 1,
4720+
/// !eq(size, 16): 1,
4721+
/// true: 0);
4722+
/// \endcode
4723+
/// By default this is true.
4724+
/// \version 18
46934725
bool TableGenBreakInsideCondOperator;
4726+
4727+
/// Insert the line break after each element of DAGArg list in TableGen.
4728+
/// \code
4729+
/// let DAGArgIns = (ins
4730+
/// i32:$src1,
4731+
/// i32:$src2
4732+
/// );
4733+
/// \endcode
4734+
/// \version 18
46944735
bool TableGenBreakInsideDAGArgList;
4736+
4737+
/// Tend to break inside square bracket in TableGen.
4738+
/// For whom likes such a style.
4739+
/// \code
4740+
/// def Def : Parent<"Def",[
4741+
/// a, b, c
4742+
/// ]> {
4743+
/// ...
4744+
/// }
4745+
/// \endcode
4746+
/// \version 18
46954747
bool TableGenPreferBreakInsideSquareBracket;
4748+
4749+
/// Insert the space around the colon inside a DAGArg list in TableGen.
4750+
/// \code
4751+
/// let DAGArgIns = (ins i32 : $src1, i32 : $src2);
4752+
/// \endcode
4753+
/// \version 18
46964754
bool TableGenSpaceAroundDAGArgColon;
4697-
std::vector<std::string> TableGenBreakingDAGArgOperators;
46984755

46994756
/// The number of columns used for tab stops.
47004757
/// \version 3.7
@@ -4793,13 +4850,12 @@ struct FormatStyle {
47934850
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
47944851
AlignConsecutiveShortCaseStatements ==
47954852
R.AlignConsecutiveShortCaseStatements &&
4796-
AlignConsecutiveTableGenCondOperatorColons ==
4797-
R.AlignConsecutiveTableGenCondOperatorColons &&
47984853
AlignConsecutiveTableGenBreakingDAGArgColons ==
47994854
R.AlignConsecutiveTableGenBreakingDAGArgColons &&
4800-
AlignConsecutiveTableGenDefinitions ==
4801-
R.AlignConsecutiveTableGenDefinitions &&
4802-
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
4855+
AlignConsecutiveTableGenCondOperatorColons ==
4856+
R.AlignConsecutiveTableGenCondOperatorColons &&
4857+
AlignConsecutiveTableGenDefinitionColons ==
4858+
R.AlignConsecutiveTableGenDefinitionColons &&
48034859
AlignEscapedNewlines == R.AlignEscapedNewlines &&
48044860
AlignOperands == R.AlignOperands &&
48054861
AlignTrailingComments == R.AlignTrailingComments &&
@@ -4949,9 +5005,17 @@ struct FormatStyle {
49495005
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
49505006
Standard == R.Standard &&
49515007
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
4952-
StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
4953-
TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
4954-
UseTab == R.UseTab &&
5008+
StatementMacros == R.StatementMacros &&
5009+
TableGenBreakingDAGArgOperators ==
5010+
R.TableGenBreakingDAGArgOperators &&
5011+
TableGenBreakInsideCondOperator ==
5012+
R.TableGenBreakInsideCondOperator &&
5013+
TableGenBreakInsideDAGArgList == R.TableGenBreakInsideDAGArgList &&
5014+
TableGenPreferBreakInsideSquareBracket ==
5015+
R.TableGenPreferBreakInsideSquareBracket &&
5016+
TableGenSpaceAroundDAGArgColon == R.TableGenSpaceAroundDAGArgColon &&
5017+
TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
5018+
TypenameMacros == R.TypenameMacros && UseTab == R.UseTab &&
49555019
VerilogBreakBetweenInstancePorts ==
49565020
R.VerilogBreakBetweenInstancePorts &&
49575021
WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;

clang/lib/Format/Format.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,8 @@ template <> struct MappingTraits<FormatStyle> {
930930
Style.AlignConsecutiveTableGenCondOperatorColons);
931931
IO.mapOptional("AlignConsecutiveTableGenBreakingDAGArgColons",
932932
Style.AlignConsecutiveTableGenBreakingDAGArgColons);
933-
IO.mapOptional("AlignConsecutiveTableGenDefinitions",
934-
Style.AlignConsecutiveTableGenDefinitions);
933+
IO.mapOptional("AlignConsecutiveTableGenDefinitionColons",
934+
Style.AlignConsecutiveTableGenDefinitionColons);
935935
IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines);
936936
IO.mapOptional("AlignOperands", Style.AlignOperands);
937937
IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments);
@@ -1130,10 +1130,8 @@ template <> struct MappingTraits<FormatStyle> {
11301130
IO.mapOptional("StatementAttributeLikeMacros",
11311131
Style.StatementAttributeLikeMacros);
11321132
IO.mapOptional("StatementMacros", Style.StatementMacros);
1133-
IO.mapOptional("TableGenAllowBreakAfterInheritColon",
1134-
Style.TableGenAllowBreakAfterInheritColon);
1135-
IO.mapOptional("TableGenAllowBreakBeforeInheritColon",
1136-
Style.TableGenAllowBreakBeforeInheritColon);
1133+
IO.mapOptional("TableGenBreakingDAGArgOperators",
1134+
Style.TableGenBreakingDAGArgOperators);
11371135
IO.mapOptional("TableGenBreakInsideCondOperator",
11381136
Style.TableGenBreakInsideCondOperator);
11391137
IO.mapOptional("TableGenBreakInsideDAGArgList",
@@ -1142,8 +1140,6 @@ template <> struct MappingTraits<FormatStyle> {
11421140
Style.TableGenPreferBreakInsideSquareBracket);
11431141
IO.mapOptional("TableGenSpaceAroundDAGArgColon",
11441142
Style.TableGenSpaceAroundDAGArgColon);
1145-
IO.mapOptional("TableGenBreakingDAGArgOperators",
1146-
Style.TableGenBreakingDAGArgOperators);
11471143
IO.mapOptional("TabWidth", Style.TabWidth);
11481144
IO.mapOptional("TypeNames", Style.TypeNames);
11491145
IO.mapOptional("TypenameMacros", Style.TypenameMacros);
@@ -1459,7 +1455,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
14591455
LLVMStyle.AlignConsecutiveShortCaseStatements = {};
14601456
LLVMStyle.AlignConsecutiveTableGenBreakingDAGArgColons = {};
14611457
LLVMStyle.AlignConsecutiveTableGenCondOperatorColons = {};
1462-
LLVMStyle.AlignConsecutiveTableGenDefinitions = {};
1458+
LLVMStyle.AlignConsecutiveTableGenDefinitionColons = {};
14631459
LLVMStyle.AlignTrailingComments = {};
14641460
LLVMStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Always;
14651461
LLVMStyle.AlignTrailingComments.OverEmptyLines = 0;
@@ -1608,8 +1604,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
16081604
LLVMStyle.StatementAttributeLikeMacros.push_back("Q_EMIT");
16091605
LLVMStyle.StatementMacros.push_back("Q_UNUSED");
16101606
LLVMStyle.StatementMacros.push_back("QT_REQUIRE_VERSION");
1611-
LLVMStyle.TableGenAllowBreakAfterInheritColon = true;
1612-
LLVMStyle.TableGenAllowBreakBeforeInheritColon = false;
1607+
LLVMStyle.TableGenBreakingDAGArgOperators = {};
16131608
LLVMStyle.TableGenBreakInsideCondOperator = true;
16141609
LLVMStyle.TableGenBreakInsideDAGArgList = false;
16151610
LLVMStyle.TableGenPreferBreakInsideSquareBracket = false;

clang/lib/Format/FormatToken.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,12 +700,8 @@ struct FormatToken {
700700
return true;
701701
if (is(TT_DictLiteral) && is(tok::greater))
702702
return true;
703-
if (is(TT_TableGenParamAngleCloser))
704-
return true;
705-
if (is(TT_TableGenListCloser))
706-
return true;
707-
return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
708-
TT_TemplateCloser);
703+
return isOneOf(tok::r_paren, tok::r_brace, tok::r_square, TT_TemplateCloser,
704+
TT_TableGenParamAngleCloser, TT_TableGenListCloser);
709705
}
710706

711707
/// Returns \c true if this is a "." or "->" accessing a member.

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ void FormatTokenLexer::tryMergePreviousTokens() {
282282
Tokens.back()->Tok.setKind(tok::string_literal);
283283
return;
284284
}
285-
if (Tokens.size() > 1 && Tokens.end()[-2]->is(tok::exclaim)) {
286-
if (Tokens.back()->is(tok::identifier) ||
287-
(Tokens.back()->is(tok::kw_if) && Tokens.back())) {
288-
}
289-
}
290285
if (tryMergeTokens({tok::exclaim, tok::identifier},
291286
TT_TableGenBangOperator)) {
292287
Tokens.back()->Tok.setKind(tok::identifier);

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5907,16 +5907,12 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
59075907
return !Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator,
59085908
TT_TableGenParamAngleCloser);
59095909
}
5910-
if (Right.is(tok::colon))
5911-
return Style.TableGenAllowBreakBeforeInheritColon;
59125910
if (Right.isOneOf(tok::semi, tok::l_brace)) {
59135911
// Avoid to break before "{"" or ";" in TableGen.
59145912
return false;
59155913
}
59165914
if (Left.is(TT_TableGenValueSuffix))
59175915
return false;
5918-
if (Left.is(tok::colon) && Right.is(tok::identifier))
5919-
return Style.TableGenAllowBreakAfterInheritColon;
59205916
if (Left.is(tok::hash) || Right.is(tok::hash))
59215917
return false;
59225918
}

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ const tooling::Replacements &WhitespaceManager::generateReplacements() {
111111
alignConsecutiveDeclarations();
112112
alignConsecutiveBitFields();
113113
alignConsecutiveAssignments();
114-
alignConsecutiveTableGenCondOperatorColons();
115-
AlignConsecutiveTableGenBreakingDAGArgColons();
116-
alignConsecutiveTableGenDefinition();
114+
if (Style.isTableGen()) {
115+
alignConsecutiveTableGenCondOperatorColons();
116+
alignConsecutiveTableGenBreakingDAGArgColons();
117+
alignConsecutiveTableGenDefinition();
118+
}
117119
alignChainedConditionals();
118120
alignTrailingComments();
119121
alignEscapedNewlines();
@@ -881,13 +883,13 @@ void WhitespaceManager::alignConsecutiveTableGenCondOperatorColons() {
881883
TT_TableGenCondOperatorColon);
882884
}
883885

884-
void WhitespaceManager::AlignConsecutiveTableGenBreakingDAGArgColons() {
886+
void WhitespaceManager::alignConsecutiveTableGenBreakingDAGArgColons() {
885887
alignConsecutiveColons(Style.AlignConsecutiveTableGenBreakingDAGArgColons,
886888
TT_TableGenDAGArgListColonToAlign);
887889
}
888890

889891
void WhitespaceManager::alignConsecutiveTableGenDefinition() {
890-
alignConsecutiveColons(Style.AlignConsecutiveTableGenDefinitions,
892+
alignConsecutiveColons(Style.AlignConsecutiveTableGenDefinitionColons,
891893
TT_InheritanceColon);
892894
}
893895

clang/lib/Format/WhitespaceManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class WhitespaceManager {
238238
void alignConsecutiveTableGenCondOperatorColons();
239239

240240
/// Align consecutive TableGen DAGArg colon over all \c Changes.
241-
void AlignConsecutiveTableGenBreakingDAGArgColons();
241+
void alignConsecutiveTableGenBreakingDAGArgColons();
242242

243243
/// Align consecutive TableGen definition over all \c Changes.
244244
void alignConsecutiveTableGenDefinition();

clang/unittests/Format/FormatTestTableGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ TEST_F(FormatTestTableGen, Values) {
192192
}
193193

194194
TEST_F(FormatTestTableGen, ClassDefinition) {
195-
verifyFormat("class Class<int x, int y = 1, string z = \"z\",\n"
196-
" int w = -1> : Parent1,\n"
197-
" Parent2<x, y> {\n"
195+
verifyFormat("class Class<int x, int y = 1, string z = \"z\", int w = -1>\n"
196+
" : Parent1,\n"
197+
" Parent2<x, y> {\n"
198198
" int Item1 = 1;\n"
199199
" int Item2;\n"
200200
" code Item3 = [{ Item3 }];\n"
@@ -313,7 +313,7 @@ TEST_F(FormatTestTableGen, DefAlignment) {
313313
"def DefDef : Parent {}\n"
314314
"def DefDefDef : Parent {}\n",
315315
Style);
316-
Style.AlignConsecutiveTableGenDefinitions.Enabled = true;
316+
Style.AlignConsecutiveTableGenDefinitionColons.Enabled = true;
317317
verifyFormat("def Def : Parent {}\n"
318318
"def DefDef : Parent {}\n"
319319
"def DefDefDef : Parent {}\n",

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) {
21742174
auto Result = annotate(("def X { let V = " + Code + "; }").str(), Style);
21752175
return decltype(Result){Result.begin() + 6, Result.end() - 3};
21762176
};
2177-
// Both of bang/cond operators
2177+
// Both of bang/cond operators.
21782178
auto Tokens = AnnotateValue("!cond(!eq(x, 0): 1, true: x)");
21792179
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
21802180
EXPECT_TOKEN(Tokens[0], tok::identifier, TT_TableGenCondOperator);

0 commit comments

Comments
 (0)