clang-format: Fix bug introduced by r208392.
Also run clang-format over clang-format's files. llvm-svn: 208409
This commit is contained in:
parent
f2056bef32
commit
b05a81debb
|
@ -82,11 +82,9 @@ static BreakableToken::Split getCommentSplit(StringRef Text,
|
||||||
return BreakableToken::Split(StringRef::npos, 0);
|
return BreakableToken::Split(StringRef::npos, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BreakableToken::Split getStringSplit(StringRef Text,
|
static BreakableToken::Split
|
||||||
unsigned UsedColumns,
|
getStringSplit(StringRef Text, unsigned UsedColumns, unsigned ColumnLimit,
|
||||||
unsigned ColumnLimit,
|
unsigned TabWidth, encoding::Encoding Encoding) {
|
||||||
unsigned TabWidth,
|
|
||||||
encoding::Encoding Encoding) {
|
|
||||||
// FIXME: Reduce unit test case.
|
// FIXME: Reduce unit test case.
|
||||||
if (Text.empty())
|
if (Text.empty())
|
||||||
return BreakableToken::Split(StringRef::npos, 0);
|
return BreakableToken::Split(StringRef::npos, 0);
|
||||||
|
|
|
@ -98,8 +98,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
|
||||||
// The opening "{" of a braced list has to be on the same line as the first
|
// The opening "{" of a braced list has to be on the same line as the first
|
||||||
// element if it is nested in another braced init list or function call.
|
// element if it is nested in another braced init list or function call.
|
||||||
if (!Current.MustBreakBefore && Previous.is(tok::l_brace) &&
|
if (!Current.MustBreakBefore && Previous.is(tok::l_brace) &&
|
||||||
Previous.Type != TT_DictLiteral &&
|
Previous.Type != TT_DictLiteral && Previous.BlockKind == BK_BracedInit &&
|
||||||
Previous.BlockKind == BK_BracedInit && Previous.Previous &&
|
Previous.Previous &&
|
||||||
Previous.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma))
|
Previous.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma))
|
||||||
return false;
|
return false;
|
||||||
// This prevents breaks like:
|
// This prevents breaks like:
|
||||||
|
@ -427,8 +427,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
||||||
!PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
|
!PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
|
||||||
PreviousNonComment->Type != TT_TemplateCloser &&
|
PreviousNonComment->Type != TT_TemplateCloser &&
|
||||||
PreviousNonComment->Type != TT_BinaryOperator &&
|
PreviousNonComment->Type != TT_BinaryOperator &&
|
||||||
Current.Type != TT_BinaryOperator &&
|
Current.Type != TT_BinaryOperator && !PreviousNonComment->opensScope())
|
||||||
!PreviousNonComment->opensScope())
|
|
||||||
State.Stack.back().BreakBeforeParameter = true;
|
State.Stack.back().BreakBeforeParameter = true;
|
||||||
|
|
||||||
// If we break after { or the [ of an array initializer, we should also break
|
// If we break after { or the [ of an array initializer, we should also break
|
||||||
|
@ -462,8 +461,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
|
||||||
const FormatToken *NextNonComment = Previous.getNextNonComment();
|
const FormatToken *NextNonComment = Previous.getNextNonComment();
|
||||||
if (!NextNonComment)
|
if (!NextNonComment)
|
||||||
NextNonComment = &Current;
|
NextNonComment = &Current;
|
||||||
if (NextNonComment->is(tok::l_brace) &&
|
if (NextNonComment->is(tok::l_brace) && NextNonComment->BlockKind == BK_Block)
|
||||||
NextNonComment->BlockKind == BK_Block)
|
|
||||||
return Current.NestingLevel == 0 ? State.FirstIndent
|
return Current.NestingLevel == 0 ? State.FirstIndent
|
||||||
: State.Stack.back().Indent;
|
: State.Stack.back().Indent;
|
||||||
if (Current.isOneOf(tok::r_brace, tok::r_square)) {
|
if (Current.isOneOf(tok::r_brace, tok::r_square)) {
|
||||||
|
@ -832,8 +830,7 @@ unsigned ContinuationIndenter::addMultilineToken(const FormatToken &Current,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool getRawStringLiteralPrefixPostfix(StringRef Text,
|
static bool getRawStringLiteralPrefixPostfix(StringRef Text, StringRef &Prefix,
|
||||||
StringRef &Prefix,
|
|
||||||
StringRef &Postfix) {
|
StringRef &Postfix) {
|
||||||
if (Text.startswith(Prefix = "R\"") || Text.startswith(Prefix = "uR\"") ||
|
if (Text.startswith(Prefix = "R\"") || Text.startswith(Prefix = "uR\"") ||
|
||||||
Text.startswith(Prefix = "UR\"") || Text.startswith(Prefix = "u8R\"") ||
|
Text.startswith(Prefix = "UR\"") || Text.startswith(Prefix = "u8R\"") ||
|
||||||
|
|
|
@ -212,7 +212,7 @@ template <> struct MappingTraits<FormatStyle> {
|
||||||
Style.SpaceBeforeAssignmentOperators);
|
Style.SpaceBeforeAssignmentOperators);
|
||||||
IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth);
|
IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth);
|
||||||
IO.mapOptional("CommentPragmas", Style.CommentPragmas);
|
IO.mapOptional("CommentPragmas", Style.CommentPragmas);
|
||||||
IO.mapOptional("ForEachMacros", Style.ForEachMacros);
|
IO.mapOptional("ForEachMacros", Style.ForEachMacros);
|
||||||
|
|
||||||
// For backward compatibility.
|
// For backward compatibility.
|
||||||
if (!IO.outputting()) {
|
if (!IO.outputting()) {
|
||||||
|
@ -240,7 +240,7 @@ template <> struct DocumentListTraits<std::vector<FormatStyle> > {
|
||||||
if (Seq.size() > 0 && Seq[0].Language == FormatStyle::LK_None) {
|
if (Seq.size() > 0 && Seq[0].Language == FormatStyle::LK_None) {
|
||||||
Template = Seq[0];
|
Template = Seq[0];
|
||||||
} else {
|
} else {
|
||||||
Template = *((const FormatStyle*)IO.getContext());
|
Template = *((const FormatStyle *)IO.getContext());
|
||||||
Template.Language = FormatStyle::LK_None;
|
Template.Language = FormatStyle::LK_None;
|
||||||
}
|
}
|
||||||
Seq.resize(Index + 1, Template);
|
Seq.resize(Index + 1, Template);
|
||||||
|
@ -1188,7 +1188,7 @@ public:
|
||||||
FirstInLineIndex(0) {
|
FirstInLineIndex(0) {
|
||||||
Lex.SetKeepWhitespaceMode(true);
|
Lex.SetKeepWhitespaceMode(true);
|
||||||
|
|
||||||
for (const std::string& ForEachMacro : Style.ForEachMacros)
|
for (const std::string &ForEachMacro : Style.ForEachMacros)
|
||||||
ForEachMacros.push_back(&IdentTable.get(ForEachMacro));
|
ForEachMacros.push_back(&IdentTable.get(ForEachMacro));
|
||||||
std::sort(ForEachMacros.begin(), ForEachMacros.end());
|
std::sort(ForEachMacros.begin(), ForEachMacros.end());
|
||||||
}
|
}
|
||||||
|
@ -1218,10 +1218,10 @@ private:
|
||||||
if (tryMergeJSRegexLiteral())
|
if (tryMergeJSRegexLiteral())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static tok::TokenKind JSIdentity[] = {tok::equalequal, tok::equal};
|
static tok::TokenKind JSIdentity[] = { tok::equalequal, tok::equal };
|
||||||
static tok::TokenKind JSNotIdentity[] = {tok::exclaimequal, tok::equal};
|
static tok::TokenKind JSNotIdentity[] = { tok::exclaimequal, tok::equal };
|
||||||
static tok::TokenKind JSShiftEqual[] = {tok::greater, tok::greater,
|
static tok::TokenKind JSShiftEqual[] = { tok::greater, tok::greater,
|
||||||
tok::greaterequal};
|
tok::greaterequal };
|
||||||
// FIXME: We probably need to change token type to mimic operator with the
|
// FIXME: We probably need to change token type to mimic operator with the
|
||||||
// correct priority.
|
// correct priority.
|
||||||
if (tryMergeTokens(JSIdentity))
|
if (tryMergeTokens(JSIdentity))
|
||||||
|
@ -1261,30 +1261,30 @@ private:
|
||||||
// "(;,{}![:?", a binary operator or 'return', as those cannot be followed by
|
// "(;,{}![:?", a binary operator or 'return', as those cannot be followed by
|
||||||
// a division.
|
// a division.
|
||||||
bool tryMergeJSRegexLiteral() {
|
bool tryMergeJSRegexLiteral() {
|
||||||
if (Tokens.size() < 2 || Tokens.back()->isNot(tok::slash) ||
|
if (Tokens.size() < 2 || Tokens.back()->isNot(tok::slash) ||
|
||||||
Tokens[Tokens.size() - 2]->is(tok::unknown))
|
Tokens[Tokens.size() - 2]->is(tok::unknown))
|
||||||
return false;
|
|
||||||
unsigned TokenCount = 0;
|
|
||||||
unsigned LastColumn = Tokens.back()->OriginalColumn;
|
|
||||||
for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
|
|
||||||
++TokenCount;
|
|
||||||
if (I[0]->is(tok::slash) && I + 1 != E &&
|
|
||||||
(I[1]->isOneOf(tok::l_paren, tok::semi, tok::l_brace, tok::r_brace,
|
|
||||||
tok::exclaim, tok::l_square, tok::colon, tok::comma,
|
|
||||||
tok::question, tok::kw_return) ||
|
|
||||||
I[1]->isBinaryOperator())) {
|
|
||||||
Tokens.resize(Tokens.size() - TokenCount);
|
|
||||||
Tokens.back()->Tok.setKind(tok::unknown);
|
|
||||||
Tokens.back()->Type = TT_RegexLiteral;
|
|
||||||
Tokens.back()->ColumnWidth += LastColumn - I[0]->OriginalColumn;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// There can't be a newline inside a regex literal.
|
|
||||||
if (I[0]->NewlinesBefore > 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
unsigned TokenCount = 0;
|
||||||
|
unsigned LastColumn = Tokens.back()->OriginalColumn;
|
||||||
|
for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
|
||||||
|
++TokenCount;
|
||||||
|
if (I[0]->is(tok::slash) && I + 1 != E &&
|
||||||
|
(I[1]->isOneOf(tok::l_paren, tok::semi, tok::l_brace, tok::r_brace,
|
||||||
|
tok::exclaim, tok::l_square, tok::colon, tok::comma,
|
||||||
|
tok::question, tok::kw_return) ||
|
||||||
|
I[1]->isBinaryOperator())) {
|
||||||
|
Tokens.resize(Tokens.size() - TokenCount);
|
||||||
|
Tokens.back()->Tok.setKind(tok::unknown);
|
||||||
|
Tokens.back()->Type = TT_RegexLiteral;
|
||||||
|
Tokens.back()->ColumnWidth += LastColumn - I[0]->OriginalColumn;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// There can't be a newline inside a regex literal.
|
||||||
|
if (I[0]->NewlinesBefore > 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tryMerge_TMacro() {
|
bool tryMerge_TMacro() {
|
||||||
|
@ -1534,7 +1534,7 @@ private:
|
||||||
// Index (in 'Tokens') of the last token that starts a new line.
|
// Index (in 'Tokens') of the last token that starts a new line.
|
||||||
unsigned FirstInLineIndex;
|
unsigned FirstInLineIndex;
|
||||||
SmallVector<FormatToken *, 16> Tokens;
|
SmallVector<FormatToken *, 16> Tokens;
|
||||||
SmallVector<IdentifierInfo*, 8> ForEachMacros;
|
SmallVector<IdentifierInfo *, 8> ForEachMacros;
|
||||||
|
|
||||||
void readRawToken(FormatToken &Tok) {
|
void readRawToken(FormatToken &Tok) {
|
||||||
Lex.LexFromRawLexer(Tok.Tok);
|
Lex.LexFromRawLexer(Tok.Tok);
|
||||||
|
@ -1713,12 +1713,10 @@ private:
|
||||||
bool LineMoved = PreviousLine && PreviousLine->Affected &&
|
bool LineMoved = PreviousLine && PreviousLine->Affected &&
|
||||||
Line->First->NewlinesBefore == 0;
|
Line->First->NewlinesBefore == 0;
|
||||||
|
|
||||||
bool IsContinuedComment = Line->First->is(tok::comment) &&
|
bool IsContinuedComment =
|
||||||
Line->First->Next == nullptr &&
|
Line->First->is(tok::comment) && Line->First->Next == nullptr &&
|
||||||
Line->First->NewlinesBefore < 2 &&
|
Line->First->NewlinesBefore < 2 && PreviousLine &&
|
||||||
PreviousLine &&
|
PreviousLine->Affected && PreviousLine->Last->is(tok::comment);
|
||||||
PreviousLine->Affected &&
|
|
||||||
PreviousLine->Last->is(tok::comment);
|
|
||||||
|
|
||||||
if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
|
if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
|
||||||
IsContinuedComment) {
|
IsContinuedComment) {
|
||||||
|
|
|
@ -64,16 +64,15 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State,
|
||||||
|
|
||||||
// Ensure that we start on the opening brace.
|
// Ensure that we start on the opening brace.
|
||||||
const FormatToken *LBrace = State.NextToken->Previous->Previous;
|
const FormatToken *LBrace = State.NextToken->Previous->Previous;
|
||||||
if (LBrace->isNot(tok::l_brace) ||
|
if (LBrace->isNot(tok::l_brace) || LBrace->BlockKind == BK_Block ||
|
||||||
LBrace->BlockKind == BK_Block ||
|
|
||||||
LBrace->Type == TT_DictLiteral ||
|
LBrace->Type == TT_DictLiteral ||
|
||||||
LBrace->Next->Type == TT_DesignatedInitializerPeriod)
|
LBrace->Next->Type == TT_DesignatedInitializerPeriod)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Calculate the number of code points we have to format this list. As the
|
// Calculate the number of code points we have to format this list. As the
|
||||||
// first token is already placed, we have to subtract it.
|
// first token is already placed, we have to subtract it.
|
||||||
unsigned RemainingCodePoints = Style.ColumnLimit - State.Column +
|
unsigned RemainingCodePoints =
|
||||||
State.NextToken->Previous->ColumnWidth;
|
Style.ColumnLimit - State.Column + State.NextToken->Previous->ColumnWidth;
|
||||||
|
|
||||||
// Find the best ColumnFormat, i.e. the best number of columns to use.
|
// Find the best ColumnFormat, i.e. the best number of columns to use.
|
||||||
const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
|
const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
|
||||||
|
@ -186,8 +185,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
|
||||||
// If this doesn't have a nested list, we require at least 6 elements in order
|
// If this doesn't have a nested list, we require at least 6 elements in order
|
||||||
// create a column layout. If it has a nested list, column layout ensures one
|
// create a column layout. If it has a nested list, column layout ensures one
|
||||||
// list element per line.
|
// list element per line.
|
||||||
if (HasNestedBracedList || Commas.size() < 5 ||
|
if (HasNestedBracedList || Commas.size() < 5 || Token->NestingLevel != 0)
|
||||||
Token->NestingLevel != 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// We can never place more than ColumnLimit / 3 items in a row (because of the
|
// We can never place more than ColumnLimit / 3 items in a row (because of the
|
||||||
|
@ -209,8 +207,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
|
||||||
HasRowWithSufficientColumns = true;
|
HasRowWithSufficientColumns = true;
|
||||||
unsigned length =
|
unsigned length =
|
||||||
(Column == Columns - 1) ? EndOfLineItemLength[i] : ItemLengths[i];
|
(Column == Columns - 1) ? EndOfLineItemLength[i] : ItemLengths[i];
|
||||||
Format.ColumnSizes[Column] =
|
Format.ColumnSizes[Column] = std::max(Format.ColumnSizes[Column], length);
|
||||||
std::max(Format.ColumnSizes[Column], length);
|
|
||||||
++Column;
|
++Column;
|
||||||
}
|
}
|
||||||
// If all rows are terminated early (e.g. by trailing comments), we don't
|
// If all rows are terminated early (e.g. by trailing comments), we don't
|
||||||
|
|
|
@ -455,7 +455,9 @@ public:
|
||||||
bool DryRun) override;
|
bool DryRun) override;
|
||||||
|
|
||||||
/// \brief Adds \p Token as the next comma to the \c CommaSeparated list.
|
/// \brief Adds \p Token as the next comma to the \c CommaSeparated list.
|
||||||
void CommaFound(const FormatToken *Token) override { Commas.push_back(Token);}
|
void CommaFound(const FormatToken *Token) override {
|
||||||
|
Commas.push_back(Token);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// \brief A struct that holds information on how to format a given list with
|
/// \brief A struct that holds information on how to format a given list with
|
||||||
|
|
|
@ -226,9 +226,8 @@ private:
|
||||||
bool StartsObjCMethodExpr =
|
bool StartsObjCMethodExpr =
|
||||||
Contexts.back().CanBeExpression && Left->Type != TT_LambdaLSquare &&
|
Contexts.back().CanBeExpression && Left->Type != TT_LambdaLSquare &&
|
||||||
CurrentToken->isNot(tok::l_brace) &&
|
CurrentToken->isNot(tok::l_brace) &&
|
||||||
(!Parent ||
|
(!Parent || Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
|
||||||
Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
|
tok::kw_return, tok::kw_throw) ||
|
||||||
tok::kw_return, tok::kw_throw) ||
|
|
||||||
Parent->isUnaryOperator() || Parent->Type == TT_ObjCForIn ||
|
Parent->isUnaryOperator() || Parent->Type == TT_ObjCForIn ||
|
||||||
Parent->Type == TT_CastRParen ||
|
Parent->Type == TT_CastRParen ||
|
||||||
getBinOpPrecedence(Parent->Tok.getKind(), true, true) > prec::Unknown);
|
getBinOpPrecedence(Parent->Tok.getKind(), true, true) > prec::Unknown);
|
||||||
|
@ -389,8 +388,7 @@ private:
|
||||||
Contexts.back().FirstObjCSelectorName = Tok->Previous;
|
Contexts.back().FirstObjCSelectorName = Tok->Previous;
|
||||||
} else if (Contexts.back().ColonIsForRangeExpr) {
|
} else if (Contexts.back().ColonIsForRangeExpr) {
|
||||||
Tok->Type = TT_RangeBasedForLoopColon;
|
Tok->Type = TT_RangeBasedForLoopColon;
|
||||||
} else if (CurrentToken &&
|
} else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
|
||||||
CurrentToken->is(tok::numeric_constant)) {
|
|
||||||
Tok->Type = TT_BitFieldColon;
|
Tok->Type = TT_BitFieldColon;
|
||||||
} else if (Contexts.size() == 1 && Line.First->isNot(tok::kw_enum)) {
|
} else if (Contexts.size() == 1 && Line.First->isNot(tok::kw_enum)) {
|
||||||
Tok->Type = TT_InheritanceColon;
|
Tok->Type = TT_InheritanceColon;
|
||||||
|
@ -604,7 +602,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resetTokenMetadata(FormatToken *Token) {
|
void resetTokenMetadata(FormatToken *Token) {
|
||||||
if (!Token) return;
|
if (!Token)
|
||||||
|
return;
|
||||||
|
|
||||||
// Reset token type in case we have already looked at it and then
|
// Reset token type in case we have already looked at it and then
|
||||||
// recovered from an error (e.g. failure to find the matching >).
|
// recovered from an error (e.g. failure to find the matching >).
|
||||||
|
@ -867,9 +866,8 @@ private:
|
||||||
if (Prev && Tok.Next && Tok.Next->Next) {
|
if (Prev && Tok.Next && Tok.Next->Next) {
|
||||||
bool NextIsUnary = Tok.Next->isUnaryOperator() ||
|
bool NextIsUnary = Tok.Next->isUnaryOperator() ||
|
||||||
Tok.Next->isOneOf(tok::amp, tok::star);
|
Tok.Next->isOneOf(tok::amp, tok::star);
|
||||||
IsCast =
|
IsCast = NextIsUnary && Tok.Next->Next->isOneOf(
|
||||||
NextIsUnary &&
|
tok::identifier, tok::numeric_constant);
|
||||||
Tok.Next->Next->isOneOf(tok::identifier, tok::numeric_constant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; Prev != Tok.MatchingParen; Prev = Prev->Previous) {
|
for (; Prev != Tok.MatchingParen; Prev = Prev->Previous) {
|
||||||
|
@ -964,7 +962,6 @@ private:
|
||||||
return TT_UnaryOperator;
|
return TT_UnaryOperator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SmallVector<Context, 8> Contexts;
|
SmallVector<Context, 8> Contexts;
|
||||||
|
|
||||||
const FormatStyle &Style;
|
const FormatStyle &Style;
|
||||||
|
@ -1331,8 +1328,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
|
||||||
// Use a slightly higher penalty after ")" so that annotations like
|
// Use a slightly higher penalty after ")" so that annotations like
|
||||||
// "const override" are kept together.
|
// "const override" are kept together.
|
||||||
bool is_short_annotation = Right.TokenText.size() < 10;
|
bool is_short_annotation = Right.TokenText.size() < 10;
|
||||||
return (Left.is(tok::r_paren) ? 100 : 120) +
|
return (Left.is(tok::r_paren) ? 100 : 120) + (is_short_annotation ? 50 : 0);
|
||||||
(is_short_annotation ? 50 : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In for-loops, prefer breaking at ',' and ';'.
|
// In for-loops, prefer breaking at ',' and ';'.
|
||||||
|
@ -1529,8 +1525,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
||||||
return false;
|
return false;
|
||||||
if (Tok.is(tok::colon))
|
if (Tok.is(tok::colon))
|
||||||
return !Line.First->isOneOf(tok::kw_case, tok::kw_default) &&
|
return !Line.First->isOneOf(tok::kw_case, tok::kw_default) &&
|
||||||
Tok.getNextNonComment() &&
|
Tok.getNextNonComment() && Tok.Type != TT_ObjCMethodExpr &&
|
||||||
Tok.Type != TT_ObjCMethodExpr && !Tok.Previous->is(tok::question) &&
|
!Tok.Previous->is(tok::question) &&
|
||||||
(Tok.Type != TT_DictLiteral || Style.SpacesInContainerLiterals);
|
(Tok.Type != TT_DictLiteral || Style.SpacesInContainerLiterals);
|
||||||
if (Tok.Previous->Type == TT_UnaryOperator ||
|
if (Tok.Previous->Type == TT_UnaryOperator ||
|
||||||
Tok.Previous->Type == TT_CastRParen)
|
Tok.Previous->Type == TT_CastRParen)
|
||||||
|
@ -1737,7 +1733,7 @@ void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) {
|
||||||
for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i)
|
for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i)
|
||||||
llvm::errs() << Tok->FakeLParens[i] << "/";
|
llvm::errs() << Tok->FakeLParens[i] << "/";
|
||||||
llvm::errs() << " FakeRParens=" << Tok->FakeRParens << "\n";
|
llvm::errs() << " FakeRParens=" << Tok->FakeRParens << "\n";
|
||||||
if (Tok->Next)
|
if (!Tok->Next)
|
||||||
assert(Tok == Line.Last);
|
assert(Tok == Line.Last);
|
||||||
Tok = Tok->Next;
|
Tok = Tok->Next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,9 +164,7 @@ public:
|
||||||
++LineLevel;
|
++LineLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
~CompoundStatementIndenter() {
|
~CompoundStatementIndenter() { LineLevel = OldLineLevel; }
|
||||||
LineLevel = OldLineLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned &LineLevel;
|
unsigned &LineLevel;
|
||||||
|
@ -207,9 +205,10 @@ private:
|
||||||
UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style,
|
UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style,
|
||||||
ArrayRef<FormatToken *> Tokens,
|
ArrayRef<FormatToken *> Tokens,
|
||||||
UnwrappedLineConsumer &Callback)
|
UnwrappedLineConsumer &Callback)
|
||||||
: Line(new UnwrappedLine), MustBreakBeforeNextToken(false),
|
: Line(new UnwrappedLine), MustBreakBeforeNextToken(false),
|
||||||
CurrentLines(&Lines), StructuralError(false), Style(Style), Tokens(nullptr),
|
CurrentLines(&Lines), StructuralError(false), Style(Style),
|
||||||
Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1) {}
|
Tokens(nullptr), Callback(Callback), AllTokens(Tokens),
|
||||||
|
PPBranchLevel(-1) {}
|
||||||
|
|
||||||
void UnwrappedLineParser::reset() {
|
void UnwrappedLineParser::reset() {
|
||||||
PPBranchLevel = -1;
|
PPBranchLevel = -1;
|
||||||
|
@ -1279,9 +1278,8 @@ void UnwrappedLineParser::parseEnum() {
|
||||||
nextToken();
|
nextToken();
|
||||||
}
|
}
|
||||||
// Eat up enum class ...
|
// Eat up enum class ...
|
||||||
if (FormatTok->Tok.is(tok::kw_class) ||
|
if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct))
|
||||||
FormatTok->Tok.is(tok::kw_struct))
|
nextToken();
|
||||||
nextToken();
|
|
||||||
while (FormatTok->Tok.getIdentifierInfo() ||
|
while (FormatTok->Tok.getIdentifierInfo() ||
|
||||||
FormatTok->isOneOf(tok::colon, tok::coloncolon)) {
|
FormatTok->isOneOf(tok::colon, tok::coloncolon)) {
|
||||||
nextToken();
|
nextToken();
|
||||||
|
@ -1476,7 +1474,7 @@ void UnwrappedLineParser::addUnwrappedLine() {
|
||||||
|
|
||||||
bool UnwrappedLineParser::eof() const { return FormatTok->Tok.is(tok::eof); }
|
bool UnwrappedLineParser::eof() const { return FormatTok->Tok.is(tok::eof); }
|
||||||
|
|
||||||
bool UnwrappedLineParser::isOnNewLine(const FormatToken& FormatTok) {
|
bool UnwrappedLineParser::isOnNewLine(const FormatToken &FormatTok) {
|
||||||
return (Line->InPPDirective || FormatTok.HasUnescapedNewline) &&
|
return (Line->InPPDirective || FormatTok.HasUnescapedNewline) &&
|
||||||
FormatTok.NewlinesBefore > 0;
|
FormatTok.NewlinesBefore > 0;
|
||||||
}
|
}
|
||||||
|
@ -1531,7 +1529,7 @@ void UnwrappedLineParser::readToken() {
|
||||||
conditionalCompilationStart(/*Unreachable=*/false);
|
conditionalCompilationStart(/*Unreachable=*/false);
|
||||||
} else if (FormatTok->Type == TT_ConflictAlternative) {
|
} else if (FormatTok->Type == TT_ConflictAlternative) {
|
||||||
conditionalCompilationAlternative();
|
conditionalCompilationAlternative();
|
||||||
} else if(FormatTok->Type == TT_ConflictEnd) {
|
} else if (FormatTok->Type == TT_ConflictEnd) {
|
||||||
conditionalCompilationEnd();
|
conditionalCompilationEnd();
|
||||||
}
|
}
|
||||||
FormatTok = Tokens->getNextToken();
|
FormatTok = Tokens->getNextToken();
|
||||||
|
|
|
@ -119,7 +119,7 @@ private:
|
||||||
void conditionalCompilationAlternative();
|
void conditionalCompilationAlternative();
|
||||||
void conditionalCompilationEnd();
|
void conditionalCompilationEnd();
|
||||||
|
|
||||||
bool isOnNewLine(const FormatToken& FormatTok);
|
bool isOnNewLine(const FormatToken &FormatTok);
|
||||||
|
|
||||||
// FIXME: We are constantly running into bugs where Line.Level is incorrectly
|
// FIXME: We are constantly running into bugs where Line.Level is incorrectly
|
||||||
// subtracted from beyond 0. Introduce a method to subtract from Line.Level
|
// subtracted from beyond 0. Introduce a method to subtract from Line.Level
|
||||||
|
|
|
@ -18,9 +18,8 @@
|
||||||
namespace clang {
|
namespace clang {
|
||||||
namespace format {
|
namespace format {
|
||||||
|
|
||||||
bool
|
bool WhitespaceManager::Change::IsBeforeInFile::
|
||||||
WhitespaceManager::Change::IsBeforeInFile::operator()(const Change &C1,
|
operator()(const Change &C1, const Change &C2) const {
|
||||||
const Change &C2) const {
|
|
||||||
return SourceMgr.isBeforeInTranslationUnit(
|
return SourceMgr.isBeforeInTranslationUnit(
|
||||||
C1.OriginalWhitespaceRange.getBegin(),
|
C1.OriginalWhitespaceRange.getBegin(),
|
||||||
C2.OriginalWhitespaceRange.getBegin());
|
C2.OriginalWhitespaceRange.getBegin());
|
||||||
|
|
Loading…
Reference in New Issue