summaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-12-10 15:42:15 +0000
committerAlexander Kornienko <alexfh@google.com>2013-12-10 15:42:15 +0000
commitefe04c204c790767ce2fd12ff8cb4e60b57eab40 (patch)
tree873b52b773efcdd60542f833b95d087b410f64cc /lib/Format/Format.cpp
parentb2c22f6eb4ee28a187423e90cd480122e0a10b72 (diff)
downloadclang-efe04c204c790767ce2fd12ff8cb4e60b57eab40.tar.gz
clang-efe04c204c790767ce2fd12ff8cb4e60b57eab40.tar.bz2
clang-efe04c204c790767ce2fd12ff8cb4e60b57eab40.tar.xz
Early attempts to format in GNU style.
Summary: 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. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2371 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196928 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp57
1 files changed, 21 insertions, 36 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index da088bf5cb..4225178405 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -103,7 +103,7 @@ template <> struct MappingTraits<FormatStyle> {
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]);
@@ -233,13 +233,6 @@ template <> struct DocumentListTraits<std::vector<FormatStyle> > {
namespace clang {
namespace format {
-void setDefaultPenalties(FormatStyle &Style) {
- Style.PenaltyBreakComment = 60;
- Style.PenaltyBreakFirstLessLess = 120;
- Style.PenaltyBreakString = 1000;
- Style.PenaltyExcessCharacter = 1000000;
-}
-
FormatStyle getLLVMStyle() {
FormatStyle LLVMStyle;
LLVMStyle.Language = FormatStyle::LK_Cpp;
@@ -263,6 +256,7 @@ FormatStyle getLLVMStyle() {
LLVMStyle.Cpp11BracedListStyle = false;
LLVMStyle.DerivePointerBinding = false;
LLVMStyle.ExperimentalAutoDetectBinPacking = false;
+ LLVMStyle.IndentBlocks = false;
LLVMStyle.IndentCaseLabels = false;
LLVMStyle.IndentFunctionDeclarationAfterType = false;
LLVMStyle.IndentWidth = 2;
@@ -282,7 +276,10 @@ FormatStyle getLLVMStyle() {
LLVMStyle.ContinuationIndentWidth = 4;
LLVMStyle.SpacesInAngles = false;
- setDefaultPenalties(LLVMStyle);
+ LLVMStyle.PenaltyBreakComment = 60;
+ LLVMStyle.PenaltyBreakFirstLessLess = 120;
+ LLVMStyle.PenaltyBreakString = 1000;
+ LLVMStyle.PenaltyExcessCharacter = 1000000;
LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19;
@@ -290,48 +287,23 @@ FormatStyle getLLVMStyle() {
}
FormatStyle getGoogleStyle() {
- FormatStyle GoogleStyle;
- GoogleStyle.Language = FormatStyle::LK_Cpp;
+ FormatStyle GoogleStyle = getLLVMStyle();
GoogleStyle.AccessModifierOffset = -1;
GoogleStyle.AlignEscapedNewlinesLeft = true;
- GoogleStyle.AlignTrailingComments = true;
- GoogleStyle.AllowAllParametersOfDeclarationOnNextLine = true;
- GoogleStyle.AllowShortFunctionsOnASingleLine = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
GoogleStyle.AllowShortLoopsOnASingleLine = true;
GoogleStyle.AlwaysBreakBeforeMultilineStrings = true;
GoogleStyle.AlwaysBreakTemplateDeclarations = true;
- GoogleStyle.BinPackParameters = true;
- GoogleStyle.BreakBeforeBinaryOperators = false;
- GoogleStyle.BreakBeforeTernaryOperators = true;
- GoogleStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
- GoogleStyle.BreakConstructorInitializersBeforeComma = false;
- GoogleStyle.ColumnLimit = 80;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
- GoogleStyle.ConstructorInitializerIndentWidth = 4;
GoogleStyle.Cpp11BracedListStyle = true;
GoogleStyle.DerivePointerBinding = true;
- GoogleStyle.ExperimentalAutoDetectBinPacking = false;
GoogleStyle.IndentCaseLabels = true;
GoogleStyle.IndentFunctionDeclarationAfterType = true;
- GoogleStyle.IndentWidth = 2;
- GoogleStyle.TabWidth = 8;
- GoogleStyle.MaxEmptyLinesToKeep = 1;
- GoogleStyle.NamespaceIndentation = FormatStyle::NI_None;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
GoogleStyle.PointerBindsToType = true;
GoogleStyle.SpacesBeforeTrailingComments = 2;
GoogleStyle.Standard = FormatStyle::LS_Auto;
- GoogleStyle.UseTab = FormatStyle::UT_Never;
- GoogleStyle.SpacesInParentheses = false;
- GoogleStyle.SpaceInEmptyParentheses = false;
- GoogleStyle.SpacesInCStyleCastParentheses = false;
- GoogleStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
- GoogleStyle.SpaceBeforeAssignmentOperators = true;
- GoogleStyle.ContinuationIndentWidth = 4;
- GoogleStyle.SpacesInAngles = false;
-
- setDefaultPenalties(GoogleStyle);
+
GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1;
@@ -385,6 +357,17 @@ FormatStyle getWebKitStyle() {
return Style;
}
+FormatStyle getGNUStyle() {
+ FormatStyle Style = getLLVMStyle();
+ Style.BreakBeforeBinaryOperators = true;
+ Style.BreakBeforeBraces = FormatStyle::BS_Allman;
+ Style.BreakBeforeTernaryOperators = true;
+ Style.ColumnLimit = 79;
+ Style.IndentBlocks = true;
+ Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+ return Style;
+}
+
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
FormatStyle *Style) {
if (Name.equals_lower("llvm")) {
@@ -398,6 +381,8 @@ bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
: getGoogleStyle();
} else if (Name.equals_lower("webkit")) {
*Style = getWebKitStyle();
+ } else if (Name.equals_lower("gnu")) {
+ *Style = getGNUStyle();
} else {
return false;
}