diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h --- a/clang/lib/Format/TokenAnnotator.h +++ b/clang/lib/Format/TokenAnnotator.h @@ -161,43 +161,46 @@ /// Adapts the indent levels of comment lines to the indent of the /// subsequent line. // FIXME: Can/should this be done in the UnwrappedLineParser? - void setCommentLineLevels(SmallVectorImpl &Lines); + void setCommentLineLevels(SmallVectorImpl &Lines) const; - void annotate(AnnotatedLine &Line); - void calculateFormattingInformation(AnnotatedLine &Line); + void annotate(AnnotatedLine &Line) const; + void calculateFormattingInformation(AnnotatedLine &Line) const; private: /// Calculate the penalty for splitting before \c Tok. unsigned splitPenalty(const AnnotatedLine &Line, const FormatToken &Tok, - bool InFunctionDecl); + bool InFunctionDecl) const; bool spaceRequiredBeforeParens(const FormatToken &Right) const; bool spaceRequiredBetween(const AnnotatedLine &Line, const FormatToken &Left, - const FormatToken &Right); + const FormatToken &Right) const; - bool spaceRequiredBefore(const AnnotatedLine &Line, const FormatToken &Right); + bool spaceRequiredBefore(const AnnotatedLine &Line, + const FormatToken &Right) const; - bool mustBreakBefore(const AnnotatedLine &Line, const FormatToken &Right); + bool mustBreakBefore(const AnnotatedLine &Line, + const FormatToken &Right) const; - bool canBreakBefore(const AnnotatedLine &Line, const FormatToken &Right); + bool canBreakBefore(const AnnotatedLine &Line, + const FormatToken &Right) const; bool mustBreakForReturnType(const AnnotatedLine &Line) const; - void printDebugInfo(const AnnotatedLine &Line); + void printDebugInfo(const AnnotatedLine &Line) const; - void calculateUnbreakableTailLengths(AnnotatedLine &Line); + void calculateUnbreakableTailLengths(AnnotatedLine &Line) const; - void calculateArrayInitializerColumnList(AnnotatedLine &Line); + void calculateArrayInitializerColumnList(AnnotatedLine &Line) const; FormatToken *calculateInitializerColumnList(AnnotatedLine &Line, FormatToken *CurrentToken, - unsigned Depth); + unsigned Depth) const; FormatStyle::PointerAlignmentStyle - getTokenReferenceAlignment(const FormatToken &PointerOrReference); + getTokenReferenceAlignment(const FormatToken &PointerOrReference) const; - FormatStyle::PointerAlignmentStyle - getTokenPointerOrReferenceAlignment(const FormatToken &PointerOrReference); + FormatStyle::PointerAlignmentStyle getTokenPointerOrReferenceAlignment( + const FormatToken &PointerOrReference) const; const FormatStyle &Style; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2523,7 +2523,7 @@ } // end anonymous namespace void TokenAnnotator::setCommentLineLevels( - SmallVectorImpl &Lines) { + SmallVectorImpl &Lines) const { const AnnotatedLine *NextNonCommentLine = nullptr; for (AnnotatedLine *Line : llvm::reverse(Lines)) { assert(Line->First); @@ -2558,7 +2558,7 @@ return Result; } -void TokenAnnotator::annotate(AnnotatedLine &Line) { +void TokenAnnotator::annotate(AnnotatedLine &Line) const { for (auto &Child : Line.Children) annotate(*Child); @@ -2725,7 +2725,7 @@ return false; } -void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { +void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const { for (AnnotatedLine *ChildLine : Line.Children) calculateFormattingInformation(*ChildLine); @@ -2845,7 +2845,8 @@ LLVM_DEBUG({ printDebugInfo(Line); }); } -void TokenAnnotator::calculateUnbreakableTailLengths(AnnotatedLine &Line) { +void TokenAnnotator::calculateUnbreakableTailLengths( + AnnotatedLine &Line) const { unsigned UnbreakableTailLength = 0; FormatToken *Current = Line.Last; while (Current) { @@ -2861,7 +2862,8 @@ } } -void TokenAnnotator::calculateArrayInitializerColumnList(AnnotatedLine &Line) { +void TokenAnnotator::calculateArrayInitializerColumnList( + AnnotatedLine &Line) const { if (Line.First == Line.Last) return; auto *CurrentToken = Line.First; @@ -2881,7 +2883,7 @@ } FormatToken *TokenAnnotator::calculateInitializerColumnList( - AnnotatedLine &Line, FormatToken *CurrentToken, unsigned Depth) { + AnnotatedLine &Line, FormatToken *CurrentToken, unsigned Depth) const { while (CurrentToken != nullptr && CurrentToken != Line.Last) { if (CurrentToken->is(tok::l_brace)) ++Depth; @@ -2901,7 +2903,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, const FormatToken &Tok, - bool InFunctionDecl) { + bool InFunctionDecl) const { const FormatToken &Left = *Tok.Previous; const FormatToken &Right = Tok; @@ -3113,7 +3115,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, const FormatToken &Left, - const FormatToken &Right) { + const FormatToken &Right) const { if (Left.is(tok::kw_return) && !Right.isOneOf(tok::semi, tok::r_paren, tok::hashhash)) return true; @@ -3491,7 +3493,7 @@ } bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, - const FormatToken &Right) { + const FormatToken &Right) const { const FormatToken &Left = *Right.Previous; // If the token is finalized don't touch it (as it could be in a @@ -3930,7 +3932,7 @@ } bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, - const FormatToken &Right) { + const FormatToken &Right) const { const FormatToken &Left = *Right.Previous; if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0) return true; @@ -4310,7 +4312,7 @@ } bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, - const FormatToken &Right) { + const FormatToken &Right) const { const FormatToken &Left = *Right.Previous; // Language-specific stuff. if (Style.isCSharp()) { @@ -4622,7 +4624,7 @@ (Left.is(TT_TemplateOpener) && !Right.is(TT_TemplateCloser)); } -void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) { +void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) const { llvm::errs() << "AnnotatedTokens(L=" << Line.Level << "):\n"; const FormatToken *Tok = Line.First; while (Tok) { @@ -4647,7 +4649,7 @@ } FormatStyle::PointerAlignmentStyle -TokenAnnotator::getTokenReferenceAlignment(const FormatToken &Reference) { +TokenAnnotator::getTokenReferenceAlignment(const FormatToken &Reference) const { assert(Reference.isOneOf(tok::amp, tok::ampamp)); switch (Style.ReferenceAlignment) { case FormatStyle::RAS_Pointer: @@ -4665,7 +4667,7 @@ FormatStyle::PointerAlignmentStyle TokenAnnotator::getTokenPointerOrReferenceAlignment( - const FormatToken &PointerOrReference) { + const FormatToken &PointerOrReference) const { if (PointerOrReference.isOneOf(tok::amp, tok::ampamp)) { switch (Style.ReferenceAlignment) { case FormatStyle::RAS_Pointer: