Skip to content

Commit c1d5118

Browse files
authored
Merge pull request #65194 from apple/dl/AST-Convert-ASTContext-getSwiftName-to-a-free-function
[AST] Convert ASTContext::getSwiftName to a free function
2 parents 19830a9 + 39bb7bf commit c1d5118

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

include/swift/AST/ASTContext.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ namespace ide {
160160
/// While the names of Foundation types aren't likely to change in
161161
/// Objective-C, their mapping into Swift can. Therefore, when
162162
/// referring to names of Foundation entities in Swift, use this enum
163-
/// and \c ASTContext::getSwiftName or \c ASTContext::getSwiftId.
163+
/// and \c swift::getSwiftName or \c ASTContext::getSwiftId.
164164
enum class KnownFoundationEntity {
165165
#define FOUNDATION_ENTITY(Name) Name,
166166
#include "swift/AST/KnownFoundationEntities.def"
@@ -170,6 +170,10 @@ enum class KnownFoundationEntity {
170170
/// entity name.
171171
Optional<KnownFoundationEntity> getKnownFoundationEntity(StringRef name);
172172

173+
/// Retrieve the Swift name for the given Foundation entity, where
174+
/// "NS" prefix stripping will apply under omit-needless-words.
175+
StringRef getSwiftName(KnownFoundationEntity kind);
176+
173177
/// Introduces a new constraint checker arena, whose lifetime is
174178
/// tied to the lifetime of this RAII object.
175179
class ConstraintCheckerArenaRAII {
@@ -1344,14 +1348,10 @@ class ASTContext final {
13441348
/// Returns memory used exclusively by constraint solver.
13451349
size_t getSolverMemory() const;
13461350

1347-
/// Retrieve the Swift name for the given Foundation entity, where
1348-
/// "NS" prefix stripping will apply under omit-needless-words.
1349-
StringRef getSwiftName(KnownFoundationEntity kind);
1350-
13511351
/// Retrieve the Swift identifier for the given Foundation entity, where
13521352
/// "NS" prefix stripping will apply under omit-needless-words.
13531353
Identifier getSwiftId(KnownFoundationEntity kind) {
1354-
return getIdentifier(getSwiftName(kind));
1354+
return getIdentifier(swift::getSwiftName(kind));
13551355
}
13561356

13571357
/// Populate \p names with visible top level module names.

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3046,7 +3046,7 @@ Optional<KnownFoundationEntity> swift::getKnownFoundationEntity(StringRef name){
30463046
.Default(None);
30473047
}
30483048

3049-
StringRef ASTContext::getSwiftName(KnownFoundationEntity kind) {
3049+
StringRef swift::getSwiftName(KnownFoundationEntity kind) {
30503050
StringRef objcName;
30513051
switch (kind) {
30523052
#define FOUNDATION_ENTITY(Name) case KnownFoundationEntity::Name: \

lib/AST/ClangTypeConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ clang::QualType ClangTypeConverter::visitStructType(StructType *type) {
248248
CHECK_NAMED_TYPE("OpaquePointer", ctx.VoidPtrTy);
249249
CHECK_NAMED_TYPE("CVaListPointer", getClangDecayedVaListType(ctx));
250250
CHECK_NAMED_TYPE("DarwinBoolean", ctx.UnsignedCharTy);
251-
CHECK_NAMED_TYPE(swiftDecl->getASTContext().getSwiftName(
251+
CHECK_NAMED_TYPE(swift::getSwiftName(
252252
KnownFoundationEntity::NSZone),
253253
ctx.VoidPtrTy);
254254
CHECK_NAMED_TYPE("WindowsBool", ctx.IntTy);

lib/ClangImporter/ImportType.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ namespace {
454454
ModuleDecl *objCModule = Impl.SwiftContext.getLoadedModule(Id_ObjectiveC);
455455
Type wrapperTy = Impl.getNamedSwiftType(
456456
objCModule,
457-
Impl.SwiftContext.getSwiftName(
457+
swift::getSwiftName(
458458
KnownFoundationEntity::NSZone));
459459
if (wrapperTy)
460460
return {wrapperTy, ImportHint::OtherPointer};
@@ -1358,7 +1358,7 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
13581358

13591359
// FIXME: Avoid string comparison by caching this identifier.
13601360
if (elementClass->getName().str() !=
1361-
impl.SwiftContext.getSwiftName(KnownFoundationEntity::NSError))
1361+
swift::getSwiftName(KnownFoundationEntity::NSError))
13621362
return Type();
13631363

13641364
if (!impl.canImportFoundationModule() ||
@@ -1369,7 +1369,7 @@ static Type maybeImportNSErrorOutParameter(ClangImporter::Implementation &impl,
13691369
if (resugarNSErrorPointer)
13701370
return impl.getNamedSwiftType(
13711371
foundationModule,
1372-
impl.SwiftContext.getSwiftName(
1372+
swift::getSwiftName(
13731373
KnownFoundationEntity::NSErrorPointer));
13741374

13751375
// The imported type is AUMP<NSError?>, but the typealias is AUMP<NSError?>?

lib/ClangImporter/MappedTypes.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ MAP_TYPE("__swift_shims_dispatch_data_t", ObjCId, 0, "Dispatch", "dispatch_data_
146146
MAP_TYPE("SEL", ObjCSel, 0, "ObjectiveC", "Selector", false, DoNothing)
147147
MAP_STDLIB_TYPE("Class", ObjCClass, 0, "AnyClass", false, DoNothing)
148148
MAP_STDLIB_TYPE(
149-
Impl.SwiftContext.getSwiftName(KnownFoundationEntity::NSInteger),
149+
swift::getSwiftName(KnownFoundationEntity::NSInteger),
150150
SignedWord, 0, "Int", false, DefineOnly)
151151

152152
// Treat NSUInteger specially: exposing it as a typealias for "Int" would be
153153
// confusing.
154154
MAP_STDLIB_TYPE(
155-
Impl.SwiftContext.getSwiftName(KnownFoundationEntity::NSUInteger),
155+
swift::getSwiftName(KnownFoundationEntity::NSUInteger),
156156
UnsignedWord, 0, "Int", false, DoNothing)
157157

158158
// CGFloat.

lib/PrintAsClang/PrimitiveTypeMapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
8888
"BOOL", None, None, false};
8989
mappedTypeNames[{ID_ObjectiveC, ctx.getIdentifier("Selector")}] = {
9090
"SEL", None, None, true};
91-
mappedTypeNames[{ID_ObjectiveC, ctx.getIdentifier(ctx.getSwiftName(
91+
mappedTypeNames[{ID_ObjectiveC, ctx.getIdentifier(swift::getSwiftName(
9292
KnownFoundationEntity::NSZone))}] = {
9393
"struct _NSZone *", None, None, true};
9494

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ static Type diagnoseUnknownType(TypeResolution resolution,
13741374
repr->overwriteNameRef(DeclNameRef(ctx.getIdentifier(RemappedTy)));
13751375

13761376
// HACK: 'NSUInteger' suggests both 'UInt' and 'Int'.
1377-
if (TypeName == ctx.getSwiftName(KnownFoundationEntity::NSUInteger)) {
1377+
if (TypeName == swift::getSwiftName(KnownFoundationEntity::NSUInteger)) {
13781378
diags.diagnose(L, diag::note_remapped_type, "UInt")
13791379
.fixItReplace(R, "UInt");
13801380
}

0 commit comments

Comments
 (0)