Index: clang/lib/Format/AffectedRangeManager.h =================================================================== --- clang/lib/Format/AffectedRangeManager.h +++ clang/lib/Format/AffectedRangeManager.h @@ -24,8 +24,8 @@ class AffectedRangeManager { public: - AffectedRangeManager(const SourceManager &SourceMgr, - const ArrayRef Ranges) + AffectedRangeManager(SourceManager const &SourceMgr, + ArrayRef const Ranges) : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {} // Determines which lines are affected by the SourceRanges given as input. @@ -34,17 +34,17 @@ bool computeAffectedLines(SmallVectorImpl &Lines); // Returns true if 'Range' intersects with one of the input ranges. - bool affectsCharSourceRange(const CharSourceRange &Range); + bool affectsCharSourceRange(CharSourceRange const &Range); private: // Returns true if the range from 'First' to 'Last' intersects with one of the // input ranges. - bool affectsTokenRange(const FormatToken &First, const FormatToken &Last, + bool affectsTokenRange(FormatToken const &First, FormatToken const &Last, bool IncludeLeadingNewlines); // Returns true if one of the input ranges intersect the leading empty lines // before 'Tok'. - bool affectsLeadingEmptyLines(const FormatToken &Tok); + bool affectsLeadingEmptyLines(FormatToken const &Tok); // Marks all lines between I and E as well as all their children as affected. void markAllAsAffected(SmallVectorImpl::iterator I, @@ -52,11 +52,11 @@ // Determines whether 'Line' is affected by the SourceRanges given as input. // Returns \c true if line or one if its children is affected. - bool nonPPLineAffected(AnnotatedLine *Line, const AnnotatedLine *PreviousLine, + bool nonPPLineAffected(AnnotatedLine *Line, AnnotatedLine const *PreviousLine, SmallVectorImpl &Lines); - const SourceManager &SourceMgr; - const SmallVector Ranges; + SourceManager const &SourceMgr; + SmallVector const Ranges; }; } // namespace format Index: clang/lib/Format/AffectedRangeManager.cpp =================================================================== --- clang/lib/Format/AffectedRangeManager.cpp +++ clang/lib/Format/AffectedRangeManager.cpp @@ -24,7 +24,7 @@ SmallVectorImpl::iterator I = Lines.begin(); SmallVectorImpl::iterator E = Lines.end(); bool SomeLineAffected = false; - const AnnotatedLine *PreviousLine = nullptr; + AnnotatedLine const *PreviousLine = nullptr; while (I != E) { AnnotatedLine *Line = *I; Line->LeadingEmptyLinesAffected = affectsLeadingEmptyLines(*Line->First); @@ -58,7 +58,7 @@ } bool AffectedRangeManager::affectsCharSourceRange( - const CharSourceRange &Range) { + CharSourceRange const &Range) { for (SmallVectorImpl::const_iterator I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { @@ -69,8 +69,8 @@ return false; } -bool AffectedRangeManager::affectsTokenRange(const FormatToken &First, - const FormatToken &Last, +bool AffectedRangeManager::affectsTokenRange(FormatToken const &First, + FormatToken const &Last, bool IncludeLeadingNewlines) { SourceLocation Start = First.WhitespaceRange.getBegin(); if (!IncludeLeadingNewlines) @@ -81,7 +81,7 @@ return affectsCharSourceRange(Range); } -bool AffectedRangeManager::affectsLeadingEmptyLines(const FormatToken &Tok) { +bool AffectedRangeManager::affectsLeadingEmptyLines(FormatToken const &Tok) { CharSourceRange EmptyLineRange = CharSourceRange::getCharRange( Tok.WhitespaceRange.getBegin(), Tok.WhitespaceRange.getBegin().getLocWithOffset(Tok.LastNewlineOffset)); @@ -99,7 +99,7 @@ } bool AffectedRangeManager::nonPPLineAffected( - AnnotatedLine *Line, const AnnotatedLine *PreviousLine, + AnnotatedLine *Line, AnnotatedLine const *PreviousLine, SmallVectorImpl &Lines) { bool SomeLineAffected = false; Line->ChildrenAffected = computeAffectedLines(Line->Children); Index: clang/lib/Format/BreakableToken.h =================================================================== --- clang/lib/Format/BreakableToken.h +++ clang/lib/Format/BreakableToken.h @@ -29,7 +29,7 @@ /// Checks if \p Token switches formatting, like /* clang-format off */. /// \p Token must be a comment. -bool switchesFormatting(const FormatToken &Token); +bool switchesFormatting(FormatToken const &Token); struct FormatStyle; @@ -231,15 +231,15 @@ virtual void updateNextToken(LineState &State) const {} protected: - BreakableToken(const FormatToken &Tok, bool InPPDirective, - encoding::Encoding Encoding, const FormatStyle &Style) + BreakableToken(FormatToken const &Tok, bool InPPDirective, + encoding::Encoding Encoding, FormatStyle const &Style) : Tok(Tok), InPPDirective(InPPDirective), Encoding(Encoding), Style(Style) {} - const FormatToken &Tok; - const bool InPPDirective; + FormatToken const &Tok; + bool const InPPDirective; const encoding::Encoding Encoding; - const FormatStyle &Style; + FormatStyle const &Style; }; class BreakableStringLiteral : public BreakableToken { @@ -248,10 +248,10 @@ /// /// \p StartColumn specifies the column in which the token will start /// after formatting. - BreakableStringLiteral(const FormatToken &Tok, unsigned StartColumn, + BreakableStringLiteral(FormatToken const &Tok, unsigned StartColumn, StringRef Prefix, StringRef Postfix, unsigned UnbreakableTailLength, bool InPPDirective, - encoding::Encoding Encoding, const FormatStyle &Style); + encoding::Encoding Encoding, FormatStyle const &Style); Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, unsigned ContentStartColumn, @@ -289,9 +289,9 @@ /// /// \p StartColumn specifies the column in which the comment will start after /// formatting. - BreakableComment(const FormatToken &Token, unsigned StartColumn, + BreakableComment(FormatToken const &Token, unsigned StartColumn, bool InPPDirective, encoding::Encoding Encoding, - const FormatStyle &Style); + FormatStyle const &Style); public: bool supportsReflow() const override { return true; } @@ -304,7 +304,7 @@ protected: // Returns the token containing the line at LineIndex. - const FormatToken &tokenAt(unsigned LineIndex) const; + FormatToken const &tokenAt(unsigned LineIndex) const; // Checks if the content of line LineIndex may be reflown with the previous // line. @@ -356,10 +356,10 @@ class BreakableBlockComment : public BreakableComment { public: - BreakableBlockComment(const FormatToken &Token, unsigned StartColumn, + BreakableBlockComment(FormatToken const &Token, unsigned StartColumn, unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective, encoding::Encoding Encoding, - const FormatStyle &Style, bool UseCRLF); + FormatStyle const &Style, bool UseCRLF); Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, unsigned ContentStartColumn, @@ -435,10 +435,10 @@ class BreakableLineCommentSection : public BreakableComment { public: - BreakableLineCommentSection(const FormatToken &Token, unsigned StartColumn, + BreakableLineCommentSection(FormatToken const &Token, unsigned StartColumn, unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective, encoding::Encoding Encoding, - const FormatStyle &Style); + FormatStyle const &Style); unsigned getRangeLength(unsigned LineIndex, unsigned Offset, StringRef::size_type Length, Index: clang/lib/Format/BreakableToken.cpp =================================================================== --- clang/lib/Format/BreakableToken.cpp +++ clang/lib/Format/BreakableToken.cpp @@ -25,7 +25,7 @@ namespace clang { namespace format { -static const char *const Blanks = " \t\v\f\r"; +static char const *const Blanks = " \t\v\f\r"; static bool IsBlank(char C) { switch (C) { case ' ': @@ -40,12 +40,12 @@ } static StringRef getLineCommentIndentPrefix(StringRef Comment, - const FormatStyle &Style) { - static const char *const KnownCStylePrefixes[] = {"///<", "//!<", "///", "//", + FormatStyle const &Style) { + static char const *const KnownCStylePrefixes[] = {"///<", "//!<", "///", "//", "//!"}; - static const char *const KnownTextProtoPrefixes[] = {"//", "#", "##", "###", + static char const *const KnownTextProtoPrefixes[] = {"//", "#", "##", "###", "####"}; - ArrayRef KnownPrefixes(KnownCStylePrefixes); + ArrayRef KnownPrefixes(KnownCStylePrefixes); if (Style.Language == FormatStyle::LK_TextProto) KnownPrefixes = KnownTextProtoPrefixes; @@ -65,7 +65,7 @@ static BreakableToken::Split getCommentSplit(StringRef Text, unsigned ContentStartColumn, unsigned ColumnLimit, unsigned TabWidth, - encoding::Encoding Encoding, const FormatStyle &Style, + encoding::Encoding Encoding, FormatStyle const &Style, bool DecorationEndsWithStar = false) { LLVM_DEBUG(llvm::dbgs() << "Comment split: \"" << Text << "\", Column limit: " << ColumnLimit @@ -183,7 +183,7 @@ return BreakableToken::Split(StringRef::npos, 0); } -bool switchesFormatting(const FormatToken &Token) { +bool switchesFormatting(FormatToken const &Token) { assert((Token.is(TT_BlockComment) || Token.is(TT_LineComment)) && "formatting regions are switched by comment tokens"); StringRef Content = Token.TokenText.substr(2).ltrim(); @@ -232,9 +232,9 @@ } BreakableStringLiteral::BreakableStringLiteral( - const FormatToken &Tok, unsigned StartColumn, StringRef Prefix, + FormatToken const &Tok, unsigned StartColumn, StringRef Prefix, StringRef Postfix, unsigned UnbreakableTailLength, bool InPPDirective, - encoding::Encoding Encoding, const FormatStyle &Style) + encoding::Encoding Encoding, FormatStyle const &Style) : BreakableToken(Tok, InPPDirective, Encoding, Style), StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix), UnbreakableTailLength(UnbreakableTailLength) { @@ -259,10 +259,10 @@ Prefix, InPPDirective, 1, StartColumn); } -BreakableComment::BreakableComment(const FormatToken &Token, +BreakableComment::BreakableComment(FormatToken const &Token, unsigned StartColumn, bool InPPDirective, encoding::Encoding Encoding, - const FormatStyle &Style) + FormatStyle const &Style) : BreakableToken(Token, InPPDirective, Encoding, Style), StartColumn(StartColumn) {} @@ -296,7 +296,7 @@ /*InPPDirective=*/false, /*Newlines=*/0, /*Spaces=*/1); } -const FormatToken &BreakableComment::tokenAt(unsigned LineIndex) const { +FormatToken const &BreakableComment::tokenAt(unsigned LineIndex) const { return Tokens[LineIndex] ? *Tokens[LineIndex] : Tok; } @@ -331,9 +331,9 @@ } BreakableBlockComment::BreakableBlockComment( - const FormatToken &Token, unsigned StartColumn, + FormatToken const &Token, unsigned StartColumn, unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective, - encoding::Encoding Encoding, const FormatStyle &Style, bool UseCRLF) + encoding::Encoding Encoding, FormatStyle const &Style, bool UseCRLF) : BreakableComment(Token, StartColumn, InPPDirective, Encoding, Style), DelimitersOnNewline(false), UnbreakableTailLength(Token.UnbreakableTailLength) { @@ -720,14 +720,14 @@ } BreakableLineCommentSection::BreakableLineCommentSection( - const FormatToken &Token, unsigned StartColumn, + FormatToken const &Token, unsigned StartColumn, unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective, - encoding::Encoding Encoding, const FormatStyle &Style) + encoding::Encoding Encoding, FormatStyle const &Style) : BreakableComment(Token, StartColumn, InPPDirective, Encoding, Style) { assert(Tok.is(TT_LineComment) && "line comment section must start with a line comment"); FormatToken *LineTok = nullptr; - for (const FormatToken *CurrentTok = &Tok; + for (FormatToken const *CurrentTok = &Tok; CurrentTok && CurrentTok->is(TT_LineComment); CurrentTok = CurrentTok->Next) { LastLineTok = LineTok; Index: clang/lib/Format/ContinuationIndenter.h =================================================================== --- clang/lib/Format/ContinuationIndenter.h +++ clang/lib/Format/ContinuationIndenter.h @@ -39,7 +39,7 @@ llvm::StringMap DelimiterStyle; llvm::StringMap EnclosingFunctionStyle; - RawStringFormatStyleManager(const FormatStyle &CodeStyle); + RawStringFormatStyleManager(FormatStyle const &CodeStyle); llvm::Optional getDelimiterStyle(StringRef Delimiter) const; @@ -51,9 +51,9 @@ public: /// Constructs a \c ContinuationIndenter to format \p Line starting in /// column \p FirstIndent. - ContinuationIndenter(const FormatStyle &Style, - const AdditionalKeywords &Keywords, - const SourceManager &SourceMgr, + ContinuationIndenter(FormatStyle const &Style, + AdditionalKeywords const &Keywords, + SourceManager const &SourceMgr, WhitespaceManager &Whitespaces, encoding::Encoding Encoding, bool BinPackInconclusiveFunctions); @@ -63,15 +63,15 @@ /// the case of formatting inside raw string literals, \p FirstStartColumn is /// the column at which the state of the parent formatter is. LineState getInitialState(unsigned FirstIndent, unsigned FirstStartColumn, - const AnnotatedLine *Line, bool DryRun); + AnnotatedLine const *Line, bool DryRun); // FIXME: canBreak and mustBreak aren't strictly indentation-related. Find a // better home. /// Returns \c true, if a line break after \p State is allowed. - bool canBreak(const LineState &State); + bool canBreak(LineState const &State); /// Returns \c true, if a line break after \p State is mandatory. - bool mustBreak(const LineState &State); + bool mustBreak(LineState const &State); /// Appends the next token to \p State and updates information /// necessary for indentation. @@ -86,7 +86,7 @@ /// Get the column limit for this line. This is the style's column /// limit, potentially reduced for preprocessor definitions. - unsigned getColumnLimit(const LineState &State) const; + unsigned getColumnLimit(LineState const &State) const; private: /// Mark the next token as consumed in \p State and modify its stacks @@ -108,20 +108,20 @@ /// Reformats a raw string literal. /// /// \returns An extra penalty induced by reformatting the token. - unsigned reformatRawStringLiteral(const FormatToken &Current, + unsigned reformatRawStringLiteral(FormatToken const &Current, LineState &State, - const FormatStyle &RawStringStyle, + FormatStyle const &RawStringStyle, bool DryRun, bool Newline); /// If the current token is at the end of the current line, handle /// the transition to the next line. - unsigned handleEndOfLine(const FormatToken &Current, LineState &State, + unsigned handleEndOfLine(FormatToken const &Current, LineState &State, bool DryRun, bool AllowBreak, bool Newline); /// If \p Current is a raw string that is configured to be reformatted, /// return the style to be used. - llvm::Optional getRawStringStyle(const FormatToken &Current, - const LineState &State); + llvm::Optional getRawStringStyle(FormatToken const &Current, + LineState const &State); /// If the current token sticks out over the end of the line, break /// it if possible. @@ -141,7 +141,7 @@ /// the column limit where possible; if false, words are allowed to protrude /// over the column limit as long as the penalty is less than the penalty /// of a break. - std::pair breakProtrudingToken(const FormatToken &Current, + std::pair breakProtrudingToken(FormatToken const &Current, LineState &State, bool AllowBreak, bool DryRun, bool Strict); @@ -149,7 +149,7 @@ /// Returns the \c BreakableToken starting at \p Current, or nullptr /// if the current token cannot be broken. std::unique_ptr - createBreakableToken(const FormatToken &Current, LineState &State, + createBreakableToken(FormatToken const &Current, LineState &State, bool AllowBreak); /// Appends the next token to \p State and updates information @@ -172,34 +172,34 @@ unsigned addTokenOnNewLine(LineState &State, bool DryRun); /// Calculate the new column for a line wrap before the next token. - unsigned getNewLineColumn(const LineState &State); + unsigned getNewLineColumn(LineState const &State); /// Adds a multiline token to the \p State. /// /// \returns Extra penalty for the first line of the literal: last line is /// handled in \c addNextStateToQueue, and the penalty for other lines doesn't /// matter, as we don't change them. - unsigned addMultilineToken(const FormatToken &Current, LineState &State); + unsigned addMultilineToken(FormatToken const &Current, LineState &State); /// Returns \c true if the next token starts a multiline string /// literal. /// /// This includes implicitly concatenated strings, strings that will be broken /// by clang-format and string literals with escaped newlines. - bool nextIsMultilineString(const LineState &State); + bool nextIsMultilineString(LineState const &State); FormatStyle Style; - const AdditionalKeywords &Keywords; - const SourceManager &SourceMgr; + AdditionalKeywords const &Keywords; + SourceManager const &SourceMgr; WhitespaceManager &Whitespaces; encoding::Encoding Encoding; bool BinPackInconclusiveFunctions; llvm::Regex CommentPragmasRegex; - const RawStringFormatStyleManager RawStringFormats; + RawStringFormatStyleManager const RawStringFormats; }; struct ParenState { - ParenState(const FormatToken *Tok, unsigned Indent, unsigned LastSpace, + ParenState(FormatToken const *Tok, unsigned Indent, unsigned LastSpace, bool AvoidBinPacking, bool NoLineBreak) : Tok(Tok), Indent(Indent), LastSpace(LastSpace), NestedBlockIndent(Indent), BreakBeforeClosingBrace(false), @@ -215,7 +215,7 @@ /// /// Not considered for memoization as it will always have the same value at /// the same token. - const FormatToken *Tok; + FormatToken const *Tok; /// The position to which a specific parenthesis level needs to be /// indented. @@ -329,7 +329,7 @@ /// array literal. bool IsInsideObjCArrayLiteral : 1; - bool operator<(const ParenState &Other) const { + bool operator<(ParenState const &Other) const { if (Indent != Other.Indent) return Indent < Other.Indent; if (LastSpace != Other.LastSpace) @@ -421,10 +421,10 @@ /// The line that is being formatted. /// /// Does not need to be considered for memoization because it doesn't change. - const AnnotatedLine *Line; + AnnotatedLine const *Line; /// Comparison operator to be able to used \c LineState in \c map. - bool operator<(const LineState &Other) const { + bool operator<(LineState const &Other) const { if (NextToken != Other.NextToken) return NextToken < Other.NextToken; if (Column != Other.Column) Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -27,14 +27,14 @@ // Returns true if a TT_SelectorName should be indented when wrapped, // false otherwise. -static bool shouldIndentWrappedSelectorName(const FormatStyle &Style, +static bool shouldIndentWrappedSelectorName(FormatStyle const &Style, LineType LineType) { return Style.IndentWrappedFunctionNames || LineType == LT_ObjCMethodDecl; } // Returns the length of everything up to the first possible line break after // the ), ], } or > matching \c Tok. -static unsigned getLengthToMatchingParen(const FormatToken &Tok, +static unsigned getLengthToMatchingParen(FormatToken const &Tok, const std::vector &Stack) { // Normally whether or not a break before T is possible is calculated and // stored in T.CanBreakBefore. Braces, array initializers and text proto @@ -83,7 +83,7 @@ // corresponds. Returns either a pointer to the matching level or nullptr if // LParen is not found in the initial portion of the stack up to // MatchingStackIndex. - auto FindParenState = [&](const FormatToken *LBrace) -> const ParenState * { + auto FindParenState = [&](FormatToken const *LBrace) -> ParenState const * { while (MatchingStackIndex >= 0 && Stack[MatchingStackIndex].Tok != LBrace) --MatchingStackIndex; return MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] : nullptr; @@ -96,7 +96,7 @@ if (End->Next->MatchingParen && End->Next->MatchingParen->isOneOf( tok::l_brace, TT_ArrayInitializerLSquare, tok::less)) { - const ParenState *State = FindParenState(End->Next->MatchingParen); + ParenState const *State = FindParenState(End->Next->MatchingParen); if (State && State->BreakBeforeClosingBrace) break; } @@ -104,7 +104,7 @@ return End->TotalLength - Tok.TotalLength + 1; } -static unsigned getLengthToNextOperator(const FormatToken &Tok) { +static unsigned getLengthToNextOperator(FormatToken const &Tok) { if (!Tok.NextOperator) return 0; return Tok.NextOperator->TotalLength - Tok.TotalLength; @@ -112,14 +112,14 @@ // Returns \c true if \c Tok is the "." or "->" of a call and starts the next // segment of a builder type call. -static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) { +static bool startsSegmentOfBuilderTypeCall(FormatToken const &Tok) { return Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope(); } // Returns \c true if \c Current starts a new parameter. -static bool startsNextParameter(const FormatToken &Current, - const FormatStyle &Style) { - const FormatToken &Previous = *Current.Previous; +static bool startsNextParameter(FormatToken const &Current, + FormatStyle const &Style) { + FormatToken const &Previous = *Current.Previous; if (Current.is(TT_CtorInitializerComma) && Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) return true; @@ -133,8 +133,8 @@ Style.BreakInheritanceList != FormatStyle::BILS_BeforeComma)); } -static bool opensProtoMessageField(const FormatToken &LessTok, - const FormatStyle &Style) { +static bool opensProtoMessageField(FormatToken const &LessTok, + FormatStyle const &Style) { if (LessTok.isNot(tok::less)) return false; return Style.Language == FormatStyle::LK_TextProto || @@ -171,7 +171,7 @@ // Returns the canonical delimiter for \p Language, or the empty string if no // canonical delimiter is specified. static StringRef -getCanonicalRawStringDelimiter(const FormatStyle &Style, +getCanonicalRawStringDelimiter(FormatStyle const &Style, FormatStyle::LanguageKind Language) { for (const auto &Format : Style.RawStringFormats) { if (Format.Language == Language) @@ -181,7 +181,7 @@ } RawStringFormatStyleManager::RawStringFormatStyleManager( - const FormatStyle &CodeStyle) { + FormatStyle const &CodeStyle) { for (const auto &RawStringFormat : CodeStyle.RawStringFormats) { llvm::Optional LanguageStyle = CodeStyle.GetLanguageStyle(RawStringFormat.Language); @@ -221,9 +221,9 @@ return It->second; } -ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style, - const AdditionalKeywords &Keywords, - const SourceManager &SourceMgr, +ContinuationIndenter::ContinuationIndenter(FormatStyle const &Style, + AdditionalKeywords const &Keywords, + SourceManager const &SourceMgr, WhitespaceManager &Whitespaces, encoding::Encoding Encoding, bool BinPackInconclusiveFunctions) @@ -234,7 +234,7 @@ LineState ContinuationIndenter::getInitialState(unsigned FirstIndent, unsigned FirstStartColumn, - const AnnotatedLine *Line, + AnnotatedLine const *Line, bool DryRun) { LineState State; State.FirstIndent = FirstIndent; @@ -274,9 +274,9 @@ return State; } -bool ContinuationIndenter::canBreak(const LineState &State) { - const FormatToken &Current = *State.NextToken; - const FormatToken &Previous = *Current.Previous; +bool ContinuationIndenter::canBreak(LineState const &State) { + FormatToken const &Current = *State.NextToken; + FormatToken const &Previous = *Current.Previous; assert(&Previous == Current.Previous); if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace && Current.closesBlockOrBlockTypeList(Style))) @@ -326,9 +326,9 @@ return !State.Stack.back().NoLineBreak; } -bool ContinuationIndenter::mustBreak(const LineState &State) { - const FormatToken &Current = *State.NextToken; - const FormatToken &Previous = *Current.Previous; +bool ContinuationIndenter::mustBreak(LineState const &State) { + FormatToken const &Current = *State.NextToken; + FormatToken const &Previous = *Current.Previous; if (Current.MustBreakBefore || Current.is(TT_InlineASMColon)) return true; if (State.Stack.back().BreakBeforeClosingBrace && @@ -365,7 +365,7 @@ getColumnLimit(State)) return true; - const FormatToken &BreakConstructorInitializersToken = + FormatToken const &BreakConstructorInitializersToken = Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon ? Previous : Current; @@ -506,7 +506,7 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline, bool DryRun, unsigned ExtraSpaces) { - const FormatToken &Current = *State.NextToken; + FormatToken const &Current = *State.NextToken; assert(!State.Stack.empty()); State.NoContinuation = false; @@ -543,13 +543,13 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, unsigned ExtraSpaces) { FormatToken &Current = *State.NextToken; - const FormatToken &Previous = *State.NextToken->Previous; + FormatToken const &Previous = *State.NextToken->Previous; if (Current.is(tok::equal) && (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) && State.Stack.back().VariablePos == 0) { State.Stack.back().VariablePos = State.Column; // Move over * and & if they are bound to the variable name. - const FormatToken *Tok = &Previous; + FormatToken const *Tok = &Previous; while (Tok && State.Stack.back().VariablePos >= Tok->ColumnWidth) { State.Stack.back().VariablePos -= Tok->ColumnWidth; if (Tok->SpacesRequiredBefore != 0) @@ -655,7 +655,7 @@ // there is a line-break right after the operator. // Exclude relational operators, as there, it is always more desirable to // have the LHS 'left' of the RHS. - const FormatToken *P = Current.getPreviousNonComment(); + FormatToken const *P = Current.getPreviousNonComment(); if (!Current.is(tok::comment) && P && (P->isOneOf(TT_BinaryOperator, tok::comma) || (P->is(TT_ConditionalExpr) && P->is(tok::colon))) && @@ -718,7 +718,7 @@ // .SecondInnerFunctionCall(); bool HasTrailingCall = false; if (Previous.MatchingParen) { - const FormatToken *Next = Previous.MatchingParen->getNextNonComment(); + FormatToken const *Next = Previous.MatchingParen->getNextNonComment(); HasTrailingCall = Next && Next->isMemberAccess(); } if (HasTrailingCall && State.Stack.size() > 1 && @@ -730,14 +730,14 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, bool DryRun) { FormatToken &Current = *State.NextToken; - const FormatToken &Previous = *State.NextToken->Previous; + FormatToken const &Previous = *State.NextToken->Previous; // Extra penalty that needs to be added because of the way certain line // breaks are chosen. unsigned Penalty = 0; - const FormatToken *PreviousNonComment = Current.getPreviousNonComment(); - const FormatToken *NextNonComment = Previous.getNextNonComment(); + FormatToken const *PreviousNonComment = Current.getPreviousNonComment(); + FormatToken const *NextNonComment = Previous.getNextNonComment(); if (!NextNonComment) NextNonComment = &Current; // The first line break on any NestingLevel causes an extra penalty in order @@ -914,17 +914,17 @@ return Penalty; } -unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { +unsigned ContinuationIndenter::getNewLineColumn(LineState const &State) { if (!State.NextToken || !State.NextToken->Previous) return 0; FormatToken &Current = *State.NextToken; - const FormatToken &Previous = *Current.Previous; + FormatToken const &Previous = *Current.Previous; // If we are continuing an expression, we want to use the continuation indent. unsigned ContinuationIndent = std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) + Style.ContinuationIndentWidth; - const FormatToken *PreviousNonComment = Current.getPreviousNonComment(); - const FormatToken *NextNonComment = Previous.getNextNonComment(); + FormatToken const *PreviousNonComment = Current.getPreviousNonComment(); + FormatToken const *NextNonComment = Previous.getNextNonComment(); if (!NextNonComment) NextNonComment = &Current; @@ -1082,7 +1082,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, bool DryRun, bool Newline) { assert(State.Stack.size()); - const FormatToken &Current = *State.NextToken; + FormatToken const &Current = *State.NextToken; if (Current.isOneOf(tok::comma, TT_BinaryOperator)) State.Stack.back().NoLineBreakInOperand = false; @@ -1105,7 +1105,7 @@ if (Style.BreakBeforeTernaryOperators && Current.is(tok::question)) State.Stack.back().QuestionColumn = State.Column; if (!Style.BreakBeforeTernaryOperators && Current.isNot(tok::colon)) { - const FormatToken *Previous = Current.Previous; + FormatToken const *Previous = Current.Previous; while (Previous && Previous->isTrailingComment()) Previous = Previous->Previous; if (Previous && Previous->is(tok::question)) @@ -1159,7 +1159,7 @@ State.Stack.back().LastSpace = State.Column; // Insert scopes created by fake parenthesis. - const FormatToken *Previous = Current.getPreviousNonComment(); + FormatToken const *Previous = Current.getPreviousNonComment(); // Add special behavior to support a format commonly used for JavaScript // closures: @@ -1223,8 +1223,8 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, bool Newline) { - const FormatToken &Current = *State.NextToken; - const FormatToken *Previous = Current.getPreviousNonComment(); + FormatToken const &Current = *State.NextToken; + FormatToken const *Previous = Current.getPreviousNonComment(); // Don't add extra indentation for the first fake parenthesis after // 'return', assignments or opening <({[. The indentation for these cases @@ -1304,7 +1304,7 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, bool Newline) { - const FormatToken &Current = *State.NextToken; + FormatToken const &Current = *State.NextToken; if (!Current.opensScope()) return; @@ -1327,7 +1327,7 @@ } else { NewIndent = State.Stack.back().LastSpace + Style.ContinuationIndentWidth; } - const FormatToken *NextNoComment = Current.getNextNonComment(); + FormatToken const *NextNoComment = Current.getNextNonComment(); bool EndsInComma = Current.MatchingParen && Current.MatchingParen->Previous && Current.MatchingParen->Previous->is(tok::comma); @@ -1390,7 +1390,7 @@ } else { // For ColumnLimit = 0, we have to figure out whether there is or has to // be a line break within this call. - for (const FormatToken *Tok = &Current; + for (FormatToken const *Tok = &Current; Tok && Tok != Current.MatchingParen; Tok = Tok->Next) { if (Tok->MustBreakBefore || (Tok->CanBreakBefore && Tok->NewlinesBefore > 0)) { @@ -1425,7 +1425,7 @@ } void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) { - const FormatToken &Current = *State.NextToken; + FormatToken const &Current = *State.NextToken; if (!Current.closesScope()) return; @@ -1450,7 +1450,7 @@ // line). if (State.Stack.back().BreakBeforeParameter && Current.MatchingParen && Current.MatchingParen->Previous) { - const FormatToken &CurrentScopeOpener = *Current.MatchingParen->Previous; + FormatToken const &CurrentScopeOpener = *Current.MatchingParen->Previous; if (CurrentScopeOpener.is(TT_ObjCMethodExpr) && CurrentScopeOpener.MatchingParen) { int NecessarySpaceInLine = @@ -1464,7 +1464,7 @@ if (Current.is(tok::r_square)) { // If this ends the array subscript expr, reset the corresponding value. - const FormatToken *NextNonComment = Current.getNextNonComment(); + FormatToken const *NextNonComment = Current.getNextNonComment(); if (NextNonComment && NextNonComment->isNot(tok::l_square)) State.Stack.back().StartOfArraySubscripts = 0; } @@ -1499,8 +1499,8 @@ } unsigned ContinuationIndenter::reformatRawStringLiteral( - const FormatToken &Current, LineState &State, - const FormatStyle &RawStringStyle, bool DryRun, bool Newline) { + FormatToken const &Current, LineState &State, + FormatStyle const &RawStringStyle, bool DryRun, bool Newline) { unsigned StartColumn = State.Column - Current.ColumnWidth; StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText); StringRef NewDelimiter = @@ -1647,7 +1647,7 @@ return Fixes.second + PrefixExcessCharacters * Style.PenaltyExcessCharacter; } -unsigned ContinuationIndenter::addMultilineToken(const FormatToken &Current, +unsigned ContinuationIndenter::addMultilineToken(FormatToken const &Current, LineState &State) { // Break before further function parameters on all levels. for (unsigned i = 0, e = State.Stack.size(); i != e; ++i) @@ -1663,7 +1663,7 @@ return 0; } -unsigned ContinuationIndenter::handleEndOfLine(const FormatToken &Current, +unsigned ContinuationIndenter::handleEndOfLine(FormatToken const &Current, LineState &State, bool DryRun, bool AllowBreak, bool Newline) { unsigned Penalty = 0; @@ -1719,7 +1719,7 @@ // Returns the enclosing function name of a token, or the empty string if not // found. -static StringRef getEnclosingFunctionName(const FormatToken &Current) { +static StringRef getEnclosingFunctionName(FormatToken const &Current) { // Look for: 'function(' or 'function(' before Current. auto Tok = Current.getPreviousNonComment(); if (!Tok || !Tok->is(tok::l_paren)) @@ -1738,8 +1738,8 @@ } llvm::Optional -ContinuationIndenter::getRawStringStyle(const FormatToken &Current, - const LineState &State) { +ContinuationIndenter::getRawStringStyle(FormatToken const &Current, + LineState const &State) { if (!Current.isStringLiteral()) return None; auto Delimiter = getRawStringDelimiter(Current.TokenText); @@ -1756,7 +1756,7 @@ } std::unique_ptr -ContinuationIndenter::createBreakableToken(const FormatToken &Current, +ContinuationIndenter::createBreakableToken(FormatToken const &Current, LineState &State, bool AllowBreak) { unsigned StartColumn = State.Column - Current.ColumnWidth; if (Current.isStringLiteral()) { @@ -1835,7 +1835,7 @@ } std::pair -ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, +ContinuationIndenter::breakProtrudingToken(FormatToken const &Current, LineState &State, bool AllowBreak, bool DryRun, bool Strict) { std::unique_ptr Token = @@ -2208,13 +2208,13 @@ return {Penalty, Exceeded}; } -unsigned ContinuationIndenter::getColumnLimit(const LineState &State) const { +unsigned ContinuationIndenter::getColumnLimit(LineState const &State) const { // In preprocessor directives reserve two chars for trailing " \" return Style.ColumnLimit - (State.Line->InPPDirective ? 2 : 0); } -bool ContinuationIndenter::nextIsMultilineString(const LineState &State) { - const FormatToken &Current = *State.NextToken; +bool ContinuationIndenter::nextIsMultilineString(LineState const &State) { + FormatToken const &Current = *State.NextToken; if (!Current.isStringLiteral() || Current.is(TT_ImplicitStringLiteral)) return false; // We never consider raw string literals "multiline" for the purpose of Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -596,7 +596,7 @@ if (!Seq.empty() && Seq[0].Language == FormatStyle::LK_None) { Template = Seq[0]; } else { - Template = *((const FormatStyle *)IO.getContext()); + Template = *((FormatStyle const *)IO.getContext()); Template.Language = FormatStyle::LK_None; } Seq.resize(Index + 1, Template); @@ -611,7 +611,7 @@ namespace format { const std::error_category &getParseCategory() { - static const ParseErrorCategory C{}; + static ParseErrorCategory const C{}; return C; } std::error_code make_error_code(ParseError e) { @@ -623,7 +623,7 @@ llvm::inconvertibleErrorCode()); } -const char *ParseErrorCategory::name() const noexcept { +char const *ParseErrorCategory::name() const noexcept { return "clang-format.parse_error"; } @@ -639,7 +639,7 @@ llvm_unreachable("unexpected parse error"); } -static FormatStyle expandPresets(const FormatStyle &Style) { +static FormatStyle expandPresets(FormatStyle const &Style) { if (Style.BreakBeforeBraces == FormatStyle::BS_Custom) return Style; FormatStyle Expanded = Style; @@ -1198,7 +1198,7 @@ return make_error_code(ParseError::Success); } -std::string configurationAsText(const FormatStyle &Style) { +std::string configurationAsText(FormatStyle const &Style) { std::string Text; llvm::raw_string_ostream Stream(Text); llvm::yaml::Output Output(Stream); @@ -1243,7 +1243,7 @@ class JavaScriptRequoter : public TokenAnalyzer { public: - JavaScriptRequoter(const Environment &Env, const FormatStyle &Style) + JavaScriptRequoter(Environment const &Env, FormatStyle const &Style) : TokenAnalyzer(Env, Style) {} std::pair @@ -1330,7 +1330,7 @@ class Formatter : public TokenAnalyzer { public: - Formatter(const Environment &Env, const FormatStyle &Style, + Formatter(Environment const &Env, FormatStyle const &Style, FormattingAttemptStatus *Status) : TokenAnalyzer(Env, Style), Status(Status) {} @@ -1374,8 +1374,8 @@ } bool - hasCpp03IncompatibleFormat(const SmallVectorImpl &Lines) { - for (const AnnotatedLine *Line : Lines) { + hasCpp03IncompatibleFormat(SmallVectorImpl const &Lines) { + for (AnnotatedLine const *Line : Lines) { if (hasCpp03IncompatibleFormat(Line->Children)) return true; for (FormatToken *Tok = Line->First->Next; Tok; Tok = Tok->Next) { @@ -1391,9 +1391,9 @@ return false; } - int countVariableAlignments(const SmallVectorImpl &Lines) { + int countVariableAlignments(SmallVectorImpl const &Lines) { int AlignmentDiff = 0; - for (const AnnotatedLine *Line : Lines) { + for (AnnotatedLine const *Line : Lines) { AlignmentDiff += countVariableAlignments(Line->Children); for (FormatToken *Tok = Line->First; Tok && Tok->Next; Tok = Tok->Next) { if (!Tok->is(TT_PointerOrReference)) @@ -1412,7 +1412,7 @@ } void - deriveLocalStyle(const SmallVectorImpl &AnnotatedLines) { + deriveLocalStyle(SmallVectorImpl const &AnnotatedLines) { bool HasBinPackedFunction = false; bool HasOnePerLineFunction = false; for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) { @@ -1448,7 +1448,7 @@ // file. class Cleaner : public TokenAnalyzer { public: - Cleaner(const Environment &Env, const FormatStyle &Style) + Cleaner(Environment const &Env, FormatStyle const &Style) : TokenAnalyzer(Env, Style), DeletedTokens(FormatTokenLess(Env.getSourceManager())) {} @@ -1491,7 +1491,7 @@ } } - bool containsOnlyComments(const AnnotatedLine &Line) { + bool containsOnlyComments(AnnotatedLine const &Line) { for (FormatToken *Tok = Line.First; Tok != nullptr; Tok = Tok->Next) { if (Tok->isNot(tok::comment)) return false; @@ -1582,7 +1582,7 @@ template void cleanupPair(FormatToken *Start, LeftKind LK, RightKind RK, bool DeleteLeft) { - auto NextNotDeleted = [this](const FormatToken &Tok) -> FormatToken * { + auto NextNotDeleted = [this](FormatToken const &Tok) -> FormatToken * { for (auto *Res = Tok.Next; Res; Res = Res->Next) if (!Res->is(tok::comment) && DeletedTokens.find(Res) == DeletedTokens.end()) @@ -1658,13 +1658,13 @@ // We store tokens in the order they appear in the translation unit so that // we do not need to sort them in `generateFixes()`. struct FormatTokenLess { - FormatTokenLess(const SourceManager &SM) : SM(SM) {} + FormatTokenLess(SourceManager const &SM) : SM(SM) {} - bool operator()(const FormatToken *LHS, const FormatToken *RHS) const { + bool operator()(FormatToken const *LHS, FormatToken const *RHS) const { return SM.isBeforeInTranslationUnit(LHS->Tok.getLocation(), RHS->Tok.getLocation()); } - const SourceManager &SM; + SourceManager const &SM; }; // Tokens to be deleted. @@ -1673,7 +1673,7 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer { public: - ObjCHeaderStyleGuesser(const Environment &Env, const FormatStyle &Style) + ObjCHeaderStyleGuesser(Environment const &Env, FormatStyle const &Style) : TokenAnalyzer(Env, Style), IsObjC(false) {} std::pair @@ -1691,9 +1691,9 @@ private: static bool - guessIsObjC(const SourceManager &SourceManager, - const SmallVectorImpl &AnnotatedLines, - const AdditionalKeywords &Keywords) { + guessIsObjC(SourceManager const &SourceManager, + SmallVectorImpl const &AnnotatedLines, + AdditionalKeywords const &Keywords) { // Keep this array sorted, since we are binary searching over it. static constexpr llvm::StringLiteral FoundationIdentifiers[] = { "CGFloat", @@ -1769,7 +1769,7 @@ }; for (auto Line : AnnotatedLines) { - for (const FormatToken *FormatTok = Line->First; FormatTok; + for (FormatToken const *FormatTok = Line->First; FormatTok; FormatTok = FormatTok->Next) { if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) && (FormatTok->Tok.getObjCKeywordID() != tok::objc_not_keyword || @@ -1840,8 +1840,8 @@ // its current line. // If `Cursor` is not on any #include, `Index` will be UINT_MAX. static std::pair -FindCursorIndex(const SmallVectorImpl &Includes, - const SmallVectorImpl &Indices, unsigned Cursor) { +FindCursorIndex(SmallVectorImpl const &Includes, + SmallVectorImpl const &Indices, unsigned Cursor) { unsigned CursorIndex = UINT_MAX; unsigned OffsetToEOL = 0; for (int i = 0, e = Includes.size(); i != e; ++i) { @@ -1889,8 +1889,8 @@ // first #include in the duplicate #includes remains. If the `Cursor` is // provided and put on a deleted #include, it will be moved to the remaining // #include in the duplicate #includes. -static void sortCppIncludes(const FormatStyle &Style, - const SmallVectorImpl &Includes, +static void sortCppIncludes(FormatStyle const &Style, + SmallVectorImpl const &Includes, ArrayRef Ranges, StringRef FileName, StringRef Code, tooling::Replacements &Replaces, unsigned *Cursor) { @@ -1971,12 +1971,12 @@ namespace { -const char CppIncludeRegexPattern[] = +char const CppIncludeRegexPattern[] = R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))"; } // anonymous namespace -tooling::Replacements sortCppIncludes(const FormatStyle &Style, StringRef Code, +tooling::Replacements sortCppIncludes(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName, tooling::Replacements &Replaces, @@ -2011,7 +2011,7 @@ Trimmed == "/* clang-format on */") FormattingOff = false; - const bool EmptyLineSkipped = + bool const EmptyLineSkipped = Trimmed.empty() && (Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Merge || Style.IncludeStyle.IncludeBlocks == @@ -2050,7 +2050,7 @@ // Returns group number to use as a first order sort on imports. Gives UINT_MAX // if the import does not match any given groups. -static unsigned findJavaImportGroup(const FormatStyle &Style, +static unsigned findJavaImportGroup(FormatStyle const &Style, StringRef ImportIdentifier) { unsigned LongestMatchIndex = UINT_MAX; unsigned LongestMatchLength = 0; @@ -2070,8 +2070,8 @@ // Import declarations with the same text will be deduplicated. Between each // import group, a newline is inserted, and within each import group, a // lexicographic sort based on ASCII value is performed. -static void sortJavaImports(const FormatStyle &Style, - const SmallVectorImpl &Imports, +static void sortJavaImports(FormatStyle const &Style, + SmallVectorImpl const &Imports, ArrayRef Ranges, StringRef FileName, StringRef Code, tooling::Replacements &Replaces) { unsigned ImportsBeginOffset = Imports.front().Offset; @@ -2140,12 +2140,12 @@ namespace { -const char JavaImportRegexPattern[] = +char const JavaImportRegexPattern[] = "^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;"; } // anonymous namespace -tooling::Replacements sortJavaImports(const FormatStyle &Style, StringRef Code, +tooling::Replacements sortJavaImports(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName, tooling::Replacements &Replaces) { @@ -2207,7 +2207,7 @@ bool isLikelyXml(StringRef Code) { return Code.ltrim().startswith("<"); } -tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, +tooling::Replacements sortIncludes(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName, unsigned *Cursor) { tooling::Replacements Replaces; @@ -2230,7 +2230,7 @@ static llvm::Expected processReplacements(T ProcessFunc, StringRef Code, const tooling::Replacements &Replaces, - const FormatStyle &Style) { + FormatStyle const &Style) { if (Replaces.empty()) return tooling::Replacements(); @@ -2248,10 +2248,10 @@ llvm::Expected formatReplacements(StringRef Code, const tooling::Replacements &Replaces, - const FormatStyle &Style) { + FormatStyle const &Style) { // We need to use lambda function here since there are two versions of // `sortIncludes`. - auto SortIncludes = [](const FormatStyle &Style, StringRef Code, + auto SortIncludes = [](FormatStyle const &Style, StringRef Code, std::vector Ranges, StringRef FileName) -> tooling::Replacements { return sortIncludes(Style, Code, Ranges, FileName); @@ -2263,7 +2263,7 @@ // We need to use lambda function here since there are two versions of // `reformat`. - auto Reformat = [](const FormatStyle &Style, StringRef Code, + auto Reformat = [](FormatStyle const &Style, StringRef Code, std::vector Ranges, StringRef FileName) -> tooling::Replacements { return reformat(Style, Code, Ranges, FileName); @@ -2286,7 +2286,7 @@ // FIXME: insert empty lines between newly created blocks. tooling::Replacements fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces, - const FormatStyle &Style) { + FormatStyle const &Style) { if (!Style.isCpp()) return Replaces; @@ -2358,10 +2358,10 @@ llvm::Expected cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, - const FormatStyle &Style) { + FormatStyle const &Style) { // We need to use lambda function here since there are two versions of // `cleanup`. - auto Cleanup = [](const FormatStyle &Style, StringRef Code, + auto Cleanup = [](FormatStyle const &Style, StringRef Code, std::vector Ranges, StringRef FileName) -> tooling::Replacements { return cleanup(Style, Code, Ranges, FileName); @@ -2374,7 +2374,7 @@ namespace internal { std::pair -reformat(const FormatStyle &Style, StringRef Code, +reformat(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, unsigned FirstStartColumn, unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName, FormattingAttemptStatus *Status) { @@ -2387,29 +2387,29 @@ return {tooling::Replacements(), 0}; typedef std::function( - const Environment &)> + Environment const &)> AnalyzerPass; SmallVector Passes; if (Style.Language == FormatStyle::LK_Cpp) { if (Style.FixNamespaceComments) - Passes.emplace_back([&](const Environment &Env) { + Passes.emplace_back([&](Environment const &Env) { return NamespaceEndCommentsFixer(Env, Expanded).process(); }); if (Style.SortUsingDeclarations) - Passes.emplace_back([&](const Environment &Env) { + Passes.emplace_back([&](Environment const &Env) { return UsingDeclarationsSorter(Env, Expanded).process(); }); } if (Style.Language == FormatStyle::LK_JavaScript && Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) - Passes.emplace_back([&](const Environment &Env) { + Passes.emplace_back([&](Environment const &Env) { return JavaScriptRequoter(Env, Expanded).process(); }); - Passes.emplace_back([&](const Environment &Env) { + Passes.emplace_back([&](Environment const &Env) { return Formatter(Env, Expanded, Status).process(); }); @@ -2440,7 +2440,7 @@ } } // namespace internal -tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, +tooling::Replacements reformat(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName, FormattingAttemptStatus *Status) { @@ -2451,7 +2451,7 @@ .first; } -tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, +tooling::Replacements cleanup(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName) { // cleanups only apply to C++ (they mostly concern ctor commas etc.) @@ -2460,7 +2460,7 @@ return Cleaner(Environment(Code, FileName, Ranges), Style).process().first; } -tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, +tooling::Replacements reformat(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName, bool *IncompleteFormat) { FormattingAttemptStatus Status; @@ -2470,7 +2470,7 @@ return Result; } -tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style, +tooling::Replacements fixNamespaceEndComments(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName) { @@ -2479,7 +2479,7 @@ .first; } -tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, +tooling::Replacements sortUsingDeclarations(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName) { @@ -2488,7 +2488,7 @@ .first; } -LangOptions getFormattingLangOpts(const FormatStyle &Style) { +LangOptions getFormattingLangOpts(FormatStyle const &Style) { LangOptions LangOpts; FormatStyle::LanguageStandard LexingStd = Style.Standard; @@ -2512,7 +2512,7 @@ return LangOpts; } -const char *StyleOptionHelpDescription = +char const *StyleOptionHelpDescription = "Coding style, currently supports:\n" " LLVM, Google, Chromium, Mozilla, WebKit.\n" "Use -style=file to load style configuration from\n" @@ -2564,9 +2564,9 @@ return GuessedLanguage; } -const char *DefaultFormatStyle = "file"; +char const *DefaultFormatStyle = "file"; -const char *DefaultFallbackStyle = "LLVM"; +char const *DefaultFallbackStyle = "LLVM"; llvm::Expected getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyleName, Index: clang/lib/Format/FormatInternal.h =================================================================== --- clang/lib/Format/FormatInternal.h +++ clang/lib/Format/FormatInternal.h @@ -70,7 +70,7 @@ /// If ``Status`` is non-null, its value will be populated with the status of /// this formatting attempt. See \c FormattingAttemptStatus. std::pair -reformat(const FormatStyle &Style, StringRef Code, +reformat(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, unsigned FirstStartColumn, unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName, FormattingAttemptStatus *Status); Index: clang/lib/Format/FormatToken.h =================================================================== --- clang/lib/Format/FormatToken.h +++ clang/lib/Format/FormatToken.h @@ -111,7 +111,7 @@ }; /// Determines the name of a token type. -const char *getTokenTypeName(TokenType Type); +char const *getTokenTypeName(TokenType Type); // Represents what type of block a set of braces open. enum BraceBlockKind { BK_Unknown, BK_Block, BK_BracedInit }; @@ -311,7 +311,7 @@ bool is(tok::TokenKind Kind) const { return Tok.is(Kind); } bool is(TokenType TT) const { return Type == TT; } - bool is(const IdentifierInfo *II) const { + bool is(IdentifierInfo const *II) const { return II && II == Tok.getIdentifierInfo(); } bool is(tok::PPKeywordKind Kind) const { @@ -492,8 +492,8 @@ } /// Returns the next token ignoring comments. - const FormatToken *getNextNonComment() const { - const FormatToken *Tok = Next; + FormatToken const *getNextNonComment() const { + FormatToken const *Tok = Next; while (Tok && Tok->is(tok::comment)) Tok = Tok->Next; return Tok; @@ -501,7 +501,7 @@ /// Returns \c true if this tokens starts a block-type list, i.e. a /// list that should be indented with a block indent. - bool opensBlockOrBlockTypeList(const FormatStyle &Style) const { + bool opensBlockOrBlockTypeList(FormatStyle const &Style) const { if (is(TT_TemplateString) && opensScope()) return true; return is(TT_ArrayInitializerLSquare) || is(TT_ProtoExtensionLSquare) || @@ -514,10 +514,10 @@ /// Returns whether the token is the left square bracket of a C++ /// structured binding declaration. - bool isCppStructuredBinding(const FormatStyle &Style) const { + bool isCppStructuredBinding(FormatStyle const &Style) const { if (!Style.isCpp() || isNot(tok::l_square)) return false; - const FormatToken *T = this; + FormatToken const *T = this; do { T = T->getPreviousNonComment(); } while (T && T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp, @@ -526,7 +526,7 @@ } /// Same as opensBlockOrBlockTypeList, but for the closing token. - bool closesBlockOrBlockTypeList(const FormatStyle &Style) const { + bool closesBlockOrBlockTypeList(FormatStyle const &Style) const { if (is(TT_TemplateString) && closesScope()) return true; return MatchingParen && MatchingParen->opensBlockOrBlockTypeList(Style); @@ -534,8 +534,8 @@ /// Return the actual namespace token, if this token starts a namespace /// block. - const FormatToken *getNamespaceToken() const { - const FormatToken *NamespaceTok = this; + FormatToken const *getNamespaceToken() const { + FormatToken const *NamespaceTok = this; if (is(tok::comment)) NamespaceTok = NamespaceTok->getNextNonComment(); // Detect "(inline|export)? namespace" in the beginning of a line. @@ -549,8 +549,8 @@ private: // Disallow copying. - FormatToken(const FormatToken &) = delete; - void operator=(const FormatToken &) = delete; + FormatToken(FormatToken const &) = delete; + void operator=(FormatToken const &) = delete; template bool startsSequenceInternal(A K1, Ts... Tokens) const { @@ -584,12 +584,12 @@ class TokenRole { public: - TokenRole(const FormatStyle &Style) : Style(Style) {} + TokenRole(FormatStyle const &Style) : Style(Style) {} virtual ~TokenRole(); /// After the \c TokenAnnotator has finished annotating all the tokens, /// this function precomputes required information for formatting. - virtual void precomputeFormattingInfos(const FormatToken *Token); + virtual void precomputeFormattingInfos(FormatToken const *Token); /// Apply the special formatting that the given role demands. /// @@ -612,20 +612,20 @@ } /// Notifies the \c Role that a comma was found. - virtual void CommaFound(const FormatToken *Token) {} + virtual void CommaFound(FormatToken const *Token) {} - virtual const FormatToken *lastComma() { return nullptr; } + virtual FormatToken const *lastComma() { return nullptr; } protected: - const FormatStyle &Style; + FormatStyle const &Style; }; class CommaSeparatedList : public TokenRole { public: - CommaSeparatedList(const FormatStyle &Style) + CommaSeparatedList(FormatStyle const &Style) : TokenRole(Style), HasNestedBracedList(false) {} - void precomputeFormattingInfos(const FormatToken *Token) override; + void precomputeFormattingInfos(FormatToken const *Token) override; unsigned formatAfterToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) override; @@ -634,11 +634,11 @@ bool DryRun) override; /// Adds \p Token as the next comma to the \c CommaSeparated list. - void CommaFound(const FormatToken *Token) override { + void CommaFound(FormatToken const *Token) override { Commas.push_back(Token); } - const FormatToken *lastComma() override { + FormatToken const *lastComma() override { if (Commas.empty()) return nullptr; return Commas.back(); @@ -663,10 +663,10 @@ /// Calculate which \c ColumnFormat fits best into /// \p RemainingCharacters. - const ColumnFormat *getColumnFormat(unsigned RemainingCharacters) const; + ColumnFormat const *getColumnFormat(unsigned RemainingCharacters) const; /// The ordered \c FormatTokens making up the commas of this list. - SmallVector Commas; + SmallVector Commas; /// The length of each of the list's items in characters including the /// trailing comma. @@ -891,7 +891,7 @@ /// Returns \c true if \p Tok is a true JavaScript identifier, returns /// \c false if it is a keyword or a pseudo keyword. - bool IsJavaScriptIdentifier(const FormatToken &Tok) const { + bool IsJavaScriptIdentifier(FormatToken const &Tok) const { return Tok.is(tok::identifier) && JsExtraKeywords.find(Tok.Tok.getIdentifierInfo()) == JsExtraKeywords.end(); @@ -899,7 +899,7 @@ /// Returns \c true if \p Tok is a C# keyword, returns /// \c false if it is a anything else. - bool isCSharpKeyword(const FormatToken &Tok) const { + bool isCSharpKeyword(FormatToken const &Tok) const { switch (Tok.Tok.getKind()) { case tok::kw_bool: case tok::kw_break: Index: clang/lib/Format/FormatToken.cpp =================================================================== --- clang/lib/Format/FormatToken.cpp +++ clang/lib/Format/FormatToken.cpp @@ -21,8 +21,8 @@ namespace clang { namespace format { -const char *getTokenTypeName(TokenType Type) { - static const char *const TokNames[] = { +char const *getTokenTypeName(TokenType Type) { + static char const *const TokNames[] = { #define TYPE(X) #X, LIST_TOKEN_TYPES #undef TYPE @@ -69,7 +69,7 @@ TokenRole::~TokenRole() {} -void TokenRole::precomputeFormattingInfos(const FormatToken *Token) {} +void TokenRole::precomputeFormattingInfos(FormatToken const *Token) {} unsigned CommaSeparatedList::formatAfterToken(LineState &State, ContinuationIndenter *Indenter, @@ -81,7 +81,7 @@ return 0; // Handled by formatFromToken // Ensure that we start on the opening brace. - const FormatToken *LBrace = + FormatToken const *LBrace = State.NextToken->Previous->getPreviousNonComment(); if (!LBrace || !LBrace->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) || LBrace->BlockKind == BK_Block || LBrace->Type == TT_DictLiteral || @@ -94,7 +94,7 @@ 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); + ColumnFormat const *Format = getColumnFormat(RemainingCodePoints); // If no ColumnFormat can be used, the braced list would generally be // bin-packed. Add a severe penalty to this so that column layouts are @@ -142,13 +142,13 @@ // Returns the lengths in code points between Begin and End (both included), // assuming that the entire sequence is put on a single line. -static unsigned CodePointsBetween(const FormatToken *Begin, - const FormatToken *End) { +static unsigned CodePointsBetween(FormatToken const *Begin, + FormatToken const *End) { assert(End->TotalLength >= Begin->TotalLength); return End->TotalLength - Begin->TotalLength + Begin->ColumnWidth; } -void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { +void CommaSeparatedList::precomputeFormattingInfos(FormatToken const *Token) { // FIXME: At some point we might want to do this for other lists, too. if (!Token->MatchingParen || !Token->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) @@ -191,10 +191,10 @@ MustBreakBeforeItem.push_back(ItemBegin->MustBreakBefore); if (ItemBegin->is(tok::l_brace)) HasNestedBracedList = true; - const FormatToken *ItemEnd = nullptr; + FormatToken const *ItemEnd = nullptr; if (i == Commas.size()) { ItemEnd = Token->MatchingParen; - const FormatToken *NonCommentEnd = ItemEnd->getPreviousNonComment(); + FormatToken const *NonCommentEnd = ItemEnd->getPreviousNonComment(); ItemLengths.push_back(CodePointsBetween(ItemBegin, NonCommentEnd)); if (Style.Cpp11BracedListStyle && !ItemEnd->Previous->isTrailingComment()) { @@ -288,7 +288,7 @@ const CommaSeparatedList::ColumnFormat * CommaSeparatedList::getColumnFormat(unsigned RemainingCharacters) const { - const ColumnFormat *BestFormat = nullptr; + ColumnFormat const *BestFormat = nullptr; for (SmallVector::const_reverse_iterator I = Formats.rbegin(), E = Formats.rend(); Index: clang/lib/Format/FormatTokenLexer.h =================================================================== --- clang/lib/Format/FormatTokenLexer.h +++ clang/lib/Format/FormatTokenLexer.h @@ -36,12 +36,12 @@ class FormatTokenLexer { public: - FormatTokenLexer(const SourceManager &SourceMgr, FileID ID, unsigned Column, - const FormatStyle &Style, encoding::Encoding Encoding); + FormatTokenLexer(SourceManager const &SourceMgr, FileID ID, unsigned Column, + FormatStyle const &Style, encoding::Encoding Encoding); ArrayRef lex(); - const AdditionalKeywords &getKeywords() { return Keywords; } + AdditionalKeywords const &getKeywords() { return Keywords; } private: void tryMergePreviousTokens(); @@ -95,9 +95,9 @@ unsigned Column; unsigned TrailingWhitespace; std::unique_ptr Lex; - const SourceManager &SourceMgr; + SourceManager const &SourceMgr; FileID ID; - const FormatStyle &Style; + FormatStyle const &Style; IdentifierTable IdentTable; AdditionalKeywords Keywords; encoding::Encoding Encoding; Index: clang/lib/Format/FormatTokenLexer.cpp =================================================================== --- clang/lib/Format/FormatTokenLexer.cpp +++ clang/lib/Format/FormatTokenLexer.cpp @@ -22,8 +22,8 @@ namespace clang { namespace format { -FormatTokenLexer::FormatTokenLexer(const SourceManager &SourceMgr, FileID ID, - unsigned Column, const FormatStyle &Style, +FormatTokenLexer::FormatTokenLexer(SourceManager const &SourceMgr, FileID ID, + unsigned Column, FormatStyle const &Style, encoding::Encoding Encoding) : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}), Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID), @@ -379,8 +379,8 @@ return; // 'Manually' lex ahead in the current file buffer. - const char *Offset = Lex->getBufferLocation(); - const char *RegexBegin = Offset - RegexToken->TokenText.size(); + char const *Offset = Lex->getBufferLocation(); + char const *RegexBegin = Offset - RegexToken->TokenText.size(); StringRef Buffer = Lex->getBuffer(); bool InCharacterClass = false; bool HaveClosingSlash = false; @@ -437,8 +437,8 @@ } // 'Manually' lex ahead in the current file buffer. - const char *Offset = Lex->getBufferLocation(); - const char *TmplBegin = Offset - BacktickToken->TokenText.size(); // at "`" + char const *Offset = Lex->getBufferLocation(); + char const *TmplBegin = Offset - BacktickToken->TokenText.size(); // at "`" for (; Offset != Lex->getBuffer().end(); ++Offset) { if (Offset[0] == '`') { StateStack.pop(); @@ -487,7 +487,7 @@ if (!HashToken->isOneOf(tok::hash, tok::hashhash)) return; // Turn the remainder of this line into a comment. - const char *CommentBegin = + char const *CommentBegin = Lex->getBufferLocation() - HashToken->TokenText.size(); // at "#" size_t From = CommentBegin - Lex->getBuffer().begin(); size_t To = Lex->getBuffer().find_first_of('\n', From); @@ -521,8 +521,8 @@ if (Macro->TokenText != "_T") return false; - const char *Start = Macro->TokenText.data(); - const char *End = Last->TokenText.data() + Last->TokenText.size(); + char const *Start = Macro->TokenText.data(); + char const *End = Last->TokenText.data() + Last->TokenText.size(); String->TokenText = StringRef(Start, End - Start); String->IsFirst = Macro->IsFirst; String->LastNewlineOffset = Macro->LastNewlineOffset; @@ -710,7 +710,7 @@ while (BackslashPos != StringRef::npos) { if (BackslashPos + 1 < FormatTok->TokenText.size() && FormatTok->TokenText[BackslashPos + 1] == '\n') { - const char *Offset = Lex->getBufferLocation(); + char const *Offset = Lex->getBufferLocation(); Offset -= FormatTok->TokenText.size(); Offset += BackslashPos + 1; resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset))); Index: clang/lib/Format/NamespaceEndCommentsFixer.h =================================================================== --- clang/lib/Format/NamespaceEndCommentsFixer.h +++ clang/lib/Format/NamespaceEndCommentsFixer.h @@ -26,13 +26,13 @@ // a preprocessor directive, the result will be the matching namespace token. // Otherwise returns null. // \p AnnotatedLines is the sequence of lines from which \p Line is a member of. -const FormatToken * -getNamespaceToken(const AnnotatedLine *Line, - const SmallVectorImpl &AnnotatedLines); +FormatToken const * +getNamespaceToken(AnnotatedLine const *Line, + SmallVectorImpl const &AnnotatedLines); class NamespaceEndCommentsFixer : public TokenAnalyzer { public: - NamespaceEndCommentsFixer(const Environment &Env, const FormatStyle &Style); + NamespaceEndCommentsFixer(Environment const &Env, FormatStyle const &Style); std::pair analyze(TokenAnnotator &Annotator, Index: clang/lib/Format/NamespaceEndCommentsFixer.cpp =================================================================== --- clang/lib/Format/NamespaceEndCommentsFixer.cpp +++ clang/lib/Format/NamespaceEndCommentsFixer.cpp @@ -24,16 +24,16 @@ namespace { // The maximal number of unwrapped lines that a short namespace spans. // Short namespaces don't need an end comment. -static const int kShortNamespaceMaxLines = 1; +static int const kShortNamespaceMaxLines = 1; // Computes the name of a namespace given the namespace token. // Returns "" for anonymous namespace. -std::string computeName(const FormatToken *NamespaceTok) { +std::string computeName(FormatToken const *NamespaceTok) { assert(NamespaceTok && NamespaceTok->isOneOf(tok::kw_namespace, TT_NamespaceMacro) && "expecting a namespace token"); std::string name = ""; - const FormatToken *Tok = NamespaceTok->getNextNonComment(); + FormatToken const *Tok = NamespaceTok->getNextNonComment(); if (NamespaceTok->is(TT_NamespaceMacro)) { // Collects all the non-comment tokens between opening parenthesis // and closing parenthesis or comma. @@ -48,7 +48,7 @@ // `namespace MACRO1 MACRO2 A::B::inline C {`, returns "A::B::inline C". // Peek for the first '::' (or '{') and then return all tokens from one // token before that up until the '{'. - const FormatToken *FirstNSTok = Tok; + FormatToken const *FirstNSTok = Tok; while (Tok && !Tok->is(tok::l_brace) && !Tok->is(tok::coloncolon)) { FirstNSTok = Tok; Tok = Tok->getNextNonComment(); @@ -66,7 +66,7 @@ } std::string computeEndCommentText(StringRef NamespaceName, bool AddNewline, - const FormatToken *NamespaceTok) { + FormatToken const *NamespaceTok) { std::string text = "// "; text += NamespaceTok->TokenText; if (NamespaceTok->is(TT_NamespaceMacro)) @@ -81,14 +81,14 @@ return text; } -bool hasEndComment(const FormatToken *RBraceTok) { +bool hasEndComment(FormatToken const *RBraceTok) { return RBraceTok->Next && RBraceTok->Next->is(tok::comment); } -bool validEndComment(const FormatToken *RBraceTok, StringRef NamespaceName, - const FormatToken *NamespaceTok) { +bool validEndComment(FormatToken const *RBraceTok, StringRef NamespaceName, + FormatToken const *NamespaceTok) { assert(hasEndComment(RBraceTok)); - const FormatToken *Comment = RBraceTok->Next; + FormatToken const *Comment = RBraceTok->Next; // Matches a valid namespace end comment. // Valid namespace end comments don't need to be edited. @@ -124,8 +124,8 @@ return NamespaceNameInComment == NamespaceName; } -void addEndComment(const FormatToken *RBraceTok, StringRef EndCommentText, - const SourceManager &SourceMgr, +void addEndComment(FormatToken const *RBraceTok, StringRef EndCommentText, + SourceManager const &SourceMgr, tooling::Replacements *Fixes) { auto EndLoc = RBraceTok->Tok.getEndLoc(); auto Range = CharSourceRange::getCharRange(EndLoc, EndLoc); @@ -136,11 +136,11 @@ } } -void updateEndComment(const FormatToken *RBraceTok, StringRef EndCommentText, - const SourceManager &SourceMgr, +void updateEndComment(FormatToken const *RBraceTok, StringRef EndCommentText, + SourceManager const &SourceMgr, tooling::Replacements *Fixes) { assert(hasEndComment(RBraceTok)); - const FormatToken *Comment = RBraceTok->Next; + FormatToken const *Comment = RBraceTok->Next; auto Range = CharSourceRange::getCharRange(Comment->getStartOfNonWhitespace(), Comment->Tok.getEndLoc()); auto Err = Fixes->add(tooling::Replacement(SourceMgr, Range, EndCommentText)); @@ -151,16 +151,16 @@ } } // namespace -const FormatToken * -getNamespaceToken(const AnnotatedLine *Line, - const SmallVectorImpl &AnnotatedLines) { +FormatToken const * +getNamespaceToken(AnnotatedLine const *Line, + SmallVectorImpl const &AnnotatedLines) { if (!Line->Affected || Line->InPPDirective || !Line->startsWith(tok::r_brace)) return nullptr; size_t StartLineIndex = Line->MatchingOpeningBlockLineIndex; if (StartLineIndex == UnwrappedLine::kInvalidIndex) return nullptr; assert(StartLineIndex < AnnotatedLines.size()); - const FormatToken *NamespaceTok = AnnotatedLines[StartLineIndex]->First; + FormatToken const *NamespaceTok = AnnotatedLines[StartLineIndex]->First; if (NamespaceTok->is(tok::l_brace)) { // "namespace" keyword can be on the line preceding '{', e.g. in styles // where BraceWrapping.AfterNamespace is true. @@ -171,20 +171,20 @@ } StringRef -getNamespaceTokenText(const AnnotatedLine *Line, - const SmallVectorImpl &AnnotatedLines) { - const FormatToken *NamespaceTok = getNamespaceToken(Line, AnnotatedLines); +getNamespaceTokenText(AnnotatedLine const *Line, + SmallVectorImpl const &AnnotatedLines) { + FormatToken const *NamespaceTok = getNamespaceToken(Line, AnnotatedLines); return NamespaceTok ? NamespaceTok->TokenText : StringRef(); } -NamespaceEndCommentsFixer::NamespaceEndCommentsFixer(const Environment &Env, - const FormatStyle &Style) +NamespaceEndCommentsFixer::NamespaceEndCommentsFixer(Environment const &Env, + FormatStyle const &Style) : TokenAnalyzer(Env, Style) {} std::pair NamespaceEndCommentsFixer::analyze( TokenAnnotator &Annotator, SmallVectorImpl &AnnotatedLines, FormatTokenLexer &Tokens) { - const SourceManager &SourceMgr = Env.getSourceManager(); + SourceManager const &SourceMgr = Env.getSourceManager(); AffectedRangeMgr.computeAffectedLines(AnnotatedLines); tooling::Replacements Fixes; std::string AllNamespaceNames = ""; @@ -192,8 +192,8 @@ StringRef NamespaceTokenText; unsigned int CompactedNamespacesCount = 0; for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) { - const AnnotatedLine *EndLine = AnnotatedLines[I]; - const FormatToken *NamespaceTok = + AnnotatedLine const *EndLine = AnnotatedLines[I]; + FormatToken const *NamespaceTok = getNamespaceToken(EndLine, AnnotatedLines); if (!NamespaceTok) continue; @@ -201,7 +201,7 @@ if (RBraceTok->Finalized) continue; RBraceTok->Finalized = true; - const FormatToken *EndCommentPrevTok = RBraceTok; + FormatToken const *EndCommentPrevTok = RBraceTok; // Namespaces often end with '};'. In that case, attach namespace end // comments to the semicolon tokens. if (RBraceTok->Next && RBraceTok->Next->is(tok::semi)) { @@ -234,7 +234,7 @@ // The next token in the token stream after the place where the end comment // token must be. This is either the next token on the current line or the // first token on the next line. - const FormatToken *EndCommentNextTok = EndCommentPrevTok->Next; + FormatToken const *EndCommentNextTok = EndCommentPrevTok->Next; if (EndCommentNextTok && EndCommentNextTok->is(tok::comment)) EndCommentNextTok = EndCommentNextTok->Next; if (!EndCommentNextTok && I + 1 < E) Index: clang/lib/Format/SortJavaScriptImports.h =================================================================== --- clang/lib/Format/SortJavaScriptImports.h +++ clang/lib/Format/SortJavaScriptImports.h @@ -24,7 +24,7 @@ // Sort JavaScript ES6 imports/exports in ``Code``. The generated replacements // only monotonically increase the length of the given code. -tooling::Replacements sortJavaScriptImports(const FormatStyle &Style, +tooling::Replacements sortJavaScriptImports(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName); Index: clang/lib/Format/SortJavaScriptImports.cpp =================================================================== --- clang/lib/Format/SortJavaScriptImports.cpp +++ clang/lib/Format/SortJavaScriptImports.cpp @@ -41,7 +41,7 @@ StringRef Alias; SourceRange Range; - bool operator==(const JsImportedSymbol &RHS) const { + bool operator==(JsImportedSymbol const &RHS) const { // Ignore Range for comparison, it is only used to stitch code together, // but imports at different code locations are still conceptually the same. return Symbol == RHS.Symbol && Alias == RHS.Alias; @@ -90,7 +90,7 @@ SourceRange Range; }; -bool operator<(const JsModuleReference &LHS, const JsModuleReference &RHS) { +bool operator<(JsModuleReference const &LHS, JsModuleReference const &RHS) { if (LHS.IsExport != RHS.IsExport) return LHS.IsExport < RHS.IsExport; if (LHS.Category != RHS.Category) @@ -118,7 +118,7 @@ // structure, making it messy to sort them using regular expressions. class JavaScriptImportSorter : public TokenAnalyzer { public: - JavaScriptImportSorter(const Environment &Env, const FormatStyle &Style) + JavaScriptImportSorter(Environment const &Env, FormatStyle const &Style) : TokenAnalyzer(Env, Style), FileContents(Env.getSourceManager().getBufferData(Env.getFileID())) {} @@ -129,7 +129,7 @@ tooling::Replacements Result; AffectedRangeMgr.computeAffectedLines(AnnotatedLines); - const AdditionalKeywords &Keywords = Tokens.getKeywords(); + AdditionalKeywords const &Keywords = Tokens.getKeywords(); SmallVector References; AnnotatedLine *FirstNonImportLine; std::tie(References, FirstNonImportLine) = @@ -234,7 +234,7 @@ } StringRef getSourceText(SourceLocation Begin, SourceLocation End) { - const SourceManager &SM = Env.getSourceManager(); + SourceManager const &SM = Env.getSourceManager(); return FileContents.substr(SM.getFileOffset(Begin), SM.getFileOffset(End) - SM.getFileOffset(Begin)); } @@ -246,7 +246,7 @@ // E.g. `import {b, a} from 'x';` -> `import {a, b} from 'x';` SmallVector Symbols = Reference.Symbols; llvm::stable_sort( - Symbols, [&](const JsImportedSymbol &LHS, const JsImportedSymbol &RHS) { + Symbols, [&](JsImportedSymbol const &LHS, JsImportedSymbol const &RHS) { return LHS.Symbol.compare_lower(RHS.Symbol) < 0; }); if (Symbols == Reference.Symbols) { @@ -274,7 +274,7 @@ // and a pointer to the first "main code" line if that is adjacent to the // affected lines of module references, nullptr otherwise. std::pair, AnnotatedLine *> - parseModuleReferences(const AdditionalKeywords &Keywords, + parseModuleReferences(AdditionalKeywords const &Keywords, SmallVectorImpl &AnnotatedLines) { SmallVector References; SourceLocation Start; @@ -328,7 +328,7 @@ // Parses a JavaScript/ECMAScript 6 module reference. // See http://www.ecma-international.org/ecma-262/6.0/#sec-scripts-and-modules // for grammar EBNF (production ModuleItem). - bool parseModuleReference(const AdditionalKeywords &Keywords, + bool parseModuleReference(AdditionalKeywords const &Keywords, JsModuleReference &Reference) { if (!Current || !Current->isOneOf(Keywords.kw_import, tok::kw_export)) return false; @@ -368,14 +368,14 @@ return true; } - bool parseModuleBindings(const AdditionalKeywords &Keywords, + bool parseModuleBindings(AdditionalKeywords const &Keywords, JsModuleReference &Reference) { if (parseStarBinding(Keywords, Reference)) return true; return parseNamedBindings(Keywords, Reference); } - bool parseStarBinding(const AdditionalKeywords &Keywords, + bool parseStarBinding(AdditionalKeywords const &Keywords, JsModuleReference &Reference) { // * as prefix from '...'; if (Current->isNot(tok::star)) @@ -391,7 +391,7 @@ return true; } - bool parseNamedBindings(const AdditionalKeywords &Keywords, + bool parseNamedBindings(AdditionalKeywords const &Keywords, JsModuleReference &Reference) { if (Current->is(tok::identifier)) { nextToken(); @@ -437,7 +437,7 @@ } }; -tooling::Replacements sortJavaScriptImports(const FormatStyle &Style, +tooling::Replacements sortJavaScriptImports(FormatStyle const &Style, StringRef Code, ArrayRef Ranges, StringRef FileName) { Index: clang/lib/Format/TokenAnalyzer.h =================================================================== --- clang/lib/Format/TokenAnalyzer.h +++ clang/lib/Format/TokenAnalyzer.h @@ -46,7 +46,7 @@ FileID getFileID() const { return ID; } - const SourceManager &getSourceManager() const { return SM; } + SourceManager const &getSourceManager() const { return SM; } ArrayRef getCharRanges() const { return CharRanges; } @@ -79,7 +79,7 @@ class TokenAnalyzer : public UnwrappedLineConsumer { public: - TokenAnalyzer(const Environment &Env, const FormatStyle &Style); + TokenAnalyzer(Environment const &Env, FormatStyle const &Style); std::pair process(); @@ -89,13 +89,13 @@ SmallVectorImpl &AnnotatedLines, FormatTokenLexer &Tokens) = 0; - void consumeUnwrappedLine(const UnwrappedLine &TheLine) override; + void consumeUnwrappedLine(UnwrappedLine const &TheLine) override; void finishRun() override; FormatStyle Style; // Stores Style, FileID and SourceManager etc. - const Environment &Env; + Environment const &Env; // AffectedRangeMgr stores ranges to be fixed. AffectedRangeManager AffectedRangeMgr; SmallVector, 2> UnwrappedLines; Index: clang/lib/Format/TokenAnalyzer.cpp =================================================================== --- clang/lib/Format/TokenAnalyzer.cpp +++ clang/lib/Format/TokenAnalyzer.cpp @@ -48,7 +48,7 @@ } } -TokenAnalyzer::TokenAnalyzer(const Environment &Env, const FormatStyle &Style) +TokenAnalyzer::TokenAnalyzer(Environment const &Env, FormatStyle const &Style) : Style(Style), Env(Env), AffectedRangeMgr(Env.getSourceManager(), Env.getCharRanges()), UnwrappedLines(1), @@ -111,7 +111,7 @@ return {Result, Penalty}; } -void TokenAnalyzer::consumeUnwrappedLine(const UnwrappedLine &TheLine) { +void TokenAnalyzer::consumeUnwrappedLine(UnwrappedLine const &TheLine) { assert(!UnwrappedLines.empty()); UnwrappedLines.back().push_back(TheLine); } Index: clang/lib/Format/TokenAnnotator.h =================================================================== --- clang/lib/Format/TokenAnnotator.h +++ clang/lib/Format/TokenAnnotator.h @@ -36,7 +36,7 @@ class AnnotatedLine { public: - AnnotatedLine(const UnwrappedLine &Line) + AnnotatedLine(UnwrappedLine const &Line) : First(Line.Tokens.front().Tok), Level(Line.Level), MatchingOpeningBlockLineIndex(Line.MatchingOpeningBlockLineIndex), MatchingClosingBlockLineIndex(Line.MatchingClosingBlockLineIndex), @@ -55,7 +55,7 @@ for (std::list::const_iterator I = ++Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) { - const UnwrappedLineNode &Node = *I; + UnwrappedLineNode const &Node = *I; Current->Next = I->Tok; I->Tok->Previous = Current; Current = Current->Next; @@ -148,15 +148,15 @@ private: // Disallow copying. - AnnotatedLine(const AnnotatedLine &) = delete; - void operator=(const AnnotatedLine &) = delete; + AnnotatedLine(AnnotatedLine const &) = delete; + void operator=(AnnotatedLine const &) = delete; }; /// Determines extra information about the tokens comprising an /// \c UnwrappedLine. class TokenAnnotator { public: - TokenAnnotator(const FormatStyle &Style, const AdditionalKeywords &Keywords) + TokenAnnotator(FormatStyle const &Style, AdditionalKeywords const &Keywords) : Style(Style), Keywords(Keywords) {} /// Adapts the indent levels of comment lines to the indent of the @@ -169,29 +169,29 @@ private: /// Calculate the penalty for splitting before \c Tok. - unsigned splitPenalty(const AnnotatedLine &Line, const FormatToken &Tok, + unsigned splitPenalty(AnnotatedLine const &Line, FormatToken const &Tok, bool InFunctionDecl); - bool spaceRequiredBeforeParens(const FormatToken &Right) const; + bool spaceRequiredBeforeParens(FormatToken const &Right) const; - bool spaceRequiredBetween(const AnnotatedLine &Line, const FormatToken &Left, - const FormatToken &Right); + bool spaceRequiredBetween(AnnotatedLine const &Line, FormatToken const &Left, + FormatToken const &Right); - bool spaceRequiredBefore(const AnnotatedLine &Line, const FormatToken &Right); + bool spaceRequiredBefore(AnnotatedLine const &Line, FormatToken const &Right); - bool mustBreakBefore(const AnnotatedLine &Line, const FormatToken &Right); + bool mustBreakBefore(AnnotatedLine const &Line, FormatToken const &Right); - bool canBreakBefore(const AnnotatedLine &Line, const FormatToken &Right); + bool canBreakBefore(AnnotatedLine const &Line, FormatToken const &Right); - bool mustBreakForReturnType(const AnnotatedLine &Line) const; + bool mustBreakForReturnType(AnnotatedLine const &Line) const; - void printDebugInfo(const AnnotatedLine &Line); + void printDebugInfo(AnnotatedLine const &Line); void calculateUnbreakableTailLengths(AnnotatedLine &Line); - const FormatStyle &Style; + FormatStyle const &Style; - const AdditionalKeywords &Keywords; + AdditionalKeywords const &Keywords; }; } // end namespace format Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -37,13 +37,13 @@ /// are valid inside @selector(...) (or a macro which /// invokes @selector(...)). So, we allow treat any identifier or /// keyword as a potential Objective-C selector component. -static bool canBeObjCSelectorComponent(const FormatToken &Tok) { +static bool canBeObjCSelectorComponent(FormatToken const &Tok) { return Tok.Tok.getIdentifierInfo() != nullptr; } /// With `Left` being '(', check if we're at either `[...](` or /// `[...]<...>(`, where the [ opens a lambda capture list. -static bool isLambdaParameterList(const FormatToken *Left) { +static bool isLambdaParameterList(FormatToken const *Left) { // Skip <...> if present. if (Left->Previous && Left->Previous->is(tok::greater) && Left->Previous->MatchingParen && @@ -63,8 +63,8 @@ /// into template parameter lists. class AnnotatingParser { public: - AnnotatingParser(const FormatStyle &Style, AnnotatedLine &Line, - const AdditionalKeywords &Keywords) + AnnotatingParser(FormatStyle const &Style, AnnotatedLine &Line, + AdditionalKeywords const &Keywords) : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false), Keywords(Keywords) { Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false)); @@ -78,7 +78,7 @@ if (NonTemplateLess.count(CurrentToken->Previous)) return false; - const FormatToken &Previous = *CurrentToken->Previous; // The '<'. + FormatToken const &Previous = *CurrentToken->Previous; // The '<'. if (Previous.Previous) { if (Previous.Previous->Tok.isLiteral()) return false; @@ -365,11 +365,11 @@ return false; } - bool isCSharpAttributeSpecifier(const FormatToken &Tok) { + bool isCSharpAttributeSpecifier(FormatToken const &Tok) { if (!Style.isCSharp()) return false; - const FormatToken *AttrTok = Tok.Next; + FormatToken const *AttrTok = Tok.Next; if (!AttrTok) return false; @@ -405,14 +405,14 @@ return false; } - bool isCpp11AttributeSpecifier(const FormatToken &Tok) { + bool isCpp11AttributeSpecifier(FormatToken const &Tok) { if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square)) return false; // The first square bracket is part of an ObjC array literal if (Tok.Previous && Tok.Previous->is(tok::at)) { return false; } - const FormatToken *AttrTok = Tok.Next->Next; + FormatToken const *AttrTok = Tok.Next->Next; if (!AttrTok) return false; // C++17 '[[using ns: foo, bar(baz, blech)]]' @@ -788,7 +788,7 @@ } else if (Contexts.back().ColonIsObjCMethodExpr || Line.startsWith(TT_ObjCMethodSpecifier)) { Tok->Type = TT_ObjCMethodExpr; - const FormatToken *BeforePrevious = Tok->Previous->Previous; + FormatToken const *BeforePrevious = Tok->Previous->Previous; // Ensure we tag all identifiers in method declarations as // TT_SelectorName. bool UnknownIdentifierInMethodDeclaration = @@ -1204,7 +1204,7 @@ } private: - bool isClosureImportStatement(const FormatToken &Tok) { + bool isClosureImportStatement(FormatToken const &Tok) { // FIXME: Closure-library specific stuff should not be hard-coded but be // configurable. return Tok.TokenText == "goog" && Tok.Next && Tok.Next->is(tok::period) && @@ -1291,7 +1291,7 @@ ~ScopedContextCreator() { P.Contexts.pop_back(); } }; - void modifyContext(const FormatToken &Current) { + void modifyContext(FormatToken const &Current) { if (Current.getPrecedence() == prec::Assignment && !Line.First->isOneOf(tok::kw_template, tok::kw_using, tok::kw_return) && // Type aliases use `type X = ...;` in TypeScript and can be exported @@ -1507,8 +1507,8 @@ Current.Previous) { if (Current.Previous->is(tok::at) && Current.isNot(Keywords.kw_interface)) { - const FormatToken &AtToken = *Current.Previous; - const FormatToken *Previous = AtToken.getPreviousNonComment(); + FormatToken const &AtToken = *Current.Previous; + FormatToken const *Previous = AtToken.getPreviousNonComment(); if (!Previous || Previous->is(TT_LeadingJavaAnnotation)) Current.Type = TT_LeadingJavaAnnotation; else @@ -1526,7 +1526,7 @@ /// /// This is a heuristic based on whether \p Tok is an identifier following /// something that is likely a type. - bool isStartOfName(const FormatToken &Tok) { + bool isStartOfName(FormatToken const &Tok) { if (Tok.isNot(tok::identifier) || !Tok.Previous) return false; @@ -1567,7 +1567,7 @@ } /// Determine whether ')' is ending a cast. - bool rParenEndsCast(const FormatToken &Tok) { + bool rParenEndsCast(FormatToken const &Tok) { // C-style casts are only used in C++ and Java. if (!Style.isCpp() && Style.Language != FormatStyle::LK_Java) return false; @@ -1641,7 +1641,7 @@ // Certain token types inside the parentheses mean that this can't be a // cast. - for (const FormatToken *Token = Tok.MatchingParen->Next; Token != &Tok; + for (FormatToken const *Token = Tok.MatchingParen->Next; Token != &Tok; Token = Token->Next) if (Token->is(TT_BinaryOperator)) return false; @@ -1672,16 +1672,16 @@ } /// Return the type of the given token assuming it is * or &. - TokenType determineStarAmpUsage(const FormatToken &Tok, bool IsExpression, + TokenType determineStarAmpUsage(FormatToken const &Tok, bool IsExpression, bool InTemplateArgument) { if (Style.Language == FormatStyle::LK_JavaScript) return TT_BinaryOperator; - const FormatToken *PrevToken = Tok.getPreviousNonComment(); + FormatToken const *PrevToken = Tok.getPreviousNonComment(); if (!PrevToken) return TT_UnaryOperator; - const FormatToken *NextToken = Tok.getNextNonComment(); + FormatToken const *NextToken = Tok.getNextNonComment(); if (!NextToken || NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_const, tok::kw_noexcept) || @@ -1733,7 +1733,7 @@ // This catches some cases where evaluation order is used as control flow: // aaa && aaa->f(); - const FormatToken *NextNextToken = NextToken->getNextNonComment(); + FormatToken const *NextNextToken = NextToken->getNextNonComment(); if (NextNextToken && NextNextToken->is(tok::arrow)) return TT_BinaryOperator; @@ -1745,8 +1745,8 @@ return TT_PointerOrReference; } - TokenType determinePlusMinusCaretUsage(const FormatToken &Tok) { - const FormatToken *PrevToken = Tok.getPreviousNonComment(); + TokenType determinePlusMinusCaretUsage(FormatToken const &Tok) { + FormatToken const *PrevToken = Tok.getPreviousNonComment(); if (!PrevToken) return TT_UnaryOperator; @@ -1769,8 +1769,8 @@ } /// Determine whether ++/-- are pre- or post-increments/-decrements. - TokenType determineIncrementUsage(const FormatToken &Tok) { - const FormatToken *PrevToken = Tok.getPreviousNonComment(); + TokenType determineIncrementUsage(FormatToken const &Tok) { + FormatToken const *PrevToken = Tok.getPreviousNonComment(); if (!PrevToken || PrevToken->is(TT_CastRParen)) return TT_UnaryOperator; if (PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::identifier)) @@ -1781,11 +1781,11 @@ SmallVector Contexts; - const FormatStyle &Style; + FormatStyle const &Style; AnnotatedLine &Line; FormatToken *CurrentToken; bool AutoFound; - const AdditionalKeywords &Keywords; + AdditionalKeywords const &Keywords; // Set of "<" tokens that do not open a template parameter list. If parseAngle // determines that a specific token can't be a template opener, it will make @@ -1794,14 +1794,14 @@ llvm::SmallPtrSet NonTemplateLess; }; -static const int PrecedenceUnaryOperator = prec::PointerToMember + 1; -static const int PrecedenceArrowAndPeriod = prec::PointerToMember + 2; +static int const PrecedenceUnaryOperator = prec::PointerToMember + 1; +static int const PrecedenceArrowAndPeriod = prec::PointerToMember + 2; /// Parses binary expressions by inserting fake parenthesis based on /// operator precedence. class ExpressionParser { public: - ExpressionParser(const FormatStyle &Style, const AdditionalKeywords &Keywords, + ExpressionParser(FormatStyle const &Style, AdditionalKeywords const &Keywords, AnnotatedLine &Line) : Style(Style), Keywords(Keywords), Current(Line.First) {} @@ -1896,7 +1896,7 @@ /// and other tokens that we treat like binary operators. int getCurrentPrecedence() { if (Current) { - const FormatToken *NextNonComment = Current->getNextNonComment(); + FormatToken const *NextNonComment = Current->getNextNonComment(); if (Current->is(TT_ConditionalExpr)) return prec::Conditional; if (NextNonComment && Current->is(TT_SelectorName) && @@ -1991,8 +1991,8 @@ Current = Current->Next; } - const FormatStyle &Style; - const AdditionalKeywords &Keywords; + FormatStyle const &Style; + AdditionalKeywords const &Keywords; FormatToken *Current; }; @@ -2000,12 +2000,12 @@ void TokenAnnotator::setCommentLineLevels( SmallVectorImpl &Lines) { - const AnnotatedLine *NextNonCommentLine = nullptr; + AnnotatedLine const *NextNonCommentLine = nullptr; for (SmallVectorImpl::reverse_iterator I = Lines.rbegin(), E = Lines.rend(); I != E; ++I) { bool CommentLine = true; - for (const FormatToken *Tok = (*I)->First; Tok; Tok = Tok->Next) { + for (FormatToken const *Tok = (*I)->First; Tok; Tok = Tok->Next) { if (!Tok->is(tok::comment)) { CommentLine = false; break; @@ -2035,7 +2035,7 @@ } } -static unsigned maxNestingDepth(const AnnotatedLine &Line) { +static unsigned maxNestingDepth(AnnotatedLine const &Line) { unsigned Result = 0; for (const auto *Tok = Line.First; Tok != nullptr; Tok = Tok->Next) Result = std::max(Result, Tok->NestingLevel); @@ -2077,9 +2077,9 @@ // This function heuristically determines whether 'Current' starts the name of a // function declaration. -static bool isFunctionDeclarationName(const FormatToken &Current, - const AnnotatedLine &Line) { - auto skipOperatorName = [](const FormatToken *Next) -> const FormatToken * { +static bool isFunctionDeclarationName(FormatToken const &Current, + AnnotatedLine const &Line) { + auto skipOperatorName = [](FormatToken const *Next) -> FormatToken const * { for (; Next; Next = Next->Next) { if (Next->is(TT_OverloadedOperatorLParen)) return Next; @@ -2099,7 +2099,7 @@ }; // Find parentheses of parameter list. - const FormatToken *Next = Current.Next; + FormatToken const *Next = Current.Next; if (Current.is(tok::kw_operator)) { if (Current.Previous && Current.Previous->is(tok::coloncolon)) return false; @@ -2140,7 +2140,7 @@ if (Next->MatchingParen->Next && Next->MatchingParen->Next->is(TT_PointerOrReference)) return true; - for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen; + for (FormatToken const *Tok = Next->Next; Tok && Tok != Next->MatchingParen; Tok = Tok->Next) { if (Tok->isOneOf(tok::l_paren, TT_TemplateOpener) && Tok->MatchingParen) { Tok = Tok->MatchingParen; @@ -2156,7 +2156,7 @@ return false; } -bool TokenAnnotator::mustBreakForReturnType(const AnnotatedLine &Line) const { +bool TokenAnnotator::mustBreakForReturnType(AnnotatedLine const &Line) const { assert(Line.MightBeFunctionDecl); if ((Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_TopLevel || @@ -2242,7 +2242,7 @@ ChildSize = LastOfChild.isTrailingComment() ? Style.ColumnLimit : LastOfChild.TotalLength + 1; } - const FormatToken *Prev = Current->Previous; + FormatToken const *Prev = Current->Previous; if (Current->MustBreakBefore || Prev->Children.size() > 1 || (Prev->Children.size() == 1 && Prev->Children[0]->First->MustBreakBefore) || @@ -2310,11 +2310,11 @@ } } -unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, - const FormatToken &Tok, +unsigned TokenAnnotator::splitPenalty(AnnotatedLine const &Line, + FormatToken const &Tok, bool InFunctionDecl) { - const FormatToken &Left = *Tok.Previous; - const FormatToken &Right = Tok; + FormatToken const &Left = *Tok.Previous; + FormatToken const &Right = Tok; if (Left.is(tok::semi)) return 0; @@ -2502,15 +2502,15 @@ return 3; } -bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const { +bool TokenAnnotator::spaceRequiredBeforeParens(FormatToken const &Right) const { return Style.SpaceBeforeParens == FormatStyle::SBPO_Always || (Style.SpaceBeforeParens == FormatStyle::SBPO_NonEmptyParentheses && Right.ParameterCount > 0); } -bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, - const FormatToken &Left, - const FormatToken &Right) { +bool TokenAnnotator::spaceRequiredBetween(AnnotatedLine const &Line, + FormatToken const &Left, + FormatToken const &Right) { if (Left.is(tok::kw_return) && Right.isNot(tok::semi)) return true; if (Left.is(Keywords.kw_assert) && Style.Language == FormatStyle::LK_Java) @@ -2606,7 +2606,7 @@ if (Right.is(tok::star) && Left.is(tok::l_paren)) return false; const auto SpaceRequiredForArrayInitializerLSquare = - [](const FormatToken &LSquareTok, const FormatStyle &Style) { + [](FormatToken const &LSquareTok, FormatStyle const &Style) { return Style.SpacesInContainerLiterals || ((Style.Language == FormatStyle::LK_Proto || Style.Language == FormatStyle::LK_TextProto) && @@ -2709,9 +2709,9 @@ return true; } -bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, - const FormatToken &Right) { - const FormatToken &Left = *Right.Previous; +bool TokenAnnotator::spaceRequiredBefore(AnnotatedLine const &Line, + FormatToken const &Right) { + FormatToken const &Left = *Right.Previous; if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo()) return true; // Never ever merge two identifiers. if (Style.isCpp()) { @@ -2762,7 +2762,7 @@ return true; if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) && Right.MatchingParen) { - const FormatToken *Next = Right.MatchingParen->getNextNonComment(); + FormatToken const *Next = Right.MatchingParen->getNextNonComment(); // An async arrow function, for example: `x = async () => foo();`, // as opposed to calling a function called async: `x = async();` if (Next && Next->is(TT_JsFatArrow)) @@ -2985,14 +2985,14 @@ } // Returns 'true' if 'Tok' is a brace we'd want to break before in Allman style. -static bool isAllmanBrace(const FormatToken &Tok) { +static bool isAllmanBrace(FormatToken const &Tok) { return Tok.is(tok::l_brace) && Tok.BlockKind == BK_Block && !Tok.isOneOf(TT_ObjCBlockLBrace, TT_LambdaLBrace, TT_DictLiteral); } -bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, - const FormatToken &Right) { - const FormatToken &Left = *Right.Previous; +bool TokenAnnotator::mustBreakBefore(AnnotatedLine const &Line, + FormatToken const &Right) { + FormatToken const &Left = *Right.Previous; if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0) return true; @@ -3045,7 +3045,7 @@ // shuffling around entries easier. Import statements, especially in // JavaScript, can be an exception to this rule. if (Style.JavaScriptWrapImports || Line.Type != LT_ImportStatement) { - const FormatToken *BeforeClosingBrace = nullptr; + FormatToken const *BeforeClosingBrace = nullptr; if ((Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) || (Style.Language == FormatStyle::LK_JavaScript && Left.is(tok::l_paren))) && @@ -3259,9 +3259,9 @@ return false; } -bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, - const FormatToken &Right) { - const FormatToken &Left = *Right.Previous; +bool TokenAnnotator::canBreakBefore(AnnotatedLine const &Line, + FormatToken const &Right) { + FormatToken const &Left = *Right.Previous; // Language-specific stuff. if (Style.Language == FormatStyle::LK_Java) { @@ -3272,7 +3272,7 @@ Keywords.kw_implements)) return true; } else if (Style.Language == FormatStyle::LK_JavaScript) { - const FormatToken *NonComment = Right.getPreviousNonComment(); + FormatToken const *NonComment = Right.getPreviousNonComment(); if (NonComment && NonComment->isOneOf( tok::kw_return, Keywords.kw_yield, tok::kw_continue, tok::kw_break, @@ -3297,7 +3297,7 @@ // function f(): a is B { ... } // Do not break before is in these cases. if (Right.is(Keywords.kw_is)) { - const FormatToken *Next = Right.getNextNonComment(); + FormatToken const *Next = Right.getNextNonComment(); // If `is` is followed by a colon, it's likely that it's a dict key, so // ignore it for this check. // For example this is common in Polymer: @@ -3534,9 +3534,9 @@ (Left.is(TT_TemplateOpener) && !Right.is(TT_TemplateCloser)); } -void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) { +void TokenAnnotator::printDebugInfo(AnnotatedLine const &Line) { llvm::errs() << "AnnotatedTokens(L=" << Line.Level << "):\n"; - const FormatToken *Tok = Line.First; + FormatToken const *Tok = Line.First; while (Tok) { llvm::errs() << " M=" << Tok->MustBreakBefore << " C=" << Tok->CanBreakBefore Index: clang/lib/Format/UnwrappedLineFormatter.h =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.h +++ clang/lib/Format/UnwrappedLineFormatter.h @@ -29,15 +29,15 @@ public: UnwrappedLineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces, - const FormatStyle &Style, - const AdditionalKeywords &Keywords, - const SourceManager &SourceMgr, + FormatStyle const &Style, + AdditionalKeywords const &Keywords, + SourceManager const &SourceMgr, FormattingAttemptStatus *Status) : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style), Keywords(Keywords), SourceMgr(SourceMgr), Status(Status) {} /// Format the current block and return the penalty. - unsigned format(const SmallVectorImpl &Lines, + unsigned format(SmallVectorImpl const &Lines, bool DryRun = false, int AdditionalIndent = 0, bool FixBadIndentation = false, unsigned FirstStartColumn = 0, unsigned NextStartColumn = 0, unsigned LastStartColumn = 0); @@ -45,28 +45,28 @@ private: /// Add a new line and the required indent before the first Token /// of the \c UnwrappedLine if there was no structural parsing error. - void formatFirstToken(const AnnotatedLine &Line, - const AnnotatedLine *PreviousLine, - const SmallVectorImpl &Lines, + void formatFirstToken(AnnotatedLine const &Line, + AnnotatedLine const *PreviousLine, + SmallVectorImpl const &Lines, unsigned Indent, unsigned NewlineIndent); /// Returns the column limit for a line, taking into account whether we /// need an escaped newline due to a continued preprocessor directive. unsigned getColumnLimit(bool InPPDirective, - const AnnotatedLine *NextLine) const; + AnnotatedLine const *NextLine) const; // Cache to store the penalty of formatting a vector of AnnotatedLines // starting from a specific additional offset. Improves performance if there // are many nested blocks. - std::map *, unsigned>, + std::map const *, unsigned>, unsigned> PenaltyCache; ContinuationIndenter *Indenter; WhitespaceManager *Whitespaces; - const FormatStyle &Style; - const AdditionalKeywords &Keywords; - const SourceManager &SourceMgr; + FormatStyle const &Style; + AdditionalKeywords const &Keywords; + SourceManager const &SourceMgr; FormattingAttemptStatus *Status; }; } // end namespace format Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -19,9 +19,9 @@ namespace { -bool startsExternCBlock(const AnnotatedLine &Line) { - const FormatToken *Next = Line.First->getNextNonComment(); - const FormatToken *NextNext = Next ? Next->getNextNonComment() : nullptr; +bool startsExternCBlock(AnnotatedLine const &Line) { + FormatToken const *Next = Line.First->getNextNonComment(); + FormatToken const *NextNext = Next ? Next->getNextNonComment() : nullptr; return Line.startsWith(tok::kw_extern) && Next && Next->isStringLiteral() && NextNext && NextNext->is(tok::l_brace); } @@ -37,8 +37,8 @@ /// given line. class LevelIndentTracker { public: - LevelIndentTracker(const FormatStyle &Style, - const AdditionalKeywords &Keywords, unsigned StartLevel, + LevelIndentTracker(FormatStyle const &Style, + AdditionalKeywords const &Keywords, unsigned StartLevel, int AdditionalIndent) : Style(Style), Keywords(Keywords), AdditionalIndent(AdditionalIndent) { for (unsigned i = 0; i != StartLevel; ++i) @@ -50,7 +50,7 @@ /// Update the indent state given that \p Line is going to be formatted /// next. - void nextLine(const AnnotatedLine &Line) { + void nextLine(AnnotatedLine const &Line) { Offset = getIndentOffset(*Line.First); // Update the indent level cache size so that we can rely on it // having the right size in adjustToUnmodifiedline. @@ -68,7 +68,7 @@ /// Update the indent state given that \p Line indent should be /// skipped. - void skipLine(const AnnotatedLine &Line) { + void skipLine(AnnotatedLine const &Line) { while (IndentForLevel.size() <= Line.Level) IndentForLevel.push_back(Indent); } @@ -78,7 +78,7 @@ /// When a line is not formatted, we move the subsequent lines on the same /// level to the same indent. /// Note that \c nextLine must have been called before this method. - void adjustToUnmodifiedLine(const AnnotatedLine &Line) { + void adjustToUnmodifiedLine(AnnotatedLine const &Line) { unsigned LevelIndent = Line.First->OriginalColumn; if (static_cast(LevelIndent) - Offset >= 0) LevelIndent -= Offset; @@ -92,7 +92,7 @@ /// /// For example, 'public:' labels in classes are offset by 1 or 2 /// characters to the left from their level. - int getIndentOffset(const FormatToken &RootToken) { + int getIndentOffset(FormatToken const &RootToken) { if (Style.Language == FormatStyle::LK_Java || Style.Language == FormatStyle::LK_JavaScript || Style.isCSharp()) return 0; @@ -117,9 +117,9 @@ return getIndent(IndentForLevel, Level - 1) + Style.IndentWidth; } - const FormatStyle &Style; - const AdditionalKeywords &Keywords; - const unsigned AdditionalIndent; + FormatStyle const &Style; + AdditionalKeywords const &Keywords; + unsigned const AdditionalIndent; /// The indent in characters for each level. std::vector IndentForLevel; @@ -134,9 +134,9 @@ unsigned Indent = 0; }; -const FormatToken *getMatchingNamespaceToken( - const AnnotatedLine *Line, - const SmallVectorImpl &AnnotatedLines) { +FormatToken const *getMatchingNamespaceToken( + AnnotatedLine const *Line, + SmallVectorImpl const &AnnotatedLines) { if (!Line->startsWith(tok::r_brace)) return nullptr; size_t StartLineIndex = Line->MatchingOpeningBlockLineIndex; @@ -146,32 +146,32 @@ return AnnotatedLines[StartLineIndex]->First->getNamespaceToken(); } -StringRef getNamespaceTokenText(const AnnotatedLine *Line) { - const FormatToken *NamespaceToken = Line->First->getNamespaceToken(); +StringRef getNamespaceTokenText(AnnotatedLine const *Line) { + FormatToken const *NamespaceToken = Line->First->getNamespaceToken(); return NamespaceToken ? NamespaceToken->TokenText : StringRef(); } StringRef getMatchingNamespaceTokenText( - const AnnotatedLine *Line, - const SmallVectorImpl &AnnotatedLines) { - const FormatToken *NamespaceToken = + AnnotatedLine const *Line, + SmallVectorImpl const &AnnotatedLines) { + FormatToken const *NamespaceToken = getMatchingNamespaceToken(Line, AnnotatedLines); return NamespaceToken ? NamespaceToken->TokenText : StringRef(); } class LineJoiner { public: - LineJoiner(const FormatStyle &Style, const AdditionalKeywords &Keywords, - const SmallVectorImpl &Lines) + LineJoiner(FormatStyle const &Style, AdditionalKeywords const &Keywords, + SmallVectorImpl const &Lines) : Style(Style), Keywords(Keywords), End(Lines.end()), Next(Lines.begin()), AnnotatedLines(Lines) {} /// Returns the next line, merging multiple lines into one if possible. - const AnnotatedLine *getNextMergedLine(bool DryRun, + AnnotatedLine const *getNextMergedLine(bool DryRun, LevelIndentTracker &IndentTracker) { if (Next == End) return nullptr; - const AnnotatedLine *Current = *Next; + AnnotatedLine const *Current = *Next; IndentTracker.nextLine(*Current); unsigned MergedLines = tryFitMultipleLinesInOne(IndentTracker, Next, End); if (MergedLines > 0 && Style.ColumnLimit == 0) @@ -193,13 +193,13 @@ tryFitMultipleLinesInOne(LevelIndentTracker &IndentTracker, SmallVectorImpl::const_iterator I, SmallVectorImpl::const_iterator E) { - const unsigned Indent = IndentTracker.getIndent(); + unsigned const Indent = IndentTracker.getIndent(); // Can't join the last line with anything. if (I + 1 == E) return 0; // We can never merge stuff if there are trailing line comments. - const AnnotatedLine *TheLine = *I; + AnnotatedLine const *TheLine = *I; if (TheLine->Last->is(TT_LineComment)) return 0; if (I[1]->Type == LT_Invalid || I[1]->First->MustBreakBefore) @@ -230,7 +230,7 @@ I != AnnotatedLines.begin()) { bool EmptyBlock = I[1]->First->is(tok::r_brace); - const FormatToken *Tok = I[-1]->First; + FormatToken const *Tok = I[-1]->First; if (Tok && Tok->is(tok::comment)) Tok = Tok->getNextNonComment(); @@ -465,11 +465,11 @@ unsigned Length = 0; bool EndsWithComment = false; bool InPPDirective = I[0]->InPPDirective; - const unsigned Level = I[0]->Level; + unsigned const Level = I[0]->Level; for (; NumStmts < 3; ++NumStmts) { if (I + 1 + NumStmts == E) break; - const AnnotatedLine *Line = I[1 + NumStmts]; + AnnotatedLine const *Line = I[1 + NumStmts]; if (Line->InPPDirective != InPPDirective) break; if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace)) @@ -522,7 +522,7 @@ return 0; // default: in switch statement if (Line.First->is(tok::kw_default)) { - const FormatToken *Tok = Line.First->getNextNonComment(); + FormatToken const *Tok = Line.First->getNextNonComment(); if (Tok && Tok->is(tok::colon)) return 0; } @@ -672,15 +672,15 @@ return 1 + I[1]->Last->TotalLength + 1 + I[2]->Last->TotalLength <= Limit; } - bool containsMustBreak(const AnnotatedLine *Line) { - for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) { + bool containsMustBreak(AnnotatedLine const *Line) { + for (FormatToken const *Tok = Line->First; Tok; Tok = Tok->Next) { if (Tok->MustBreakBefore) return true; } return false; } - void join(AnnotatedLine &A, const AnnotatedLine &B) { + void join(AnnotatedLine &A, AnnotatedLine const &B) { assert(!A.Last->Next); assert(!B.First->Previous); if (B.Affected) @@ -695,12 +695,12 @@ } } - const FormatStyle &Style; - const AdditionalKeywords &Keywords; - const SmallVectorImpl::const_iterator End; + FormatStyle const &Style; + AdditionalKeywords const &Keywords; + SmallVectorImpl::const_iterator const End; SmallVectorImpl::const_iterator Next; - const SmallVectorImpl &AnnotatedLines; + SmallVectorImpl const &AnnotatedLines; }; static void markFinalized(FormatToken *Tok) { @@ -712,9 +712,9 @@ } #ifndef NDEBUG -static void printLineState(const LineState &State) { +static void printLineState(LineState const &State) { llvm::dbgs() << "State: "; - for (const ParenState &P : State.Stack) { + for (ParenState const &P : State.Stack) { llvm::dbgs() << (P.Tok ? P.Tok->TokenText : "F") << "|" << P.Indent << "|" << P.LastSpace << "|" << P.NestedBlockIndent << " "; } @@ -726,7 +726,7 @@ class LineFormatter { public: LineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces, - const FormatStyle &Style, + FormatStyle const &Style, UnwrappedLineFormatter *BlockFormatter) : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style), BlockFormatter(BlockFormatter) {} @@ -735,7 +735,7 @@ /// Formats an \c AnnotatedLine and returns the penalty. /// /// If \p DryRun is \c false, directly applies the changes. - virtual unsigned formatLine(const AnnotatedLine &Line, unsigned FirstIndent, + virtual unsigned formatLine(AnnotatedLine const &Line, unsigned FirstIndent, unsigned FirstStartColumn, bool DryRun) = 0; protected: @@ -761,7 +761,7 @@ /// break or don't break. bool formatChildren(LineState &State, bool NewLine, bool DryRun, unsigned &Penalty) { - const FormatToken *LBrace = State.NextToken->getPreviousNonComment(); + FormatToken const *LBrace = State.NextToken->getPreviousNonComment(); FormatToken &Previous = *State.NextToken->Previous; if (!LBrace || LBrace->isNot(tok::l_brace) || LBrace->BlockKind != BK_Block || Previous.Children.size() == 0) @@ -790,7 +790,7 @@ if (Previous.Children.size() > 1) return false; - const AnnotatedLine *Child = Previous.Children[0]; + AnnotatedLine const *Child = Previous.Children[0]; // We can't put the closing "}" on a line with a trailing comment. if (Child->Last->isTrailingComment()) return false; @@ -817,7 +817,7 @@ private: WhitespaceManager *Whitespaces; - const FormatStyle &Style; + FormatStyle const &Style; UnwrappedLineFormatter *BlockFormatter; }; @@ -826,13 +826,13 @@ public: NoColumnLimitLineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces, - const FormatStyle &Style, + FormatStyle const &Style, UnwrappedLineFormatter *BlockFormatter) : LineFormatter(Indenter, Whitespaces, Style, BlockFormatter) {} /// Formats the line, simply keeping all of the input's line breaking /// decisions. - unsigned formatLine(const AnnotatedLine &Line, unsigned FirstIndent, + unsigned formatLine(AnnotatedLine const &Line, unsigned FirstIndent, unsigned FirstStartColumn, bool DryRun) override { assert(!DryRun); LineState State = Indenter->getInitialState(FirstIndent, FirstStartColumn, @@ -853,12 +853,12 @@ class NoLineBreakFormatter : public LineFormatter { public: NoLineBreakFormatter(ContinuationIndenter *Indenter, - WhitespaceManager *Whitespaces, const FormatStyle &Style, + WhitespaceManager *Whitespaces, FormatStyle const &Style, UnwrappedLineFormatter *BlockFormatter) : LineFormatter(Indenter, Whitespaces, Style, BlockFormatter) {} /// Puts all tokens into a single line. - unsigned formatLine(const AnnotatedLine &Line, unsigned FirstIndent, + unsigned formatLine(AnnotatedLine const &Line, unsigned FirstIndent, unsigned FirstStartColumn, bool DryRun) override { unsigned Penalty = 0; LineState State = @@ -877,13 +877,13 @@ public: OptimizingLineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces, - const FormatStyle &Style, + FormatStyle const &Style, UnwrappedLineFormatter *BlockFormatter) : LineFormatter(Indenter, Whitespaces, Style, BlockFormatter) {} /// Formats the line by finding the best line breaks with line lengths /// below the column limit. - unsigned formatLine(const AnnotatedLine &Line, unsigned FirstIndent, + unsigned formatLine(AnnotatedLine const &Line, unsigned FirstIndent, unsigned FirstStartColumn, bool DryRun) override { LineState State = Indenter->getInitialState(FirstIndent, FirstStartColumn, &Line, DryRun); @@ -914,7 +914,7 @@ /// An edge in the solution space from \c Previous->State to \c State, /// inserting a newline dependent on the \c NewLine. struct StateNode { - StateNode(const LineState &State, bool NewLine, StateNode *Previous) + StateNode(LineState const &State, bool NewLine, StateNode *Previous) : State(State), NewLine(NewLine), Previous(Previous) {} LineState State; bool NewLine; @@ -1052,13 +1052,13 @@ } // anonymous namespace unsigned UnwrappedLineFormatter::format( - const SmallVectorImpl &Lines, bool DryRun, + SmallVectorImpl const &Lines, bool DryRun, int AdditionalIndent, bool FixBadIndentation, unsigned FirstStartColumn, unsigned NextStartColumn, unsigned LastStartColumn) { LineJoiner Joiner(Style, Keywords, Lines); // Try to look up already computed penalty in DryRun-mode. - std::pair *, unsigned> CacheKey( + std::pair const *, unsigned> CacheKey( &Lines, AdditionalIndent); auto CacheIt = PenaltyCache.find(CacheKey); if (DryRun && CacheIt != PenaltyCache.end()) @@ -1068,17 +1068,17 @@ unsigned Penalty = 0; LevelIndentTracker IndentTracker(Style, Keywords, Lines[0]->Level, AdditionalIndent); - const AnnotatedLine *PreviousLine = nullptr; - const AnnotatedLine *NextLine = nullptr; + AnnotatedLine const *PreviousLine = nullptr; + AnnotatedLine const *NextLine = nullptr; // The minimum level of consecutive lines that have been formatted. unsigned RangeMinLevel = UINT_MAX; bool FirstLine = true; - for (const AnnotatedLine *Line = + for (AnnotatedLine const *Line = Joiner.getNextMergedLine(DryRun, IndentTracker); Line; Line = NextLine, FirstLine = false) { - const AnnotatedLine &TheLine = *Line; + AnnotatedLine const &TheLine = *Line; unsigned Indent = IndentTracker.getIndent(); // We continue formatting unchanged lines to adjust their indent, e.g. if a @@ -1136,7 +1136,7 @@ // If no token in the current line is affected, we still need to format // affected children. if (TheLine.ChildrenAffected) - for (const FormatToken *Tok = TheLine.First; Tok; Tok = Tok->Next) + for (FormatToken const *Tok = TheLine.First; Tok; Tok = Tok->Next) if (!Tok->Children.empty()) format(Tok->Children, DryRun); @@ -1175,8 +1175,8 @@ } void UnwrappedLineFormatter::formatFirstToken( - const AnnotatedLine &Line, const AnnotatedLine *PreviousLine, - const SmallVectorImpl &Lines, unsigned Indent, + AnnotatedLine const &Line, AnnotatedLine const *PreviousLine, + SmallVectorImpl const &Lines, unsigned Indent, unsigned NewlineIndent) { FormatToken &RootToken = *Line.First; if (RootToken.is(tok::eof)) { @@ -1242,7 +1242,7 @@ unsigned UnwrappedLineFormatter::getColumnLimit(bool InPPDirective, - const AnnotatedLine *NextLine) const { + AnnotatedLine const *NextLine) const { // In preprocessor directives reserve two chars for trailing " \" if the // next line continues the preprocessor directive. bool ContinuesPPDirective = Index: clang/lib/Format/UnwrappedLineParser.h =================================================================== --- clang/lib/Format/UnwrappedLineParser.h +++ clang/lib/Format/UnwrappedLineParser.h @@ -58,7 +58,7 @@ /// line with the corresponding closing brace. size_t MatchingClosingBlockLineIndex = kInvalidIndex; - static const size_t kInvalidIndex = -1; + static size_t const kInvalidIndex = -1; unsigned FirstStartColumn = 0; }; @@ -66,7 +66,7 @@ class UnwrappedLineConsumer { public: virtual ~UnwrappedLineConsumer() {} - virtual void consumeUnwrappedLine(const UnwrappedLine &Line) = 0; + virtual void consumeUnwrappedLine(UnwrappedLine const &Line) = 0; virtual void finishRun() = 0; }; @@ -74,8 +74,8 @@ class UnwrappedLineParser { public: - UnwrappedLineParser(const FormatStyle &Style, - const AdditionalKeywords &Keywords, + UnwrappedLineParser(FormatStyle const &Style, + AdditionalKeywords const &Keywords, unsigned FirstStartColumn, ArrayRef Tokens, UnwrappedLineConsumer &Callback); @@ -147,8 +147,8 @@ // NextTok specifies the next token. A null pointer NextTok is supported, and // signifies either the absence of a next token, or that the next token // shouldn't be taken into accunt for the analysis. - void distributeComments(const SmallVectorImpl &Comments, - const FormatToken *NextTok); + void distributeComments(SmallVectorImpl const &Comments, + FormatToken const *NextTok); // Adds the comment preceding the next token to unwrapped lines. void flushComments(bool NewlineBeforeNext); @@ -164,7 +164,7 @@ void conditionalCompilationAlternative(); void conditionalCompilationEnd(); - bool isOnNewLine(const FormatToken &FormatTok); + bool isOnNewLine(FormatToken const &FormatTok); // Compute hash of the current preprocessor branch. // This is used to identify the different branches, and thus track if block @@ -202,8 +202,8 @@ // whether we are in a compound statement or not. std::vector DeclarationScopeStack; - const FormatStyle &Style; - const AdditionalKeywords &Keywords; + FormatStyle const &Style; + AdditionalKeywords const &Keywords; llvm::Regex CommentPragmasRegex; Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -56,16 +56,16 @@ std::vector &Stack; }; -static bool isLineComment(const FormatToken &FormatTok) { +static bool isLineComment(FormatToken const &FormatTok) { return FormatTok.is(tok::comment) && !FormatTok.TokenText.startswith("/*"); } // Checks if \p FormatTok is a line comment that continues the line comment // \p Previous. The original column of \p MinColumnToken is used to determine // whether \p FormatTok is indented enough to the right to continue \p Previous. -static bool continuesLineComment(const FormatToken &FormatTok, - const FormatToken *Previous, - const FormatToken *MinColumnToken) { +static bool continuesLineComment(FormatToken const &FormatTok, + FormatToken const *Previous, + FormatToken const *MinColumnToken) { if (!Previous || !MinColumnToken) return false; unsigned MinContinueColumn = @@ -171,7 +171,7 @@ class CompoundStatementIndenter { public: CompoundStatementIndenter(UnwrappedLineParser *Parser, - const FormatStyle &Style, unsigned &LineLevel) + FormatStyle const &Style, unsigned &LineLevel) : CompoundStatementIndenter(Parser, LineLevel, Style.BraceWrapping.AfterControlStatement, Style.BraceWrapping.IndentBraces) {} @@ -221,8 +221,8 @@ } // end anonymous namespace -UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style, - const AdditionalKeywords &Keywords, +UnwrappedLineParser::UnwrappedLineParser(FormatStyle const &Style, + AdditionalKeywords const &Keywords, unsigned FirstStartColumn, ArrayRef Tokens, UnwrappedLineConsumer &Callback) @@ -395,7 +395,7 @@ // definitions, too. unsigned StoredPosition = Tokens->getPosition(); FormatToken *Tok = FormatTok; - const FormatToken *PrevTok = Tok->Previous; + FormatToken const *PrevTok = Tok->Previous; // Keep a stack of positions of lbrace tokens. We will // update information about whether an lbrace starts a // braced init list or a different block during the loop. @@ -516,7 +516,7 @@ } template -static inline void hash_combine(std::size_t &seed, const T &v) { +static inline void hash_combine(std::size_t &seed, T const &v) { std::hash hasher; seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } @@ -534,7 +534,7 @@ bool MunchSemi) { assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) && "'{' or macro block token expected"); - const bool MacroBlock = FormatTok->is(TT_MacroBlockBegin); + bool const MacroBlock = FormatTok->is(TT_MacroBlockBegin); FormatTok->BlockKind = BK_Block; size_t PPStartHash = computePPHash(); @@ -591,7 +591,7 @@ } } -static bool isGoogScope(const UnwrappedLine &Line) { +static bool isGoogScope(UnwrappedLine const &Line) { // FIXME: Closure-library specific stuff should not be hard-coded but be // configurable. if (Line.Tokens.size() < 4) @@ -609,8 +609,8 @@ return I->Tok->is(tok::l_paren); } -static bool isIIFE(const UnwrappedLine &Line, - const AdditionalKeywords &Keywords) { +static bool isIIFE(UnwrappedLine const &Line, + AdditionalKeywords const &Keywords) { // Look for the start of an immediately invoked anonymous function. // https://en.wikipedia.org/wiki/Immediately-invoked_function_expression // This is commonly done in JavaScript to create a new, anonymous scope. @@ -627,8 +627,8 @@ return I->Tok->is(tok::l_paren); } -static bool ShouldBreakBeforeBrace(const FormatStyle &Style, - const FormatToken &InitialToken) { +static bool ShouldBreakBeforeBrace(FormatStyle const &Style, + FormatToken const &InitialToken) { if (InitialToken.isOneOf(tok::kw_namespace, TT_NamespaceMacro)) return Style.BraceWrapping.AfterNamespace; if (InitialToken.is(tok::kw_class)) @@ -880,8 +880,8 @@ Tok.isNot(tok::kw_noexcept); } -static bool mustBeJSIdent(const AdditionalKeywords &Keywords, - const FormatToken *FormatTok) { +static bool mustBeJSIdent(AdditionalKeywords const &Keywords, + FormatToken const *FormatTok) { // FIXME: This returns true for C/C++ keywords like 'struct'. return FormatTok->is(tok::identifier) && (FormatTok->Tok.getIdentifierInfo() == nullptr || @@ -895,8 +895,8 @@ Keywords.kw_from)); } -static bool mustBeJSIdentOrValue(const AdditionalKeywords &Keywords, - const FormatToken *FormatTok) { +static bool mustBeJSIdentOrValue(AdditionalKeywords const &Keywords, + FormatToken const *FormatTok) { return FormatTok->Tok.isLiteral() || FormatTok->isOneOf(tok::kw_true, tok::kw_false) || mustBeJSIdent(Keywords, FormatTok); @@ -904,8 +904,8 @@ // isJSDeclOrStmt returns true if |FormatTok| starts a declaration or statement // when encountered after a value (see mustBeJSIdentOrValue). -static bool isJSDeclOrStmt(const AdditionalKeywords &Keywords, - const FormatToken *FormatTok) { +static bool isJSDeclOrStmt(AdditionalKeywords const &Keywords, + FormatToken const *FormatTok) { return FormatTok->isOneOf( tok::kw_return, Keywords.kw_yield, // conditionals @@ -1131,7 +1131,7 @@ break; } do { - const FormatToken *Previous = FormatTok->Previous; + FormatToken const *Previous = FormatTok->Previous; switch (FormatTok->Tok.getKind()) { case tok::at: nextToken(); @@ -1506,7 +1506,7 @@ } bool UnwrappedLineParser::tryToParseLambdaIntroducer() { - const FormatToken *Previous = FormatTok->Previous; + FormatToken const *Previous = FormatTok->Previous; if (Previous && (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new, tok::kw_delete, tok::l_square) || @@ -1876,7 +1876,7 @@ assert(FormatTok->isOneOf(tok::kw_namespace, TT_NamespaceMacro) && "'namespace' expected"); - const FormatToken &InitialToken = *FormatTok; + FormatToken const &InitialToken = *FormatTok; nextToken(); if (InitialToken.is(TT_NamespaceMacro)) { parseParens(); @@ -2176,7 +2176,7 @@ } void UnwrappedLineParser::parseRecord(bool ParseAsExpr) { - const FormatToken &InitialToken = *FormatTok; + FormatToken const &InitialToken = *FormatTok; nextToken(); // The actual identifier can be a nested name specifier, and in macros @@ -2442,7 +2442,7 @@ addUnwrappedLine(); } -LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line, +LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(UnwrappedLine const &Line, StringRef Prefix = "") { llvm::dbgs() << Prefix << "Line(" << Line.Level << ", FSC=" << Line.FirstStartColumn << ")" @@ -2457,7 +2457,7 @@ for (std::list::const_iterator I = Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) { - const UnwrappedLineNode &Node = *I; + UnwrappedLineNode const &Node = *I; for (SmallVectorImpl::const_iterator I = Node.Children.begin(), E = Node.Children.end(); @@ -2491,15 +2491,15 @@ bool UnwrappedLineParser::eof() const { return FormatTok->Tok.is(tok::eof); } -bool UnwrappedLineParser::isOnNewLine(const FormatToken &FormatTok) { +bool UnwrappedLineParser::isOnNewLine(FormatToken const &FormatTok) { return (Line->InPPDirective || FormatTok.HasUnescapedNewline) && FormatTok.NewlinesBefore > 0; } // Checks if \p FormatTok is a line comment that continues the line comment // section on \p Line. -static bool continuesLineCommentSection(const FormatToken &FormatTok, - const UnwrappedLine &Line, +static bool continuesLineCommentSection(FormatToken const &FormatTok, + UnwrappedLine const &Line, llvm::Regex &CommentPragmasRegex) { if (Line.Tokens.empty()) return false; @@ -2577,12 +2577,12 @@ // a, // first line // // second line // }; - const FormatToken *MinColumnToken = Line.Tokens.front().Tok; + FormatToken const *MinColumnToken = Line.Tokens.front().Tok; // Scan for '{//'. If found, use the column of '{' as a min column for line // comment section continuation. - const FormatToken *PreviousToken = nullptr; - for (const UnwrappedLineNode &Node : Line.Tokens) { + FormatToken const *PreviousToken = nullptr; + for (UnwrappedLineNode const &Node : Line.Tokens) { if (PreviousToken && PreviousToken->is(tok::l_brace) && isLineComment(*Node.Tok)) { MinColumnToken = PreviousToken; @@ -2642,8 +2642,8 @@ } void UnwrappedLineParser::distributeComments( - const SmallVectorImpl &Comments, - const FormatToken *NextTok) { + SmallVectorImpl const &Comments, + FormatToken const *NextTok) { // Whether or not a line comment token continues a line is controlled by // the method continuesLineCommentSection, with the following caveat: // Index: clang/lib/Format/UsingDeclarationsSorter.h =================================================================== --- clang/lib/Format/UsingDeclarationsSorter.h +++ clang/lib/Format/UsingDeclarationsSorter.h @@ -22,7 +22,7 @@ class UsingDeclarationsSorter : public TokenAnalyzer { public: - UsingDeclarationsSorter(const Environment &Env, const FormatStyle &Style); + UsingDeclarationsSorter(Environment const &Env, FormatStyle const &Style); std::pair analyze(TokenAnnotator &Annotator, Index: clang/lib/Format/UsingDeclarationsSorter.cpp =================================================================== --- clang/lib/Format/UsingDeclarationsSorter.cpp +++ clang/lib/Format/UsingDeclarationsSorter.cpp @@ -65,13 +65,13 @@ } struct UsingDeclaration { - const AnnotatedLine *Line; + AnnotatedLine const *Line; std::string Label; - UsingDeclaration(const AnnotatedLine *Line, const std::string &Label) + UsingDeclaration(AnnotatedLine const *Line, const std::string &Label) : Line(Line), Label(Label) {} - bool operator<(const UsingDeclaration &Other) const { + bool operator<(UsingDeclaration const &Other) const { return compareLabels(Label, Other.Label) < 0; } }; @@ -84,10 +84,10 @@ /// and not type aliases, as in: /// using A = B::C; /// Type aliases are in general not safe to permute. -std::string computeUsingDeclarationLabel(const FormatToken *UsingTok) { +std::string computeUsingDeclarationLabel(FormatToken const *UsingTok) { assert(UsingTok && UsingTok->is(tok::kw_using) && "Expecting a using token"); std::string Label; - const FormatToken *Tok = UsingTok->Next; + FormatToken const *Tok = UsingTok->Next; if (Tok && Tok->is(tok::kw_typename)) { Label.append("typename "); Tok = Tok->Next; @@ -113,9 +113,9 @@ void endUsingDeclarationBlock( SmallVectorImpl *UsingDeclarations, - const SourceManager &SourceMgr, tooling::Replacements *Fixes) { + SourceManager const &SourceMgr, tooling::Replacements *Fixes) { bool BlockAffected = false; - for (const UsingDeclaration &Declaration : *UsingDeclarations) { + for (UsingDeclaration const &Declaration : *UsingDeclarations) { if (Declaration.Line->Affected) { BlockAffected = true; break; @@ -131,7 +131,7 @@ SortedUsingDeclarations.erase( std::unique(SortedUsingDeclarations.begin(), SortedUsingDeclarations.end(), - [](const UsingDeclaration &a, const UsingDeclaration &b) { + [](UsingDeclaration const &a, UsingDeclaration const &b) { return a.Label == b.Label; }), SortedUsingDeclarations.end()); @@ -177,14 +177,14 @@ } // namespace -UsingDeclarationsSorter::UsingDeclarationsSorter(const Environment &Env, - const FormatStyle &Style) +UsingDeclarationsSorter::UsingDeclarationsSorter(Environment const &Env, + FormatStyle const &Style) : TokenAnalyzer(Env, Style) {} std::pair UsingDeclarationsSorter::analyze( TokenAnnotator &Annotator, SmallVectorImpl &AnnotatedLines, FormatTokenLexer &Tokens) { - const SourceManager &SourceMgr = Env.getSourceManager(); + SourceManager const &SourceMgr = Env.getSourceManager(); AffectedRangeMgr.computeAffectedLines(AnnotatedLines); tooling::Replacements Fixes; SmallVector UsingDeclarations; Index: clang/lib/Format/WhitespaceManager.h =================================================================== --- clang/lib/Format/WhitespaceManager.h +++ clang/lib/Format/WhitespaceManager.h @@ -36,7 +36,7 @@ /// There may be multiple calls to \c breakToken for a given token. class WhitespaceManager { public: - WhitespaceManager(const SourceManager &SourceMgr, const FormatStyle &Style, + WhitespaceManager(SourceManager const &SourceMgr, FormatStyle const &Style, bool UseCRLF) : SourceMgr(SourceMgr), Style(Style), UseCRLF(UseCRLF) {} @@ -56,7 +56,7 @@ /// /// Needs to be called for every token for which \c replaceWhitespace /// was not called. - void addUntouchableToken(const FormatToken &Tok, bool InPPDirective); + void addUntouchableToken(FormatToken const &Tok, bool InPPDirective); llvm::Error addReplacement(const tooling::Replacement &Replacement); @@ -74,7 +74,7 @@ /// /// When \p InPPDirective is true, escaped newlines are inserted. \p Spaces is /// used to align backslashes correctly. - void replaceWhitespaceInToken(const FormatToken &Tok, unsigned Offset, + void replaceWhitespaceInToken(FormatToken const &Tok, unsigned Offset, unsigned ReplaceChars, StringRef PreviousPostfix, StringRef CurrentPrefix, bool InPPDirective, @@ -89,11 +89,11 @@ /// Functor to sort changes in original source order. class IsBeforeInFile { public: - IsBeforeInFile(const SourceManager &SourceMgr) : SourceMgr(SourceMgr) {} - bool operator()(const Change &C1, const Change &C2) const; + IsBeforeInFile(SourceManager const &SourceMgr) : SourceMgr(SourceMgr) {} + bool operator()(Change const &C1, Change const &C2) const; private: - const SourceManager &SourceMgr; + SourceManager const &SourceMgr; }; /// Creates a \c Change. @@ -105,7 +105,7 @@ /// /// \p StartOfTokenColumn and \p InPPDirective will be used to lay out /// trailing comments and escaped newlines. - Change(const FormatToken &Tok, bool CreateReplacement, + Change(FormatToken const &Tok, bool CreateReplacement, SourceRange OriginalWhitespaceRange, int Spaces, unsigned StartOfTokenColumn, unsigned NewlinesBefore, StringRef PreviousLinePostfix, StringRef CurrentLinePrefix, @@ -115,7 +115,7 @@ // this change inserts whitespace. // FIXME: Currently this is not set correctly for breaks inside comments, as // the \c BreakableToken is still doing its own alignment. - const FormatToken *Tok; + FormatToken const *Tok; bool CreateReplacement; // Changes might be in the middle of a token, so we cannot just keep the @@ -154,7 +154,7 @@ // comment. \c IndentationOffset is a relative column offset to this // change, so that the correct column can be reconstructed at the end of // the alignment process. - const Change *StartOfBlockComment; + Change const *StartOfBlockComment; int IndentationOffset; // A combination of indent level and nesting level, which are used in @@ -207,9 +207,9 @@ unsigned Spaces, unsigned WhitespaceStartColumn); SmallVector Changes; - const SourceManager &SourceMgr; + SourceManager const &SourceMgr; tooling::Replacements Replaces; - const FormatStyle &Style; + FormatStyle const &Style; bool UseCRLF; }; Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -18,13 +18,13 @@ namespace format { bool WhitespaceManager::Change::IsBeforeInFile::operator()( - const Change &C1, const Change &C2) const { + Change const &C1, Change const &C2) const { return SourceMgr.isBeforeInTranslationUnit( C1.OriginalWhitespaceRange.getBegin(), C2.OriginalWhitespaceRange.getBegin()); } -WhitespaceManager::Change::Change(const FormatToken &Tok, +WhitespaceManager::Change::Change(FormatToken const &Tok, bool CreateReplacement, SourceRange OriginalWhitespaceRange, int Spaces, unsigned StartOfTokenColumn, @@ -55,7 +55,7 @@ /*IsInsideToken=*/false)); } -void WhitespaceManager::addUntouchableToken(const FormatToken &Tok, +void WhitespaceManager::addUntouchableToken(FormatToken const &Tok, bool InPPDirective) { if (Tok.Finalized) return; @@ -72,7 +72,7 @@ } void WhitespaceManager::replaceWhitespaceInToken( - const FormatToken &Tok, unsigned Offset, unsigned ReplaceChars, + FormatToken const &Tok, unsigned Offset, unsigned ReplaceChars, StringRef PreviousPostfix, StringRef CurrentPrefix, bool InPPDirective, unsigned Newlines, int Spaces) { if (Tok.Finalized) @@ -115,7 +115,7 @@ SourceMgr.getFileOffset(PreviousOriginalWhitespaceEnd); assert(PreviousOriginalWhitespaceEndOffset <= OriginalWhitespaceStartOffset); - const char *const PreviousOriginalWhitespaceEndData = + char const *const PreviousOriginalWhitespaceEndData = SourceMgr.getCharacterData(PreviousOriginalWhitespaceEnd); StringRef Text(PreviousOriginalWhitespaceEndData, SourceMgr.getCharacterData(OriginalWhitespaceStart) - @@ -326,7 +326,7 @@ // that are split across multiple lines. See the test case in FormatTest.cpp // that mentions "split function parameter alignment" for an example of this. template -static unsigned AlignTokens(const FormatStyle &Style, F &&Matches, +static unsigned AlignTokens(FormatStyle const &Style, F &&Matches, SmallVector &Changes, unsigned StartAt) { unsigned MinColumn = 0; @@ -478,7 +478,7 @@ if (!Style.AlignConsecutiveMacros) return; - auto AlignMacrosMatches = [](const Change &C) { + auto AlignMacrosMatches = [](Change const &C) { const FormatToken *Current = C.Tok; unsigned SpacesRequiredBefore = 1; @@ -559,7 +559,7 @@ AlignTokens( Style, - [&](const Change &C) { + [&](Change const &C) { // Do not align on equal signs that are first on a line. if (C.NewlinesBefore > 0) return false; @@ -747,7 +747,7 @@ void WhitespaceManager::generateChanges() { for (unsigned i = 0, e = Changes.size(); i != e; ++i) { - const Change &C = Changes[i]; + Change const &C = Changes[i]; if (i > 0) { assert(Changes[i - 1].OriginalWhitespaceRange.getBegin() != C.OriginalWhitespaceRange.getBegin() &&