diff options
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp')
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp index 24dd705e37b1..41d62a462ab4 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -67,39 +67,35 @@ void ClangPersistentVariables::RemovePersistentVariable( llvm::Optional<CompilerType> ClangPersistentVariables::GetCompilerTypeFromPersistentDecl( ConstString type_name) { - CompilerType compiler_type; - if (clang::TypeDecl *tdecl = llvm::dyn_cast_or_null<clang::TypeDecl>( - GetPersistentDecl(type_name))) { - compiler_type.SetCompilerType( - ClangASTContext::GetASTContext(&tdecl->getASTContext()), - reinterpret_cast<lldb::opaque_compiler_type_t>( - const_cast<clang::Type *>(tdecl->getTypeForDecl()))); - return compiler_type; + PersistentDecl p = m_persistent_decls.lookup(type_name.GetCString()); + + if (p.m_decl == nullptr) + return llvm::None; + + if (clang::TypeDecl *tdecl = llvm::dyn_cast<clang::TypeDecl>(p.m_decl)) { + opaque_compiler_type_t t = static_cast<opaque_compiler_type_t>( + const_cast<clang::Type *>(tdecl->getTypeForDecl())); + return CompilerType(p.m_context, t); } return llvm::None; } void ClangPersistentVariables::RegisterPersistentDecl(ConstString name, - clang::NamedDecl *decl) { - m_persistent_decls.insert( - std::pair<const char *, clang::NamedDecl *>(name.GetCString(), decl)); + clang::NamedDecl *decl, + ClangASTContext *ctx) { + PersistentDecl p = {decl, ctx}; + m_persistent_decls.insert(std::make_pair(name.GetCString(), p)); if (clang::EnumDecl *enum_decl = llvm::dyn_cast<clang::EnumDecl>(decl)) { for (clang::EnumConstantDecl *enumerator_decl : enum_decl->enumerators()) { - m_persistent_decls.insert(std::pair<const char *, clang::NamedDecl *>( - ConstString(enumerator_decl->getNameAsString()).GetCString(), - enumerator_decl)); + p = {enumerator_decl, ctx}; + m_persistent_decls.insert(std::make_pair( + ConstString(enumerator_decl->getNameAsString()).GetCString(), p)); } } } clang::NamedDecl * ClangPersistentVariables::GetPersistentDecl(ConstString name) { - PersistentDeclMap::const_iterator i = - m_persistent_decls.find(name.GetCString()); - - if (i == m_persistent_decls.end()) - return nullptr; - else - return i->second; + return m_persistent_decls.lookup(name.GetCString()).m_decl; } |