diff options
author | Paul Hoad <mydeveloperday@gmail.com> | 2019-09-12 10:07:14 +0000 |
---|---|---|
committer | Paul Hoad <mydeveloperday@gmail.com> | 2019-09-12 10:07:14 +0000 |
commit | 3867a2d51076494a19c02a2d5c4e4167bd6cbe0e (patch) | |
tree | 3fab02b769d07df0c08176b4c6831a46bb868703 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | f1286621eb9672c07a67075624f97310eadd2632 (diff) | |
download | bcm5719-llvm-3867a2d51076494a19c02a2d5c4e4167bd6cbe0e.tar.gz bcm5719-llvm-3867a2d51076494a19c02a2d5c4e4167bd6cbe0e.zip |
[clang-format] Add new style option IndentGotoLabels
Summary:
This option determines whether goto labels are indented according to scope. Setting this option to false causes goto labels to be flushed to the left.
This is mostly copied from [[ http://lists.llvm.org/pipermail/cfe-dev/2015-September/045014.html | this patch ]] submitted by Christian Neukirchen that didn't make its way into trunk.
```
true: false:
int f() { vs. int f() {
if (foo()) { if (foo()) {
label1: label1:
bar(); bar();
} }
label2: label2:
return 1; return 1;
} }
```
Reviewers: klimek, MyDeveloperDay
Reviewed By: MyDeveloperDay
Subscribers: cfe-commits
Tags: #clang, #clang-tools-extra
Patch by: tetsuo-cpp
Differential Revision: https://reviews.llvm.org/D67037
llvm-svn: 371719
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index bbb243dd329..e552a055b04 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1351,7 +1351,7 @@ void UnwrappedLineParser::parseStructuralElement() { (TokenCount == 2 && Line->Tokens.front().Tok->is(tok::comment))) { if (FormatTok->Tok.is(tok::colon) && !Line->MustBeDeclaration) { Line->Tokens.begin()->Tok->MustBreakBefore = true; - parseLabel(); + parseLabel(!Style.IndentGotoLabels); return; } // Recognize function-like macro usages without trailing semicolon as @@ -1970,11 +1970,13 @@ void UnwrappedLineParser::parseDoWhile() { parseStructuralElement(); } -void UnwrappedLineParser::parseLabel() { +void UnwrappedLineParser::parseLabel(bool LeftAlignLabel) { nextToken(); unsigned OldLineLevel = Line->Level; if (Line->Level > 1 || (!Line->InPPDirective && Line->Level > 0)) --Line->Level; + if (LeftAlignLabel) + Line->Level = 0; if (CommentsBeforeNextToken.empty() && FormatTok->Tok.is(tok::l_brace)) { CompoundStatementIndenter Indenter(this, Line->Level, Style.BraceWrapping.AfterCaseLabel, |