[Lldb-commits] [lldb] r336734 - Refactor ClangUserExpression::Parse [NFC]
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 10 15:12:39 PDT 2018
Author: teemperor
Date: Tue Jul 10 15:12:39 2018
New Revision: 336734
URL: http://llvm.org/viewvc/llvm-project?rev=336734&view=rev
Log:
Refactor ClangUserExpression::Parse [NFC]
Summary:
This patch splits out functionality from the `Parse` method into different methods.
This benefits the code completion work (which should reuse those methods) and makes the
code a bit more readable.
Note that this patch is as minimal as possible. Some of the code in the new methods definitely
needs more refactoring.
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D48339
Modified:
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=336734&r1=336733&r2=336734&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp Tue Jul 10 15:12:39 2018
@@ -322,17 +322,8 @@ private:
};
} // namespace
-bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
- ExecutionContext &exe_ctx,
- lldb_private::ExecutionPolicy execution_policy,
- bool keep_result_in_memory,
- bool generate_debug_info) {
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
-
- Status err;
-
- InstallContext(exe_ctx);
-
+bool ClangUserExpression::SetupPersistentState(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx) {
if (Target *target = exe_ctx.GetTargetPtr()) {
if (PersistentExpressionState *persistent_state =
target->GetPersistentExpressionStateForLanguage(
@@ -349,26 +340,15 @@ bool ClangUserExpression::Parse(Diagnost
"error: couldn't start parsing (no target)");
return false;
}
+ return true;
+}
- ScanContext(exe_ctx, err);
-
- if (!err.Success()) {
- diagnostic_manager.PutString(eDiagnosticSeverityWarning, err.AsCString());
- }
-
- ////////////////////////////////////
- // Generate the expression
- //
-
- ApplyObjcCastHack(m_expr_text);
-
- std::string prefix = m_expr_prefix;
-
+static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target) {
if (ClangModulesDeclVendor *decl_vendor =
- m_target->GetClangModulesDeclVendor()) {
+ target->GetClangModulesDeclVendor()) {
const ClangModulesDeclVendor::ModuleVector &hand_imported_modules =
llvm::cast<ClangPersistentVariables>(
- m_target->GetPersistentExpressionStateForLanguage(
+ target->GetPersistentExpressionStateForLanguage(
lldb::eLanguageTypeC))
->GetHandLoadedClangModules();
ClangModulesDeclVendor::ModuleVector modules_for_macros;
@@ -377,7 +357,7 @@ bool ClangUserExpression::Parse(Diagnost
modules_for_macros.push_back(module);
}
- if (m_target->GetEnableAutoImportClangModules()) {
+ if (target->GetEnableAutoImportClangModules()) {
if (StackFrame *frame = exe_ctx.GetFramePtr()) {
if (Block *block = frame->GetFrameBlock()) {
SymbolContext sc;
@@ -394,8 +374,13 @@ bool ClangUserExpression::Parse(Diagnost
}
}
}
+}
- lldb::LanguageType lang_type = lldb::eLanguageTypeUnknown;
+llvm::Optional<lldb::LanguageType> ClangUserExpression::GetLanguageForExpr(
+ DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) {
+ lldb::LanguageType lang_type = lldb::LanguageType::eLanguageTypeUnknown;
+
+ std::string prefix = m_expr_prefix;
if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) {
m_transformed_text = m_expr_text;
@@ -415,9 +400,50 @@ bool ClangUserExpression::Parse(Diagnost
exe_ctx)) {
diagnostic_manager.PutString(eDiagnosticSeverityError,
"couldn't construct expression body");
- return false;
+ return llvm::Optional<lldb::LanguageType>();
}
}
+ return lang_type;
+}
+
+bool ClangUserExpression::PrepareForParsing(
+ DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) {
+ InstallContext(exe_ctx);
+
+ if (!SetupPersistentState(diagnostic_manager, exe_ctx))
+ return false;
+
+ Status err;
+ ScanContext(exe_ctx, err);
+
+ if (!err.Success()) {
+ diagnostic_manager.PutString(eDiagnosticSeverityWarning, err.AsCString());
+ }
+
+ ////////////////////////////////////
+ // Generate the expression
+ //
+
+ ApplyObjcCastHack(m_expr_text);
+
+ SetupDeclVendor(exe_ctx, m_target);
+ return true;
+}
+
+bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx,
+ lldb_private::ExecutionPolicy execution_policy,
+ bool keep_result_in_memory,
+ bool generate_debug_info) {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+
+ if (!PrepareForParsing(diagnostic_manager, exe_ctx))
+ return false;
+
+ lldb::LanguageType lang_type = lldb::LanguageType::eLanguageTypeUnknown;
+ if (auto new_lang = GetLanguageForExpr(diagnostic_manager, exe_ctx)) {
+ lang_type = new_lang.getValue();
+ }
if (log)
log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str());
Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h?rev=336734&r1=336733&r2=336734&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h Tue Jul 10 15:12:39 2018
@@ -174,6 +174,13 @@ private:
lldb::addr_t struct_address,
DiagnosticManager &diagnostic_manager) override;
+ llvm::Optional<lldb::LanguageType> GetLanguageForExpr(
+ DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx);
+ bool SetupPersistentState(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx);
+ bool PrepareForParsing(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx);
+
ClangUserExpressionHelper m_type_system_helper;
class ResultDelegate : public Materializer::PersistentVariableDelegate {
More information about the lldb-commits
mailing list