|
13 | 13 | #include "clang/Basic/Builtins.h" |
14 | 14 | #include "clang/Basic/DiagnosticOptions.h" |
15 | 15 | #include "clang/Basic/FileEntry.h" |
| 16 | +#include "clang/Basic/LangOptions.h" |
16 | 17 | #include "clang/Basic/LangStandard.h" |
17 | 18 | #include "clang/Basic/Sarif.h" |
18 | 19 | #include "clang/Basic/SourceLocation.h" |
@@ -114,25 +115,18 @@ class DeserializedDeclsLineRangePrinter : public ASTConsumer, |
114 | 115 | } |
115 | 116 |
|
116 | 117 | static Position GetEndSpelling(const SourceManager &SM, |
117 | | - const CharSourceRange &R, |
| 118 | + const CharSourceRange &Range, |
118 | 119 | 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); |
119 | 123 | 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 | | - } |
129 | 124 | // Relex the token past the end location of the last token in the source |
130 | 125 | // range. If it's a semicolon, advance the location by one token. |
131 | 126 | Token PossiblySemi; |
132 | 127 | Lexer::getRawToken(End, PossiblySemi, SM, LangOpts, true); |
133 | 128 | if (PossiblySemi.is(tok::semi)) |
134 | | - End = Lexer::getLocForEndOfToken(PossiblySemi.getLocation(), 0, SM, |
135 | | - LangOpts); |
| 129 | + End = End.getLocWithOffset(1); |
136 | 130 | return {SM.getSpellingLineNumber(End), SM.getSpellingColumnNumber(End)}; |
137 | 131 | } |
138 | 132 | }; |
|
0 commit comments