teemperor created this revision. teemperor added reviewers: labath, aprantl. Herald added subscribers: lldb-commits, JDevlieghere. Herald added a project: LLDB.
Currently we do our RTTI check for ClangExternalASTSourceCommon by using this global map of ClangExternalASTSourceCommon where every instance is registering and deregistering itself on creation/destruction. Then we can do the RTTI check by looking up in this map from ClangASTContext. This patch removes this whole thing and just adds LLVM-style RTTI support to ClangExternalASTSourceCommon which is possible with D71397 <https://reviews.llvm.org/D71397>. Repository: rLLDB LLDB https://reviews.llvm.org/D71398 Files: lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h lldb/source/Symbol/ClangASTContext.cpp lldb/source/Symbol/ClangExternalASTSourceCommon.cpp
Index: lldb/source/Symbol/ClangExternalASTSourceCommon.cpp =================================================================== --- lldb/source/Symbol/ClangExternalASTSourceCommon.cpp +++ lldb/source/Symbol/ClangExternalASTSourceCommon.cpp @@ -13,43 +13,9 @@ using namespace lldb_private; -typedef llvm::DenseMap<clang::ExternalASTSource *, - ClangExternalASTSourceCommon *> - ASTSourceMap; +char ClangExternalASTSourceCommon::ID; -static ASTSourceMap &GetSourceMap(std::unique_lock<std::mutex> &guard) { - // Intentionally leaked to avoid problems with global destructors. - static ASTSourceMap *s_source_map = new ASTSourceMap; - static std::mutex s_mutex; - std::unique_lock<std::mutex> locked_guard(s_mutex); - guard.swap(locked_guard); - return *s_source_map; -} - -ClangExternalASTSourceCommon * -ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source) { - std::unique_lock<std::mutex> guard; - ASTSourceMap &source_map = GetSourceMap(guard); - - ASTSourceMap::iterator iter = source_map.find(source); - - if (iter != source_map.end()) { - return iter->second; - } else { - return nullptr; - } -} - -ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() - : clang::ExternalASTSource() { - std::unique_lock<std::mutex> guard; - GetSourceMap(guard)[this] = this; -} - -ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon() { - std::unique_lock<std::mutex> guard; - GetSourceMap(guard).erase(this); -} +ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon() {} ClangASTMetadata * ClangExternalASTSourceCommon::GetMetadata(const void *object) { Index: lldb/source/Symbol/ClangASTContext.cpp =================================================================== --- lldb/source/Symbol/ClangASTContext.cpp +++ lldb/source/Symbol/ClangASTContext.cpp @@ -2407,22 +2407,16 @@ void ClangASTContext::SetMetadata(clang::ASTContext *ast, const void *object, ClangASTMetadata &metadata) { - ClangExternalASTSourceCommon *external_source = - ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); - - if (external_source) - external_source->SetMetadata(object, metadata); + if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(ast->getExternalSource())) + A->SetMetadata(object, metadata); } ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast, const void *object) { - ClangExternalASTSourceCommon *external_source = - ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); - if (external_source) - return external_source->GetMetadata(object); - else - return nullptr; + if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(ast->getExternalSource())) + return A->GetMetadata(object); + return nullptr; } bool ClangASTContext::SetTagTypeKind(clang::QualType tag_qual_type, Index: lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h =================================================================== --- lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h +++ lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h @@ -122,15 +122,17 @@ }; class ClangExternalASTSourceCommon : public clang::ExternalASTSource { + static char ID; public: - ClangExternalASTSourceCommon(); + ClangExternalASTSourceCommon() = default; ~ClangExternalASTSourceCommon() override; ClangASTMetadata *GetMetadata(const void *object); void SetMetadata(const void *object, ClangASTMetadata &metadata); - static ClangExternalASTSourceCommon *Lookup(clang::ExternalASTSource *source); - + // LLVM-style RTTI. + bool isA(const void *ClassID) const override { return ClassID == &ID; } + static bool classof(const ExternalASTSource *S) { return S->isA(&ID); } private: typedef llvm::DenseMap<const void *, ClangASTMetadata> MetadataMap;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits