From 5eb87cf30fcbfe64719d996cadc4f10a6047cc2c Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 5 Aug 2019 20:31:47 +0000 Subject: [PATCH] [lldb][NFC] Refactor ClangUserExpression::UpdateLanguageForExpr The UpdateLanguageForExpr should only update the language, but over time it started to do also do different things related to the generation of the expression source code. This patch refactors all the source code generation part into its own function. llvm-svn: 367922 --- .../Clang/ClangUserExpression.cpp | 28 +++++++++++-------- .../Clang/ClangUserExpression.h | 9 +++--- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index 6e8aa688a73b..2787a3e5a3db 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -378,10 +378,21 @@ static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target) { } } -void ClangUserExpression::UpdateLanguageForExpr( +void ClangUserExpression::UpdateLanguageForExpr() { + m_expr_lang = lldb::LanguageType::eLanguageTypeUnknown; + if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) + return; + if (m_in_cplusplus_method) + m_expr_lang = lldb::eLanguageTypeC_plus_plus; + else if (m_in_objectivec_method) + m_expr_lang = lldb::eLanguageTypeObjC; + else + m_expr_lang = lldb::eLanguageTypeC; +} + +void ClangUserExpression::CreateSourceCode( DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, std::vector modules_to_import, bool for_completion) { - m_expr_lang = lldb::LanguageType::eLanguageTypeUnknown; std::string prefix = m_expr_prefix; @@ -390,14 +401,7 @@ void ClangUserExpression::UpdateLanguageForExpr( } else { std::unique_ptr source_code( ClangExpressionSourceCode::CreateWrapped(prefix.c_str(), - m_expr_text.c_str())); - - if (m_in_cplusplus_method) - m_expr_lang = lldb::eLanguageTypeC_plus_plus; - else if (m_in_objectivec_method) - m_expr_lang = lldb::eLanguageTypeObjC; - else - m_expr_lang = lldb::eLanguageTypeC; + m_expr_text.c_str())); if (!source_code->GetText(m_transformed_text, m_expr_lang, m_in_static_method, exe_ctx, !m_ctx_obj, @@ -506,8 +510,8 @@ bool ClangUserExpression::PrepareForParsing( LLDB_LOG(log, "List of imported modules in expression: {0}", llvm::make_range(used_modules.begin(), used_modules.end())); - UpdateLanguageForExpr(diagnostic_manager, exe_ctx, used_modules, - for_completion); + UpdateLanguageForExpr(); + CreateSourceCode(diagnostic_manager, exe_ctx, used_modules, for_completion); return true; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h index 24c152bdb45d..7ddc7b6312d0 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h @@ -176,10 +176,11 @@ private: DiagnosticManager &diagnostic_manager) override; std::vector GetModulesToImport(ExecutionContext &exe_ctx); - void UpdateLanguageForExpr(DiagnosticManager &diagnostic_manager, - ExecutionContext &exe_ctx, - std::vector modules_to_import, - bool for_completion); + void CreateSourceCode(DiagnosticManager &diagnostic_manager, + ExecutionContext &exe_ctx, + std::vector modules_to_import, + bool for_completion); + void UpdateLanguageForExpr(); bool SetupPersistentState(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx); bool PrepareForParsing(DiagnosticManager &diagnostic_manager,