[clang] [clang-format] Add LeftWithLastLine to AlignEscapedNewlines option (PR #93402)
https://github.com/HazardyKnusperkeks approved this pull request. Nice https://github.com/llvm/llvm-project/pull/93402 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/92617 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)
@@ -803,6 +803,46 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState , bool DryRun, return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while, tok::kw_switch); }; + // Detecting functions is brittle. It would be better if we could annotate + // the LParen type of functions/calls. + const auto IsFunctionDeclParen = [&](const FormatToken ) { +return Tok.is(tok::l_paren) && Tok.Previous && + (Tok.Previous->is(TT_FunctionDeclarationName) || +(Tok.Previous->Previous && + Tok.Previous->Previous->is(tok::coloncolon) && + Tok.Previous->Previous->Previous && + Tok.Previous->Previous->Previous->is(TT_FunctionDeclarationName))); + }; + const auto IsFunctionCallParen = [&](const FormatToken ) { +return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous && + Tok.Previous->is(tok::identifier); HazardyKnusperkeks wrote: What about lambdas? https://github.com/llvm/llvm-project/pull/93140 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)
@@ -803,6 +803,46 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState , bool DryRun, return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while, tok::kw_switch); }; + // Detecting functions is brittle. It would be better if we could annotate + // the LParen type of functions/calls. + const auto IsFunctionDeclParen = [&](const FormatToken ) { +return Tok.is(tok::l_paren) && Tok.Previous && + (Tok.Previous->is(TT_FunctionDeclarationName) || +(Tok.Previous->Previous && + Tok.Previous->Previous->is(tok::coloncolon) && + Tok.Previous->Previous->Previous && + Tok.Previous->Previous->Previous->is(TT_FunctionDeclarationName))); + }; + const auto IsFunctionCallParen = [&](const FormatToken ) { +return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous && + Tok.Previous->is(tok::identifier); + }; + const auto IsInTemplateString = [&](const FormatToken ) { +if (!Style.isJavaScript()) + return false; +for (const FormatToken *Prev = Prev; Prev = Prev->Previous) { + if (Prev->is(TT_TemplateString) && Prev->opensScope()) +return true; + if (Prev->is(TT_TemplateString) && Prev->closesScope()) +break; +} +return false; + }; + const auto IsNotSimpleFunction = [&](const FormatToken ) { HazardyKnusperkeks wrote: What is a simple function? A bit more comments would be nice. https://github.com/llvm/llvm-project/pull/93140 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Improve BlockIndent at ColumnLimit (PR #93140)
@@ -6157,6 +6157,12 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine , return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf())); } + if (Left.isOneOf(tok::r_paren, TT_TrailingAnnotation) && HazardyKnusperkeks wrote: Is this related? https://github.com/llvm/llvm-project/pull/93140 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Correctly annotate C++ alternative operators in C (PR #92880)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/92880 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ClangFormat] Add DiagHandler for getStyle function (PR #91317)
HazardyKnusperkeks wrote: For the record, I see no harm in this PR and would also merge it without an issue. Just giving @mydeveloperday a bit more time to answer. :) https://github.com/llvm/llvm-project/pull/91317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add space after a word token (PR #92741)
HazardyKnusperkeks wrote: > > Since I am by no means an expert on Clang, a few questions arose > > > > * As Clang formats the code correctly (no code changes necessary) when > > instead of `xor` a different function name e.g. `xooor` is used, I wonder > > why `xor` is tokenized as Unary operator in the first place in C? > > * Is C and C++ using the same tokenizations? > > clang-format formats all C code as C++. Since `xor` is a C++ keyword, it's > lexed as `tok::caret`, which is then erroneously annotated as > `TT_UnaryOperator`. This bug was uncovered by #90161. > > > * How to properly distinguish between the C and C++ language in Clang > > Format? > > clang-format can't do it properly. @mydeveloperday, @HazardyKnusperkeks, and > @rymiel may know more about why we didn't add `LK_C` to the > [`Language`](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#language) > option. If I remember correctly, I was in favor of adding a C language. > Because if this code was in a .h and not a .c you wouldn't know what language > you were in There are certainly headers which are ambiguous, and we could add an option to set the language of such headers. But if we hit a `class`, `namespace`, or a `::` we could fairly certain use it as C++ header. Similar to `guessIsObjC`, and skip checking for C++ if the new option is set to C++ (which of course would be the default, to keep existing behavior). https://github.com/llvm/llvm-project/pull/92741 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format]: Annotate colons found in inline assembly (PR #92617)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/92617 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add SpacesInParensOption for filtering repeated parens (PR #77522)
@@ -4644,22 +4644,36 @@ struct FormatStyle { /// # Should be declared this way: /// SpacesInParens: Custom /// SpacesInParensOptions: + /// ExceptDoubleParentheses: false /// InConditionalStatements: true /// Other: true /// \endcode struct SpacesInParensCustom { +/// Override any of the following options to prevent addition of space +/// between the first two parentheses in situations where a pair of +/// parentheses have been used. +/// \code +/// true: +/// __attribute__(( noreturn )) +/// __decltype__(( x )) +/// if (( a = b )) +/// \endcode +/// false: +///Uses the applicable option. +bool ExceptDoubleParentheses; /// Put a space in parentheses only inside conditional statements /// (``for/if/while/switch...``). /// \code ///true: false: -///if ( a ) { ... } vs. if (a) { ... } +///if ( ( a ) ) { ... } vs. if ((a)) { ... } HazardyKnusperkeks wrote: Don't change this. If you want to show your option, adapt its documentation. https://github.com/llvm/llvm-project/pull/77522 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a regression in annotating struct braces (PR #92352)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/92352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't always break before << between string literals (PR #92214)
https://github.com/HazardyKnusperkeks approved this pull request. I think this is a reasonable compromise. https://github.com/llvm/llvm-project/pull/92214 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Move LeftRightQualifierAlignmentFixer::is...() (PR #91930)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/91930 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/91712 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add option to remove leading blank lines (PR #91221)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/91221 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in annotating struct braces (PR #90555)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/90555 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Set Change.TokenLength to ColumnWidth (PR #90378)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/90378 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Return early in isWordLike() for non-Verilog (PR #90363)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/90363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add a space after a word token only if required (PR #90161)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/90161 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Annotate enum braces as BK_Block (PR #89871)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/89871 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Remove YAML hack to emit a BasedOnStyle comment (PR #89228)
https://github.com/HazardyKnusperkeks approved this pull request. I don't see a use case for that comment, and thus I see no problem in removing it. https://github.com/llvm/llvm-project/pull/89228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Correctly annotate list init braces of class types (PR #89706)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/89706 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Remove YAML hack to emit a BasedOnStyle comment (PR #89228)
https://github.com/HazardyKnusperkeks edited https://github.com/llvm/llvm-project/pull/89228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Remove YAML hack to emit a BasedOnStyle comment (PR #89228)
https://github.com/HazardyKnusperkeks commented: The question is, is there any real benefit of putting the commented style in the output? https://github.com/llvm/llvm-project/pull/89228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Remove YAML hack to emit a BasedOnStyle comment (PR #89228)
@@ -807,12 +807,18 @@ template <> struct MappingTraits { FormatStyle PredefinedStyle; if (getPredefinedStyle(StyleName, Style.Language, ) && Style == PredefinedStyle) { - IO.mapOptional("# BasedOnStyle", StyleName); HazardyKnusperkeks wrote: How hard would it be to add that? https://github.com/llvm/llvm-project/pull/89228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Remove YAML hack to emit a BasedOnStyle comment (PR #89228)
@@ -807,12 +807,18 @@ template <> struct MappingTraits { FormatStyle PredefinedStyle; if (getPredefinedStyle(StyleName, Style.Language, ) && Style == PredefinedStyle) { - IO.mapOptional("# BasedOnStyle", StyleName); + // For convenience, emit the info which style this matches. However, + // setting BasedOnStyle will override all other keys when importing, + // so we set a helper key that is ignored when importing. + // Ideally, we'd want a YAML comment here, but that's not supported. + IO.mapOptional("OrigBasedOnStyle", StyleName); BasedOnStyle = StyleName; break; } } } else { + StringRef OrigBasedOnStyle; // ignored + IO.mapOptional("OrigBasedOnStyle", OrigBasedOnStyle); HazardyKnusperkeks wrote: If we go that way, why read it back? This does not have any effect. https://github.com/llvm/llvm-project/pull/89228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Annotate ampamp after new/delete as BinaryOperator (PR #89033)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/89033 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -5598,11 +5598,45 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine , // FIXME: Breaking after newlines seems useful in general. Turn this into an // option and recognize more cases like endl etc, and break independent of // what comes after operator lessless. - if (Right.is(tok::lessless) && Right.Next && - Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && - Left.TokenText.ends_with("\\n\"")) { -return true; + switch (Style.BreakStreamOperator) { + case FormatStyle::BCOS_BetweenStrings: { +if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) && +Right.Next->is(tok::string_literal)) { + return true; +} +break; + } + case FormatStyle::BCOS_BetweenNewlineStrings: { +if (Right.is(tok::lessless) && Right.Next && +Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && +Left.TokenText.ends_with("\\n\"")) { + return true; +} +break; + } + case FormatStyle::BCOS_Always: { +// Don't break after the very first << or >> +// but the Left token can be os or std::os so HazardyKnusperkeks wrote: Still don't understand the part of `os` or `std::os`. https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -2193,6 +2193,41 @@ struct FormatStyle { /// \version 3.7 bool BreakBeforeTernaryOperators; + /// Different ways to Break Between Chevrons. + enum BreakChevronOperatorStyle : int8_t { +/// Break using ColumnLimit rules. +/// \code +/// os << "a" << "b" << "\n"; +/// \endcode +BCOS_Never, +/// Break between adjacent strings. +/// \code +/// os << "a" +/// << "b" +/// << "\n"; +/// \endcode +BCOS_BetweenStrings, +/// Break between adjacent strings that end with \n. +/// \code +/// os << "a\n" +/// << "b" << "c\n" +/// << "\n"; +/// \endcode +BCOS_BetweenNewlineStrings, +/// Break between adjacent chevrons. +/// \code +/// os << "a\n" +/// << "b" +/// << "c\n" +/// << "\n"; +/// \endcode +BCOS_Always + }; + + /// Break Between Chevron Operators + /// \version 19 + BreakChevronOperatorStyle BreakChevronOperator; HazardyKnusperkeks wrote: That's good. https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -5598,10 +5598,34 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine , // FIXME: Breaking after newlines seems useful in general. Turn this into an // option and recognize more cases like endl etc, and break independent of // what comes after operator lessless. - if (Right.is(tok::lessless) && Right.Next && - Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && - Left.TokenText.ends_with("\\n\"")) { -return true; + if (Style.BreakChevronOperator == FormatStyle::BCOS_BetweenStrings) { +if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) && +Right.Next->is(tok::string_literal)) { + return true; +} + } + if (Style.BreakChevronOperator == FormatStyle::BCOS_BetweenNewlineStrings) { +if (Right.is(tok::lessless) && Right.Next && +Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && +Left.TokenText.ends_with("\\n\"")) { + return true; +} + } + if (Style.BreakChevronOperator == FormatStyle::BCOS_Always) { +// can be std::os or os HazardyKnusperkeks wrote: Yeah ok, but I'd skip the `os`. https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -5598,10 +5598,34 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine , // FIXME: Breaking after newlines seems useful in general. Turn this into an // option and recognize more cases like endl etc, and break independent of // what comes after operator lessless. - if (Right.is(tok::lessless) && Right.Next && - Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && - Left.TokenText.ends_with("\\n\"")) { -return true; + if (Style.BreakChevronOperator == FormatStyle::BCOS_BetweenStrings) { +if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) && +Right.Next->is(tok::string_literal)) { + return true; +} + } + if (Style.BreakChevronOperator == FormatStyle::BCOS_BetweenNewlineStrings) { +if (Right.is(tok::lessless) && Right.Next && +Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && +Left.TokenText.ends_with("\\n\"")) { + return true; +} + } + if (Style.BreakChevronOperator == FormatStyle::BCOS_Always) { +// can be std::os or os +auto *FirstChevron = Right.Previous; +while (FirstChevron) { HazardyKnusperkeks wrote: Is there a test case which utilizes this loop? https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -2193,6 +2193,41 @@ struct FormatStyle { /// \version 3.7 bool BreakBeforeTernaryOperators; + /// Different ways to Break Between Chevrons. + enum BreakChevronOperatorStyle : int8_t { +/// Break using ColumnLimit rules. +/// \code +/// os << "a" << "b" << "\n"; +/// \endcode +BCOS_Never, +/// Break between adjacent strings. +/// \code +/// os << "a" +/// << "b" +/// << "\n"; +/// \endcode +BCOS_BetweenStrings, +/// Break between adjacent strings that end with \n. +/// \code +/// os << "a\n" +/// << "b" << "c\n" +/// << "\n"; +/// \endcode +BCOS_BetweenNewlineStrings, +/// Break between adjacent chevrons. +/// \code +/// os << "a\n" +/// << "b" +/// << "c\n" +/// << "\n"; +/// \endcode +BCOS_Always + }; + + /// Break Between Chevron Operators HazardyKnusperkeks wrote: ```suggestion /// Break Between Chevron Operators. ``` https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -2193,6 +2193,41 @@ struct FormatStyle { /// \version 3.7 bool BreakBeforeTernaryOperators; + /// Different ways to Break Between Chevrons. + enum BreakChevronOperatorStyle : int8_t { +/// Break using ColumnLimit rules. +/// \code +/// os << "a" << "b" << "\n"; +/// \endcode +BCOS_Never, HazardyKnusperkeks wrote: Maybe call it _normal_? It certainly isn't never, as you yourself documented. https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -5598,10 +5598,34 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine , // FIXME: Breaking after newlines seems useful in general. Turn this into an // option and recognize more cases like endl etc, and break independent of // what comes after operator lessless. - if (Right.is(tok::lessless) && Right.Next && - Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && - Left.TokenText.ends_with("\\n\"")) { -return true; + if (Style.BreakChevronOperator == FormatStyle::BCOS_BetweenStrings) { HazardyKnusperkeks wrote: I'd go for a `switch`. https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -2193,6 +2193,41 @@ struct FormatStyle { /// \version 3.7 bool BreakBeforeTernaryOperators; + /// Different ways to Break Between Chevrons. + enum BreakChevronOperatorStyle : int8_t { +/// Break using ColumnLimit rules. +/// \code +/// os << "a" << "b" << "\n"; +/// \endcode +BCOS_Never, +/// Break between adjacent strings. +/// \code +/// os << "a" +/// << "b" +/// << "\n"; +/// \endcode +BCOS_BetweenStrings, +/// Break between adjacent strings that end with \n. +/// \code +/// os << "a\n" +/// << "b" << "c\n" +/// << "\n"; +/// \endcode +BCOS_BetweenNewlineStrings, +/// Break between adjacent chevrons. +/// \code +/// os << "a\n" +/// << "b" +/// << "c\n" +/// << "\n"; +/// \endcode +BCOS_Always + }; + + /// Break Between Chevron Operators + /// \version 19 + BreakChevronOperatorStyle BreakChevronOperator; HazardyKnusperkeks wrote: I had to google _chevron_, didn't know that word. This is the _left shift operator_, or maybe double angle braces. https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] revert to string << string handling to previous default (PR #88490)
@@ -5598,10 +5598,34 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine , // FIXME: Breaking after newlines seems useful in general. Turn this into an // option and recognize more cases like endl etc, and break independent of // what comes after operator lessless. - if (Right.is(tok::lessless) && Right.Next && - Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && - Left.TokenText.ends_with("\\n\"")) { -return true; + if (Style.BreakChevronOperator == FormatStyle::BCOS_BetweenStrings) { +if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) && +Right.Next->is(tok::string_literal)) { + return true; +} + } + if (Style.BreakChevronOperator == FormatStyle::BCOS_BetweenNewlineStrings) { +if (Right.is(tok::lessless) && Right.Next && +Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) && +Left.TokenText.ends_with("\\n\"")) { + return true; +} + } + if (Style.BreakChevronOperator == FormatStyle::BCOS_Always) { +// can be std::os or os HazardyKnusperkeks wrote: I don't understand that comment. https://github.com/llvm/llvm-project/pull/88490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add txtpb to the list of supported TextProto extensions (PR #88355)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/88355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a regression in ContinuationIndenter (PR #88414)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/88414 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add txtpb to the list of supported TextProto extensions (PR #88355)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/88355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't merge a short block for SBS_Never (PR #88238)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/88238 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [polly] [clang-format] Correctly annotate braces in macros (PR #87953)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/87953 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Added unittest of TableGen formatting w.r.t. block type calculation. (PR #87924)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/87924 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Add getNextNonComment() to FormatTokenSource (PR #87868)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/87868 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakFunctionDefinitionParameters option (PR #84988)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/84988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle C++ Core Guidelines suppression tags (PR #86458)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/86458 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Exit clang-format-diff only after all diffs are printed (PR #86776)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/86776 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/86254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/86254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakFunctionDefinitionParameters option (PR #84988)
@@ -7951,6 +7951,24 @@ TEST_F(FormatTest, AllowAllArgumentsOnNextLineDontAlign) { Input, Style); } +TEST_F(FormatTest, BreakFunctionDefinitionParameters) { HazardyKnusperkeks wrote: As I understand you want this, so that you can put all arguments on a single line. My advice is put that in the tests also, so no one could break it by accident. https://github.com/llvm/llvm-project/pull/84988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakFunctionDefinitionParameters option (PR #84988)
@@ -2218,6 +2218,11 @@ struct FormatStyle { /// \version 3.8 bool BreakAfterJavaFieldAnnotations; + /// If ``true``, clang-format will always break before function definition + /// parameters + /// \version 19 + bool BreakFunctionDefinitionParameters; HazardyKnusperkeks wrote: Not only here, but also in the `operator==`, `mapping` and `getLLVMStyle` function. https://github.com/llvm/llvm-project/pull/84988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle C++ Core Guidelines suppression tags (PR #86458)
@@ -4827,6 +4827,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine , Right.is(TT_TemplateOpener)) { return true; } +if (Left.is(tok::identifier) && Right.is(tok::numeric_constant) && +Right.TokenText[0] == '.') { HazardyKnusperkeks wrote: So I figured, but wouldn't that now also happen with `type .5`? And `type 5` is invalid code to begin with. https://github.com/llvm/llvm-project/pull/86458 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakFunctionDefinitionParameters option (PR #84988)
@@ -7951,6 +7951,24 @@ TEST_F(FormatTest, AllowAllArgumentsOnNextLineDontAlign) { Input, Style); } +TEST_F(FormatTest, BreakFunctionDefinitionParameters) { + FormatStyle Style = getLLVMStyleWithColumns(80); HazardyKnusperkeks wrote: ```suggestion FormatStyle Style = getLLVMStyle(); EXPECT_FALSE(Style.BreakFunctionDefinitionParameters); ``` https://github.com/llvm/llvm-project/pull/84988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakFunctionDefinitionParameters option (PR #84988)
@@ -2218,6 +2218,11 @@ struct FormatStyle { /// \version 3.8 bool BreakAfterJavaFieldAnnotations; + /// If ``true``, clang-format will always break before function definition + /// parameters + /// \version 19 + bool BreakFunctionDefinitionParameters; HazardyKnusperkeks wrote: Please sort your code on all locations directly after `BreakConstructorInitializers`. It seems there is something unsorted. https://github.com/llvm/llvm-project/pull/84988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakFunctionDefinitionParameters option (PR #84988)
@@ -5317,6 +5318,12 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine , if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0) return true; + if (Style.BreakFunctionDefinitionParameters && Line.MightBeFunctionDecl && HazardyKnusperkeks wrote: Are all those checks needed? https://github.com/llvm/llvm-project/pull/84988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakFunctionDefinitionParameters option (PR #84988)
@@ -2218,6 +2218,11 @@ struct FormatStyle { /// \version 3.8 bool BreakAfterJavaFieldAnnotations; + /// If ``true``, clang-format will always break before function definition + /// parameters HazardyKnusperkeks wrote: ```suggestion /// parameters. ``` Please also provide an example with on and off. https://github.com/llvm/llvm-project/pull/84988 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)
@@ -19056,6 +19056,9 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { verifyFormat("inta(int x);\n" "double b();", Alignment); + verifyFormat("inta(const Test & = Test());\n" HazardyKnusperkeks wrote: I wanted to see a version where the arguments are aligned, you need a break in the argument list. Either by providing more arguments, or (preferred) by using a reduced `ColumnLimit` for that test. https://github.com/llvm/llvm-project/pull/86254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)
@@ -464,10 +464,11 @@ AlignTokenSequence(const FormatStyle , unsigned Start, unsigned End, if (i + 1 != Changes.size()) Changes[i + 1].PreviousEndOfTokenColumn += Shift; -// If PointerAlignment is PAS_Right, keep *s or next to the token +// If PointerAlignment is PAS_Right, keep *s or next to the token, +// except if the token is equal, then a space is needed. if ((Style.PointerAlignment == FormatStyle::PAS_Right || Style.ReferenceAlignment == FormatStyle::RAS_Right) && -CurrentChange.Spaces != 0) { +CurrentChange.Spaces != 0 && !CurrentChange.Tok->is(tok::equal)) { HazardyKnusperkeks wrote: ```suggestion CurrentChange.Spaces != 0 && CurrentChange.Tok->isNot(tok::equal)) { ``` https://github.com/llvm/llvm-project/pull/86254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle C++ Core Guidelines suppression tags (PR #86458)
@@ -4827,6 +4827,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine , Right.is(TT_TemplateOpener)) { return true; } +if (Left.is(tok::identifier) && Right.is(tok::numeric_constant) && +Right.TokenText[0] == '.') { HazardyKnusperkeks wrote: Do we need the check for `.`? https://github.com/llvm/llvm-project/pull/86458 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a crash with AlignArrayOfStructures option (PR #86420)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/86420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-forma] Support `PointerAlignment: Left` for pointer to member (PR #86253)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/86253 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)
@@ -471,6 +471,9 @@ AlignTokenSequence(const FormatStyle , unsigned Start, unsigned End, Previous >= 0 && Changes[Previous].Tok->getType() == TT_PointerOrReference; --Previous) { +// Don't align function default argument using return type maximum size +if (Changes[Previous + 1].Tok->is(tok::equal)) + continue; HazardyKnusperkeks wrote: I have multiple issues with this snippet: * I don't understand the comment. * Comments end in full stop. * You execute this in a loop, but it is either true on the first run or never. https://github.com/llvm/llvm-project/pull/86254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)
@@ -19056,6 +19056,9 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { verifyFormat("inta(int x);\n" "double b();", Alignment); + verifyFormat("inta(const Test & = Test());\n" HazardyKnusperkeks wrote: I'd like to see something like ``` c++ int foo(someType & whatever, differentType & foo, Test & = Test()); ``` Maybe in some other variants, I want to see the alignment of the arguments. https://github.com/llvm/llvm-project/pull/86254 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (PR #86150)
HazardyKnusperkeks wrote: My pleasure. https://github.com/llvm/llvm-project/pull/86150 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (PR #86150)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/86150 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)
HazardyKnusperkeks wrote: Presumably fixed by #85760 https://github.com/llvm/llvm-project/pull/83149 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/85760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fixed the warning in building document for TableGenBreakingDAGArgOperators. (PR #85760)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/85760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (PR #85470)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/85470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/83149 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in SpaceInEmptyBlock option (PR #85508)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/85508 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Correctly parse C++11 attributes in enum specifiers (PR #85498)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/85498 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (PR #85470)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/85470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in annotating FunctionDeclarationName (PR #85361)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/85361 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions" (PR #85353)
HazardyKnusperkeks wrote: > Reverts #84599 > > This broke the presubmit bot. Any logs to show what was broken? https://github.com/llvm/llvm-project/pull/85353 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/84346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)
HazardyKnusperkeks wrote: > > I mean multiple threads in the same process with different languages. maybe > > unlikely, but not impossible. > > But libFormat/clang-format are _not_ multithreaded, right? clang-format is not, but libFormat I don't know. I know my IDE uses directly libFormat. I will not block this, but I will also not approve it. https://github.com/llvm/llvm-project/pull/84599 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)
@@ -1842,6 +1846,19 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState , Style.ContinuationIndentWidth + std::max(CurrentState.LastSpace, CurrentState.StartOfFunctionCall); +if (Style.isTableGen()) { + if (Current.is(TT_TableGenDAGArgOpenerToBreak) && + Style.TableGenBreakInsideDAGArg == FormatStyle::DAS_BreakElements) { HazardyKnusperkeks wrote: ```suggestion if (Style.isTableGen() && Current.is(TT_TableGenDAGArgOpenerToBreak) && Style.TableGenBreakInsideDAGArg == FormatStyle::DAS_BreakElements) { ``` https://github.com/llvm/llvm-project/pull/83149 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)
@@ -332,6 +332,84 @@ TEST_F(FormatTestTableGen, Assert) { verifyFormat("assert !le(DefVar1, 0), \"Assert1\";\n"); } +TEST_F(FormatTestTableGen, DAGArgBreakElements) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_TableGen); + Style.ColumnLimit = 60; + // By default, the DAGArg does not have a break inside. + verifyFormat("def Def : Parent {\n" HazardyKnusperkeks wrote: ```suggestion ASSERT_EQ(Style.TableGenBreakInsideDAGArg, FormatStyle::DAS_DontBreak); verifyFormat("def Def : Parent {\n" ``` https://github.com/llvm/llvm-project/pull/83149 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)
@@ -2332,6 +2332,77 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) { EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener); EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser); EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_FunctionLBrace); + + // DAGArg breaking options. They use different token types depending on what + // is specified. + Style.TableGenBreakInsideDAGArg = FormatStyle::DAS_BreakElements; + + // When TableGenBreakInsideDAGArg is DAS_BreakElements and + // TableGenBreakingDAGArgOperators is not specified, it makes all the DAGArg + // elements to have line break. + Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak); + EXPECT_TOKEN(Tokens[1], tok::identifier, + TT_TableGenDAGArgOperatorID); // ins + EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak); + EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser); + + Tokens = AnnotateValue("(other type1:$src1, type2:$src2)"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak); + EXPECT_TOKEN(Tokens[1], tok::identifier, + TT_TableGenDAGArgOperatorID); // other + EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak); + EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser); + + // For non-identifier operators, breaks after the operator. + Tokens = AnnotateValue("(!cast(\"Name\") type1:$src1, type2:$src2)"); + ASSERT_EQ(Tokens.size(), 16u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak); + EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_TableGenDAGArgOperatorToBreak); + EXPECT_TOKEN(Tokens[11], tok::comma, TT_TableGenDAGArgListCommaToBreak); + EXPECT_TOKEN(Tokens[15], tok::r_paren, TT_TableGenDAGArgCloser); + + Style.TableGenBreakInsideDAGArg = FormatStyle::DAS_BreakAll; + + // When TableGenBreakInsideDAGArg is DAS_BreakAll and + // TableGenBreakingDAGArgOperators is not specified, it makes all the DAGArg + // to have line break inside it. + Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak); + EXPECT_TOKEN(Tokens[1], tok::identifier, + TT_TableGenDAGArgOperatorToBreak); // ins + EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak); + EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser); + + Tokens = AnnotateValue("(other type1:$src1, type2:$src2)"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak); + EXPECT_TOKEN(Tokens[1], tok::identifier, + TT_TableGenDAGArgOperatorToBreak); // other + EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak); + EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser); + + // If TableGenBreakingDAGArgOperators is specified, it is limited to the + // specified operators. + Style.TableGenBreakingDAGArgOperators = {"ins", "outs"}; + Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak); + EXPECT_TOKEN(Tokens[1], tok::identifier, + TT_TableGenDAGArgOperatorToBreak); // ins + EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak); + EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser); + + Tokens = AnnotateValue("(other type1:$src1, type2:$src2)"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpener); + EXPECT_TOKEN(Tokens[1], tok::identifier, + TT_Unknown); // other HazardyKnusperkeks wrote: ```suggestion EXPECT_TOKEN(Tokens[1], tok::identifier, TT_Unknown); // other ``` This should fit? https://github.com/llvm/llvm-project/pull/83149 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)
HazardyKnusperkeks wrote: > > What happens if you use libFormat concurrently? > > Can you elaborate? Doesn't each process get its own copy of the globals of a > shared library? I mean multiple threads in the same process with different languages. maybe unlikely, but not impossible. https://github.com/llvm/llvm-project/pull/84599 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)
HazardyKnusperkeks wrote: Then I'd go back to `Style.isCpp()`. What happens if you use libFormat concurrently? https://github.com/llvm/llvm-project/pull/84599 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)
HazardyKnusperkeks wrote: That's okay for clang-format, but you couldn't use libFormat with different languages at once anymore. I dislike global state in libraries. https://github.com/llvm/llvm-project/pull/84599 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)
HazardyKnusperkeks wrote: > I think you need to run `clang/docs/tools/dump_format_help.py`. https://github.com/llvm/llvm-project/pull/84346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)
@@ -535,6 +541,9 @@ static bool format(StringRef FileName) { Rewrite.getEditBuffer(ID).write(outs()); } } + if (ErrorOnIncompleteFormat && !Status.FormatComplete) +return true; + return false; HazardyKnusperkeks wrote: ```suggestion return ErrorOnIncompleteFormat && !Status.FormatComplete; ``` https://github.com/llvm/llvm-project/pull/84346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)
https://github.com/HazardyKnusperkeks edited https://github.com/llvm/llvm-project/pull/84346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)
https://github.com/HazardyKnusperkeks commented: I think you need to run `clang/docs/tools/dump_format_help.py`. https://github.com/llvm/llvm-project/pull/84346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][doc] fix documentation for clang-format (PR #83415)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/83415 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Replace Style.isCpp() with IsCpp (PR #83533)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/83533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Enable again some operator tests (PR #83380)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/83380 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Replace Style.isCpp() with IsCpp (PR #83533)
HazardyKnusperkeks wrote: The question is: why? And why handle c++ different than all other languages? https://github.com/llvm/llvm-project/pull/83533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignConsecutiveTableGenDefinitions option. (PR #83008)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/83008 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code (PR #82957)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/82957 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
@@ -849,7 +851,12 @@ void WhitespaceManager::alignConsecutiveAssignments() { } void WhitespaceManager::alignConsecutiveBitFields() { - if (!Style.AlignConsecutiveBitFields.Enabled) + alignConsecutiveColons(Style.AlignConsecutiveBitFields, TT_BitFieldColon); +} + +void WhitespaceManager::alignConsecutiveColons( +const FormatStyle::AlignConsecutiveStyle , TokenType Type) { HazardyKnusperkeks wrote: You're right. I made the mistake thinking it was just an `enum`. https://github.com/llvm/llvm-project/pull/82878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add a parameter to getStyle() and guessLanguage() (PR #82911)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/82911 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
https://github.com/HazardyKnusperkeks edited https://github.com/llvm/llvm-project/pull/82878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
@@ -849,7 +851,12 @@ void WhitespaceManager::alignConsecutiveAssignments() { } void WhitespaceManager::alignConsecutiveBitFields() { - if (!Style.AlignConsecutiveBitFields.Enabled) + alignConsecutiveColons(Style.AlignConsecutiveBitFields, TT_BitFieldColon); +} + +void WhitespaceManager::alignConsecutiveColons( +const FormatStyle::AlignConsecutiveStyle , TokenType Type) { HazardyKnusperkeks wrote: ```suggestion FormatStyle::AlignConsecutiveStyle AlignStyle, TokenType Type) { ``` No need for the reference. https://github.com/llvm/llvm-project/pull/82878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (PR #82878)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/82878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][NFC] Enable RemoveSemicolon for clang-format style (PR #82735)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/82735 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/81611 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)
@@ -55,5 +59,271 @@ TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) { verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;"); } +TEST_F(FormatTestTableGen, LiteralsAndIdentifiers) { + verifyFormat("def LiteralAndIdentifiers {\n" + " let someInteger = -42;\n" + " let 0startID = $TokVarName;\n" + " let 0xstartInteger = 0x42;\n" + " let someIdentifier = $TokVarName;\n" + "}\n"); +} + +TEST_F(FormatTestTableGen, BangOperators) { + verifyFormat("def BangOperators {\n" + " let IfOpe = !if(\n" + " !not(!and(!gt(!add(1, 2), !sub(3, 4)), !isa($x))),\n" + " !foldl(0, !listconcat(!range(5, 6), !range(7, 8)),\n" + " total, rec, !add(total, rec.Number)),\n" + " !tail(!range(9, 10)));\n" + " let ForeachOpe = !foreach(\n" + " arg, arglist,\n" + " !if(!isa(arg.Type),\n" + " !add(!cast(arg).Number, x), arg));\n" + " let CondOpe1 = !cond(!eq(size, 1): 1,\n" + " !eq(size, 2): 1,\n" + " !eq(size, 4): 1,\n" + " !eq(size, 8): 1,\n" + " !eq(size, 16): 1,\n" + " true: 0);\n" + " let CondOpe2 = !cond(!lt(x, 0): \"negativenegative\",\n" + " !eq(x, 0): \"zerozero\",\n" + " true: \"positivepositive\");\n" + " let CondOpe2WithComment = !cond(!lt(x, 0): // negative\n" + " \"negativenegative\",\n" + " !eq(x, 0): // zero\n" + " \"zerozero\",\n" + " true: // default\n" + " \"positivepositive\");\n" + "}\n"); +} + +TEST_F(FormatTestTableGen, Include) { + verifyFormat("include \"test/IncludeFile.h\"\n"); +} + +TEST_F(FormatTestTableGen, Types) { + verifyFormat("def Types : list, bits<3>, list> {}\n"); +} + +TEST_F(FormatTestTableGen, SimpleValue1_SingleLiterals) { + verifyFormat("def SimpleValue {\n" + " let Integer = 42;\n" + " let String = \"some string\";\n" + "}\n"); +} + +TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) { + // test::messUp does not understand multiline TableGen code-literals. + // We have to give the result and the strings to format manually. + std::string DefWithCode = HazardyKnusperkeks wrote: ```suggestion StringRef DefWithCode = ``` No need to allocate. https://github.com/llvm/llvm-project/pull/81611 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits