1 //===-- UserSettingsController.cpp ----------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/UserSettingsController.h"
11 #include "lldb/Interpreter/OptionValueProperties.h"
12 #include "lldb/Utility/Status.h"
13 #include "lldb/Utility/Stream.h"
17 namespace lldb_private
{
18 class CommandInterpreter
;
20 namespace lldb_private
{
23 namespace lldb_private
{
24 class ExecutionContext
;
26 namespace lldb_private
{
31 using namespace lldb_private
;
33 Properties::Properties() = default;
35 Properties::Properties(const lldb::OptionValuePropertiesSP
&collection_sp
)
36 : m_collection_sp(collection_sp
) {}
38 Properties::~Properties() = default;
41 Properties::GetPropertyValue(const ExecutionContext
*exe_ctx
,
42 llvm::StringRef path
, Status
&error
) const {
43 OptionValuePropertiesSP
properties_sp(GetValueProperties());
45 return properties_sp
->GetSubValue(exe_ctx
, path
, error
);
46 return lldb::OptionValueSP();
49 Status
Properties::SetPropertyValue(const ExecutionContext
*exe_ctx
,
50 VarSetOperationType op
,
52 llvm::StringRef value
) {
53 OptionValuePropertiesSP
properties_sp(GetValueProperties());
55 return properties_sp
->SetSubValue(exe_ctx
, op
, path
, value
);
56 return Status::FromErrorString("no properties");
59 void Properties::DumpAllPropertyValues(const ExecutionContext
*exe_ctx
,
60 Stream
&strm
, uint32_t dump_mask
,
62 OptionValuePropertiesSP
properties_sp(GetValueProperties());
67 llvm::json::Value json
= properties_sp
->ToJSON(exe_ctx
);
68 strm
.Printf("%s", llvm::formatv("{0:2}", json
).str().c_str());
70 properties_sp
->DumpValue(exe_ctx
, strm
, dump_mask
);
73 void Properties::DumpAllDescriptions(CommandInterpreter
&interpreter
,
75 strm
.PutCString("Top level variables:\n\n");
77 OptionValuePropertiesSP
properties_sp(GetValueProperties());
79 return properties_sp
->DumpAllDescriptions(interpreter
, strm
);
82 Status
Properties::DumpPropertyValue(const ExecutionContext
*exe_ctx
,
84 llvm::StringRef property_path
,
85 uint32_t dump_mask
, bool is_json
) {
86 OptionValuePropertiesSP
properties_sp(GetValueProperties());
88 return properties_sp
->DumpPropertyValue(exe_ctx
, strm
, property_path
,
91 return Status::FromErrorString("empty property list");
95 Properties::Apropos(llvm::StringRef keyword
,
96 std::vector
<const Property
*> &matching_properties
) const {
97 OptionValuePropertiesSP
properties_sp(GetValueProperties());
99 properties_sp
->Apropos(keyword
, matching_properties
);
101 return matching_properties
.size();
104 llvm::StringRef
Properties::GetExperimentalSettingsName() {
105 static constexpr llvm::StringLiteral
g_experimental("experimental");
106 return g_experimental
;
109 bool Properties::IsSettingExperimental(llvm::StringRef setting
) {
113 llvm::StringRef experimental
= GetExperimentalSettingsName();
114 size_t dot_pos
= setting
.find_first_of('.');
115 return setting
.take_front(dot_pos
) == experimental
;