@@ -8617,51 +8617,6 @@ bool RefactoringActionExpandMacro::isApplicable(ResolvedCursorInfoPtr Info,
8617
8617
return !getMacroExpansionBuffers (Diag.SourceMgr , Info).empty ();
8618
8618
}
8619
8619
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
-
8665
8620
bool RefactoringActionExpandMacro::performChange () {
8666
8621
auto bufferIDs = getMacroExpansionBuffers (SM, CursorInfo);
8667
8622
if (bufferIDs.empty ())
@@ -8682,33 +8637,6 @@ bool RefactoringActionExpandMacro::performChange() {
8682
8637
rewrittenBuffer.empty ())
8683
8638
continue ;
8684
8639
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
-
8712
8640
// `TheFile` is the file of the actual expansion site, where as
8713
8641
// `OriginalFile` is the possibly enclosing buffer. Concretely:
8714
8642
// ```
@@ -8727,6 +8655,7 @@ bool RefactoringActionExpandMacro::performChange() {
8727
8655
// site (`@_someBufferName`). Thus, we need to include the path to the
8728
8656
// original source as well. Note that this path could itself be another
8729
8657
// expansion.
8658
+ auto originalSourceRange = generatedInfo->originalSourceRange ;
8730
8659
SourceFile *originalFile =
8731
8660
MD->getSourceFileContainingLocation (originalSourceRange.getStart ());
8732
8661
StringRef originalPath;
0 commit comments