mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Introduce special decl names
Special DeclNames represent names that do not have an identifier in the surface language. This implies serializing the information about whether a name is special together with its identifier (if it is not special) in both the module file and the swift lookup table.
This commit is contained in:
@@ -1091,13 +1091,30 @@ static bool isFunctionTypeNoEscape(Type Ty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Converts a DeclBaseName to a string by assigning special names strings and
|
||||
/// escaping identifiers that would clash with these strings using '`'
|
||||
static StringRef getEscapedName(DeclBaseName name) {
|
||||
switch (name.getKind()) {
|
||||
case DeclBaseName::Kind::Subscript:
|
||||
return "subscript";
|
||||
case DeclBaseName::Kind::Normal:
|
||||
return llvm::StringSwitch<StringRef>(name.getIdentifier().str())
|
||||
.Case("subscript", "`subscript`")
|
||||
.Default(name.getIdentifier().str());
|
||||
}
|
||||
}
|
||||
|
||||
static StringRef getPrintedName(SDKContext &Ctx, ValueDecl *VD) {
|
||||
llvm::SmallString<32> Result;
|
||||
if (auto FD = dyn_cast<AbstractFunctionDecl>(VD)) {
|
||||
auto DM = FD->getFullName();
|
||||
|
||||
// TODO: Handle special names
|
||||
Result.append(DM.getBaseName().empty() ? "_" :DM.getBaseIdentifier().str());
|
||||
if (DM.getBaseName().empty()) {
|
||||
Result.append("_");
|
||||
} else {
|
||||
Result.append(getEscapedName(DM.getBaseName()));
|
||||
}
|
||||
|
||||
Result.append("(");
|
||||
for (auto Arg : DM.getArgumentNames()) {
|
||||
Result.append(Arg.empty() ? "_" : Arg.str());
|
||||
@@ -1107,8 +1124,7 @@ static StringRef getPrintedName(SDKContext &Ctx, ValueDecl *VD) {
|
||||
return Ctx.buffer(Result.str());
|
||||
}
|
||||
auto DM = VD->getFullName();
|
||||
// TODO: Handle special names
|
||||
Result.append(DM.getBaseIdentifier().str());
|
||||
Result.append(getEscapedName(DM.getBaseName()));
|
||||
return Ctx.buffer(Result.str());
|
||||
}
|
||||
|
||||
@@ -1147,9 +1163,8 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty) :
|
||||
TypeAttrs.push_back(TypeAttrKind::TAK_noescape);
|
||||
}
|
||||
|
||||
// TODO: Handle special names
|
||||
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD) : Ctx(Ctx),
|
||||
Name(VD->hasName() ? VD->getBaseName().getIdentifier().str() : Ctx.buffer("_")),
|
||||
Name(VD->hasName() ? getEscapedName(VD->getBaseName()) : Ctx.buffer("_")),
|
||||
PrintedName(getPrintedName(Ctx, VD)), DKind(VD->getKind()),
|
||||
USR(calculateUsr(Ctx, VD)), Location(calculateLocation(Ctx, VD)),
|
||||
ModuleName(VD->getModuleContext()->getName().str()),
|
||||
|
||||
Reference in New Issue
Block a user