diff options
author | Owen Pan <owenpiano@gmail.com> | 2023-10-22 23:01:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-22 23:01:27 -0700 |
commit | 0374bbba4c455e5f862a32581cc8d37690fb3b60 (patch) | |
tree | 027cda62a45d2bbfd5bbb0e1d64729d5aeafecc5 /clang/lib | |
parent | cdf713cdb9daee20dc593e493e904a845f0f6c8d (diff) | |
download | llvm-0374bbba4c455e5f862a32581cc8d37690fb3b60.zip llvm-0374bbba4c455e5f862a32581cc8d37690fb3b60.tar.gz llvm-0374bbba4c455e5f862a32581cc8d37690fb3b60.tar.bz2 |
[clang-format] Add a new style for the clang-format source code (#69814)
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Format/Format.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index acbed56..ff7cb09 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -834,8 +834,8 @@ template <> struct MappingTraits<FormatStyle> { 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, &PredefinedStyle) && @@ -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")) |