Skip to content

Provide macro module name in MacroExpansionExpr creation #76505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6481,8 +6481,10 @@ class MacroExpansionExpr final : public Expr,
}

static MacroExpansionExpr *
create(DeclContext *dc, SourceLoc sigilLoc, DeclNameRef macroName,
DeclNameLoc macroNameLoc, SourceLoc leftAngleLoc,
create(DeclContext *dc, SourceLoc sigilLoc,
DeclNameRef moduleName, DeclNameLoc moduleNameLoc,
DeclNameRef macroName, DeclNameLoc macroNameLoc,
SourceLoc leftAngleLoc,
ArrayRef<TypeRepr *> genericArgs, SourceLoc rightAngleLoc,
ArgumentList *argList, MacroRoles roles, bool isImplicit = false,
Type ty = Type());
Expand Down
10 changes: 6 additions & 4 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2783,17 +2783,19 @@ TypeJoinExpr::forBranchesOfSingleValueStmtExpr(ASTContext &ctx, Type joinType,
}

MacroExpansionExpr *MacroExpansionExpr::create(
DeclContext *dc, SourceLoc sigilLoc, DeclNameRef macroName,
DeclNameLoc macroNameLoc, SourceLoc leftAngleLoc,
DeclContext *dc, SourceLoc sigilLoc,
DeclNameRef moduleName, DeclNameLoc moduleNameLoc,
DeclNameRef macroName, DeclNameLoc macroNameLoc,
SourceLoc leftAngleLoc,
ArrayRef<TypeRepr *> genericArgs, SourceLoc rightAngleLoc,
ArgumentList *argList, MacroRoles roles, bool isImplicit,
Type ty
) {
ASTContext &ctx = dc->getASTContext();
MacroExpansionInfo *info = new (ctx) MacroExpansionInfo{
sigilLoc,
/*moduleName*/ DeclNameRef(),
/*moduleNameLoc*/ DeclNameLoc(),
moduleName,
moduleNameLoc,
macroName,
macroNameLoc,
leftAngleLoc,
Expand Down
4 changes: 3 additions & 1 deletion lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3484,7 +3484,9 @@ ParserResult<Expr> Parser::parseExprMacroExpansion(bool isExprBasic) {
return makeParserResult(
status,
MacroExpansionExpr::create(
CurDeclContext, poundLoc, macroNameRef, macroNameLoc, leftAngleLoc,
CurDeclContext, poundLoc,
/*module name=*/DeclNameRef(), /*module name loc=*/DeclNameLoc(),
macroNameRef, macroNameLoc, leftAngleLoc,
Context.AllocateCopy(genericArgs), rightAngleLoc, argList,
CurDeclContext->isTypeContext() ? MacroRole::Declaration
: getFreestandingMacroRoles()));
Expand Down
4 changes: 3 additions & 1 deletion lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3032,7 +3032,9 @@ namespace {
auto macro = cast<MacroDecl>(overload.choice.getDecl());
ConcreteDeclRef macroRef = resolveConcreteDeclRef(macro, locator);
auto *expansion = MacroExpansionExpr::create(
dc, expr->getStartLoc(), DeclNameRef(macro->getName()),
dc, expr->getStartLoc(),
/*module name=*/DeclNameRef(), /*module name loc=*/DeclNameLoc(),
DeclNameRef(macro->getName()),
DeclNameLoc(expr->getLoc()), SourceLoc(), {}, SourceLoc(), nullptr,
MacroRole::Expression, /*isImplicit=*/true, expandedType);
expansion->setMacroRef(macroRef);
Expand Down
6 changes: 4 additions & 2 deletions lib/Sema/TypeCheckMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,8 +2023,10 @@ ConcreteDeclRef ResolveMacroRequest::evaluate(Evaluator &evaluator,
} else {
SourceRange genericArgsRange = macroRef.getGenericArgsRange();
macroExpansion = MacroExpansionExpr::create(
dc, macroRef.getSigilLoc(), macroRef.getMacroName(),
macroRef.getMacroNameLoc(), genericArgsRange.Start,
dc, macroRef.getSigilLoc(),
macroRef.getModuleName(), macroRef.getModuleNameLoc(),
macroRef.getMacroName(), macroRef.getMacroNameLoc(),
genericArgsRange.Start,
macroRef.getGenericArgs(), genericArgsRange.End,
macroRef.getArgs(), roles);
}
Expand Down