@@ -216,6 +216,19 @@ static void appendRange(
216
216
while (!token.is (tok::eof)) {
217
217
lexer.lex (token);
218
218
219
+ // Skip over #sourceLocation's in the file.
220
+ if (token.is (tok::pound_sourceLocation)) {
221
+ lexer.lex (token);
222
+
223
+ // Skip from the left paren to the right paren.
224
+ assert (token.is (tok::l_paren));
225
+ while (!token.is (tok::r_paren)) {
226
+ lexer.lex (token);
227
+ }
228
+
229
+ nonCommentStart = Lexer::getLocForEndOfToken (sourceMgr, token.getLoc ());
230
+ }
231
+
219
232
if (token.is (tok::comment)) {
220
233
// Grab the start of the full comment token (with leading trivia as well)
221
234
SourceLoc commentLoc = token.getLoc ();
@@ -224,31 +237,37 @@ static void appendRange(
224
237
SourceLoc endLoc = Lexer::getLocForEndOfToken (sourceMgr, token.getLoc ());
225
238
226
239
// The comment token's range includes leading/trailing whitespace, so trim
227
- // whitespace and only strip the portions of the comment that are not whitespace.
240
+ // whitespace and only strip the portions of the comment that are not
241
+ // whitespace.
228
242
CharSourceRange range = CharSourceRange (sourceMgr, commentLoc, endLoc);
229
243
StringRef fullTokenText = sourceMgr.extractText (range);
230
- unsigned leadingWhitespace = fullTokenText.size () - fullTokenText.ltrim ().size ();
244
+ unsigned leadingWhitespace = fullTokenText.size () -
245
+ fullTokenText.ltrim ().size ();
231
246
if (leadingWhitespace > 0 ) {
232
247
commentLoc = commentLoc.getAdvancedLoc (leadingWhitespace);
233
248
}
234
249
235
- unsigned trailingWhitespace = fullTokenText.size () - fullTokenText.rtrim ().size ();
250
+ unsigned trailingWhitespace = fullTokenText.size () -
251
+ fullTokenText.rtrim ().size ();
236
252
if (trailingWhitespace > 0 ) {
237
253
endLoc = endLoc.getAdvancedLoc (-trailingWhitespace);
238
254
}
239
255
240
- // First, extract the text up to the start of the comment, including the whitespace.
256
+ // First, extract the text up to the start of the comment, including the
257
+ // whitespace.
241
258
auto charRange = CharSourceRange (sourceMgr, nonCommentStart, commentLoc);
242
259
StringRef text = sourceMgr.extractText (charRange);
243
260
scratch.append (text.begin (), text.end ());
244
261
245
- // Next, search through the comment text to see if it's a block comment with a newline. If so
246
- // we need to re-insert a newline to avoid fusing multi-line tokens together.
262
+ // Next, search through the comment text to see if it's a block comment
263
+ // with a newline. If so we need to re-insert a newline to avoid fusing
264
+ // multi-line tokens together.
247
265
auto commentTextRange = CharSourceRange (sourceMgr, commentLoc, endLoc);
248
266
StringRef commentText = sourceMgr.extractText (commentTextRange);
249
267
bool hasNewline = commentText.find_first_of (" \n\r " ) != StringRef::npos;
250
268
251
- // Use a newline as a filler character if the comment itself had a newline in it.
269
+ // Use a newline as a filler character if the comment itself had a newline
270
+ // in it.
252
271
char filler = hasNewline ? ' \n ' : ' ' ;
253
272
254
273
// Append a single whitespace filler character, to avoid fusing tokens.
0 commit comments