diff options
author | Hirofumi Nakamura <k.nakamura.hirofumi@gmail.com> | 2024-02-16 21:35:45 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-16 21:35:45 +0900 |
commit | 8c1c94e8c15855ad41cfec83af61a27740e6941f (patch) | |
tree | 003b22153e72351a95dcdfd0c6b7ce367649ef0c /clang/lib/Format/ContinuationIndenter.cpp | |
parent | bfda580b087a4c44e59fb05af0015d2a14c8dada (diff) | |
download | llvm-8c1c94e8c15855ad41cfec83af61a27740e6941f.zip llvm-8c1c94e8c15855ad41cfec83af61a27740e6941f.tar.gz llvm-8c1c94e8c15855ad41cfec83af61a27740e6941f.tar.bz2 |
[clang-format] Support of TableGen basic format restrictions. (#81611)
- Allow/force to break the line or not.
- Allow/force to insert space or not.
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 159d130..97500ee 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -821,6 +821,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign && !CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() && Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) && + Previous.isNot(TT_TableGenDAGArgOpener) && !(Current.MacroParent && Previous.MacroParent) && (Current.isNot(TT_LineComment) || Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) { @@ -1250,7 +1251,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { return CurrentState.Indent; } if ((Current.isOneOf(tok::r_brace, tok::r_square) || - (Current.is(tok::greater) && Style.isProto())) && + (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen()))) && State.Stack.size() > 1) { if (Current.closesBlockOrBlockTypeList(Style)) return State.Stack[State.Stack.size() - 2].NestedBlockIndent; @@ -1278,6 +1279,12 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) { return State.Stack[State.Stack.size() - 2].LastSpace; } + // When DAGArg closer exists top of line, it should be aligned in the similar + // way as function call above. + if (Style.isTableGen() && Current.is(TT_TableGenDAGArgCloser) && + State.Stack.size() > 1) { + return State.Stack[State.Stack.size() - 2].LastSpace; + } if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent && (Current.is(tok::r_paren) || (Current.is(tok::r_brace) && Current.MatchingParen && @@ -1696,7 +1703,9 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, (!Previous || Previous->isNot(tok::kw_return) || (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) && (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign || - PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) { + PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) && + (!Style.isTableGen() || + (Previous && Previous->is(TT_TableGenDAGArgListComma)))) { NewParenState.Indent = std::max( std::max(State.Column, NewParenState.Indent), CurrentState.LastSpace); } @@ -1942,6 +1951,7 @@ void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) { (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) || (Current.is(tok::r_brace) && State.NextToken != State.Line->First) || State.NextToken->is(TT_TemplateCloser) || + State.NextToken->is(TT_TableGenListCloser) || (Current.is(tok::greater) && Current.is(TT_DictLiteral)))) { State.Stack.pop_back(); } |