summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorRoman Kashitsyn <romankashicin@gmail.com>2014-08-11 12:18:01 +0000
committerRoman Kashitsyn <romankashicin@gmail.com>2014-08-11 12:18:01 +0000
commita043cedf0aa6c22437ee9b898da99b5d80db7c09 (patch)
tree5ff864f008f6f3941f537f5b8fa13baa4fceb338 /clang/lib/Format
parent5082ce0ab875b8cf683d758c012c6ece099cbe98 (diff)
downloadbcm5719-llvm-a043cedf0aa6c22437ee9b898da99b5d80db7c09.tar.gz
bcm5719-llvm-a043cedf0aa6c22437ee9b898da99b5d80db7c09.zip
Fixes bug 20587 - Add K&R break before braces style
Summary: http://llvm.org/bugs/show_bug.cgi?id=20587 Added K&R style. It could be enabled by the following option: ``` BreakBeforeBraces: KernighanRitchie ``` This style is like `Attach`, but break *only* before function declarations. As I can see, no additional logic required to support this style, any style different from other styles automagically satisfies K&R. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D4837 llvm-svn: 215354
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 9f355c930ea..7e55e04c7f7 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -434,6 +434,19 @@ static bool IsGoogScope(const UnwrappedLine &Line) {
return I->Tok->is(tok::l_paren);
}
+static bool ShouldBreakBeforeBrace(const FormatStyle &Style,
+ const FormatToken &InitialToken) {
+ switch (Style.BreakBeforeBraces) {
+ case FormatStyle::BS_Linux:
+ return InitialToken.isOneOf(tok::kw_namespace, tok::kw_class);
+ case FormatStyle::BS_Allman:
+ case FormatStyle::BS_GNU:
+ return true;
+ default:
+ return false;
+ }
+}
+
void UnwrappedLineParser::parseChildBlock() {
FormatTok->BlockKind = BK_Block;
nextToken();
@@ -1167,13 +1180,13 @@ void UnwrappedLineParser::parseTryCatch() {
void UnwrappedLineParser::parseNamespace() {
assert(FormatTok->Tok.is(tok::kw_namespace) && "'namespace' expected");
+
+ const FormatToken &InitialToken = *FormatTok;
nextToken();
if (FormatTok->Tok.is(tok::identifier))
nextToken();
if (FormatTok->Tok.is(tok::l_brace)) {
- if (Style.BreakBeforeBraces == FormatStyle::BS_Linux ||
- Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
- Style.BreakBeforeBraces == FormatStyle::BS_GNU)
+ if (ShouldBreakBeforeBrace(Style, InitialToken))
addUnwrappedLine();
bool AddLevel = Style.NamespaceIndentation == FormatStyle::NI_All ||
@@ -1327,6 +1340,7 @@ void UnwrappedLineParser::parseEnum() {
}
void UnwrappedLineParser::parseRecord() {
+ const FormatToken &InitialToken = *FormatTok;
nextToken();
if (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::kw___attribute,
tok::kw___declspec, tok::kw_alignas)) {
@@ -1361,9 +1375,7 @@ void UnwrappedLineParser::parseRecord() {
}
}
if (FormatTok->Tok.is(tok::l_brace)) {
- if (Style.BreakBeforeBraces == FormatStyle::BS_Linux ||
- Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
- Style.BreakBeforeBraces == FormatStyle::BS_GNU)
+ if (ShouldBreakBeforeBrace(Style, InitialToken))
addUnwrappedLine();
parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/true,
OpenPOWER on IntegriCloud