diff options
| author | Raphael Isemann <teemperor@gmail.com> | 2019-12-17 16:12:07 +0100 |
|---|---|---|
| committer | Raphael Isemann <teemperor@gmail.com> | 2019-12-18 13:50:05 +0100 |
| commit | d8a3194987301672fbd50f4e5703952381f0157c (patch) | |
| tree | 7edbad6f22e088f765fcaf95d27987f1cbaac111 /lldb/source/Plugins/ExpressionParser | |
| parent | 55c57408b0e70b188b0505e011172f13ec3b15fc (diff) | |
| download | bcm5719-llvm-d8a3194987301672fbd50f4e5703952381f0157c.tar.gz bcm5719-llvm-d8a3194987301672fbd50f4e5703952381f0157c.zip | |
[lldb][NFC] Add unit test for persistent variable lookup with ClangExpressionDeclMap
This adds a unit test for looking up persistent declarations in the scratch AST
context. Also adds the `GetPersistentDecl` hook to the ClangExpressionDeclMap
that this unit test can emulate looking up persistent variables without having
a lldb_private::Target.
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser')
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp | 28 | ||||
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h | 8 |
2 files changed, 26 insertions, 10 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index 33867fb4d45..23202766892 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -734,29 +734,33 @@ void ClangExpressionDeclMap::MaybeRegisterFunctionBody( } } -void ClangExpressionDeclMap::SearchPersistenDecls(NameSearchContext &context, - const ConstString name, - unsigned int current_id) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); +clang::NamedDecl *ClangExpressionDeclMap::GetPersistentDecl(ConstString name) { if (!m_parser_vars) - return; + return nullptr; Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr(); if (!target) - return; + return nullptr; ClangASTContext *scratch_clang_ast_context = ClangASTContext::GetScratch(*target); if (!scratch_clang_ast_context) - return; + return nullptr; ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext(); if (!scratch_ast_context) - return; + return nullptr; + + return m_parser_vars->m_persistent_vars->GetPersistentDecl(name); +} + +void ClangExpressionDeclMap::SearchPersistenDecls(NameSearchContext &context, + const ConstString name, + unsigned int current_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); - NamedDecl *persistent_decl = - m_parser_vars->m_persistent_vars->GetPersistentDecl(name); + NamedDecl *persistent_decl = GetPersistentDecl(name); if (!persistent_decl) return; @@ -1409,6 +1413,10 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls( if (name.GetStringRef().startswith("$__lldb")) return; + // No ParserVars means we can't do register or variable lookup. + if (!m_parser_vars) + return; + ExpressionVariableSP pvar_sp( m_parser_vars->m_persistent_vars->GetVariable(name)); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h index 223fd320109..41e41c1f1fe 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h @@ -283,6 +283,14 @@ public: CompilerDeclContext &namespace_decl, unsigned int current_id); +protected: + /// Retrieves the declaration with the given name from the storage of + /// persistent declarations. + /// + /// \return + /// A persistent decl with the given name or a nullptr. + virtual clang::NamedDecl *GetPersistentDecl(ConstString name); + private: ExpressionVariableList m_found_entities; ///< All entities that were looked up for the parser. |

