Skip to content

Commit 5df8173

Browse files
committed
[AST] Convert ASTContext::getSwiftName to static
The `getSwiftName` function uses only its argument, and can be `static`. This a removes the requirement that callers have an `ASTContext` instance.
1 parent 6c54fef commit 5df8173

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

include/swift/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,12 +1334,12 @@ class ASTContext final {
13341334

13351335
/// Retrieve the Swift name for the given Foundation entity, where
13361336
/// "NS" prefix stripping will apply under omit-needless-words.
1337-
StringRef getSwiftName(KnownFoundationEntity kind);
1337+
static StringRef getSwiftName(KnownFoundationEntity kind);
13381338

13391339
/// Retrieve the Swift identifier for the given Foundation entity, where
13401340
/// "NS" prefix stripping will apply under omit-needless-words.
13411341
Identifier getSwiftId(KnownFoundationEntity kind) {
1342-
return getIdentifier(getSwiftName(kind));
1342+
return getIdentifier(ASTContext::getSwiftName(kind));
13431343
}
13441344

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

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(ASTContext::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+
ASTContext::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+
ASTContext::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+
ASTContext::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+
ASTContext::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+
ASTContext::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(ASTContext::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
@@ -1373,7 +1373,7 @@ static Type diagnoseUnknownType(TypeResolution resolution,
13731373
repr->overwriteNameRef(DeclNameRef(ctx.getIdentifier(RemappedTy)));
13741374

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

0 commit comments

Comments
 (0)