1 //====-- UserSettingsController.cpp ------------------------------*- C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Core/UserSettingsController.h"
11
12 #include "lldb/Interpreter/OptionValueProperties.h"
13 #include "lldb/Utility/Status.h"
14 #include "lldb/Utility/Stream.h"
15
16 #include <memory>
17
18 namespace lldb_private {
19 class CommandInterpreter;
20 }
21 namespace lldb_private {
22 class ConstString;
23 }
24 namespace lldb_private {
25 class ExecutionContext;
26 }
27 namespace lldb_private {
28 class Property;
29 }
30
31 using namespace lldb;
32 using namespace lldb_private;
33
34 lldb::OptionValueSP
GetPropertyValue(const ExecutionContext * exe_ctx,llvm::StringRef path,bool will_modify,Status & error) const35 Properties::GetPropertyValue(const ExecutionContext *exe_ctx,
36 llvm::StringRef path, bool will_modify,
37 Status &error) const {
38 OptionValuePropertiesSP properties_sp(GetValueProperties());
39 if (properties_sp)
40 return properties_sp->GetSubValue(exe_ctx, path, will_modify, error);
41 return lldb::OptionValueSP();
42 }
43
SetPropertyValue(const ExecutionContext * exe_ctx,VarSetOperationType op,llvm::StringRef path,llvm::StringRef value)44 Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx,
45 VarSetOperationType op,
46 llvm::StringRef path,
47 llvm::StringRef value) {
48 OptionValuePropertiesSP properties_sp(GetValueProperties());
49 if (properties_sp)
50 return properties_sp->SetSubValue(exe_ctx, op, path, value);
51 Status error;
52 error.SetErrorString("no properties");
53 return error;
54 }
55
DumpAllPropertyValues(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)56 void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx,
57 Stream &strm, uint32_t dump_mask) {
58 OptionValuePropertiesSP properties_sp(GetValueProperties());
59 if (properties_sp)
60 return properties_sp->DumpValue(exe_ctx, strm, dump_mask);
61 }
62
DumpAllDescriptions(CommandInterpreter & interpreter,Stream & strm) const63 void Properties::DumpAllDescriptions(CommandInterpreter &interpreter,
64 Stream &strm) const {
65 strm.PutCString("Top level variables:\n\n");
66
67 OptionValuePropertiesSP properties_sp(GetValueProperties());
68 if (properties_sp)
69 return properties_sp->DumpAllDescriptions(interpreter, strm);
70 }
71
DumpPropertyValue(const ExecutionContext * exe_ctx,Stream & strm,llvm::StringRef property_path,uint32_t dump_mask)72 Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx,
73 Stream &strm,
74 llvm::StringRef property_path,
75 uint32_t dump_mask) {
76 OptionValuePropertiesSP properties_sp(GetValueProperties());
77 if (properties_sp) {
78 return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path,
79 dump_mask);
80 }
81 Status error;
82 error.SetErrorString("empty property list");
83 return error;
84 }
85
86 size_t
Apropos(llvm::StringRef keyword,std::vector<const Property * > & matching_properties) const87 Properties::Apropos(llvm::StringRef keyword,
88 std::vector<const Property *> &matching_properties) const {
89 OptionValuePropertiesSP properties_sp(GetValueProperties());
90 if (properties_sp) {
91 properties_sp->Apropos(keyword, matching_properties);
92 }
93 return matching_properties.size();
94 }
95
96 lldb::OptionValuePropertiesSP
GetSubProperty(const ExecutionContext * exe_ctx,const ConstString & name)97 Properties::GetSubProperty(const ExecutionContext *exe_ctx,
98 const ConstString &name) {
99 OptionValuePropertiesSP properties_sp(GetValueProperties());
100 if (properties_sp)
101 return properties_sp->GetSubProperty(exe_ctx, name);
102 return lldb::OptionValuePropertiesSP();
103 }
104
GetExperimentalSettingsName()105 const char *Properties::GetExperimentalSettingsName() { return "experimental"; }
106
IsSettingExperimental(llvm::StringRef setting)107 bool Properties::IsSettingExperimental(llvm::StringRef setting) {
108 if (setting.empty())
109 return false;
110
111 llvm::StringRef experimental = GetExperimentalSettingsName();
112 size_t dot_pos = setting.find_first_of('.');
113 return setting.take_front(dot_pos) == experimental;
114 }
115