summaryrefslogtreecommitdiff
path: root/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-05-13 12:51:40 +0000
committerManuel Klimek <klimek@google.com>2013-05-13 12:51:40 +0000
commit44135b8836fc3ffb84e540d8a097955271ccbc23 (patch)
tree160dabbbded29093ad678301b8fdb4fbcd4fdab4 /lib/Format/UnwrappedLineParser.cpp
parentaf64032b085d3711405dbe8d98f71c463e0fb52b (diff)
downloadclang-44135b8836fc3ffb84e540d8a097955271ccbc23.tar.gz
clang-44135b8836fc3ffb84e540d8a097955271ccbc23.tar.bz2
clang-44135b8836fc3ffb84e540d8a097955271ccbc23.tar.xz
Implements brace breaking styles.
We now support "Linux" and "Stroustrup" brace breaking styles, which gets us one step closer to support formatting WebKit, KDE & Linux code. Linux brace breaking style: namespace a { class A { void f() { if (x) { f(); } else { g(); } } } } Stroustrup brace breaking style: namespace a { class A { void f() { if (x) { f(); } else { g(); } } } } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181700 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--lib/Format/UnwrappedLineParser.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 722af5d2b7..a08790d80d 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -402,6 +402,10 @@ void UnwrappedLineParser::parseStructuralElement() {
// structural element.
// FIXME: Figure out cases where this is not true, and add projections for
// them (the one we know is missing are lambdas).
+ if (Style.BreakBeforeBraces == FormatStyle::BS_Linux ||
+ Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
+ addUnwrappedLine();
+
parseBlock(/*MustBeDeclaration=*/ false);
addUnwrappedLine();
return;
@@ -577,6 +581,9 @@ void UnwrappedLineParser::parseNamespace() {
if (FormatTok.Tok.is(tok::identifier))
nextToken();
if (FormatTok.Tok.is(tok::l_brace)) {
+ if (Style.BreakBeforeBraces == FormatStyle::BS_Linux)
+ addUnwrappedLine();
+
parseBlock(/*MustBeDeclaration=*/ true, 0);
// Munch the semicolon after a namespace. This is more common than one would
// think. Puttin the semicolon into its own line is very ugly.
@@ -751,8 +758,12 @@ void UnwrappedLineParser::parseRecord() {
}
}
}
- if (FormatTok.Tok.is(tok::l_brace))
+ if (FormatTok.Tok.is(tok::l_brace)) {
+ if (Style.BreakBeforeBraces == FormatStyle::BS_Linux)
+ addUnwrappedLine();
+
parseBlock(/*MustBeDeclaration=*/ true);
+ }
// We fall through to parsing a structural element afterwards, so
// class A {} n, m;
// will end up in one unwrapped line.