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