@@ -118,47 +118,19 @@ findMembersUsedInInitExpr(const CXXCtorInitializer *Initializer,
118118 return Results;
119119}
120120
121- // / Returns the next token after `Loc` (including comment tokens).
122- static std::optional<Token> getTokenAfter (SourceLocation Loc,
123- const SourceManager &SM,
124- const LangOptions &LangOpts) {
125- if (Loc.isMacroID ()) {
126- return std::nullopt ;
127- }
128- Loc = Lexer::getLocForEndOfToken (Loc, 0 , SM, LangOpts);
129-
130- // Break down the source location.
131- std::pair<FileID, unsigned > LocInfo = SM.getDecomposedLoc (Loc);
132-
133- // Try to load the file buffer.
134- bool InvalidTemp = false ;
135- StringRef File = SM.getBufferData (LocInfo.first , &InvalidTemp);
136- if (InvalidTemp)
137- return std::nullopt ;
138-
139- const char *TokenBegin = File.data () + LocInfo.second ;
140-
141- Lexer lexer (SM.getLocForStartOfFile (LocInfo.first ), LangOpts, File.begin (),
142- TokenBegin, File.end ());
143- lexer.SetCommentRetentionState (true );
144- // Find the token.
145- Token Tok;
146- lexer.LexFromRawLexer (Tok);
147- return Tok;
148- }
149-
150121// / Returns the end of the trailing comments after `Loc`.
151122static SourceLocation getEndOfTrailingComment (SourceLocation Loc,
152123 const SourceManager &SM,
153124 const LangOptions &LangOpts) {
154125 // We consider any following comment token that is indented more than the
155126 // first comment to be part of the trailing comment.
156127 const unsigned Column = SM.getPresumedColumnNumber (Loc);
157- std::optional<Token> Tok = getTokenAfter (Loc, SM, LangOpts);
128+ std::optional<Token> Tok =
129+ Lexer::findNextToken (Loc, SM, LangOpts, /* IncludeComments=*/ true );
158130 while (Tok && Tok->is (tok::comment) &&
159131 SM.getPresumedColumnNumber (Tok->getLocation ()) > Column) {
160132 Loc = Tok->getEndLoc ();
161- Tok = getTokenAfter (Loc, SM, LangOpts);
133+ Tok = Lexer::findNextToken (Loc, SM, LangOpts, /* IncludeComments= */ true );
162134 }
163135 return Loc;
164136}
0 commit comments