@@ -3033,53 +3033,22 @@ ClangNode ClangImporter::getEffectiveClangNode(const Decl *decl) const {
3033
3033
void ClangImporter::lookupTypeDecl (
3034
3034
StringRef rawName, ClangTypeKind kind,
3035
3035
llvm::function_ref<void (TypeDecl *)> receiver) {
3036
- clang::DeclarationName clangName (
3037
- &Impl.Instance ->getASTContext ().Idents .get (rawName));
3038
-
3039
- SmallVector<clang::Sema::LookupNameKind, 1 > lookupKinds;
3040
- switch (kind) {
3041
- case ClangTypeKind::Typedef:
3042
- lookupKinds.push_back (clang::Sema::LookupOrdinaryName);
3043
- break ;
3044
- case ClangTypeKind::Tag:
3045
- lookupKinds.push_back (clang::Sema::LookupTagName);
3046
- lookupKinds.push_back (clang::Sema::LookupNamespaceName);
3047
- break ;
3048
- case ClangTypeKind::ObjCProtocol:
3049
- lookupKinds.push_back (clang::Sema::LookupObjCProtocolName);
3050
- break ;
3051
- }
3052
-
3053
- // Perform name lookup into the global scope.
3054
- auto &sema = Impl.Instance ->getSema ();
3036
+ auto &ctx = Impl.SwiftContext ;
3037
+ auto name = DeclName (ctx.getIdentifier (rawName));
3055
3038
bool foundViaClang = false ;
3056
-
3057
- for (auto lookupKind : lookupKinds) {
3058
- clang::LookupResult lookupResult (sema, clangName, clang::SourceLocation (),
3059
- lookupKind);
3060
- if (!Impl.DisableSourceImport &&
3061
- sema.LookupName (lookupResult, /* Scope=*/ sema.TUScope )) {
3062
- for (auto clangDecl : lookupResult) {
3063
- if (!isa<clang::TypeDecl>(clangDecl) &&
3064
- !isa<clang::NamespaceDecl>(clangDecl) &&
3065
- !isa<clang::ObjCContainerDecl>(clangDecl) &&
3066
- !isa<clang::ObjCCompatibleAliasDecl>(clangDecl)) {
3067
- continue ;
3068
- }
3069
- Decl *imported = Impl.importDecl (clangDecl, Impl.CurrentVersion );
3070
-
3071
- // Namespaces are imported as extensions for enums.
3072
- if (auto ext = dyn_cast_or_null<ExtensionDecl>(imported)) {
3073
- imported = ext->getExtendedNominal ();
3074
- }
3075
- if (auto *importedType = dyn_cast_or_null<TypeDecl>(imported)) {
3076
- foundViaClang = true ;
3077
- receiver (importedType);
3078
- }
3079
- }
3039
+ auto consumer = makeDeclConsumer (
3040
+ [&foundViaClang, receiver](Decl *found, DeclVisibilityKind) {
3041
+ // Namespaces are imported as extensions for enums.
3042
+ if (auto ext = dyn_cast_or_null<ExtensionDecl>(found)) {
3043
+ found = ext->getExtendedNominal ();
3080
3044
}
3081
- }
3082
-
3045
+ if (auto *importedType = dyn_cast_or_null<TypeDecl>(found)) {
3046
+ foundViaClang = true ;
3047
+ receiver (importedType);
3048
+ }
3049
+ });
3050
+
3051
+ ctx.getClangModuleLoader ()->lookupValue (name, consumer);
3083
3052
// If Clang couldn't find the type, query the DWARFImporterDelegate.
3084
3053
if (!foundViaClang)
3085
3054
Impl.lookupTypeDeclDWARF (rawName, kind, receiver);
0 commit comments