Make single-line if statements optional.
Now, "if (a) return;" is only allowed, if this option is set.
Also add a Chromium style which is currently identical to Google style
except for this option.
llvm-svn: 172431
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 4e9fd40..a221e4c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -117,6 +117,7 @@
LLVMStyle.IndentCaseLabels = false;
LLVMStyle.SpacesBeforeTrailingComments = 1;
LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
+ LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
LLVMStyle.ObjCSpaceBeforeReturnType = true;
return LLVMStyle;
@@ -132,11 +133,18 @@
GoogleStyle.IndentCaseLabels = true;
GoogleStyle.SpacesBeforeTrailingComments = 2;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+ GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
GoogleStyle.ObjCSpaceBeforeReturnType = false;
return GoogleStyle;
}
+FormatStyle getChromiumStyle() {
+ FormatStyle ChromiumStyle = getGoogleStyle();
+ ChromiumStyle.AllowShortIfStatementsOnASingleLine = false;
+ return ChromiumStyle;
+}
+
struct OptimizationParameters {
unsigned PenaltyIndentLevel;
unsigned PenaltyLevelDecrease;
@@ -1441,6 +1449,8 @@
void tryMergeSimpleIf(std::vector<AnnotatedLine>::iterator &I,
std::vector<AnnotatedLine>::iterator E,
unsigned Limit) {
+ if (!Style.AllowShortIfStatementsOnASingleLine)
+ return;
AnnotatedLine &Line = *I;
if (!fitsIntoLimit((I + 1)->First, Limit))
return;