summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-12-24 13:31:25 +0000
committerDaniel Jasper <djasper@google.com>2013-12-24 13:31:25 +0000
commit234379fbf6ba09b4f9a540f408cf28b3fd85b16d (patch)
treec812b0d94f0ce78e812ecc6629c567f8694d86e8 /clang/lib/Format/Format.cpp
parentce3721057d4edf48b73de9f002b2ab5bea3d2518 (diff)
downloadbcm5719-llvm-234379fbf6ba09b4f9a540f408cf28b3fd85b16d.tar.gz
bcm5719-llvm-234379fbf6ba09b4f9a540f408cf28b3fd85b16d.zip
clang-format: (WebKit) Disallow 1-line constructors with initializers.
Before: Constructor() : a(a) {} After: Constructor() : a(a) { } This style guide is pretty precise about this. llvm-svn: 197980
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index cff6fc5f6d9..b7b41c9741a 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -480,7 +480,7 @@ public:
SmallVectorImpl<AnnotatedLine *>::const_iterator I,
SmallVectorImpl<AnnotatedLine *>::const_iterator E) {
// We can never merge stuff if there are trailing line comments.
- AnnotatedLine *TheLine = *I;
+ const AnnotatedLine *TheLine = *I;
if (TheLine->Last->Type == TT_LineComment)
return 0;
@@ -498,7 +498,8 @@ public:
if (I + 1 == E || I[1]->Type == LT_Invalid)
return 0;
- if (TheLine->Last->Type == TT_FunctionLBrace) {
+ if (TheLine->Last->Type == TT_FunctionLBrace &&
+ TheLine->First != TheLine->Last) {
return Style.AllowShortFunctionsOnASingleLine
? tryMergeSimpleBlock(I, E, Limit)
: 0;
@@ -510,9 +511,11 @@ public:
}
if (I[1]->First->Type == TT_FunctionLBrace &&
Style.BreakBeforeBraces != FormatStyle::BS_Attach) {
- // Reduce the column limit by the number of spaces we need to insert
- // around braces.
- Limit = Limit > 3 ? Limit - 3 : 0;
+ // Check for Limit <= 2 to accomodate for the " {".
+ if (Limit <= 2 || (Style.ColumnLimit == 0 && containsMustBreak(TheLine)))
+ return 0;
+ Limit -= 2;
+
unsigned MergedLines = 0;
if (Style.AllowShortFunctionsOnASingleLine) {
MergedLines = tryMergeSimpleBlock(I + 1, E, Limit);
@@ -641,6 +644,14 @@ private:
return 1 + I[1]->Last->TotalLength + 1 + I[2]->Last->TotalLength <= Limit;
}
+ bool containsMustBreak(const AnnotatedLine *Line) {
+ for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) {
+ if (Tok->MustBreakBefore)
+ return true;
+ }
+ return false;
+ }
+
const FormatStyle &Style;
};
OpenPOWER on IntegriCloud