Skip to content

Commit

Permalink
[lldb] Eliminate {Get,Set}PropertyAtIndexAsFileSpec (NFC)
Browse files Browse the repository at this point in the history
This patch is a continuation of 6f8b33f and eliminates the
{Get,Set}PropertyAtIndexAsFileSpec functions.
  • Loading branch information
JDevlieghere committed May 5, 2023
1 parent 3145e60 commit ab73a9c
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 58 deletions.
9 changes: 7 additions & 2 deletions lldb/include/lldb/Interpreter/OptionValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "lldb/Utility/Cloneable.h"
#include "lldb/Utility/CompletionRequest.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-defines.h"
#include "lldb/lldb-private-enumerations.h"
Expand Down Expand Up @@ -269,9 +270,9 @@ class OptionValue {

bool SetEnumerationValue(int64_t value);

FileSpec GetFileSpecValue() const;
std::optional<FileSpec> GetFileSpecValue() const;

bool SetFileSpecValue(const FileSpec &file_spec);
bool SetFileSpecValue(FileSpec file_spec);

FileSpecList GetFileSpecListValue() const;

Expand Down Expand Up @@ -334,6 +335,8 @@ class OptionValue {
return GetCharValue();
if constexpr (std::is_same_v<T, lldb::Format>)
return GetFormatValue();
if constexpr (std::is_same_v<T, FileSpec>)
return GetFileSpecValue();
if constexpr (std::is_same_v<T, lldb::LanguageType>)
return GetLanguageValue();
if constexpr (std::is_same_v<T, llvm::StringRef>)
Expand Down Expand Up @@ -362,6 +365,8 @@ class OptionValue {

bool SetValueAs(lldb::LanguageType v) { return SetLanguageValue(v); }

bool SetValueAs(FileSpec v) { return SetFileSpecValue(v); }

template <typename T, std::enable_if_t<std::is_enum_v<T>, bool> = true>
bool SetValueAs(T t) {
return SetEnumerationValue(t);
Expand Down
7 changes: 0 additions & 7 deletions lldb/include/lldb/Interpreter/OptionValueProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ class OptionValueProperties
OptionValueFileSpec *GetPropertyAtIndexAsOptionValueFileSpec(
uint32_t idx, const ExecutionContext *exe_ctx = nullptr) const;

FileSpec
GetPropertyAtIndexAsFileSpec(uint32_t idx,
const ExecutionContext *exe_ctx = nullptr) const;

bool SetPropertyAtIndexAsFileSpec(uint32_t idx, const FileSpec &file_spec,
const ExecutionContext *exe_ctx = nullptr);

OptionValuePathMappings *GetPropertyAtIndexAsOptionValuePathMappings(
uint32_t idx, const ExecutionContext *exe_ctx = nullptr) const;

Expand Down
18 changes: 8 additions & 10 deletions lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,23 @@ bool ModuleListProperties::GetEnableBackgroundLookup() const {
}

FileSpec ModuleListProperties::GetClangModulesCachePath() const {
return m_collection_sp
->GetPropertyAtIndexAsOptionValueFileSpec(ePropertyClangModulesCachePath)
->GetCurrentValue();
const uint32_t idx = ePropertyClangModulesCachePath;
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

bool ModuleListProperties::SetClangModulesCachePath(const FileSpec &path) {
return m_collection_sp->SetPropertyAtIndexAsFileSpec(
ePropertyClangModulesCachePath, path);
const uint32_t idx = ePropertyClangModulesCachePath;
return SetPropertyAtIndex(idx, path);
}

FileSpec ModuleListProperties::GetLLDBIndexCachePath() const {
return m_collection_sp
->GetPropertyAtIndexAsOptionValueFileSpec(ePropertyLLDBIndexCachePath)
->GetCurrentValue();
const uint32_t idx = ePropertyLLDBIndexCachePath;
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

bool ModuleListProperties::SetLLDBIndexCachePath(const FileSpec &path) {
return m_collection_sp->SetPropertyAtIndexAsFileSpec(
ePropertyLLDBIndexCachePath, path);
const uint32_t idx = ePropertyLLDBIndexCachePath;
return SetPropertyAtIndex(idx, path);
}

bool ModuleListProperties::GetEnableLLDBIndexCache() const {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void CommandInterpreter::SetOpenTranscriptInEditor(bool enable) {

FileSpec CommandInterpreter::GetSaveSessionDirectory() const {
const uint32_t idx = ePropertySaveSessionDirectory;
return m_collection_sp->GetPropertyAtIndexAsFileSpec(idx);
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

void CommandInterpreter::SetSaveSessionDirectory(llvm::StringRef path) {
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Interpreter/OptionValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ bool OptionValue::SetEnumerationValue(int64_t value) {
return false;
}

FileSpec OptionValue::GetFileSpecValue() const {
std::optional<FileSpec> OptionValue::GetFileSpecValue() const {
const OptionValueFileSpec *option_value = GetAsFileSpec();
if (option_value)
return option_value->GetCurrentValue();
return FileSpec();
return {};
}

bool OptionValue::SetFileSpecValue(const FileSpec &file_spec) {
bool OptionValue::SetFileSpecValue(FileSpec file_spec) {
OptionValueFileSpec *option_value = GetAsFileSpec();
if (option_value) {
option_value->SetCurrentValue(file_spec, false);
Expand Down
23 changes: 0 additions & 23 deletions lldb/source/Interpreter/OptionValueProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,29 +287,6 @@ OptionValueProperties::GetPropertyAtIndexAsOptionValueFileSpec(
return nullptr;
}

FileSpec OptionValueProperties::GetPropertyAtIndexAsFileSpec(
uint32_t idx, const ExecutionContext *exe_ctx) const {
const Property *property = GetPropertyAtIndex(idx, exe_ctx);
if (property) {
OptionValue *value = property->GetValue().get();
if (value)
return value->GetFileSpecValue();
}
return FileSpec();
}

bool OptionValueProperties::SetPropertyAtIndexAsFileSpec(
uint32_t idx, const FileSpec &new_file_spec,
const ExecutionContext *exe_ctx) {
const Property *property = GetPropertyAtIndex(idx, exe_ctx);
if (property) {
OptionValue *value = property->GetValue().get();
if (value)
return value->SetFileSpecValue(new_file_spec);
}
return false;
}

OptionValueSInt64 *OptionValueProperties::GetPropertyAtIndexAsOptionValueSInt64(
uint32_t idx, const ExecutionContext *exe_ctx) const {
const Property *property = GetPropertyAtIndex(idx, exe_ctx);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PluginProperties : public Properties {
}

FileSpec GetEmulatorPath() {
return m_collection_sp->GetPropertyAtIndexAsFileSpec(ePropertyEmulatorPath);
return GetPropertyAtIndexAs<FileSpec>(ePropertyEmulatorPath, {});
}

Args GetEmulatorArgs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class PluginProperties : public Properties {

FileSpec GetTargetDefinitionFile() const {
const uint32_t idx = ePropertyTargetDefinitionFile;
return m_collection_sp->GetPropertyAtIndexAsFileSpec(idx);
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

bool GetUseSVR4() const {
Expand Down
7 changes: 3 additions & 4 deletions lldb/source/Target/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,12 @@ bool PlatformProperties::SetUseModuleCache(bool use_module_cache) {
}

FileSpec PlatformProperties::GetModuleCacheDirectory() const {
return m_collection_sp->GetPropertyAtIndexAsFileSpec(
ePropertyModuleCacheDirectory);
return GetPropertyAtIndexAs<FileSpec>(ePropertyModuleCacheDirectory, {});
}

bool PlatformProperties::SetModuleCacheDirectory(const FileSpec &dir_spec) {
return m_collection_sp->SetPropertyAtIndexAsFileSpec(
ePropertyModuleCacheDirectory, dir_spec);
return m_collection_sp->SetPropertyAtIndex(ePropertyModuleCacheDirectory,
dir_spec);
}

void PlatformProperties::SetDefaultModuleCacheDirectory(
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void ProcessProperties::SetExtraStartupCommands(const Args &args) {

FileSpec ProcessProperties::GetPythonOSPluginPath() const {
const uint32_t idx = ePropertyPythonOSPluginPath;
return m_collection_sp->GetPropertyAtIndexAsFileSpec(idx);
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

uint32_t ProcessProperties::GetVirtualAddressableBits() const {
Expand All @@ -229,7 +229,7 @@ void ProcessProperties::SetVirtualAddressableBits(uint32_t bits) {
}
void ProcessProperties::SetPythonOSPluginPath(const FileSpec &file) {
const uint32_t idx = ePropertyPythonOSPluginPath;
m_collection_sp->SetPropertyAtIndexAsFileSpec(idx, file);
SetPropertyAtIndex(idx, file);
}

bool ProcessProperties::GetIgnoreBreakpointsInExpressions() const {
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4452,7 +4452,7 @@ bool TargetProperties::GetEnableNotifyAboutFixIts() const {

FileSpec TargetProperties::GetSaveJITObjectsDir() const {
const uint32_t idx = ePropertySaveObjectsDir;
return m_collection_sp->GetPropertyAtIndexAsFileSpec(idx);
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

void TargetProperties::CheckJITObjectsDir() {
Expand Down Expand Up @@ -4529,7 +4529,7 @@ uint32_t TargetProperties::GetMaximumMemReadSize() const {

FileSpec TargetProperties::GetStandardInputPath() const {
const uint32_t idx = ePropertyInputPath;
return m_collection_sp->GetPropertyAtIndexAsFileSpec(idx);
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

void TargetProperties::SetStandardInputPath(llvm::StringRef path) {
Expand All @@ -4539,7 +4539,7 @@ void TargetProperties::SetStandardInputPath(llvm::StringRef path) {

FileSpec TargetProperties::GetStandardOutputPath() const {
const uint32_t idx = ePropertyOutputPath;
return m_collection_sp->GetPropertyAtIndexAsFileSpec(idx);
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

void TargetProperties::SetStandardOutputPath(llvm::StringRef path) {
Expand All @@ -4549,7 +4549,7 @@ void TargetProperties::SetStandardOutputPath(llvm::StringRef path) {

FileSpec TargetProperties::GetStandardErrorPath() const {
const uint32_t idx = ePropertyErrorPath;
return m_collection_sp->GetPropertyAtIndexAsFileSpec(idx);
return GetPropertyAtIndexAs<FileSpec>(idx, {});
}

void TargetProperties::SetStandardErrorPath(llvm::StringRef path) {
Expand Down

0 comments on commit ab73a9c

Please sign in to comment.