1
1
#include " llvm/ADT/STLExtras.h"
2
2
#include " swift/Basic/Defer.h"
3
3
#include " swift/SIL/SILDeclRef.h"
4
+ #include " swift/AST/ASTMangler.h"
4
5
#include < swift/APIDigester/ModuleAnalyzerNodes.h>
5
6
#include < algorithm>
6
7
@@ -98,7 +99,8 @@ SDKNodeRoot::SDKNodeRoot(SDKNodeInitInfo Info): SDKNode(Info, SDKNodeKind::Root)
98
99
JsonFormatVer(Info.JsonFormatVer.hasValue() ? *Info.JsonFormatVer : DIGESTER_JSON_DEFAULT_VERSION) {}
99
100
100
101
SDKNodeDecl::SDKNodeDecl (SDKNodeInitInfo Info, SDKNodeKind Kind)
101
- : SDKNode(Info, Kind), DKind(Info.DKind), Usr(Info.Usr), Loc(Info.Loc),
102
+ : SDKNode(Info, Kind), DKind(Info.DKind), Usr(Info.Usr),
103
+ MangledName(Info.MangledName), Loc(Info.Loc),
102
104
Location(Info.Location), ModuleName(Info.ModuleName),
103
105
DeclAttributes(Info.DeclAttrs), IsImplicit(Info.IsImplicit),
104
106
IsStatic(Info.IsStatic), IsDeprecated(Info.IsDeprecated),
@@ -120,7 +122,8 @@ SDKNodeType::SDKNodeType(SDKNodeInitInfo Info, SDKNodeKind Kind):
120
122
ParamValueOwnership(Info.ParamValueOwnership) {}
121
123
122
124
SDKNodeTypeNominal::SDKNodeTypeNominal (SDKNodeInitInfo Info):
123
- SDKNodeType(Info, SDKNodeKind::TypeNominal), USR(Info.Usr) {}
125
+ SDKNodeType(Info, SDKNodeKind::TypeNominal), USR(Info.Usr),
126
+ MangledName(Info.MangledName) {}
124
127
125
128
SDKNodeTypeFunc::SDKNodeTypeFunc (SDKNodeInitInfo Info):
126
129
SDKNodeType(Info, SDKNodeKind::TypeFunc) {}
@@ -139,7 +142,8 @@ SDKNodeDeclType::SDKNodeDeclType(SDKNodeInitInfo Info):
139
142
140
143
SDKNodeConformance::SDKNodeConformance (SDKNodeInitInfo Info):
141
144
SDKNode(Info, SDKNodeKind::Conformance),
142
- Usr(Info.Usr), IsABIPlaceholder(Info.IsABIPlaceholder) {}
145
+ Usr(Info.Usr), MangledName(Info.MangledName),
146
+ IsABIPlaceholder(Info.IsABIPlaceholder) {}
143
147
144
148
SDKNodeTypeWitness::SDKNodeTypeWitness (SDKNodeInitInfo Info):
145
149
SDKNode(Info, SDKNodeKind::TypeWitness) {}
@@ -1036,6 +1040,18 @@ static StringRef calculateUsr(SDKContext &Ctx, ValueDecl *VD) {
1036
1040
return StringRef ();
1037
1041
}
1038
1042
1043
+ static StringRef calculateMangledName (SDKContext &Ctx, ValueDecl *VD) {
1044
+ if (isFromClang (VD)) {
1045
+ // Don't mangle clang symbols.
1046
+ return StringRef ();
1047
+ }
1048
+ if (auto *attr = VD->getAttrs ().getAttribute <SILGenNameAttr>()) {
1049
+ return Ctx.buffer (attr->Name );
1050
+ }
1051
+ Mangle::ASTMangler NewMangler;
1052
+ return Ctx.buffer (NewMangler.mangleAnyDecl (VD, true ));
1053
+ }
1054
+
1039
1055
static StringRef calculateLocation (SDKContext &SDKCtx, Decl *D) {
1040
1056
if (SDKCtx.getOpts ().AvoidLocation )
1041
1057
return StringRef ();
@@ -1298,6 +1314,7 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty, TypeInitInfo Info) :
1298
1314
// If this is a nominal type, get its Usr.
1299
1315
if (auto *ND = Ty->getAnyNominal ()) {
1300
1316
Usr = calculateUsr (Ctx, ND);
1317
+ MangledName = calculateMangledName (Ctx, ND);
1301
1318
}
1302
1319
}
1303
1320
@@ -1415,6 +1432,7 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD)
1415
1432
Name = getSimpleName (VD);
1416
1433
PrintedName = getPrintedName (Ctx, VD);
1417
1434
Usr = calculateUsr (Ctx, VD);
1435
+ MangledName = calculateMangledName (Ctx, VD);
1418
1436
IsThrowing = isFuncThrowing (VD);
1419
1437
IsStatic = VD->isStatic ();
1420
1438
IsOverriding = VD->getOverriddenDecl ();
@@ -1970,13 +1988,15 @@ void SDKNodeRoot::jsonize(json::Output &out) {
1970
1988
void SDKNodeConformance::jsonize (json::Output &out) {
1971
1989
SDKNode::jsonize (out);
1972
1990
output (out, KeyKind::KK_usr, Usr);
1991
+ output (out, KeyKind::KK_mangledName, MangledName);
1973
1992
output (out, KeyKind::KK_isABIPlaceholder, IsABIPlaceholder);
1974
1993
}
1975
1994
1976
1995
void SDKNodeDecl::jsonize (json::Output &out) {
1977
1996
SDKNode::jsonize (out);
1978
1997
out.mapRequired (getKeyContent (Ctx, KeyKind::KK_declKind).data (), DKind);
1979
1998
output (out, KeyKind::KK_usr, Usr);
1999
+ output (out, KeyKind::KK_mangledName, MangledName);
1980
2000
output (out, KeyKind::KK_location, Location);
1981
2001
output (out, KeyKind::KK_moduleName, ModuleName);
1982
2002
output (out, KeyKind::KK_genericSig, GenericSig);
0 commit comments