void ModuleFile::lookupClassMembers(Module::AccessPathTy accessPath, VisibleDeclConsumer &consumer) { PrettyModuleFileDeserialization stackEntry(*this); assert(accessPath.size() <= 1 && "can only refer to top-level decls"); if (!ClassMembersByName) return; if (!accessPath.empty()) { for (const auto &list : ClassMembersByName->data()) { for (auto item : list) { auto vd = cast<ValueDecl>(getDecl(item.second)); auto dc = vd->getDeclContext(); while (!dc->getParent()->isModuleScopeContext()) dc = dc->getParent(); if (auto nominal = dc->getAsNominalTypeOrNominalTypeExtensionContext()) if (nominal->getName() == accessPath.front().first) consumer.foundDecl(vd, DeclVisibilityKind::DynamicLookup); } } return; } for (const auto &list : ClassMembersByName->data()) { for (auto item : list) consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)), DeclVisibilityKind::DynamicLookup); } }
void ModuleFile::lookupVisibleDecls(Module::AccessPathTy accessPath, VisibleDeclConsumer &consumer, NLKind lookupKind) { PrettyModuleFileDeserialization stackEntry(*this); assert(accessPath.size() <= 1 && "can only refer to top-level decls"); if (!TopLevelDecls) return; if (!accessPath.empty()) { auto iter = TopLevelDecls->find(accessPath.front().first); if (iter == TopLevelDecls->end()) return; for (auto item : *iter) consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)), DeclVisibilityKind::VisibleAtTopLevel); return; } for (auto entry : TopLevelDecls->data()) { for (auto item : entry) consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)), DeclVisibilityKind::VisibleAtTopLevel); } }
void ModuleFile::lookupClassMember(Module::AccessPathTy accessPath, DeclName name, SmallVectorImpl<ValueDecl*> &results) { PrettyModuleFileDeserialization stackEntry(*this); assert(accessPath.size() <= 1 && "can only refer to top-level decls"); if (!ClassMembersByName) return; auto iter = ClassMembersByName->find(name.getBaseName()); if (iter == ClassMembersByName->end()) return; if (!accessPath.empty()) { // As a hack to avoid completely redoing how the module is indexed, we take // the simple-name-based lookup then filter by the compound name if we have // one. if (name.isSimpleName()) { for (auto item : *iter) { auto vd = cast<ValueDecl>(getDecl(item.second)); auto dc = vd->getDeclContext(); while (!dc->getParent()->isModuleScopeContext()) dc = dc->getParent(); if (auto nominal = dc->getAsNominalTypeOrNominalTypeExtensionContext()) if (nominal->getName() == accessPath.front().first) results.push_back(vd); } } else { for (auto item : *iter) { auto vd = cast<ValueDecl>(getDecl(item.second)); if (!vd->getFullName().matchesRef(name)) continue; auto dc = vd->getDeclContext(); while (!dc->getParent()->isModuleScopeContext()) dc = dc->getParent(); if (auto nominal = dc->getAsNominalTypeOrNominalTypeExtensionContext()) if (nominal->getName() == accessPath.front().first) results.push_back(vd); } } return; } for (auto item : *iter) { auto vd = cast<ValueDecl>(getDecl(item.second)); results.push_back(vd); } }