@@ -8617,51 +8617,6 @@ bool RefactoringActionExpandMacro::isApplicable(ResolvedCursorInfoPtr Info,
86178617 return !getMacroExpansionBuffers (Diag.SourceMgr , Info).empty ();
86188618}
86198619
8620- // / Given the expanded code for a particular macro, perform whitespace
8621- // / adjustments to make the refactoring more.
8622- static StringRef adjustMacroExpansionWhitespace (
8623- GeneratedSourceInfo::Kind kind, StringRef expandedCode,
8624- llvm::SmallString<64 > &scratch
8625- ) {
8626- scratch.clear ();
8627-
8628- switch (kind) {
8629- case GeneratedSourceInfo::ExpressionMacroExpansion:
8630- case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
8631- return expandedCode;
8632-
8633- case GeneratedSourceInfo::AccessorMacroExpansion:
8634- // For accessor macros, wrap curly braces around the buffer contents.
8635- scratch += " {\n " ;
8636- scratch += expandedCode;
8637- scratch += " \n }" ;
8638- return scratch;
8639-
8640- case GeneratedSourceInfo::MemberAttributeMacroExpansion:
8641- // For member-attribute macros, add a space at the end.
8642- scratch += expandedCode;
8643- scratch += " " ;
8644- return scratch;
8645-
8646- case GeneratedSourceInfo::PeerMacroExpansion:
8647- case GeneratedSourceInfo::ConformanceMacroExpansion:
8648- // For peers and conformances, add a newline to create some separation.
8649- scratch += " \n " ;
8650- LLVM_FALLTHROUGH;
8651-
8652- case GeneratedSourceInfo::MemberMacroExpansion:
8653- // For members, add a newline.
8654- scratch += " \n " ;
8655- scratch += expandedCode;
8656- scratch += " \n " ;
8657- return scratch;
8658-
8659- case GeneratedSourceInfo::ReplacedFunctionBody:
8660- case GeneratedSourceInfo::PrettyPrinted:
8661- return expandedCode;
8662- }
8663- }
8664-
86658620bool RefactoringActionExpandMacro::performChange () {
86668621 auto bufferIDs = getMacroExpansionBuffers (SM, CursorInfo);
86678622 if (bufferIDs.empty ())
@@ -8682,33 +8637,6 @@ bool RefactoringActionExpandMacro::performChange() {
86828637 rewrittenBuffer.empty ())
86838638 continue ;
86848639
8685- auto originalSourceRange = generatedInfo->originalSourceRange ;
8686-
8687- SmallString<64 > scratchBuffer;
8688- if (generatedInfo->kind == GeneratedSourceInfo::MemberMacroExpansion) {
8689- // For member macros, adjust the source range from before-the-close-brace
8690- // to after-the-open-brace.
8691- ASTNode node = ASTNode::getFromOpaqueValue (generatedInfo->astNode );
8692- auto decl = node.dyn_cast <Decl *>();
8693- if (!decl)
8694- continue ;
8695-
8696- SourceLoc leftBraceLoc;
8697- if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
8698- leftBraceLoc = nominal->getBraces ().Start ;
8699- } else if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
8700- leftBraceLoc = ext->getBraces ().Start ;
8701- }
8702- if (leftBraceLoc.isInvalid ())
8703- continue ;
8704-
8705- auto afterLeftBraceLoc = Lexer::getLocForEndOfToken (SM, leftBraceLoc);
8706- originalSourceRange = CharSourceRange (afterLeftBraceLoc, 0 );
8707- }
8708-
8709- rewrittenBuffer = adjustMacroExpansionWhitespace (
8710- generatedInfo->kind , rewrittenBuffer, scratchBuffer);
8711-
87128640 // `TheFile` is the file of the actual expansion site, where as
87138641 // `OriginalFile` is the possibly enclosing buffer. Concretely:
87148642 // ```
@@ -8727,6 +8655,7 @@ bool RefactoringActionExpandMacro::performChange() {
87278655 // site (`@_someBufferName`). Thus, we need to include the path to the
87288656 // original source as well. Note that this path could itself be another
87298657 // expansion.
8658+ auto originalSourceRange = generatedInfo->originalSourceRange ;
87308659 SourceFile *originalFile =
87318660 MD->getSourceFileContainingLocation (originalSourceRange.getStart ());
87328661 StringRef originalPath;
0 commit comments