@@ -3275,11 +3275,6 @@ void ClangModuleUnit::lookupValue(DeclName name, NLKind lookupKind,
32753275 if (auto lookupTable = owner.findLookupTable (clangModule)) {
32763276 // Search it.
32773277 owner.lookupValue (*lookupTable, name, *consumer);
3278- if (getASTContext ().LangOpts .EnableExperimentalClangImporterDiagnostics ) {
3279- if (results.empty ()) {
3280- owner.diagnoseValue (*lookupTable, name);
3281- }
3282- }
32833278 }
32843279}
32853280
@@ -4127,7 +4122,7 @@ void ClangImporter::Implementation::lookupVisibleDecls(
41274122 DeclBaseName name = baseName.toDeclBaseName (SwiftContext);
41284123 if (!lookupValue (table, name, consumer) &&
41294124 SwiftContext.LangOpts .EnableExperimentalEagerClangModuleDiagnostics ) {
4130- diagnoseValue (table, name);
4125+ diagnoseTopLevelValue ( name);
41314126 }
41324127 }
41334128}
@@ -4183,30 +4178,42 @@ void ClangImporter::Implementation::lookupAllObjCMembers(
41834178 }
41844179}
41854180
4186- void ClangImporter::Implementation::diagnoseValue (SwiftLookupTable &table,
4187- DeclName name) {
4188- auto &clangCtx = getClangASTContext ();
4189- auto clangTU = clangCtx. getTranslationUnitDecl ();
4190-
4191- if (name. isOperator ()) {
4192- for ( auto entry : table. lookupMemberOperators (name. getBaseName ( ))) {
4193- diagnoseTargetDirectly (entry);
4181+ void ClangImporter::Implementation::diagnoseTopLevelValue (
4182+ const DeclName & name) {
4183+ forEachLookupTable ([&](SwiftLookupTable &table) -> bool {
4184+ for ( const auto &entry :
4185+ table. lookup (name. getBaseName (),
4186+ EffectiveClangContext (
4187+ getClangASTContext (). getTranslationUnitDecl () ))) {
4188+ diagnoseTargetDirectly (importDiagnosticTargetFromLookupTableEntry ( entry) );
41944189 }
4195- }
4190+ return false ;
4191+ });
4192+ }
41964193
4197- for (auto entry : table.lookup (name.getBaseName (), clangTU)) {
4198- diagnoseTargetDirectly (importDiagnosticTargetFromLookupTableEntry (entry));
4199- }
4194+ void ClangImporter::Implementation::diagnoseMemberValue (
4195+ const DeclName &name, const clang::DeclContext *container) {
4196+ forEachLookupTable ([&](SwiftLookupTable &table) -> bool {
4197+ for (const auto &entry :
4198+ table.lookup (name.getBaseName (), EffectiveClangContext (container))) {
4199+ if (clang::NamedDecl *nd = entry.get <clang::NamedDecl *>()) {
4200+ // We are only interested in members of a particular context,
4201+ // skip other contexts.
4202+ if (nd->getDeclContext () != container)
4203+ continue ;
4204+
4205+ diagnoseTargetDirectly (
4206+ importDiagnosticTargetFromLookupTableEntry (entry));
4207+ }
4208+ // If the entry is not a NamedDecl, it is a form of macro, which cannot be
4209+ // a member value.
4210+ }
4211+ return false ;
4212+ });
42004213}
42014214
42024215void ClangImporter::Implementation::diagnoseTargetDirectly (
42034216 ImportDiagnosticTarget target) {
4204- if (!(SwiftContext.LangOpts .EnableExperimentalClangImporterDiagnostics ||
4205- SwiftContext.LangOpts .EnableExperimentalEagerClangModuleDiagnostics ) ||
4206- DiagnosedValues.count (target))
4207- return ;
4208-
4209- DiagnosedValues.insert (target);
42104217 if (const clang::Decl *decl = target.dyn_cast <const clang::Decl *>()) {
42114218 Walker.TraverseDecl (const_cast <clang::Decl *>(decl));
42124219 } else if (const clang::MacroInfo *macro =
@@ -4363,8 +4370,6 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
43634370 recordDecl->getClangDecl ()) {
43644371 if (auto import = ctx.getClangModuleLoader ()->importDeclDirectly (named))
43654372 result.push_back (cast<ValueDecl>(import ));
4366- else if (ctx.LangOpts .EnableExperimentalClangImporterDiagnostics )
4367- ctx.getClangModuleLoader ()->diagnoseDeclDirectly (named);
43684373 }
43694374 }
43704375
@@ -4497,22 +4502,6 @@ ClangImporter::Implementation::loadNamedMembers(
44974502 return Members;
44984503}
44994504
4500- void ClangImporter::Implementation::diagnoseMissingNamedMember (
4501- const IterableDeclContext *IDC, DeclName name) {
4502- Optional<clang::Module *> containingModule =
4503- getClangSubmoduleForDecl (IDC->getDecl ()->getClangDecl ());
4504- assert (containingModule &&
4505- " Members should never be loaded from a forward-declared decl" );
4506- auto allResults = evaluateOrDefault (
4507- SwiftContext.evaluator ,
4508- ClangDirectLookupRequest ({const_cast <Decl *>(IDC->getDecl ()),
4509- IDC->getDecl ()->getClangDecl (), name}),
4510- {});
4511- for (auto entry : allResults) {
4512- diagnoseTargetDirectly (importDiagnosticTargetFromLookupTableEntry (entry));
4513- }
4514- }
4515-
45164505EffectiveClangContext ClangImporter::Implementation::getEffectiveClangContext (
45174506 const NominalTypeDecl *nominal) {
45184507 // If we have a Clang declaration, look at it to determine the
@@ -4747,6 +4736,23 @@ Decl *ClangImporter::importDeclDirectly(const clang::NamedDecl *decl) {
47474736 return Impl.importDecl (decl, Impl.CurrentVersion );
47484737}
47494738
4750- void ClangImporter::diagnoseDeclDirectly (const clang::NamedDecl *decl) {
4751- Impl.diagnoseTargetDirectly (decl);
4739+ void ClangImporter::diagnoseTopLevelValue (const DeclName &name) {
4740+ Impl.diagnoseTopLevelValue (name);
4741+ }
4742+
4743+ void ClangImporter::diagnoseMemberValue (const DeclName &name,
4744+ const Type &baseType) {
4745+ if (!baseType->getAnyNominal ())
4746+ return ;
4747+
4748+ SmallVector<NominalTypeDecl *, 4 > nominalTypesToLookInto;
4749+ namelookup::extractDirectlyReferencedNominalTypes (baseType,
4750+ nominalTypesToLookInto);
4751+ for (auto containerDecl : nominalTypesToLookInto) {
4752+ const clang::Decl *clangContainerDecl = containerDecl->getClangDecl ();
4753+ if (clangContainerDecl && isa<clang::DeclContext>(clangContainerDecl)) {
4754+ Impl.diagnoseMemberValue (name,
4755+ cast<clang::DeclContext>(clangContainerDecl));
4756+ }
4757+ }
47524758}
0 commit comments