[PATCH] Early attempts to format in GNU style.
Alexander Kornienko
alexfh at google.com
Tue Dec 10 07:06:04 PST 2013
Hi djasper,
This still misses a few important features, so there's no mention of
this style in the help message, but a few style rules are implemented.
http://llvm-reviews.chandlerc.com/D2371
Files:
include/clang/Format/Format.h
lib/Format/Format.cpp
unittests/Format/FormatTest.cpp
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<StringRef> 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]));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2371.1.patch
Type: text/x-patch
Size: 2543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131210/8bfdf4f0/attachment.bin>
More information about the cfe-commits
mailing list