Skip to content

Commit 72c51cc

Browse files
committed
Simplify the code by using Lexer::getAsCharRange to advance to the end location of the end token in the range.
1 parent b2a908f commit 72c51cc

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/Basic/Builtins.h"
1414
#include "clang/Basic/DiagnosticOptions.h"
1515
#include "clang/Basic/FileEntry.h"
16+
#include "clang/Basic/LangOptions.h"
1617
#include "clang/Basic/LangStandard.h"
1718
#include "clang/Basic/Sarif.h"
1819
#include "clang/Basic/SourceLocation.h"
@@ -114,25 +115,18 @@ class DeserializedDeclsLineRangePrinter : public ASTConsumer,
114115
}
115116

116117
static Position GetEndSpelling(const SourceManager &SM,
117-
const CharSourceRange &R,
118+
const CharSourceRange &Range,
118119
const LangOptions &LangOpts) {
120+
// For token ranges, compute end location for end character of the range.
121+
// The end location of returned range is exclusive.
122+
CharSourceRange R = Lexer::getAsCharRange(Range, SM, LangOpts);
119123
SourceLocation End = R.getEnd();
120-
if (R.isTokenRange()) {
121-
// Compute end location for end character of the range.
122-
// The returned location is exclusive.
123-
End = Lexer::getLocForEndOfToken(End, 0, SM, LangOpts);
124-
} else {
125-
// If end already points at the last character in the range, advance one
126-
// location, so that end location is exclusive.
127-
End = End.getLocWithOffset(1);
128-
}
129124
// Relex the token past the end location of the last token in the source
130125
// range. If it's a semicolon, advance the location by one token.
131126
Token PossiblySemi;
132127
Lexer::getRawToken(End, PossiblySemi, SM, LangOpts, true);
133128
if (PossiblySemi.is(tok::semi))
134-
End = Lexer::getLocForEndOfToken(PossiblySemi.getLocation(), 0, SM,
135-
LangOpts);
129+
End = End.getLocWithOffset(1);
136130
return {SM.getSpellingLineNumber(End), SM.getSpellingColumnNumber(End)};
137131
}
138132
};

0 commit comments

Comments
 (0)