aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-14 16:24:39 +0000
committerDaniel Jasper <djasper@google.com>2013-01-14 16:24:39 +0000
commit6f5bb2c93c31a7977382c5079d85db8ca3267cd0 (patch)
treedaac9f82905181c4b2baa1fba3cd7a172776771a /lib/Format/Format.cpp
parentfd0ca976bd55167364ba1178e884d275cc6ef30b (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172431 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 4e9fd405df..a221e4cce7 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -117,6 +117,7 @@ FormatStyle getLLVMStyle() {
LLVMStyle.IndentCaseLabels = false;
LLVMStyle.SpacesBeforeTrailingComments = 1;
LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
+ LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
LLVMStyle.ObjCSpaceBeforeReturnType = true;
return LLVMStyle;
@@ -132,11 +133,18 @@ FormatStyle getGoogleStyle() {
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 @@ private:
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;