[Lldb-commits] [lldb] 81f9c43 - [lldb] Migrate to GetPropertyAtIndexAs for ArchSpec (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri May 5 14:44:07 PDT 2023


Author: Jonas Devlieghere
Date: 2023-05-05T14:43:59-07:00
New Revision: 81f9c4323bb5828d21ba5c5f3d593e94b00fb744

URL: https://github.com/llvm/llvm-project/commit/81f9c4323bb5828d21ba5c5f3d593e94b00fb744
DIFF: https://github.com/llvm/llvm-project/commit/81f9c4323bb5828d21ba5c5f3d593e94b00fb744.diff

LOG: [lldb] Migrate to GetPropertyAtIndexAs for ArchSpec (NFC)

Use the templated GetPropertyAtIndexAs helper for ArchSpec.

Added: 
    

Modified: 
    lldb/include/lldb/Interpreter/OptionValue.h
    lldb/include/lldb/Interpreter/OptionValueProperties.h
    lldb/source/Interpreter/OptionValue.cpp
    lldb/source/Interpreter/OptionValueProperties.cpp
    lldb/source/Target/Target.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h
index 8735106c3d14..730ec65dd054 100644
--- a/lldb/include/lldb/Interpreter/OptionValue.h
+++ b/lldb/include/lldb/Interpreter/OptionValue.h
@@ -10,6 +10,7 @@
 #define LLDB_INTERPRETER_OPTIONVALUE_H
 
 #include "lldb/Core/FormatEntity.h"
+#include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/Cloneable.h"
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/ConstString.h"
@@ -307,6 +308,10 @@ class OptionValue {
 
   bool SetUUIDValue(const UUID &uuid);
 
+  std::optional<ArchSpec> GetArchSpecValue() const;
+
+  bool SetArchSpecValue(ArchSpec arch_spec);
+
   bool OptionWasSet() const { return m_value_was_set; }
 
   void SetOptionWasSet() { m_value_was_set = true; }
@@ -346,6 +351,8 @@ class OptionValue {
       return GetLanguageValue();
     if constexpr (std::is_same_v<T, llvm::StringRef>)
       return GetStringValue();
+    if constexpr (std::is_same_v<T, ArchSpec>)
+      return GetArchSpecValue();
     if constexpr (std::is_enum_v<T>)
       if (std::optional<int64_t> value = GetEnumerationValue())
         return static_cast<T>(*value);
@@ -372,6 +379,8 @@ class OptionValue {
 
   bool SetValueAs(FileSpec v) { return SetFileSpecValue(v); }
 
+  bool SetValueAs(ArchSpec v) { return SetArchSpecValue(v); }
+
   template <typename T, std::enable_if_t<std::is_enum_v<T>, bool> = true>
   bool SetValueAs(T t) {
     return SetEnumerationValue(t);

diff  --git a/lldb/include/lldb/Interpreter/OptionValueProperties.h b/lldb/include/lldb/Interpreter/OptionValueProperties.h
index f4e119cdd83d..5a6bf2a81e4b 100644
--- a/lldb/include/lldb/Interpreter/OptionValueProperties.h
+++ b/lldb/include/lldb/Interpreter/OptionValueProperties.h
@@ -106,9 +106,6 @@ class OptionValueProperties
   Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op,
                      llvm::StringRef path, llvm::StringRef value) override;
 
-  OptionValueArch *GetPropertyAtIndexAsOptionValueArch(
-      uint32_t idx, const ExecutionContext *exe_ctx = nullptr) const;
-
   bool
   GetPropertyAtIndexAsArgs(uint32_t idx, Args &args,
                            const ExecutionContext *exe_ctx = nullptr) const;

diff  --git a/lldb/source/Interpreter/OptionValue.cpp b/lldb/source/Interpreter/OptionValue.cpp
index b9da1f122ebe..d29f86db8235 100644
--- a/lldb/source/Interpreter/OptionValue.cpp
+++ b/lldb/source/Interpreter/OptionValue.cpp
@@ -431,6 +431,20 @@ bool OptionValue::SetUUIDValue(const UUID &uuid) {
   return false;
 }
 
+std::optional<ArchSpec> OptionValue::GetArchSpecValue() const {
+  if (const OptionValueArch *option_value = GetAsArch())
+    return option_value->GetCurrentValue();
+  return {};
+}
+
+bool OptionValue::SetArchSpecValue(ArchSpec arch_spec) {
+  if (OptionValueArch *option_value = GetAsArch()) {
+    option_value->SetCurrentValue(arch_spec, false);
+    return true;
+  }
+  return false;
+}
+
 const char *OptionValue::GetBuiltinTypeAsCString(Type t) {
   switch (t) {
   case eTypeInvalid:

diff  --git a/lldb/source/Interpreter/OptionValueProperties.cpp b/lldb/source/Interpreter/OptionValueProperties.cpp
index 29dfe92860ae..a061c41982fc 100644
--- a/lldb/source/Interpreter/OptionValueProperties.cpp
+++ b/lldb/source/Interpreter/OptionValueProperties.cpp
@@ -193,14 +193,6 @@ OptionValueProperties::GetPropertyAtIndexAsOptionValueFileSpecList(
   return nullptr;
 }
 
-OptionValueArch *OptionValueProperties::GetPropertyAtIndexAsOptionValueArch(
-    uint32_t idx, const ExecutionContext *exe_ctx) const {
-  const Property *property = GetPropertyAtIndex(idx, exe_ctx);
-  if (property)
-    return property->GetValue()->GetAsArch();
-  return nullptr;
-}
-
 bool OptionValueProperties::GetPropertyAtIndexAsArgs(
     uint32_t idx, Args &args, const ExecutionContext *exe_ctx) const {
   const Property *property = GetPropertyAtIndex(idx, exe_ctx);

diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 7df4af8dd0f2..b5a6e4ad22e4 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -4153,18 +4153,13 @@ void TargetProperties::SetInjectLocalVariables(ExecutionContext *exe_ctx,
 }
 
 ArchSpec TargetProperties::GetDefaultArchitecture() const {
-  OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch(
-      ePropertyDefaultArch);
-  if (value)
-    return value->GetCurrentValue();
-  return ArchSpec();
+  const uint32_t idx = ePropertyDefaultArch;
+  return GetPropertyAtIndexAs<ArchSpec>(idx, {});
 }
 
 void TargetProperties::SetDefaultArchitecture(const ArchSpec &arch) {
-  OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch(
-      ePropertyDefaultArch);
-  if (value)
-    return value->SetCurrentValue(arch, true);
+  const uint32_t idx = ePropertyDefaultArch;
+  SetPropertyAtIndex(idx, arch);
 }
 
 bool TargetProperties::GetMoveToNearestCode() const {


        


More information about the lldb-commits mailing list