};
class ClangExternalASTSourceCommon : public clang::ExternalASTSource {
+
+ /// LLVM-style RTTI.
+ static char ID;
+
public:
- ClangExternalASTSourceCommon();
~ClangExternalASTSourceCommon() override;
ClangASTMetadata *GetMetadata(const clang::Decl *object);
m_type_metadata[object] = metadata;
}
- static ClangExternalASTSourceCommon *Lookup(clang::ExternalASTSource *source);
-
+ /// LLVM-style RTTI.
+ /// \{
+ bool isA(const void *ClassID) const override {
+ return ClassID == &ID || ExternalASTSource::isA(ClassID);
+ }
+ static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
+ /// \}
private:
typedef llvm::DenseMap<const clang::Decl *, ClangASTMetadata> DeclMetadataMap;
typedef llvm::DenseMap<const clang::Type *, ClangASTMetadata> TypeMetadataMap;
void ClangASTContext::SetMetadata(const clang::Decl *object,
ClangASTMetadata &metadata) {
- ClangExternalASTSourceCommon *external_source =
- ClangExternalASTSourceCommon::Lookup(
- getASTContext()->getExternalSource());
-
- if (external_source)
- external_source->SetMetadata(object, metadata);
+ if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
+ getASTContext()->getExternalSource()))
+ A->SetMetadata(object, metadata);
}
void ClangASTContext::SetMetadata(const clang::Type *object,
ClangASTMetadata &metadata) {
- ClangExternalASTSourceCommon *external_source =
- ClangExternalASTSourceCommon::Lookup(
- getASTContext()->getExternalSource());
-
- if (external_source)
- external_source->SetMetadata(object, metadata);
+ if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
+ getASTContext()->getExternalSource()))
+ A->SetMetadata(object, metadata);
}
ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast,
const clang::Decl *object) {
- ClangExternalASTSourceCommon *external_source =
- ClangExternalASTSourceCommon::Lookup(ast->getExternalSource());
-
- if (external_source)
- return external_source->GetMetadata(object);
+ if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
+ ast->getExternalSource()))
+ return A->GetMetadata(object);
return nullptr;
}
ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast,
const clang::Type *object) {
- ClangExternalASTSourceCommon *external_source =
- ClangExternalASTSourceCommon::Lookup(ast->getExternalSource());
-
- if (external_source)
- return external_source->GetMetadata(object);
+ if (auto *A = llvm::dyn_cast_or_null<ClangExternalASTSourceCommon>(
+ ast->getExternalSource()))
+ return A->GetMetadata(object);
return nullptr;
}
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 clang::Decl *object) {