diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-11-20 13:41:44 +0100 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-11-20 14:17:35 +0100 |
commit | c34478f5f6c7ef1ae8fb3605fbdec0634d543fed (patch) | |
tree | fdc50789fd2358b41881aa71df7a877327c49b17 /lldb/source/Plugins/ExpressionParser | |
parent | b80e483c4205d216f6648d7e217183694fe9a55e (diff) | |
download | bcm5719-llvm-c34478f5f6c7ef1ae8fb3605fbdec0634d543fed.tar.gz bcm5719-llvm-c34478f5f6c7ef1ae8fb3605fbdec0634d543fed.zip |
[lldb][NFC] Move ClangExpressionDeclMap's persistent decl search into its own function
Searching persistent decls is a small subset of the things
FindExternalVisibleDecls does. It should be its own function instead
of being encapsulated in this `do { } while(false);` pattern.
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser')
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp | 108 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h | 18 |
2 files changed, 73 insertions, 53 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index f8e448ffcb6..da106f4f8f4 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -771,19 +771,64 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls( ClangASTSource::FindExternalVisibleDecls(context); } +void ClangExpressionDeclMap::MaybeRegisterFunctionBody( + FunctionDecl *copied_function_decl) { + if (copied_function_decl->getBody() && m_parser_vars->m_code_gen) { + clang::DeclGroupRef decl_group_ref(copied_function_decl); + m_parser_vars->m_code_gen->HandleTopLevelDecl(decl_group_ref); + } +} + +void ClangExpressionDeclMap::SearchPersistenDecls(NameSearchContext &context, + const ConstString name, + unsigned int current_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr(); + if (!target) + return; + + ClangASTContext *scratch_clang_ast_context = + target->GetScratchClangASTContext(); + + if (!scratch_clang_ast_context) + return; + + ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext(); + + if (!scratch_ast_context) + return; + + NamedDecl *persistent_decl = + m_parser_vars->m_persistent_vars->GetPersistentDecl(name); + + if (!persistent_decl) + return; + + Decl *parser_persistent_decl = CopyDecl(persistent_decl); + + if (!parser_persistent_decl) + return; + + NamedDecl *parser_named_decl = dyn_cast<NamedDecl>(parser_persistent_decl); + + if (!parser_named_decl) + return; + + if (clang::FunctionDecl *parser_function_decl = + llvm::dyn_cast<clang::FunctionDecl>(parser_named_decl)) { + MaybeRegisterFunctionBody(parser_function_decl); + } + + LLDB_LOGF(log, " CEDM::FEVD[%u] Found persistent decl %s", current_id, + name.GetCString()); + + context.AddNamedDecl(parser_named_decl); +} void ClangExpressionDeclMap::FindExternalVisibleDecls( NameSearchContext &context, lldb::ModuleSP module_sp, CompilerDeclContext &namespace_decl, unsigned int current_id) { assert(m_ast_context); - std::function<void(clang::FunctionDecl *)> MaybeRegisterFunctionBody = - [this](clang::FunctionDecl *copied_function_decl) { - if (copied_function_decl->getBody() && m_parser_vars->m_code_gen) { - DeclGroupRef decl_group_ref(copied_function_decl); - m_parser_vars->m_code_gen->HandleTopLevelDecl(decl_group_ref); - } - }; - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); SymbolContextList sc_list; @@ -802,51 +847,8 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls( lldb::eSymbolContextBlock); // Try the persistent decls, which take precedence over all else. - if (!namespace_decl) { - do { - if (!target) - break; - - ClangASTContext *scratch_clang_ast_context = - target->GetScratchClangASTContext(); - - if (!scratch_clang_ast_context) - break; - - ASTContext *scratch_ast_context = - scratch_clang_ast_context->getASTContext(); - - if (!scratch_ast_context) - break; - - NamedDecl *persistent_decl = - m_parser_vars->m_persistent_vars->GetPersistentDecl(name); - - if (!persistent_decl) - break; - - Decl *parser_persistent_decl = CopyDecl(persistent_decl); - - if (!parser_persistent_decl) - break; - - NamedDecl *parser_named_decl = - dyn_cast<NamedDecl>(parser_persistent_decl); - - if (!parser_named_decl) - break; - - if (clang::FunctionDecl *parser_function_decl = - llvm::dyn_cast<clang::FunctionDecl>(parser_named_decl)) { - MaybeRegisterFunctionBody(parser_function_decl); - } - - LLDB_LOGF(log, " CEDM::FEVD[%u] Found persistent decl %s", current_id, - name.GetCString()); - - context.AddNamedDecl(parser_named_decl); - } while (false); - } + if (!namespace_decl) + SearchPersistenDecls(context, name, current_id); if (name.GetCString()[0] == '$' && !namespace_decl) { static ConstString g_lldb_class_name("$__lldb_class"); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h index 060067c3572..4b80248ceac 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h @@ -372,6 +372,24 @@ private: /// from persistent variables. uint64_t GetParserID() { return (uint64_t) this; } + /// Should be called on all copied functions. + void MaybeRegisterFunctionBody(clang::FunctionDecl *copied_function_decl); + + /// Searches the persistent decls of the target for entities with the + /// given name. + /// + /// \param[in] context + /// The NameSearchContext that can construct Decls for this name. + /// + /// \param[in] name + /// The name of the entities that need to be found. + /// + /// \param[in] current_id + /// The ID for the current FindExternalVisibleDecls invocation, + /// for logging purposes. + void SearchPersistenDecls(NameSearchContext &context, const ConstString name, + unsigned int current_id); + /// Given a target, find a variable that matches the given name and type. /// /// \param[in] target |