[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2024-06-26 Thread via cfe-commits

mydeveloperday wrote:

> Where is the documentation for the value? CLion reports `clang-format` option 
> as an error by the reason. No doc, no schema rule.

Personally, I'm not a fan of CLion enough to care! especially following 
JetBrains slating of clang-format:  (thanks for doing that at a massive public 
C++ forum without contacting us), their content even questionable as to its 
accuracy. 

https://www.youtube.com/watch?v=NnQraMtpvws
https://blog.jetbrains.com/clion/2023/12/a-clangformat-story-and-the-third-clion-nova-update/

Maybe they can try contributing rather than complaining.

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2024-06-19 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

> Where is the documentation for the value? CLion reports `clang-format` option 
> as an error by the reason. No doc, no schema rule.

There:
> I don't want to "advertise" this new style in the documentation but am 
> willing to be overruled by the majority.

There is none, on purpose.


https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2024-06-19 Thread Alexey Utkin via cfe-commits

alexey-utkin wrote:

Where is the documentation for the value? CLion reports `clang-format`  option 
as an error by the reason. No doc, no schema rule.

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-23 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/69814

>From 78a2661ba7a18ecf8b09be71f6959fbc9fcf70fe Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 20 Oct 2023 23:01:38 -0700
Subject: [PATCH 1/2] [clang-format] Add a new style for the clang-format
 source code

---
 clang/include/clang/Format/Format.h|  2 ++
 clang/lib/Format/Format.cpp| 18 +++---
 clang/unittests/Format/ConfigParseTest.cpp |  7 +++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ed92ef6fc655522..4c344135d25163c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4861,6 +4861,8 @@ FormatStyle getGNUStyle();
 /// 
https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
 FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
 
+FormatStyle getClangFormatStyle();
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index acbed56a86e141f..2f988c4eaf35a57 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -834,8 +834,8 @@ template <> struct MappingTraits {
 
 StringRef BasedOnStyle;
 if (IO.outputting()) {
-  StringRef Styles[] = {"LLVM",   "Google", "Chromium", "Mozilla",
-"WebKit", "GNU","Microsoft"};
+  StringRef Styles[] = {"LLVM",   "Google", "Chromium",  "Mozilla",
+"WebKit", "GNU","Microsoft", "clang-format"};
   for (StringRef StyleName : Styles) {
 FormatStyle PredefinedStyle;
 if (getPredefinedStyle(StyleName, Style.Language, ) &&
@@ -1915,6 +1915,16 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind 
Language) {
   return Style;
 }
 
+FormatStyle getClangFormatStyle() {
+  FormatStyle Style = getLLVMStyle();
+  Style.InsertBraces = true;
+  Style.InsertNewlineAtEOF = true;
+  Style.LineEnding = FormatStyle::LE_LF;
+  Style.RemoveBracesLLVM = true;
+  Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  return Style;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1939,6 +1949,8 @@ bool getPredefinedStyle(StringRef Name, 
FormatStyle::LanguageKind Language,
 *Style = getGNUStyle();
   else if (Name.equals_insensitive("microsoft"))
 *Style = getMicrosoftStyle(Language);
+  else if (Name.equals_insensitive("clang-format"))
+*Style = getClangFormatStyle();
   else if (Name.equals_insensitive("none"))
 *Style = getNoStyle();
   else if (Name.equals_insensitive("inheritparentconfig"))
@@ -3841,7 +3853,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
-"   Mozilla, WebKit.\n"
+"   Mozilla, WebKit, clang-format.\n"
 "2. 'file' to load style configuration from a\n"
 "   .clang-format file in one of the parent directories\n"
 "   of the source file (for stdin, see --assume-filename).\n"
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index c35c82955f6a558..ba79c8d72f09552 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -63,6 +63,13 @@ TEST(ConfigParseTest, GetsPredefinedStyleByName) {
   EXPECT_TRUE(getPredefinedStyle("gnU", FormatStyle::LK_Cpp, [2]));
   EXPECT_ALL_STYLES_EQUAL(Styles);
 
+  Styles[0] = getClangFormatStyle();
+  EXPECT_TRUE(
+  getPredefinedStyle("clang-format", FormatStyle::LK_Cpp, [1]));
+  EXPECT_TRUE(
+  getPredefinedStyle("Clang-format", FormatStyle::LK_Cpp, [2]));
+  EXPECT_ALL_STYLES_EQUAL(Styles);
+
   EXPECT_FALSE(getPredefinedStyle("qwerty", FormatStyle::LK_Cpp, [0]));
 }
 

>From 614f56310840a87e9a0d9aa2ece3693d375d00b6 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 21 Oct 2023 14:44:06 -0700
Subject: [PATCH 2/2] Don't show the undocumented clang-format style in help

---
 clang/lib/Format/Format.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2f988c4eaf35a57..ff7cb097a59d6a0 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3853,7 +3853,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
-"   Mozilla, WebKit, clang-format.\n"
+"   Mozilla, WebKit.\n"
 "2. 'file' to load style configuration from a\n"
 "   .clang-format file in one of the parent directories\n"
 "   of the source file (for stdin, see --assume-filename).\n"


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

owenca wrote:

Yep. Each file will contain only `BasedOnStyle: clang-format`.

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

> > What is your goal with that style?
> 
> It was actually your [idea](https://reviews.llvm.org/D153208#4431239). 

I know, but I thought the thought was dropped. :)

So the intent is to use it on our `.clang-format` files?

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

owenca wrote:

I was wondering myself. Will undo it before merging.

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Emilia Kond via cfe-commits

https://github.com/rymiel approved this pull request.


https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Emilia Kond via cfe-commits

rymiel wrote:

> I don't want to "advertise" this new style in the documentation but am 
> willing to be overruled by the majority.

But you added it to the help text?

(I'm fine with this being undocumented)

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

owenca wrote:

> What is your goal with that style?

It was actually your [idea](https://reviews.llvm.org/D153208#4431239).  

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.

What is your goal with that style?

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

owenca wrote:

I don't want to "advertise" this new style in the documentation but am willing 
to be overruled by the majority.

https://github.com/llvm/llvm-project/pull/69814
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/69814

None

>From 78a2661ba7a18ecf8b09be71f6959fbc9fcf70fe Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 20 Oct 2023 23:01:38 -0700
Subject: [PATCH] [clang-format] Add a new style for the clang-format source
 code

---
 clang/include/clang/Format/Format.h|  2 ++
 clang/lib/Format/Format.cpp| 18 +++---
 clang/unittests/Format/ConfigParseTest.cpp |  7 +++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ed92ef6fc655522..4c344135d25163c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4861,6 +4861,8 @@ FormatStyle getGNUStyle();
 /// 
https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
 FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
 
+FormatStyle getClangFormatStyle();
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index acbed56a86e141f..2f988c4eaf35a57 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -834,8 +834,8 @@ template <> struct MappingTraits {
 
 StringRef BasedOnStyle;
 if (IO.outputting()) {
-  StringRef Styles[] = {"LLVM",   "Google", "Chromium", "Mozilla",
-"WebKit", "GNU","Microsoft"};
+  StringRef Styles[] = {"LLVM",   "Google", "Chromium",  "Mozilla",
+"WebKit", "GNU","Microsoft", "clang-format"};
   for (StringRef StyleName : Styles) {
 FormatStyle PredefinedStyle;
 if (getPredefinedStyle(StyleName, Style.Language, ) &&
@@ -1915,6 +1915,16 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind 
Language) {
   return Style;
 }
 
+FormatStyle getClangFormatStyle() {
+  FormatStyle Style = getLLVMStyle();
+  Style.InsertBraces = true;
+  Style.InsertNewlineAtEOF = true;
+  Style.LineEnding = FormatStyle::LE_LF;
+  Style.RemoveBracesLLVM = true;
+  Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  return Style;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1939,6 +1949,8 @@ bool getPredefinedStyle(StringRef Name, 
FormatStyle::LanguageKind Language,
 *Style = getGNUStyle();
   else if (Name.equals_insensitive("microsoft"))
 *Style = getMicrosoftStyle(Language);
+  else if (Name.equals_insensitive("clang-format"))
+*Style = getClangFormatStyle();
   else if (Name.equals_insensitive("none"))
 *Style = getNoStyle();
   else if (Name.equals_insensitive("inheritparentconfig"))
@@ -3841,7 +3853,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
-"   Mozilla, WebKit.\n"
+"   Mozilla, WebKit, clang-format.\n"
 "2. 'file' to load style configuration from a\n"
 "   .clang-format file in one of the parent directories\n"
 "   of the source file (for stdin, see --assume-filename).\n"
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index c35c82955f6a558..ba79c8d72f09552 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -63,6 +63,13 @@ TEST(ConfigParseTest, GetsPredefinedStyleByName) {
   EXPECT_TRUE(getPredefinedStyle("gnU", FormatStyle::LK_Cpp, [2]));
   EXPECT_ALL_STYLES_EQUAL(Styles);
 
+  Styles[0] = getClangFormatStyle();
+  EXPECT_TRUE(
+  getPredefinedStyle("clang-format", FormatStyle::LK_Cpp, [1]));
+  EXPECT_TRUE(
+  getPredefinedStyle("Clang-format", FormatStyle::LK_Cpp, [2]));
+  EXPECT_ALL_STYLES_EQUAL(Styles);
+
   EXPECT_FALSE(getPredefinedStyle("qwerty", FormatStyle::LK_Cpp, [0]));
 }
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits