1321369Sdim//====-- UserSettingsController.cpp ------------------------------*- C++-*-===// 2254721Semaste// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6254721Semaste// 7254721Semaste//===----------------------------------------------------------------------===// 8254721Semaste 9321369Sdim#include "lldb/Core/UserSettingsController.h" 10254721Semaste 11288943Sdim#include "lldb/Interpreter/OptionValueProperties.h" 12321369Sdim#include "lldb/Utility/Status.h" 13321369Sdim#include "lldb/Utility/Stream.h" 14254721Semaste 15344779Sdim#include <memory> 16321369Sdim 17321369Sdimnamespace lldb_private { 18321369Sdimclass CommandInterpreter; 19321369Sdim} 20321369Sdimnamespace lldb_private { 21321369Sdimclass ConstString; 22321369Sdim} 23321369Sdimnamespace lldb_private { 24321369Sdimclass ExecutionContext; 25321369Sdim} 26321369Sdimnamespace lldb_private { 27321369Sdimclass Property; 28321369Sdim} 29321369Sdim 30254721Semasteusing namespace lldb; 31254721Semasteusing namespace lldb_private; 32254721Semaste 33254721Semastelldb::OptionValueSP 34321369SdimProperties::GetPropertyValue(const ExecutionContext *exe_ctx, 35321369Sdim llvm::StringRef path, bool will_modify, 36321369Sdim Status &error) const { 37314564Sdim OptionValuePropertiesSP properties_sp(GetValueProperties()); 38314564Sdim if (properties_sp) 39314564Sdim return properties_sp->GetSubValue(exe_ctx, path, will_modify, error); 40314564Sdim return lldb::OptionValueSP(); 41254721Semaste} 42254721Semaste 43321369SdimStatus Properties::SetPropertyValue(const ExecutionContext *exe_ctx, 44321369Sdim VarSetOperationType op, 45321369Sdim llvm::StringRef path, 46321369Sdim llvm::StringRef value) { 47314564Sdim OptionValuePropertiesSP properties_sp(GetValueProperties()); 48314564Sdim if (properties_sp) 49314564Sdim return properties_sp->SetSubValue(exe_ctx, op, path, value); 50321369Sdim Status error; 51314564Sdim error.SetErrorString("no properties"); 52314564Sdim return error; 53254721Semaste} 54254721Semaste 55314564Sdimvoid Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx, 56314564Sdim Stream &strm, uint32_t dump_mask) { 57314564Sdim OptionValuePropertiesSP properties_sp(GetValueProperties()); 58314564Sdim if (properties_sp) 59314564Sdim return properties_sp->DumpValue(exe_ctx, strm, dump_mask); 60254721Semaste} 61254721Semaste 62314564Sdimvoid Properties::DumpAllDescriptions(CommandInterpreter &interpreter, 63314564Sdim Stream &strm) const { 64314564Sdim strm.PutCString("Top level variables:\n\n"); 65254721Semaste 66314564Sdim OptionValuePropertiesSP properties_sp(GetValueProperties()); 67314564Sdim if (properties_sp) 68314564Sdim return properties_sp->DumpAllDescriptions(interpreter, strm); 69254721Semaste} 70254721Semaste 71321369SdimStatus Properties::DumpPropertyValue(const ExecutionContext *exe_ctx, 72321369Sdim Stream &strm, 73321369Sdim llvm::StringRef property_path, 74321369Sdim uint32_t dump_mask) { 75314564Sdim OptionValuePropertiesSP properties_sp(GetValueProperties()); 76314564Sdim if (properties_sp) { 77314564Sdim return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path, 78314564Sdim dump_mask); 79314564Sdim } 80321369Sdim Status error; 81314564Sdim error.SetErrorString("empty property list"); 82314564Sdim return error; 83254721Semaste} 84254721Semaste 85254721Semastesize_t 86314564SdimProperties::Apropos(llvm::StringRef keyword, 87314564Sdim std::vector<const Property *> &matching_properties) const { 88314564Sdim OptionValuePropertiesSP properties_sp(GetValueProperties()); 89314564Sdim if (properties_sp) { 90314564Sdim properties_sp->Apropos(keyword, matching_properties); 91314564Sdim } 92314564Sdim return matching_properties.size(); 93254721Semaste} 94254721Semaste 95254721Semastelldb::OptionValuePropertiesSP 96314564SdimProperties::GetSubProperty(const ExecutionContext *exe_ctx, 97353358Sdim ConstString name) { 98314564Sdim OptionValuePropertiesSP properties_sp(GetValueProperties()); 99314564Sdim if (properties_sp) 100314564Sdim return properties_sp->GetSubProperty(exe_ctx, name); 101314564Sdim return lldb::OptionValuePropertiesSP(); 102254721Semaste} 103254721Semaste 104314564Sdimconst char *Properties::GetExperimentalSettingsName() { return "experimental"; } 105309124Sdim 106314564Sdimbool Properties::IsSettingExperimental(llvm::StringRef setting) { 107314564Sdim if (setting.empty()) 108314564Sdim return false; 109309124Sdim 110314564Sdim llvm::StringRef experimental = GetExperimentalSettingsName(); 111314564Sdim size_t dot_pos = setting.find_first_of('.'); 112314564Sdim return setting.take_front(dot_pos) == experimental; 113309124Sdim} 114