diff options
author | Alexander Kornienko <alexfh@google.com> | 2017-04-11 09:55:00 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2017-04-11 09:55:00 +0000 |
commit | d4fa2e634876672a680a300442ed917761a8c3ff (patch) | |
tree | 7f4503b025bc11c7af8ebd4d3097fe07420945e4 /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 4fc5f3c02e57136c7c4055bd2f83a56bb79d37e5 (diff) | |
download | bcm5719-llvm-d4fa2e634876672a680a300442ed917761a8c3ff.tar.gz bcm5719-llvm-d4fa2e634876672a680a300442ed917761a8c3ff.zip |
[clang-format] Handle NSString literals by merging tokens.
Summary:
This fixes a few outstanding bugs:
* incorrect breaking of NSString literals containing double-width characters;
* inconsistent formatting of ObjC dictionary literals containing NSString
literals;
* AlwaysBreakBeforeMultilineStrings ignoring implicitly-concatenated NSString
literals.
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D31706
llvm-svn: 299927
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index c3f386bd673..73ae10a29f8 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -679,11 +679,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { if (Current.is(tok::identifier) && Current.Next && Current.Next->is(TT_DictLiteral)) return State.Stack.back().Indent; - if (NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0) - return State.StartOfStringLiteral; if (NextNonComment->is(TT_ObjCStringLiteral) && State.StartOfStringLiteral != 0) return State.StartOfStringLiteral - 1; + if (NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0) + return State.StartOfStringLiteral; if (NextNonComment->is(tok::lessless) && State.Stack.back().FirstLessLess != 0) return State.Stack.back().FirstLessLess; @@ -864,10 +864,10 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, moveStatePastScopeOpener(State, Newline); moveStatePastFakeRParens(State); - if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) - State.StartOfStringLiteral = State.Column; if (Current.is(TT_ObjCStringLiteral) && State.StartOfStringLiteral == 0) State.StartOfStringLiteral = State.Column + 1; + else if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) + State.StartOfStringLiteral = State.Column; else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) && !Current.isStringLiteral()) State.StartOfStringLiteral = 0; @@ -1175,18 +1175,12 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, StringRef Text = Current.TokenText; StringRef Prefix; StringRef Postfix; - bool IsNSStringLiteral = false; // FIXME: Handle whitespace between '_T', '(', '"..."', and ')'. // FIXME: Store Prefix and Suffix (or PrefixLength and SuffixLength to // reduce the overhead) for each FormatToken, which is a string, so that we // don't run multiple checks here on the hot path. - if (Text.startswith("\"") && Current.Previous && - Current.Previous->is(tok::at)) { - IsNSStringLiteral = true; - Prefix = "@\""; - } if ((Text.endswith(Postfix = "\"") && - (IsNSStringLiteral || Text.startswith(Prefix = "\"") || + (Text.startswith(Prefix = "@\"") || Text.startswith(Prefix = "\"") || Text.startswith(Prefix = "u\"") || Text.startswith(Prefix = "U\"") || Text.startswith(Prefix = "u8\"") || Text.startswith(Prefix = "L\""))) || |