summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-07-31 23:16:02 +0000
committerDaniel Jasper <djasper@google.com>2013-07-31 23:16:02 +0000
commit65ee347285832ef21c6850e4820fcc4d6fa16cb6 (patch)
treeee0f987c3e20f2014b0bcac97b4b5fb204d337b2 /clang/lib/Format/UnwrappedLineParser.cpp
parent44a6ed8d4e0a3f9a99b5e506a7e83ce4dda8ff54 (diff)
downloadbcm5719-llvm-65ee347285832ef21c6850e4820fcc4d6fa16cb6.tar.gz
bcm5719-llvm-65ee347285832ef21c6850e4820fcc4d6fa16cb6.zip
clang-format: Add more options to namespace indentation.
With this patch, clang-format can be configured to: * not indent in namespace at all (former behavior). * indent in namespace as in other blocks. * indent only in inner namespaces (as required by WebKit style). Also fix alignment of access specifiers in WebKit style. Patch started by Marek Kurdej. Thank you! llvm-svn: 187540
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 939a301e9d7..94fbf078dcf 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -319,8 +319,7 @@ void UnwrappedLineParser::calculateBraceTypes() {
FormatTok = Tokens->setPosition(StoredPosition);
}
-void UnwrappedLineParser::parseBlock(bool MustBeDeclaration,
- unsigned AddLevels) {
+void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel) {
assert(FormatTok->Tok.is(tok::l_brace) && "'{' expected");
unsigned InitialLevel = Line->Level;
nextToken();
@@ -329,7 +328,8 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration,
ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
MustBeDeclaration);
- Line->Level += AddLevels;
+ if (AddLevel)
+ ++Line->Level;
parseLevel(/*HasOpeningBrace=*/true);
if (!FormatTok->Tok.is(tok::r_brace)) {
@@ -550,7 +550,7 @@ void UnwrappedLineParser::parseStructuralElement() {
if (FormatTok->Tok.is(tok::string_literal)) {
nextToken();
if (FormatTok->Tok.is(tok::l_brace)) {
- parseBlock(/*MustBeDeclaration=*/true, 0);
+ parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
addUnwrappedLine();
return;
}
@@ -794,7 +794,10 @@ void UnwrappedLineParser::parseNamespace() {
if (Style.BreakBeforeBraces == FormatStyle::BS_Linux)
addUnwrappedLine();
- parseBlock(/*MustBeDeclaration=*/true, 0);
+ bool AddLevel = Style.NamespaceIndentation == FormatStyle::NI_All ||
+ (Style.NamespaceIndentation == FormatStyle::NI_Inner &&
+ DeclarationScopeStack.size() > 1);
+ parseBlock(/*MustBeDeclaration=*/true, AddLevel);
// Munch the semicolon after a namespace. This is more common than one would
// think. Puttin the semicolon into its own line is very ugly.
if (FormatTok->Tok.is(tok::semi))
@@ -874,7 +877,7 @@ void UnwrappedLineParser::parseSwitch() {
if (FormatTok->Tok.is(tok::l_paren))
parseParens();
if (FormatTok->Tok.is(tok::l_brace)) {
- parseBlock(/*MustBeDeclaration=*/false, 1);
+ parseBlock(/*MustBeDeclaration=*/false);
addUnwrappedLine();
} else {
addUnwrappedLine();
OpenPOWER on IntegriCloud