@@ -4824,7 +4824,8 @@ static Identifier encodeLocalPrecheckedDiscriminator(
4824
4824
4825
4825
void ASTMangler::appendMacroExpansionContext (
4826
4826
SourceLoc loc, DeclContext *origDC,
4827
- const FreestandingMacroExpansion *expansion
4827
+ Identifier macroName,
4828
+ unsigned macroDiscriminator
4828
4829
) {
4829
4830
origDC = MacroDiscriminatorContext::getInnermostMacroContext (origDC);
4830
4831
BaseEntitySignature nullBase (nullptr );
@@ -4833,9 +4834,9 @@ void ASTMangler::appendMacroExpansionContext(
4833
4834
if (auto outermostLocalDC = getOutermostLocalContext (origDC)) {
4834
4835
auto innermostNonlocalDC = outermostLocalDC->getParent ();
4835
4836
appendContext (innermostNonlocalDC, nullBase, StringRef ());
4836
- Identifier name = expansion-> getMacroName (). getBaseIdentifier () ;
4837
+ Identifier name = macroName ;
4837
4838
ASTContext &ctx = origDC->getASTContext ();
4838
- unsigned discriminator = expansion-> getDiscriminator () ;
4839
+ unsigned discriminator = macroDiscriminator ;
4839
4840
name = encodeLocalPrecheckedDiscriminator (ctx, name, discriminator);
4840
4841
appendIdentifier (name.str ());
4841
4842
} else {
@@ -4940,7 +4941,10 @@ void ASTMangler::appendMacroExpansionContext(
4940
4941
return appendMacroExpansionLoc ();
4941
4942
4942
4943
// Append our own context and discriminator.
4943
- appendMacroExpansionContext (outerExpansionLoc, origDC, expansion);
4944
+ appendMacroExpansionContext (
4945
+ outerExpansionLoc, origDC,
4946
+ macroName,
4947
+ macroDiscriminator);
4944
4948
appendMacroExpansionOperator (
4945
4949
baseName.userFacingName (), role, discriminator);
4946
4950
}
@@ -4967,16 +4971,14 @@ void ASTMangler::appendMacroExpansionOperator(
4967
4971
}
4968
4972
4969
4973
static StringRef getPrivateDiscriminatorIfNecessary (
4970
- const MacroExpansionExpr *expansion) {
4971
- auto dc = MacroDiscriminatorContext::getInnermostMacroContext (
4972
- expansion->getDeclContext ());
4973
- auto decl = dc->getAsDecl ();
4974
+ const DeclContext *macroDC) {
4975
+ auto decl = macroDC->getAsDecl ();
4974
4976
if (decl && !decl->isOutermostPrivateOrFilePrivateScope ())
4975
4977
return StringRef ();
4976
4978
4977
4979
// Mangle non-local private declarations with a textual discriminator
4978
4980
// based on their enclosing file.
4979
- auto topLevelSubcontext = dc ->getModuleScopeContext ();
4981
+ auto topLevelSubcontext = macroDC ->getModuleScopeContext ();
4980
4982
SourceFile *sf = dyn_cast<SourceFile>(topLevelSubcontext);
4981
4983
if (!sf)
4982
4984
return StringRef ();
@@ -4992,6 +4994,13 @@ static StringRef getPrivateDiscriminatorIfNecessary(
4992
4994
return discriminator.str ();
4993
4995
}
4994
4996
4997
+ static StringRef getPrivateDiscriminatorIfNecessary (
4998
+ const MacroExpansionExpr *expansion) {
4999
+ auto dc = MacroDiscriminatorContext::getInnermostMacroContext (
5000
+ expansion->getDeclContext ());
5001
+ return getPrivateDiscriminatorIfNecessary (dc);
5002
+ }
5003
+
4995
5004
static StringRef getPrivateDiscriminatorIfNecessary (
4996
5005
const FreestandingMacroExpansion *expansion) {
4997
5006
switch (expansion->getFreestandingMacroKind ()) {
@@ -5008,7 +5017,8 @@ void
5008
5017
ASTMangler::appendMacroExpansion (const FreestandingMacroExpansion *expansion) {
5009
5018
appendMacroExpansionContext (expansion->getPoundLoc (),
5010
5019
expansion->getDeclContext (),
5011
- expansion);
5020
+ expansion->getMacroName ().getBaseIdentifier (),
5021
+ expansion->getDiscriminator ());
5012
5022
auto privateDiscriminator = getPrivateDiscriminatorIfNecessary (expansion);
5013
5023
if (!privateDiscriminator.empty ()) {
5014
5024
appendIdentifier (privateDiscriminator);
@@ -5020,6 +5030,42 @@ ASTMangler::appendMacroExpansion(const FreestandingMacroExpansion *expansion) {
5020
5030
expansion->getDiscriminator ());
5021
5031
}
5022
5032
5033
+ void ASTMangler::appendMacroExpansion (ClosureExpr *attachedTo,
5034
+ CustomAttr *attr,
5035
+ MacroDecl *macro) {
5036
+ auto &ctx = attachedTo->getASTContext ();
5037
+ auto discriminator =
5038
+ ctx.getNextMacroDiscriminator (attachedTo,
5039
+ macro->getBaseName ());
5040
+
5041
+ appendMacroExpansionContext (
5042
+ attr->getLocation (),
5043
+ attachedTo,
5044
+ macro->getBaseName ().getIdentifier (),
5045
+ discriminator);
5046
+
5047
+ auto privateDiscriminator =
5048
+ getPrivateDiscriminatorIfNecessary (attachedTo);
5049
+ if (!privateDiscriminator.empty ()) {
5050
+ appendIdentifier (privateDiscriminator);
5051
+ appendOperator (" Ll" );
5052
+ }
5053
+
5054
+ appendMacroExpansionOperator (
5055
+ macro->getBaseName ().userFacingName (),
5056
+ MacroRole::Body,
5057
+ discriminator);
5058
+ }
5059
+
5060
+ std::string
5061
+ ASTMangler::mangleAttachedMacroExpansion (ClosureExpr *attachedTo,
5062
+ CustomAttr *attr,
5063
+ MacroDecl *macro) {
5064
+ beginMangling ();
5065
+ appendMacroExpansion (attachedTo, attr, macro);
5066
+ return finalize ();
5067
+ }
5068
+
5023
5069
std::string
5024
5070
ASTMangler::mangleMacroExpansion (const FreestandingMacroExpansion *expansion) {
5025
5071
beginMangling ();
0 commit comments