[Lldb-commits] [lldb] [lldb] unique_ptr-ify some GetUserExpression APIs. (PR #106034)
Lang Hames via lldb-commits
lldb-commits at lists.llvm.org
Sun Aug 25 21:17:14 PDT 2024
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/106034
These methods already returned a uniquely owned object, this just makes them self-documenting.
>From b115f38e01488e0622f5ab1d064b873f9459efeb Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Mon, 26 Aug 2024 13:56:04 +1000
Subject: [PATCH] [lldb] unique_ptr-ify some GetUserExpression APIs.
These methods already returned a uniquely owned object, this just makes them
self-documenting.
---
lldb/include/lldb/Symbol/TypeSystem.h | 2 +-
lldb/include/lldb/Target/Target.h | 2 +-
lldb/source/Breakpoint/BreakpointLocation.cpp | 4 ++--
lldb/source/Breakpoint/Watchpoint.cpp | 4 ++--
.../Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 6 +++---
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h | 10 ++++------
lldb/source/Target/Target.cpp | 6 +++---
7 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index 7d48f9b316138c..b1ed5df3013a2b 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -495,7 +495,7 @@ class TypeSystem : public PluginInterface,
return IsPointerOrReferenceType(type, nullptr);
}
- virtual UserExpression *GetUserExpression(
+ virtual std::unique_ptr<UserExpression> GetUserExpression(
llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language,
Expression::ResultType desired_type,
const EvaluateExpressionOptions &options, ValueObject *ctx_obj) {
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index 7f4d607f5427df..95e3aaf02b19d5 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1174,7 +1174,7 @@ class Target : public std::enable_shared_from_this<Target>,
// parameters have the same meaning as for the UserExpression constructor.
// Returns a new-ed object which the caller owns.
- UserExpression *
+ std::unique_ptr<UserExpression>
GetUserExpressionForLanguage(llvm::StringRef expr, llvm::StringRef prefix,
SourceLanguage language,
Expression::ResultType desired_type,
diff --git a/lldb/source/Breakpoint/BreakpointLocation.cpp b/lldb/source/Breakpoint/BreakpointLocation.cpp
index 41911fad41c648..8ef6b844230505 100644
--- a/lldb/source/Breakpoint/BreakpointLocation.cpp
+++ b/lldb/source/Breakpoint/BreakpointLocation.cpp
@@ -251,9 +251,9 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx,
if (comp_unit)
language = comp_unit->GetLanguage();
- m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(
+ m_user_expression_sp = GetTarget().GetUserExpressionForLanguage(
condition_text, llvm::StringRef(), language, Expression::eResultTypeAny,
- EvaluateExpressionOptions(), nullptr, error));
+ EvaluateExpressionOptions(), nullptr, error);
if (error.Fail()) {
LLDB_LOGF(log, "Error getting condition expression: %s.",
error.AsCString());
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp
index 715e83c76697b2..577ee81d687dcb 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -463,9 +463,9 @@ void Watchpoint::SetCondition(const char *condition) {
} else {
// Pass nullptr for expr_prefix (no translation-unit level definitions).
Status error;
- m_condition_up.reset(m_target.GetUserExpressionForLanguage(
+ m_condition_up = m_target.GetUserExpressionForLanguage(
condition, {}, {}, UserExpression::eResultTypeAny,
- EvaluateExpressionOptions(), nullptr, error));
+ EvaluateExpressionOptions(), nullptr, error);
if (error.Fail()) {
// FIXME: Log something...
m_condition_up.reset();
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 695801da9da69a..2e2f4be6343791 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -9741,7 +9741,7 @@ void ScratchTypeSystemClang::Dump(llvm::raw_ostream &output) {
}
}
-UserExpression *ScratchTypeSystemClang::GetUserExpression(
+std::unique_ptr<UserExpression> ScratchTypeSystemClang::GetUserExpression(
llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language,
Expression::ResultType desired_type,
const EvaluateExpressionOptions &options, ValueObject *ctx_obj) {
@@ -9749,8 +9749,8 @@ UserExpression *ScratchTypeSystemClang::GetUserExpression(
if (!target_sp)
return nullptr;
- return new ClangUserExpression(*target_sp.get(), expr, prefix, language,
- desired_type, options, ctx_obj);
+ return std::make_unique<ClangUserExpression>(
+ *target_sp.get(), expr, prefix, language, desired_type, options, ctx_obj);
}
FunctionCaller *ScratchTypeSystemClang::GetFunctionCaller(
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index e39aedec7e3902..fc29a2e5eaefc7 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -1299,12 +1299,10 @@ class ScratchTypeSystemClang : public TypeSystemClang {
/// \see lldb_private::TypeSystem::Dump
void Dump(llvm::raw_ostream &output) override;
- UserExpression *GetUserExpression(llvm::StringRef expr,
- llvm::StringRef prefix,
- SourceLanguage language,
- Expression::ResultType desired_type,
- const EvaluateExpressionOptions &options,
- ValueObject *ctx_obj) override;
+ std::unique_ptr<UserExpression> GetUserExpression(
+ llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language,
+ Expression::ResultType desired_type,
+ const EvaluateExpressionOptions &options, ValueObject *ctx_obj) override;
FunctionCaller *GetFunctionCaller(const CompilerType &return_type,
const Address &function_address,
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 260974bddedf3a..f40fb1c10a5630 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -2511,7 +2511,7 @@ Target::GetPersistentExpressionStateForLanguage(lldb::LanguageType language) {
return nullptr;
}
-UserExpression *Target::GetUserExpressionForLanguage(
+std::unique_ptr<UserExpression> Target::GetUserExpressionForLanguage(
llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language,
Expression::ResultType desired_type,
const EvaluateExpressionOptions &options, ValueObject *ctx_obj,
@@ -2534,8 +2534,8 @@ UserExpression *Target::GetUserExpressionForLanguage(
return nullptr;
}
- auto *user_expr = ts->GetUserExpression(expr, prefix, language, desired_type,
- options, ctx_obj);
+ auto user_expr = ts->GetUserExpression(expr, prefix, language, desired_type,
+ options, ctx_obj);
if (!user_expr)
error.SetErrorStringWithFormat(
"Could not create an expression for language %s",
More information about the lldb-commits
mailing list