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"
@@ -165,8 +166,6 @@ getMacroSignature(
165
166
typealias->getGenericSignature (), typealias->getUnderlyingType ());
166
167
}
167
168
168
-
169
-
170
169
// / Create a macro.
171
170
static MacroDecl *createMacro (
172
171
ModuleDecl *mod, Identifier macroName,
@@ -370,8 +369,10 @@ Expr *swift::expandMacroExpr(
370
369
NullTerminatedStringRef evaluatedSource;
371
370
372
371
MacroDecl *macro = cast<MacroDecl>(macroRef.getDecl ());
372
+ {
373
+ PrettyStackTraceExpr debugStack (ctx, " expanding macro" , expr);
373
374
374
- switch (macro->implementationKind ) {
375
+ switch (macro->implementationKind ) {
375
376
case MacroDecl::ImplementationKind::Builtin: {
376
377
// Builtin macros are handled via ASTGen.
377
378
auto astGenSourceFile = sourceFile->exportedSourceFile ;
@@ -382,8 +383,8 @@ Expr *swift::expandMacroExpr(
382
383
const char *evaluatedSourceAddress;
383
384
ptrdiff_t evaluatedSourceLength;
384
385
swift_ASTGen_evaluateMacro (
385
- astGenSourceFile, expr->getStartLoc ().getOpaquePointerValue (),
386
- &evaluatedSourceAddress, &evaluatedSourceLength);
386
+ astGenSourceFile, expr->getStartLoc ().getOpaquePointerValue (),
387
+ &evaluatedSourceAddress, &evaluatedSourceLength);
387
388
if (!evaluatedSourceAddress)
388
389
return nullptr ;
389
390
evaluatedSource = NullTerminatedStringRef (evaluatedSourceAddress,
@@ -396,18 +397,19 @@ Expr *swift::expandMacroExpr(
396
397
auto bufferID = sourceFile->getBufferID ();
397
398
auto sourceFileText = sourceMgr.getEntireTextForBuffer (*bufferID);
398
399
auto evaluated = plugin->invokeRewrite (
399
- /* targetModuleName*/ dc->getParentModule ()->getName ().str (),
400
- /* filePath*/ sourceFile->getFilename (),
401
- /* sourceFileText*/ sourceFileText,
402
- /* range*/ Lexer::getCharSourceRangeFromSourceRange (
403
- sourceMgr, expr->getSourceRange ()),
404
- ctx);
400
+ /* targetModuleName*/ dc->getParentModule ()->getName ().str (),
401
+ /* filePath*/ sourceFile->getFilename (),
402
+ /* sourceFileText*/ sourceFileText,
403
+ /* range*/ Lexer::getCharSourceRangeFromSourceRange (
404
+ sourceMgr, expr->getSourceRange ()),
405
+ ctx);
405
406
if (evaluated)
406
407
evaluatedSource = *evaluated;
407
408
else
408
409
return nullptr ;
409
410
break ;
410
411
}
412
+ }
411
413
}
412
414
413
415
// Figure out a reasonable name for the macro expansion buffer.
@@ -483,6 +485,8 @@ Expr *swift::expandMacroExpr(
483
485
ContextualTypePurpose::CTP_CoerceOperand
484
486
};
485
487
488
+ PrettyStackTraceExpr debugStack (
489
+ ctx, " type checking expanded macro" , expandedExpr);
486
490
Type realExpandedType = TypeChecker::typeCheckExpression (
487
491
expandedExpr, dc, contextualType);
488
492
if (!realExpandedType)
0 commit comments