Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -359,6 +359,10 @@ /// http://www.webkit.org/coding/coding-style.html FormatStyle getWebKitStyle(); +/// \brief Returns a format style complying with GNU Coding Standards: +/// http://www.gnu.org/prep/standards/standards.html +FormatStyle getGNUStyle(); + /// \brief Gets a predefined style for the specified language by name. /// /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -103,7 +103,7 @@ if (IO.outputting()) { StringRef StylesArray[] = { "LLVM", "Google", "Chromium", - "Mozilla", "WebKit" }; + "Mozilla", "WebKit", "GNU" }; ArrayRef Styles(StylesArray); for (size_t i = 0, e = Styles.size(); i < e; ++i) { StringRef StyleName(Styles[i]); @@ -385,6 +385,16 @@ return Style; } +FormatStyle getGNUStyle() { + FormatStyle Style = getLLVMStyle(); + Style.BreakBeforeBinaryOperators = true; + Style.BreakBeforeBraces = FormatStyle::BS_Allman; + Style.BreakBeforeTernaryOperators = true; + Style.ColumnLimit = 79; + Style.SpaceBeforeParens = FormatStyle::SBPO_Always; + return Style; +} + bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style) { if (Name.equals_lower("llvm")) { @@ -398,6 +408,8 @@ : getGoogleStyle(); } else if (Name.equals_lower("webkit")) { *Style = getWebKitStyle(); + } else if (Name.equals_lower("gnu")) { + *Style = getGNUStyle(); } else { return false; } Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -6992,6 +6992,11 @@ EXPECT_TRUE(getPredefinedStyle("wEbKit", FormatStyle::LK_Cpp, &Styles[2])); EXPECT_ALL_STYLES_EQUAL(Styles); + Styles[0] = getGNUStyle(); + EXPECT_TRUE(getPredefinedStyle("GNU", FormatStyle::LK_Cpp, &Styles[1])); + EXPECT_TRUE(getPredefinedStyle("gnU", FormatStyle::LK_Cpp, &Styles[2])); + EXPECT_ALL_STYLES_EQUAL(Styles); + EXPECT_FALSE(getPredefinedStyle("qwerty", FormatStyle::LK_Cpp, &Styles[0])); }