Loading clang/include/clang/Format/Format.h +2 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading clang/lib/Format/Format.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -835,7 +835,7 @@ template <> struct MappingTraits<FormatStyle> { StringRef BasedOnStyle; if (IO.outputting()) { StringRef Styles[] = {"LLVM", "Google", "Chromium", "Mozilla", "WebKit", "GNU", "Microsoft"}; "WebKit", "GNU", "Microsoft", "clang-format"}; for (StringRef StyleName : Styles) { FormatStyle PredefinedStyle; if (getPredefinedStyle(StyleName, Style.Language, &PredefinedStyle) && Loading Loading @@ -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; Loading @@ -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")) Loading clang/unittests/Format/ConfigParseTest.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,13 @@ TEST(ConfigParseTest, GetsPredefinedStyleByName) { EXPECT_TRUE(getPredefinedStyle("gnU", FormatStyle::LK_Cpp, &Styles[2])); EXPECT_ALL_STYLES_EQUAL(Styles); Styles[0] = getClangFormatStyle(); EXPECT_TRUE( getPredefinedStyle("clang-format", FormatStyle::LK_Cpp, &Styles[1])); EXPECT_TRUE( getPredefinedStyle("Clang-format", FormatStyle::LK_Cpp, &Styles[2])); EXPECT_ALL_STYLES_EQUAL(Styles); EXPECT_FALSE(getPredefinedStyle("qwerty", FormatStyle::LK_Cpp, &Styles[0])); } Loading Loading
clang/include/clang/Format/Format.h +2 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading
clang/lib/Format/Format.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -835,7 +835,7 @@ template <> struct MappingTraits<FormatStyle> { StringRef BasedOnStyle; if (IO.outputting()) { StringRef Styles[] = {"LLVM", "Google", "Chromium", "Mozilla", "WebKit", "GNU", "Microsoft"}; "WebKit", "GNU", "Microsoft", "clang-format"}; for (StringRef StyleName : Styles) { FormatStyle PredefinedStyle; if (getPredefinedStyle(StyleName, Style.Language, &PredefinedStyle) && Loading Loading @@ -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; Loading @@ -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")) Loading
clang/unittests/Format/ConfigParseTest.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,13 @@ TEST(ConfigParseTest, GetsPredefinedStyleByName) { EXPECT_TRUE(getPredefinedStyle("gnU", FormatStyle::LK_Cpp, &Styles[2])); EXPECT_ALL_STYLES_EQUAL(Styles); Styles[0] = getClangFormatStyle(); EXPECT_TRUE( getPredefinedStyle("clang-format", FormatStyle::LK_Cpp, &Styles[1])); EXPECT_TRUE( getPredefinedStyle("Clang-format", FormatStyle::LK_Cpp, &Styles[2])); EXPECT_ALL_STYLES_EQUAL(Styles); EXPECT_FALSE(getPredefinedStyle("qwerty", FormatStyle::LK_Cpp, &Styles[0])); } Loading