@@ -83,6 +83,11 @@ using AssociativityCacheType =
83
83
llvm::DenseMap<std::pair<PrecedenceGroupDecl *, PrecedenceGroupDecl *>,
84
84
Associativity>;
85
85
86
+ #define FOR_KNOWN_FOUNDATION_TYPES (MACRO ) \
87
+ MACRO (NSError) \
88
+ MACRO(NSNumber) \
89
+ MACRO(NSValue)
90
+
86
91
struct ASTContext::Implementation {
87
92
Implementation ();
88
93
~Implementation ();
@@ -153,8 +158,11 @@ struct ASTContext::Implementation {
153
158
// / The declaration of ObjectiveC.ObjCBool.
154
159
StructDecl *ObjCBoolDecl = nullptr ;
155
160
156
- // / The declaration of Foundation.NSError.
157
- ClassDecl *NSErrorDecl = nullptr ;
161
+ #define CACHE_FOUNDATION_DECL (NAME ) \
162
+ /* * The declaration of Foundation.NAME. */ \
163
+ ClassDecl *NAME##Decl = nullptr ;
164
+ FOR_KNOWN_FOUNDATION_TYPES (CACHE_FOUNDATION_DECL)
165
+ #undef CACHE_FOUNDATION_DECL
158
166
159
167
// Declare cached declarations for each of the known declarations.
160
168
#define FUNC_DECL (Name, Id ) FuncDecl *Get##Name = nullptr ;
@@ -743,25 +751,30 @@ StructDecl *ASTContext::getObjCBoolDecl() const {
743
751
return Impl.ObjCBoolDecl ;
744
752
}
745
753
746
- ClassDecl *ASTContext::getNSErrorDecl () const {
747
- if (!Impl.NSErrorDecl ) {
748
- if (ModuleDecl *M = getLoadedModule (Id_Foundation)) {
749
- // Note: use unqualified lookup so we find NSError regardless of
750
- // whether it's defined in the Foundation module or the Clang
751
- // Foundation module it imports.
752
- UnqualifiedLookup lookup (getIdentifier (" NSError" ), M, nullptr );
753
- if (auto type = lookup.getSingleTypeResult ()) {
754
- if (auto classDecl = dyn_cast<ClassDecl>(type)) {
755
- if (classDecl->getGenericParams () == nullptr ) {
756
- Impl.NSErrorDecl = classDecl;
757
- }
758
- }
759
- }
760
- }
761
- }
762
-
763
- return Impl.NSErrorDecl ;
764
- }
754
+ #define GET_FOUNDATION_DECL (NAME ) \
755
+ ClassDecl *ASTContext::get##NAME##Decl() const { \
756
+ if (!Impl.NAME ##Decl) { \
757
+ if (ModuleDecl *M = getLoadedModule (Id_Foundation)) { \
758
+ /* Note: use unqualified lookup so we find NSError regardless of */ \
759
+ /* whether it's defined in the Foundation module or the Clang */ \
760
+ /* Foundation module it imports. */ \
761
+ UnqualifiedLookup lookup (getIdentifier (#NAME), M, nullptr ); \
762
+ if (auto type = lookup.getSingleTypeResult ()) { \
763
+ if (auto classDecl = dyn_cast<ClassDecl>(type)) { \
764
+ if (classDecl->getGenericParams () == nullptr ) { \
765
+ Impl.NAME ##Decl = classDecl; \
766
+ } \
767
+ } \
768
+ } \
769
+ } \
770
+ } \
771
+ \
772
+ return Impl.NAME ##Decl; \
773
+ }
774
+
775
+ FOR_KNOWN_FOUNDATION_TYPES (GET_FOUNDATION_DECL)
776
+ #undef GET_FOUNDATION_DECL
777
+ #undef FOR_KNOWN_FOUNDATION_TYPES
765
778
766
779
ProtocolDecl *ASTContext::getProtocol (KnownProtocolKind kind) const {
767
780
// Check whether we've already looked for and cached this protocol.
@@ -4056,6 +4069,21 @@ bool ASTContext::isTypeBridgedInExternalModule(
4056
4069
nominal->getParentModule ()->getName () == Id_CoreMedia);
4057
4070
}
4058
4071
4072
+ bool ASTContext::isObjCClassWithMultipleSwiftBridgedTypes (Type t) {
4073
+ auto clas = t->getClassOrBoundGenericClass ();
4074
+ if (!clas)
4075
+ return false ;
4076
+
4077
+ if (clas == getNSErrorDecl ())
4078
+ return true ;
4079
+ if (clas == getNSNumberDecl ())
4080
+ return true ;
4081
+ if (clas == getNSValueDecl ())
4082
+ return true ;
4083
+
4084
+ return false ;
4085
+ }
4086
+
4059
4087
Type ASTContext::getBridgedToObjC (const DeclContext *dc, Type type,
4060
4088
Type *bridgedValueType) const {
4061
4089
if (type->isBridgeableObjectType ()) {
0 commit comments