diff options
author | Daniel Jasper <djasper@google.com> | 2013-12-20 06:22:01 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-12-20 06:22:01 +0000 |
commit | 04b6a081fc37e48bb54e99888f13bdb712cb923e (patch) | |
tree | 43806ce7c453da6e68241d4221e9d02db720b3a7 /clang/lib/Format/ContinuationIndenter.cpp | |
parent | ce0709aa61367def36a86186cf9b91230333ae2c (diff) | |
download | bcm5719-llvm-04b6a081fc37e48bb54e99888f13bdb712cb923e.tar.gz bcm5719-llvm-04b6a081fc37e48bb54e99888f13bdb712cb923e.zip |
clang-format: Better support for multi-line wide string literals.
Before:
SomeFunction(L"A" L"B");
After:
SomeFunction(L"A"
L"B");
llvm-svn: 197785
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 3860aeb9e75..c3eeb8fd678 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -352,8 +352,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, State.Column = State.Stack[State.Stack.size() - 2].LastSpace; else State.Column = State.FirstIndent; - } else if (Current.is(tok::string_literal) && - State.StartOfStringLiteral != 0) { + } else if (Current.isStringLiteral() && State.StartOfStringLiteral != 0) { State.Column = State.StartOfStringLiteral; State.Stack.back().BreakBeforeParameter = true; } else if (Current.is(tok::lessless) && @@ -664,10 +663,10 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, } } - if (Current.is(tok::string_literal) && State.StartOfStringLiteral == 0) { + if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) { State.StartOfStringLiteral = State.Column; - } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash, - tok::string_literal)) { + } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) && + !Current.isStringLiteral()) { State.StartOfStringLiteral = 0; } @@ -737,19 +736,14 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, if (Current.Type == TT_ImplicitStringLiteral) return 0; - if (!Current.isOneOf(tok::string_literal, tok::wide_string_literal, - tok::utf8_string_literal, tok::utf16_string_literal, - tok::utf32_string_literal, tok::comment)) + if (!Current.isStringLiteral() && !Current.is(tok::comment)) return 0; llvm::OwningPtr<BreakableToken> Token; unsigned StartColumn = State.Column - Current.ColumnWidth; unsigned ColumnLimit = getColumnLimit(State); - if (Current.isOneOf(tok::string_literal, tok::wide_string_literal, - tok::utf8_string_literal, tok::utf16_string_literal, - tok::utf32_string_literal) && - Current.Type != TT_ImplicitStringLiteral) { + if (Current.isStringLiteral()) { // Don't break string literals inside preprocessor directives (except for // #define directives, as their contents are stored in separate lines and // are not affected by this check). @@ -858,8 +852,8 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, State.Stack[i].BreakBeforeParameter = true; } - Penalty += Current.is(tok::string_literal) ? Style.PenaltyBreakString - : Style.PenaltyBreakComment; + Penalty += Current.isStringLiteral() ? Style.PenaltyBreakString + : Style.PenaltyBreakComment; State.Stack.back().LastSpace = StartColumn; } @@ -873,7 +867,7 @@ unsigned ContinuationIndenter::getColumnLimit(const LineState &State) const { bool ContinuationIndenter::nextIsMultilineString(const LineState &State) { const FormatToken &Current = *State.NextToken; - if (!Current.is(tok::string_literal)) + if (!Current.isStringLiteral()) return false; // We never consider raw string literals "multiline" for the purpose of // AlwaysBreakBeforeMultilineStrings implementation as they are special-cased @@ -883,7 +877,7 @@ bool ContinuationIndenter::nextIsMultilineString(const LineState &State) { if (Current.IsMultiline) return true; if (Current.getNextNonComment() && - Current.getNextNonComment()->is(tok::string_literal)) + Current.getNextNonComment()->isStringLiteral()) return true; // Implicit concatenation. if (State.Column + Current.ColumnWidth + Current.UnbreakableTailLength > Style.ColumnLimit) |