diff options
| author | Raphael Isemann <teemperor@gmail.com> | 2019-12-28 22:00:27 +0100 |
|---|---|---|
| committer | Raphael Isemann <teemperor@gmail.com> | 2019-12-28 22:45:23 +0100 |
| commit | 36fb199ecaa5c75bd339f530277cd6d1f32033b3 (patch) | |
| tree | 692726b2945b476f56d82e99d1ef5b88a42acc08 /lldb/source/Plugins/ExpressionParser | |
| parent | 0acfc493171a880215327ecd70e3e01e1cd493df (diff) | |
| download | bcm5719-llvm-36fb199ecaa5c75bd339f530277cd6d1f32033b3.tar.gz bcm5719-llvm-36fb199ecaa5c75bd339f530277cd6d1f32033b3.zip | |
[lldb][NFC] Remove GetASTContext call in ClangPersistentVariables
We try to build a CompilerType from the persistent decls so we need
a ClangASTContext. With this patch the ClangPersistentVariables store
the associated ClangASTContext of the persistent decls (which is
always the scratch ClangASTContext) and no longer call GetASTContext
to map back from clang::ASTContext to ClangASTContext.
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser')
3 files changed, 36 insertions, 27 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp index 1caac9e11cb..5e6a1ac2a08 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp @@ -448,12 +448,17 @@ void ASTResultSynthesizer::RecordPersistentDecl(NamedDecl *D) { } void ASTResultSynthesizer::CommitPersistentDecls() { + PersistentExpressionState *state = + m_target.GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC); + auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state); + ClangASTContext *scratch_ctx = ClangASTContext::GetScratch(m_target); + for (clang::NamedDecl *decl : m_decls) { StringRef name = decl->getName(); ConstString name_cs(name.str().c_str()); Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl( - &ClangASTContext::GetScratch(m_target)->getASTContext(), decl); + &scratch_ctx->getASTContext(), decl); if (!D_scratch) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); @@ -471,10 +476,8 @@ void ASTResultSynthesizer::CommitPersistentDecls() { } if (NamedDecl *NamedDecl_scratch = dyn_cast<NamedDecl>(D_scratch)) - llvm::cast<ClangPersistentVariables>( - m_target.GetPersistentExpressionStateForLanguage( - lldb::eLanguageTypeC)) - ->RegisterPersistentDecl(name_cs, NamedDecl_scratch); + persistent_vars->RegisterPersistentDecl(name_cs, NamedDecl_scratch, + scratch_ctx); } } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp index 24dd705e37b..7423f623efb 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -68,38 +68,36 @@ 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; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h index 95e6c3ac963..434196b35fd 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h @@ -62,7 +62,8 @@ public: llvm::Optional<CompilerType> GetCompilerTypeFromPersistentDecl(ConstString type_name) override; - void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl); + void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl, + ClangASTContext *ctx); clang::NamedDecl *GetPersistentDecl(ConstString name); @@ -80,7 +81,14 @@ private: // The counter used by GetNextPersistentVariableName uint32_t m_next_persistent_variable_id = 0; - typedef llvm::DenseMap<const char *, clang::NamedDecl *> PersistentDeclMap; + struct PersistentDecl { + /// The persistent decl. + clang::NamedDecl *m_decl = nullptr; + /// The ClangASTContext for the ASTContext of m_decl. + ClangASTContext *m_context = nullptr; + }; + + typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap; PersistentDeclMap m_persistent_decls; ///< Persistent entities declared by the user. |

