|
29 | 29 | #include "swift/Basic/SourceManager.h"
|
30 | 30 | #include "swift/Basic/StringExtras.h"
|
31 | 31 | #include "swift/Demangling/Demangler.h"
|
| 32 | +#include "swift/Demangling/ManglingMacros.h" |
32 | 33 | #include "swift/Parse/Lexer.h"
|
33 | 34 | #include "swift/Subsystems.h"
|
34 | 35 |
|
@@ -310,6 +311,20 @@ ExternalMacroDefinitionRequest::evaluate(
|
310 | 311 | return ExternalMacroDefinition{nullptr};
|
311 | 312 | }
|
312 | 313 |
|
| 314 | +/// Adjust the given mangled name for a macro expansion to produce a valid |
| 315 | +/// buffer name. |
| 316 | +static std::string adjustMacroExpansionBufferName(StringRef name) { |
| 317 | + std::string result; |
| 318 | + if (name.startswith(MANGLING_PREFIX_STR)) { |
| 319 | + result += MACRO_EXPANSION_BUFFER_MANGLING_PREFIX; |
| 320 | + name = name.drop_front(StringRef(MANGLING_PREFIX_STR).size()); |
| 321 | + } |
| 322 | + |
| 323 | + result += name; |
| 324 | + result += ".swift"; |
| 325 | + return result; |
| 326 | +} |
| 327 | + |
313 | 328 | bool ExpandMemberAttributeMacros::evaluate(Evaluator &evaluator,
|
314 | 329 | Decl *decl) const {
|
315 | 330 | auto *parentDecl = decl->getDeclContext()->getAsDecl();
|
@@ -468,12 +483,12 @@ Expr *swift::expandMacroExpr(
|
468 | 483 |
|
469 | 484 | // Figure out a reasonable name for the macro expansion buffer.
|
470 | 485 | std::string bufferName;
|
471 |
| - { |
| 486 | + if (auto expansionExpr = dyn_cast<MacroExpansionExpr>(expr)) { |
472 | 487 | Mangle::ASTMangler mangler;
|
473 |
| - if (auto expansionExpr = dyn_cast<MacroExpansionExpr>(expr)) |
474 |
| - bufferName = mangler.mangleMacroExpansion(expansionExpr); |
475 |
| - else |
476 |
| - bufferName = "<macro expansion>"; |
| 488 | + bufferName = adjustMacroExpansionBufferName( |
| 489 | + mangler.mangleMacroExpansion(expansionExpr)); |
| 490 | + } else { |
| 491 | + bufferName = "macro-expansion"; |
477 | 492 | }
|
478 | 493 |
|
479 | 494 | // Dump macro expansions to standard output, if requested.
|
|
0 commit comments