[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-13 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/84599 >From 43238d58ff490073c13ff621faddceb89b05b22e Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 8 Mar 2024 19:47:54 -0800 Subject: [PATCH 1/2] [clang-format][NFC] Eliminate the IsCpp parameter in all functions

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-11 Thread Owen Pan via cfe-commits
owenca 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? https://github.com/llvm/llvm-project/pull/84599 ___ cfe-commits

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-10 Thread Owen Pan via cfe-commits
owenca wrote: > Then I'd go back to `Style.isCpp()`. That would still require passing `Style.isCpp()` as the parameter to the `FormatToken` (and other) functions. > What happens if you use libFormat concurrently? Can you elaborate? Doesn't each process get its own copy of the globals of a

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-09 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/84599 >From 43238d58ff490073c13ff621faddceb89b05b22e Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 8 Mar 2024 19:47:54 -0800 Subject: [PATCH 1/2] [clang-format][NFC] Eliminate the IsCpp parameter in all functions

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-09 Thread Owen Pan via cfe-commits
owenca wrote: > That's okay for clang-format, but you couldn't use libFormat with different > languages at once anymore. I believe we still could because `IsCpp` is set to `Style.isCpp()` every time new instances of the classes are constructed. I'll add a couple of test cases to demonstrate

[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

2024-03-09 Thread Owen Pan via cfe-commits
owenca wrote: > Thanks for doing this. Does it mean we would have to add every type we use to > our config? It would be much more convenient if clang-format treated the > argument list the same way that it treats in definitions. For example > > ```shell > printf "int\niso_time(time_t) {

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-08 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/84599 >From 43238d58ff490073c13ff621faddceb89b05b22e Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 8 Mar 2024 19:47:54 -0800 Subject: [PATCH] [clang-format][NFC] Eliminate the IsCpp parameter in all functions

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

2024-03-08 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/84599 None >From bd3e866189ad4c238ea0afbbc30fbe88e0406eb9 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 8 Mar 2024 19:47:54 -0800 Subject: [PATCH] [clang-format][NFC] Eliminate the IsCpp parameter in all

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-08 Thread Owen Pan via cfe-commits
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/83709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-08 Thread Owen Pan via cfe-commits
owenca wrote: > Just thinking out loud and maybe not for this patch but for a more general > solution, what we seem to never do is collect information about types local > to the file as we go; For example what if a first pass identified types from > declarations and function argument

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-08 Thread Owen Pan via cfe-commits
owenca wrote: > Can the TypeNames mechanism be prepopulated with this list of types instead? I don't see how that would work. Please note that the TypeNames option is not specific to C/C++/Objective-C. Otherwise, I could simply change `isTypeName(bool IsCpp)` to `isCppTypeName()`.

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-05 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/83709 >From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 2 Mar 2024 22:08:29 -0800 Subject: [PATCH 1/6] [clang-format] Handle common C++ non-keyword types as such Fixes

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-05 Thread Owen Pan via cfe-commits
@@ -620,6 +620,23 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) { ASSERT_EQ(Tokens.size(), 8u) << Tokens; EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown); EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator); + + Tokens = annotate("#define FOO(bar)

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-05 Thread Owen Pan via cfe-commits
@@ -268,20 +268,24 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( if (isPossibleMacro(TypeToken)) return Tok; + const bool IsCpp = Style.isCpp(); + // The case `const long long int volatile` -> `long long int const volatile` // The case

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-05 Thread Owen Pan via cfe-commits
@@ -71,8 +71,21 @@ bool FormatToken::isSimpleTypeSpecifier() const { } } -bool FormatToken::isTypeOrIdentifier() const { - return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier); +// Sorted common C++ non-keyword types. +static SmallVector

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-05 Thread Owen Pan via cfe-commits
owenca wrote: > > It does fix the example given. > > #83400 has 6 real-world examples. This patch fixes none of them. It also has > a reduced testcase, which this patch does fix. But fixing the reduced > testcase without fixing the real-world examples is not fixing the bug. You took what I

[clang] [clang-format][doc] fix documentation for clang-format (PR #83415)

2024-03-04 Thread Owen Pan via cfe-commits
https://github.com/owenca approved this pull request. 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] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/83709 >From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 2 Mar 2024 22:08:29 -0800 Subject: [PATCH 1/5] [clang-format] Handle common C++ non-keyword types as such Fixes

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/83709 >From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 2 Mar 2024 22:08:29 -0800 Subject: [PATCH 1/4] [clang-format] Handle common C++ non-keyword types as such Fixes

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/83709 >From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 2 Mar 2024 22:08:29 -0800 Subject: [PATCH 1/3] [clang-format] Handle common C++ non-keyword types as such Fixes

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } +// Sorted common C++ non-keyword types. +static SmallVector CppNonKeywordTypes = { +"byte", "int16_t", "int32_t", "int64_t", "int8_t", +"size_t", "uint16_t", "uint32_t",

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } +// Sorted common C++ non-keyword types. +static SmallVector CppNonKeywordTypes = { +"byte", "int16_t", "int32_t", "int64_t", "int8_t", +"size_t", "uint16_t", "uint32_t",

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
owenca wrote: > But looking for a parenthesized single identifier addresses all of the > examples in the issue. I don't think it would work, but you are welcome to submit a patch to prove me wrong.  https://github.com/llvm/llvm-project/pull/83709

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
owenca wrote: > > This patch does not only fix formatting of C-casting to a C++ standard > > type. It correctly identifies (most of) such types and might have fixed > > other kinds of bugs. > > Sure, this patch seems like a good change. But it does not fix #83400. It does fix the example

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } +// Sorted common C++ non-keyword types. +static SmallVector CppNonKeywordTypes = { +"byte", "int16_t", "int32_t", "int64_t", "int8_t", +"size_t", "uint16_t", "uint32_t",

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } +// Sorted common C++ non-keyword types. +static SmallVector CppNonKeywordTypes = { +"byte", "int16_t", "int32_t", "int64_t", "int8_t", owenca wrote: Good point

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
owenca wrote: > > > Another possibility to consider for the original bug: > > > `(single_identifier)` is almost certainly a cast, not redundant > > > parentheses, unless `single_identifier` names a macro argument. So I > > > wonder if that would be a better heuristic to use to fix the

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } +// Sorted common C++ non-keyword types. +static SmallVector CppNonKeywordTypes = { +"byte", "int16_t", "int32_t", "int64_t", "int8_t", +"size_t", "uint16_t", "uint32_t",

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } +// Sorted common C++ non-keyword types. +static SmallVector CppNonKeywordTypes = { +"byte", "int16_t", "int32_t", "int64_t", "int8_t", +"size_t", "uint16_t", "uint32_t",

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
owenca wrote: > Another possibility to consider for the original bug: `(single_identifier)` > is almost certainly a cast, not redundant parentheses, unless > `single_identifier` names a macro argument. So I wonder if that would be a > better heuristic to use to fix the regression. I don’t

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } +// Sorted common C++ non-keyword types. +static SmallVector CppNonKeywordTypes = { +"byte", "int16_t", "int32_t", "int64_t", "int8_t", +"size_t", "uint16_t", "uint32_t",

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/83709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } +// Sorted common C++ non-keyword types. +static SmallVector CppNonKeywordTypes = { +"byte", "int16_t", "int32_t", "int64_t", "int8_t", +"size_t", "uint16_t", "uint32_t",

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const { case tok::kw_decltype: case tok::kw__Atomic: return true; + case tok::identifier: +return IsCpp && std::binary_search(CppNonKeywordTypes.begin(), +

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/83709 >From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 2 Mar 2024 22:08:29 -0800 Subject: [PATCH 1/2] [clang-format] Handle common C++ non-keyword types as such Fixes

[clang] [clang-format][doc] fix documentation for clang-format (PR #83415)

2024-03-02 Thread Owen Pan via cfe-commits
https://github.com/owenca edited 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][doc] fix documentation for clang-format (PR #83415)

2024-03-02 Thread Owen Pan via cfe-commits
owenca wrote: > So I did added a simple search and replace to the generating script so now > every time [[[NAME]]] is reference it will use the members name. Nice! Though why `[[[NAME]]]` in particular? Can we use `` instead? https://github.com/llvm/llvm-project/pull/83415

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-02 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/83709 Fixes #83400. >From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 2 Mar 2024 22:08:29 -0800 Subject: [PATCH] [clang-format] Handle common C++ non-keyword types as

[clang] [clang-format][NFC] Replace Style.isCpp() with IsCpp (PR #83533)

2024-03-02 Thread Owen Pan via cfe-commits
https://github.com/owenca closed 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][NFC] Replace Style.isCpp() with IsCpp (PR #83533)

2024-03-01 Thread Owen Pan via cfe-commits
owenca wrote: > The question is: why? And why handle c++ different than all other languages? This is the preparation for fixing/extending `FormatToken::isSimpleTypeSpecifier()`, which I'll add a couple of parameters to, e.g. `isSimpleTypeSpecifier(bool IsCpp, const LangOptions )`. Also, this

[clang] [clang-format][doc] fix documentation for clang-format (PR #83415)

2024-02-29 Thread Owen Pan via cfe-commits
https://github.com/owenca edited 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][Documentation] fix documentation for clang-format (PR #83415)

2024-02-29 Thread Owen Pan via cfe-commits
owenca wrote: Hi, you need to edit `clang/include/clang/Format/Format.h` and then run `clang/docs/tools/dump_format_style.py` to regenerate `clang/docs/ClangFormatStyleOptions.rst`. https://github.com/llvm/llvm-project/pull/83415 ___ cfe-commits

[clang] [clang-format][NFC] Replace Style.isCpp() with IsCpp (PR #83533)

2024-02-29 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/83533 None >From a643963e818a9c6c4abea93c15f8c48f7291a837 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Thu, 29 Feb 2024 23:07:58 -0800 Subject: [PATCH] [clang-format][NFC] Replace Style.isCpp() with IsCpp ---

[clang] [clang-format] Enable again some operator tests (PR #83380)

2024-02-29 Thread Owen Pan via cfe-commits
https://github.com/owenca approved this pull request. 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] Enable again some operator tests (PR #83380)

2024-02-29 Thread Owen Pan via cfe-commits
@@ -16710,7 +16705,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { verifyFormat("typedef void (*cb)(int);", SpaceFuncDef); verifyFormat("T A::operator()();", SpaceFuncDef); verifyFormat("X A::operator++(T);", SpaceFuncDef); - // verifyFormat("T A::operator() ()

[clang] [clang-format] Enable again some operator tests (PR #83380)

2024-02-29 Thread Owen Pan via cfe-commits
https://github.com/owenca edited 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] Enable again some operator tests (PR #83380)

2024-02-29 Thread Owen Pan via cfe-commits
@@ -16671,9 +16667,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { SpaceFuncDecl); verifyFormat("int f () throw(Deprecated);", SpaceFuncDecl); verifyFormat("typedef void (*cb)(int);", SpaceFuncDecl); - // FIXME these tests regressed behaviour. -

[clang] [clang-format] Enable again some operator tests (PR #83380)

2024-02-29 Thread Owen Pan via cfe-commits
@@ -16797,7 +16792,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { verifyFormat("int f() throw (Deprecated);", SomeSpace2); verifyFormat("typedef void (*cb) (int);", SomeSpace2); verifyFormat("T A::operator()();", SomeSpace2); - // verifyFormat("X A::operator++

[clang] [clang-format] Enable again some operator tests (PR #83380)

2024-02-29 Thread Owen Pan via cfe-commits
@@ -16710,7 +16705,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { verifyFormat("typedef void (*cb)(int);", SpaceFuncDef); verifyFormat("T A::operator()();", SpaceFuncDef); verifyFormat("X A::operator++(T);", SpaceFuncDef); - // verifyFormat("T A::operator() ()

[clang] [clang-format] Enable again some operator tests (PR #83380)

2024-02-29 Thread Owen Pan via cfe-commits
@@ -16797,7 +16792,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { verifyFormat("int f() throw (Deprecated);", SomeSpace2); verifyFormat("typedef void (*cb) (int);", SomeSpace2); verifyFormat("T A::operator()();", SomeSpace2); - // verifyFormat("X A::operator++

[clang] [clang-format] Enable again some operator tests (PR #83380)

2024-02-29 Thread Owen Pan via cfe-commits
@@ -16671,9 +16667,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { SpaceFuncDecl); verifyFormat("int f () throw(Deprecated);", SpaceFuncDecl); verifyFormat("typedef void (*cb)(int);", SpaceFuncDecl); - // FIXME these tests regressed behaviour. -

[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

2024-02-26 Thread Owen Pan via cfe-commits
owenca wrote: > > @HighCommander4 I got a better idea. It seems that we don't need to add the > > parameter! See #82957. I think all you need to do is to call `getStyle()` > > with the default `""` for the `StringRef Code` argument to skip the > > Objective-C guesser. > > Thanks. That does

[clang] [clang-format] Add a parameter to getStyle() and guessLanguage() (PR #82911)

2024-02-26 Thread Owen Pan via cfe-commits
https://github.com/owenca closed 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][NFC] Skip ObjCHeaderStyleGuesser for empty code (PR #82957)

2024-02-26 Thread Owen Pan via cfe-commits
https://github.com/owenca closed 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 a parameter to getStyle() and guessLanguage() (PR #82911)

2024-02-25 Thread Owen Pan via cfe-commits
owenca wrote: I will abandon this pull request if #82957 gets approved. 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 a parameter to getStyle() and guessLanguage() (PR #82911)

2024-02-25 Thread Owen Pan via cfe-commits
https://github.com/owenca converted_to_draft 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] Limit how much work guessLanguage() can do (PR #78925)

2024-02-25 Thread Owen Pan via cfe-commits
owenca wrote: @HighCommander4 I got a better idea. It seems that we don't need to add the parameter! See #82957. I think all you need to do is to call `getStyle()` with the default `""` for the `StringRef Code` argument to skip the Objective-C guesser.

[clang] [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code (PR #82957)

2024-02-25 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/82957 None >From 9334d008b4c7ae13fdeb674a6bb9b4dc62c6a1dd Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sun, 25 Feb 2024 20:58:25 -0800 Subject: [PATCH] [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code

[clang] 085f9b0 - [clang-format][doc] Update documentation for RemoveSemicolon

2024-02-25 Thread Owen Pan via cfe-commits
Author: Owen Pan Date: 2024-02-25T16:08:37-08:00 New Revision: 085f9b0d146fc99bbb0e193593aad696fc50a056 URL: https://github.com/llvm/llvm-project/commit/085f9b0d146fc99bbb0e193593aad696fc50a056 DIFF: https://github.com/llvm/llvm-project/commit/085f9b0d146fc99bbb0e193593aad696fc50a056.diff

[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

2024-02-25 Thread Owen Pan via cfe-commits
owenca wrote: @HighCommander4 see #82911 https://github.com/llvm/llvm-project/pull/78925 ___ 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)

2024-02-25 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/82911 Add a boolean parameter GuessObjC that defaults to true. This allows e.g. clangd to bypass ObjCHeaderStyleGuesser.process() by passing false for the parameter. >From bd85fd1dff5ac7b72913ed175daec3809896e6c0 Mon

[clang] [clang-format][NFC] Enable RemoveSemicolon for clang-format style (PR #82735)

2024-02-23 Thread Owen Pan via cfe-commits
https://github.com/owenca closed 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] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

2024-02-23 Thread Owen Pan via cfe-commits
@@ -420,6 +420,8 @@ struct UnwrappedLineNode { SmallVector Children; }; +std::ostream <<(std::ostream , const UnwrappedLine ); + owenca wrote: Ah, thanks for the explanation. https://github.com/llvm/llvm-project/pull/82523

[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

2024-02-23 Thread Owen Pan via cfe-commits
@@ -90,6 +90,12 @@ class ScopedDeclarationState { } // end anonymous namespace +std::ostream <<(std::ostream , const UnwrappedLine ) { + llvm::raw_os_ostream OS(Stream); + printLine(OS, Line); + return Stream; +} + owenca wrote: Delete.

[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

2024-02-23 Thread Owen Pan via cfe-commits
@@ -287,6 +287,21 @@ TEST_F(FormatTestMacroExpansion, Style); } +TEST_F(FormatTestMacroExpansion, IndentChildrenWithinMacroCall) { + FormatStyle Style = getGoogleStyleWithColumns(22); + Style.Macros.push_back("MACRO(a, b)=a=(b)"); + verifyFormat("void f()

[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

2024-02-23 Thread Owen Pan via cfe-commits
@@ -19,6 +19,7 @@ #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/DenseSet.h" #include "llvm/Support/Debug.h" +#include owenca wrote: Not needed explicitly. https://github.com/llvm/llvm-project/pull/82523

[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

2024-02-23 Thread Owen Pan via cfe-commits
@@ -420,6 +420,8 @@ struct UnwrappedLineNode { SmallVector Children; }; +std::ostream <<(std::ostream , const UnwrappedLine ); + owenca wrote: Delete. https://github.com/llvm/llvm-project/pull/82523 ___

[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

2024-02-22 Thread Owen Pan via cfe-commits
owenca wrote: > > If we add a `bool GuessObjC` parameter to `guessLanguage()`, would that > > solve the problem? > > I assume you mean making it so that when clangd calls into `guessLanguage()`, > the ObjC guessing algorithm is skipped entirely. I'm not familiar with clangd use cases, but I

[clang] [clang-format][NFC] Enable RemoveSemicolon for clang-format style (PR #82735)

2024-02-22 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/82735 Also insert separators for decimal integers longer than 4 digits. >From e0a9d61283276bddda8231b599697cf4d497ff0a Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Thu, 22 Feb 2024 20:56:47 -0800 Subject: [PATCH]

[clang] [clang-format] Fix crash in TokenAnnotator (PR #82349)

2024-02-22 Thread Owen Pan via cfe-commits
https://github.com/owenca approved this pull request. https://github.com/llvm/llvm-project/pull/82349 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-02-22 Thread Owen Pan via cfe-commits
owenca wrote: > As a side note, I tried adding these two tests but they fail, meaning the > cursor is still incorrectly computed with CRLF when replacing lines. > > This is due to adding lines between the include groups (with Regroup option), > as this new line is added with only the

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-02-22 Thread Owen Pan via cfe-commits
@@ -3134,20 +3135,24 @@ static void sortCppIncludes(const FormatStyle , } result += Includes[Index].Text; if (Cursor && CursorIndex == Index) - *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset; + NewCursor = IncludesBeginOffset +

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-02-22 Thread Owen Pan via cfe-commits
https://github.com/owenca commented: `git diff Format.cpp` output: ``` --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3116,6 +3116,7 @@ static void sortCppIncludes(const FormatStyle , return; } + const auto OldCursor = Cursor ? *Cursor : 0; std::string

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-02-22 Thread Owen Pan via cfe-commits
@@ -3134,20 +3135,24 @@ static void sortCppIncludes(const FormatStyle , } result += Includes[Index].Text; if (Cursor && CursorIndex == Index) - *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset; + NewCursor = IncludesBeginOffset +

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-02-22 Thread Owen Pan via cfe-commits
@@ -3134,20 +3135,24 @@ static void sortCppIncludes(const FormatStyle , } result += Includes[Index].Text; if (Cursor && CursorIndex == Index) - *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset; + NewCursor = IncludesBeginOffset +

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-02-22 Thread Owen Pan via cfe-commits
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/77456 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-02-22 Thread Owen Pan via cfe-commits
@@ -3123,6 +3123,7 @@ static void sortCppIncludes(const FormatStyle , } std::string result; + unsigned NewCursor = UINT_MAX; owenca wrote: ```suggestion const auto OldCursor = Cursor ? *Cursor : 0; ``` https://github.com/llvm/llvm-project/pull/77456

[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

2024-02-21 Thread Owen Pan via cfe-commits
owenca wrote: > However, for clangd users, a crucial difference between `guessLanguage()` vs. > other code in libFormat that uses `UnwrappedLineParser`, is that > `guessLanguage()` gets called as soon as a file is opened in the editor, > while the other code is only called if the user

[clang] [clang-format] Fix crash in TokenAnnotator (PR #82349)

2024-02-20 Thread Owen Pan via cfe-commits
@@ -13503,6 +13503,9 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) { verifyFormat("{"); verifyFormat("#})"); verifyNoCrash("(/**/[:!] ?[)."); + verifyNoCrash("struct X{" +" operator iunt(" owenca wrote: ```suggestion

[clang] [clang-format] Fix crash in TokenAnnotator (PR #82349)

2024-02-20 Thread Owen Pan via cfe-commits
@@ -3817,7 +3817,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const { do { Tok = Tok->Next; } while (Tok && Tok->isNot(TT_OverloadedOperatorLParen)); -if (!Tok) +if (!Tok || !Tok->Next)

[clang] [clang-format] Fix RemoveSemicolon for empty functions (PR #82278)

2024-02-20 Thread Owen Pan via cfe-commits
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/82278 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

2024-02-20 Thread Owen Pan via cfe-commits
owenca wrote: > > couldn't we just use the .clang-format-ignore file to say... hey don't > > bother with this file, we can't do it... > > I think that's a good solution for avoiding the OOM when actually trying to > format the file, in combination with this patch for avoiding the OOM in >

[clang] 119a728 - [clang-format][NFC] Remove redundant calls to guessIsObjC()

2024-02-20 Thread Owen Pan via cfe-commits
Author: Owen Pan Date: 2024-02-20T00:28:26-08:00 New Revision: 119a72866f0e143127355fe6e03f57c4f8bab1ae URL: https://github.com/llvm/llvm-project/commit/119a72866f0e143127355fe6e03f57c4f8bab1ae DIFF: https://github.com/llvm/llvm-project/commit/119a72866f0e143127355fe6e03f57c4f8bab1ae.diff

[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

2024-02-19 Thread Owen Pan via cfe-commits
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/81848 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Fix RemoveSemicolon for empty functions (PR #82278)

2024-02-19 Thread Owen Pan via cfe-commits
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/82278 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Fix RemoveSemicolon for empty ctors/dtors (PR #82278)

2024-02-19 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/82278 Fixes #79833. >From 4bcf6dba8b97096801be550c4a8d1626ed57e475 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Mon, 19 Feb 2024 13:11:29 -0800 Subject: [PATCH] [clang-format] Fix RemoveSemicolon for empty

[clang] [polly] [clang-format] Correctly annotate block braces of empty ctors/dtors (PR #82097)

2024-02-19 Thread Owen Pan via cfe-commits
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/82097 ___ 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 block braces of empty ctors/dtors (PR #82097)

2024-02-16 Thread Owen Pan via cfe-commits
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/82097 >From f02c1acefe642065cae01ced98b168ce33b98d47 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 16 Feb 2024 23:27:12 -0800 Subject: [PATCH 1/2] [clang-format] Correctly annotate block braces of empty

[clang] [polly] [clang-format] Correctly annotate block braces of empty ctors/dtors (PR #82097)

2024-02-16 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/82097 Also reformat polly. Fixes #79834. >From f02c1acefe642065cae01ced98b168ce33b98d47 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 16 Feb 2024 23:27:12 -0800 Subject: [PATCH] [clang-format] Correctly annotate

[clang] [clang-format] Don't sort qualifiers across preprocessor directives (PR #81958)

2024-02-16 Thread Owen Pan via cfe-commits
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/81958 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Don't sort qualifiers across preprocessor directives (PR #81958)

2024-02-16 Thread Owen Pan via cfe-commits
owenca wrote: > LGTM, as long as someone doesn't say it should be > > ```c++ > #if FOO >constexpr > #endif >inline >int i = 0; > ``` > > but I think this change is fine..I would rather we didn't try and support > that.. thank you. Yep! Otherwise, you would have to handle the

[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

2024-02-16 Thread Owen Pan via cfe-commits
@@ -22893,6 +22893,19 @@ TEST_F(FormatTest, FormatsLambdas) { LLVMWithBeforeLambdaBody); verifyFormat("FctWithTwoParams_SLS_All([]() { return 43; }, 87);", LLVMWithBeforeLambdaBody); + verifyFormat( + "FctWithTwoParams_SLS_All(\n" + "

[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

2024-02-16 Thread Owen Pan via cfe-commits
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/81848 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

2024-02-16 Thread Owen Pan via cfe-commits
https://github.com/owenca approved this pull request. https://github.com/llvm/llvm-project/pull/81848 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] 92ef408 - [clang-format] Delete a redundant newline at the end of a test case

2024-02-16 Thread Owen Pan via cfe-commits
Author: Owen Pan Date: 2024-02-16T01:47:49-08:00 New Revision: 92ef40874d58d4fca4b7657c31ab2538e1301f26 URL: https://github.com/llvm/llvm-project/commit/92ef40874d58d4fca4b7657c31ab2538e1301f26 DIFF: https://github.com/llvm/llvm-project/commit/92ef40874d58d4fca4b7657c31ab2538e1301f26.diff

[clang] [clang-format] Don't sort qualifiers across preprocessor directives (PR #81958)

2024-02-15 Thread Owen Pan via cfe-commits
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/81958 Fixes #80579. >From 13614f5760a26ba6134abdd555176a1aa2ed3974 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Thu, 15 Feb 2024 17:37:44 -0800 Subject: [PATCH] [clang-format] Don't sort qualifiers across

[clang] 6087d7b - [clang-format][NFC] Sort options in Format.cpp

2024-02-14 Thread Owen Pan via cfe-commits
Author: Owen Pan Date: 2024-02-14T21:40:07-08:00 New Revision: 6087d7bc0a9d7d4ad2c94a131c2bc427b767c9d7 URL: https://github.com/llvm/llvm-project/commit/6087d7bc0a9d7d4ad2c94a131c2bc427b767c9d7 DIFF: https://github.com/llvm/llvm-project/commit/6087d7bc0a9d7d4ad2c94a131c2bc427b767c9d7.diff

[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

2024-02-14 Thread Owen Pan via cfe-commits
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/81591 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

2024-02-14 Thread Owen Pan via cfe-commits
https://github.com/owenca approved this pull request. https://github.com/llvm/llvm-project/pull/81591 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

2024-02-13 Thread Owen Pan via cfe-commits
@@ -1130,14 +1129,13 @@ template <> struct MappingTraits { // AlwaysBreakAfterReturnType was not, initialize the latter from the // former for backwards compatibility. owenca wrote: ```suggestion // BreakAfterReturnType was not, initialize the

<    1   2   3   4   5   6   7   8   9   10   >