1f678e45dSDimitry Andric //====-- UserSettingsController.cpp ------------------------------*- C++-*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10435933ddSDimitry Andric #include "lldb/Core/UserSettingsController.h"
11f678e45dSDimitry Andric
121c3bbb01SEd Maste #include "lldb/Interpreter/OptionValueProperties.h"
135517e702SDimitry Andric #include "lldb/Utility/Status.h"
14f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
15f678e45dSDimitry Andric
16*b5893f02SDimitry Andric #include <memory>
17f678e45dSDimitry Andric
18f678e45dSDimitry Andric namespace lldb_private {
19f678e45dSDimitry Andric class CommandInterpreter;
20f678e45dSDimitry Andric }
21f678e45dSDimitry Andric namespace lldb_private {
22f678e45dSDimitry Andric class ConstString;
23f678e45dSDimitry Andric }
24f678e45dSDimitry Andric namespace lldb_private {
25f678e45dSDimitry Andric class ExecutionContext;
26f678e45dSDimitry Andric }
27f678e45dSDimitry Andric namespace lldb_private {
28f678e45dSDimitry Andric class Property;
29f678e45dSDimitry Andric }
30ac7ddfbfSEd Maste
31ac7ddfbfSEd Maste using namespace lldb;
32ac7ddfbfSEd Maste using namespace lldb_private;
33ac7ddfbfSEd Maste
34ac7ddfbfSEd Maste lldb::OptionValueSP
GetPropertyValue(const ExecutionContext * exe_ctx,llvm::StringRef path,bool will_modify,Status & error) const355517e702SDimitry Andric Properties::GetPropertyValue(const ExecutionContext *exe_ctx,
365517e702SDimitry Andric llvm::StringRef path, bool will_modify,
375517e702SDimitry Andric Status &error) const {
38ac7ddfbfSEd Maste OptionValuePropertiesSP properties_sp(GetValueProperties());
39ac7ddfbfSEd Maste if (properties_sp)
40ac7ddfbfSEd Maste return properties_sp->GetSubValue(exe_ctx, path, will_modify, error);
41ac7ddfbfSEd Maste return lldb::OptionValueSP();
42ac7ddfbfSEd Maste }
43ac7ddfbfSEd Maste
SetPropertyValue(const ExecutionContext * exe_ctx,VarSetOperationType op,llvm::StringRef path,llvm::StringRef value)445517e702SDimitry Andric Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx,
455517e702SDimitry Andric VarSetOperationType op,
465517e702SDimitry Andric llvm::StringRef path,
47435933ddSDimitry Andric llvm::StringRef value) {
48ac7ddfbfSEd Maste OptionValuePropertiesSP properties_sp(GetValueProperties());
49ac7ddfbfSEd Maste if (properties_sp)
50ac7ddfbfSEd Maste return properties_sp->SetSubValue(exe_ctx, op, path, value);
515517e702SDimitry Andric Status error;
52ac7ddfbfSEd Maste error.SetErrorString("no properties");
53ac7ddfbfSEd Maste return error;
54ac7ddfbfSEd Maste }
55ac7ddfbfSEd Maste
DumpAllPropertyValues(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)56435933ddSDimitry Andric void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx,
57435933ddSDimitry Andric Stream &strm, uint32_t dump_mask) {
58ac7ddfbfSEd Maste OptionValuePropertiesSP properties_sp(GetValueProperties());
59ac7ddfbfSEd Maste if (properties_sp)
60ac7ddfbfSEd Maste return properties_sp->DumpValue(exe_ctx, strm, dump_mask);
61ac7ddfbfSEd Maste }
62ac7ddfbfSEd Maste
DumpAllDescriptions(CommandInterpreter & interpreter,Stream & strm) const63435933ddSDimitry Andric void Properties::DumpAllDescriptions(CommandInterpreter &interpreter,
64435933ddSDimitry Andric Stream &strm) const {
65ac7ddfbfSEd Maste strm.PutCString("Top level variables:\n\n");
66ac7ddfbfSEd Maste
67ac7ddfbfSEd Maste OptionValuePropertiesSP properties_sp(GetValueProperties());
68ac7ddfbfSEd Maste if (properties_sp)
69ac7ddfbfSEd Maste return properties_sp->DumpAllDescriptions(interpreter, strm);
70ac7ddfbfSEd Maste }
71ac7ddfbfSEd Maste
DumpPropertyValue(const ExecutionContext * exe_ctx,Stream & strm,llvm::StringRef property_path,uint32_t dump_mask)725517e702SDimitry Andric Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx,
735517e702SDimitry Andric Stream &strm,
745517e702SDimitry Andric llvm::StringRef property_path,
75435933ddSDimitry Andric uint32_t dump_mask) {
76ac7ddfbfSEd Maste OptionValuePropertiesSP properties_sp(GetValueProperties());
77435933ddSDimitry Andric if (properties_sp) {
78435933ddSDimitry Andric return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path,
79ac7ddfbfSEd Maste dump_mask);
80ac7ddfbfSEd Maste }
815517e702SDimitry Andric Status error;
82ac7ddfbfSEd Maste error.SetErrorString("empty property list");
83ac7ddfbfSEd Maste return error;
84ac7ddfbfSEd Maste }
85ac7ddfbfSEd Maste
86ac7ddfbfSEd Maste size_t
Apropos(llvm::StringRef keyword,std::vector<const Property * > & matching_properties) const87435933ddSDimitry Andric Properties::Apropos(llvm::StringRef keyword,
88435933ddSDimitry Andric std::vector<const Property *> &matching_properties) const {
89ac7ddfbfSEd Maste OptionValuePropertiesSP properties_sp(GetValueProperties());
90435933ddSDimitry Andric if (properties_sp) {
91ac7ddfbfSEd Maste properties_sp->Apropos(keyword, matching_properties);
92ac7ddfbfSEd Maste }
93ac7ddfbfSEd Maste return matching_properties.size();
94ac7ddfbfSEd Maste }
95ac7ddfbfSEd Maste
96ac7ddfbfSEd Maste lldb::OptionValuePropertiesSP
GetSubProperty(const ExecutionContext * exe_ctx,const ConstString & name)97ac7ddfbfSEd Maste Properties::GetSubProperty(const ExecutionContext *exe_ctx,
98435933ddSDimitry Andric const ConstString &name) {
99ac7ddfbfSEd Maste OptionValuePropertiesSP properties_sp(GetValueProperties());
100ac7ddfbfSEd Maste if (properties_sp)
101ac7ddfbfSEd Maste return properties_sp->GetSubProperty(exe_ctx, name);
102ac7ddfbfSEd Maste return lldb::OptionValuePropertiesSP();
103ac7ddfbfSEd Maste }
104ac7ddfbfSEd Maste
GetExperimentalSettingsName()105435933ddSDimitry Andric const char *Properties::GetExperimentalSettingsName() { return "experimental"; }
1064bb0738eSEd Maste
IsSettingExperimental(llvm::StringRef setting)107435933ddSDimitry Andric bool Properties::IsSettingExperimental(llvm::StringRef setting) {
108435933ddSDimitry Andric if (setting.empty())
1094bb0738eSEd Maste return false;
1104bb0738eSEd Maste
111435933ddSDimitry Andric llvm::StringRef experimental = GetExperimentalSettingsName();
112435933ddSDimitry Andric size_t dot_pos = setting.find_first_of('.');
113435933ddSDimitry Andric return setting.take_front(dot_pos) == experimental;
1144bb0738eSEd Maste }
115