@@ -271,7 +271,6 @@ ASTSourceFileScope::ASTSourceFileScope(SourceFile *SF,
271
271
if (auto enclosingSF = SF->getEnclosingSourceFile ()) {
272
272
SourceLoc parentLoc;
273
273
auto macroRole = SF->getFulfilledMacroRole ();
274
- auto expansion = SF->getMacroExpansion ();
275
274
276
275
// Determine the parent source location based on the macro role.
277
276
AbstractFunctionDecl *bodyForDecl = nullptr ;
@@ -283,35 +282,20 @@ ASTSourceFileScope::ASTSourceFileScope(SourceFile *SF,
283
282
case MacroRole::MemberAttribute:
284
283
case MacroRole::Conformance:
285
284
case MacroRole::Extension:
286
- parentLoc = expansion.getStartLoc ();
285
+ case MacroRole::Member:
286
+ case MacroRole::Peer:
287
+ case MacroRole::Preamble:
288
+ parentLoc = SF->getMacroInsertionRange ().End ;;
287
289
break ;
288
- case MacroRole::Preamble: {
289
- // Preamble macro roles start at the beginning of the macro body.
290
- auto func = cast<AbstractFunctionDecl>(expansion.get <Decl *>());
291
- parentLoc = func->getMacroExpandedBody ()->getStartLoc ();
292
- break ;
293
- }
294
- case MacroRole::Body:
290
+ case MacroRole::Body: {
291
+ // Use the end location of the function decl itself as the parentLoc
292
+ // for the new function body scope. This is different from the end
293
+ // location of the original source range, which is after the end of the
294
+ // function decl.
295
+ auto expansion = SF->getMacroExpansion ();
295
296
parentLoc = expansion.getEndLoc ();
296
297
bodyForDecl = cast<AbstractFunctionDecl>(expansion.get <Decl *>());
297
298
break ;
298
- case MacroRole::Peer: {
299
- ASTContext &ctx = SF->getASTContext ();
300
- SourceManager &sourceMgr = ctx.SourceMgr ;
301
- auto generatedSourceInfo =
302
- *sourceMgr.getGeneratedSourceInfo (*SF->getBufferID ());
303
-
304
- ASTNode node = ASTNode::getFromOpaqueValue (generatedSourceInfo.astNode );
305
- parentLoc = Lexer::getLocForEndOfToken (sourceMgr, node.getEndLoc ());
306
- break ;
307
- }
308
- case MacroRole::Member: {
309
- // For synthesized member macros, take the end loc of the
310
- // enclosing declaration (before the closing brace), because
311
- // the macro expansion is inside this scope.
312
- auto *decl = expansion.getAsDeclContext ()->getAsDecl ();
313
- parentLoc = decl->getEndLoc ();
314
- break ;
315
299
}
316
300
}
317
301
0 commit comments