19
19
#include " swift/AST/ASTContext.h"
20
20
#include " swift/AST/CompilerPlugin.h"
21
21
#include " swift/AST/Expr.h"
22
+ #include " swift/AST/PrettyStackTrace.h"
22
23
#include " swift/AST/SourceFile.h"
23
24
#include " swift/AST/TypeCheckRequests.h"
24
25
#include " swift/Basic/Defer.h"
@@ -163,8 +164,6 @@ getMacroSignature(
163
164
typealias->getGenericSignature (), typealias->getUnderlyingType ());
164
165
}
165
166
166
-
167
-
168
167
// / Create a macro.
169
168
static MacroDecl *createMacro (
170
169
ModuleDecl *mod, Identifier macroName,
@@ -368,8 +367,10 @@ Expr *swift::expandMacroExpr(
368
367
NullTerminatedStringRef evaluatedSource;
369
368
370
369
MacroDecl *macro = cast<MacroDecl>(macroRef.getDecl ());
370
+ {
371
+ PrettyStackTraceExpr debugStack (ctx, " expanding macro" , expr);
371
372
372
- switch (macro->implementationKind ) {
373
+ switch (macro->implementationKind ) {
373
374
case MacroDecl::ImplementationKind::Builtin: {
374
375
// Builtin macros are handled via ASTGen.
375
376
auto astGenSourceFile = sourceFile->exportedSourceFile ;
@@ -380,8 +381,8 @@ Expr *swift::expandMacroExpr(
380
381
const char *evaluatedSourceAddress;
381
382
ptrdiff_t evaluatedSourceLength;
382
383
swift_ASTGen_evaluateMacro (
383
- astGenSourceFile, expr->getStartLoc ().getOpaquePointerValue (),
384
- &evaluatedSourceAddress, &evaluatedSourceLength);
384
+ astGenSourceFile, expr->getStartLoc ().getOpaquePointerValue (),
385
+ &evaluatedSourceAddress, &evaluatedSourceLength);
385
386
if (!evaluatedSourceAddress)
386
387
return nullptr ;
387
388
evaluatedSource = NullTerminatedStringRef (evaluatedSourceAddress,
@@ -394,18 +395,19 @@ Expr *swift::expandMacroExpr(
394
395
auto bufferID = sourceFile->getBufferID ();
395
396
auto sourceFileText = sourceMgr.getEntireTextForBuffer (*bufferID);
396
397
auto evaluated = plugin->invokeRewrite (
397
- /* targetModuleName*/ dc->getParentModule ()->getName ().str (),
398
- /* filePath*/ sourceFile->getFilename (),
399
- /* sourceFileText*/ sourceFileText,
400
- /* range*/ Lexer::getCharSourceRangeFromSourceRange (
401
- sourceMgr, expr->getSourceRange ()),
402
- ctx);
398
+ /* targetModuleName*/ dc->getParentModule ()->getName ().str (),
399
+ /* filePath*/ sourceFile->getFilename (),
400
+ /* sourceFileText*/ sourceFileText,
401
+ /* range*/ Lexer::getCharSourceRangeFromSourceRange (
402
+ sourceMgr, expr->getSourceRange ()),
403
+ ctx);
403
404
if (evaluated)
404
405
evaluatedSource = *evaluated;
405
406
else
406
407
return nullptr ;
407
408
break ;
408
409
}
410
+ }
409
411
}
410
412
411
413
// Figure out a reasonable name for the macro expansion buffer.
@@ -481,6 +483,8 @@ Expr *swift::expandMacroExpr(
481
483
ContextualTypePurpose::CTP_CoerceOperand
482
484
};
483
485
486
+ PrettyStackTraceExpr debugStack (
487
+ ctx, " type checking expanded macro" , expandedExpr);
484
488
Type realExpandedType = TypeChecker::typeCheckExpression (
485
489
expandedExpr, dc, contextualType);
486
490
if (!realExpandedType)
0 commit comments