diff options
author | Daniel Jasper <djasper@google.com> | 2013-07-25 11:31:57 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-07-25 11:31:57 +0000 |
commit | 516d7971b317d54622c8267ceeeb87186cc9153c (patch) | |
tree | f7eaeda6fea747ce65c79253ae1f421728248e27 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | e38ea680ccb9d6ab82e07bfa7a05055ce46cda4f (diff) | |
download | bcm5719-llvm-516d7971b317d54622c8267ceeeb87186cc9153c.tar.gz bcm5719-llvm-516d7971b317d54622c8267ceeeb87186cc9153c.zip |
clang-format: Fix switch/case interaction with macros.
Before:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name
switch (OpCode) {
CASE(Add);
CASE(Subtract);
default:
return operations::Unknown;
}
After:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name;
switch (OpCode) {
CASE(Add);
CASE(Subtract);
default:
return operations::Unknown;
}
llvm-svn: 187118
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 77f98bffda2..939a301e9d7 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -213,6 +213,7 @@ void UnwrappedLineParser::parseFile() { } void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) { + bool SwitchLabelEncountered = false; do { switch (FormatTok->Tok.getKind()) { case tok::comment: @@ -232,6 +233,13 @@ void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) { nextToken(); addUnwrappedLine(); break; + case tok::kw_default: + case tok::kw_case: + if (!SwitchLabelEncountered) + Line->Level += Style.IndentCaseLabels; + SwitchLabelEncountered = true; + parseStructuralElement(); + break; default: parseStructuralElement(); break; @@ -314,6 +322,7 @@ void UnwrappedLineParser::calculateBraceTypes() { void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, unsigned AddLevels) { assert(FormatTok->Tok.is(tok::l_brace) && "'{' expected"); + unsigned InitialLevel = Line->Level; nextToken(); addUnwrappedLine(); @@ -324,13 +333,13 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, parseLevel(/*HasOpeningBrace=*/true); if (!FormatTok->Tok.is(tok::r_brace)) { - Line->Level -= AddLevels; + Line->Level = InitialLevel; StructuralError = true; return; } nextToken(); // Munch the closing brace. - Line->Level -= AddLevels; + Line->Level = InitialLevel; } void UnwrappedLineParser::parsePPDirective() { @@ -865,13 +874,13 @@ void UnwrappedLineParser::parseSwitch() { if (FormatTok->Tok.is(tok::l_paren)) parseParens(); if (FormatTok->Tok.is(tok::l_brace)) { - parseBlock(/*MustBeDeclaration=*/false, Style.IndentCaseLabels ? 2 : 1); + parseBlock(/*MustBeDeclaration=*/false, 1); addUnwrappedLine(); } else { addUnwrappedLine(); - Line->Level += (Style.IndentCaseLabels ? 2 : 1); + ++Line->Level; parseStructuralElement(); - Line->Level -= (Style.IndentCaseLabels ? 2 : 1); + --Line->Level; } } |