Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame^] | 1 | //====-- UserSettingsController.cpp ------------------------------*- C++-*-===// |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10 | #include "lldb/Core/UserSettingsController.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame^] | 11 | |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 12 | #include "lldb/Interpreter/OptionValueProperties.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 13 | #include "lldb/Utility/Error.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 14 | #include "lldb/Utility/Stream.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame^] | 15 | |
| 16 | #include <memory> // for shared_ptr |
| 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 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 30 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 31 | using namespace lldb; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 32 | using namespace lldb_private; |
| 33 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 34 | lldb::OptionValueSP |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 35 | Properties::GetPropertyValue(const ExecutionContext *exe_ctx, llvm::StringRef path, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | bool will_modify, Error &error) const { |
| 37 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 38 | if (properties_sp) |
| 39 | return properties_sp->GetSubValue(exe_ctx, path, will_modify, error); |
| 40 | return lldb::OptionValueSP(); |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | Error Properties::SetPropertyValue(const ExecutionContext *exe_ctx, |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 44 | VarSetOperationType op, llvm::StringRef path, |
| 45 | llvm::StringRef value) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 47 | if (properties_sp) |
| 48 | return properties_sp->SetSubValue(exe_ctx, op, path, value); |
| 49 | Error error; |
| 50 | error.SetErrorString("no properties"); |
| 51 | return error; |
Jim Ingham | 9585275 | 2010-09-07 20:27:09 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx, |
| 55 | Stream &strm, uint32_t dump_mask) { |
| 56 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 57 | if (properties_sp) |
| 58 | return properties_sp->DumpValue(exe_ctx, strm, dump_mask); |
Jim Ingham | 9585275 | 2010-09-07 20:27:09 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | void Properties::DumpAllDescriptions(CommandInterpreter &interpreter, |
| 62 | Stream &strm) const { |
| 63 | strm.PutCString("Top level variables:\n\n"); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 66 | if (properties_sp) |
| 67 | return properties_sp->DumpAllDescriptions(interpreter, strm); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | Error Properties::DumpPropertyValue(const ExecutionContext *exe_ctx, |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 71 | Stream &strm, llvm::StringRef property_path, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | uint32_t dump_mask) { |
| 73 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 74 | if (properties_sp) { |
| 75 | return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path, |
| 76 | dump_mask); |
| 77 | } |
| 78 | Error error; |
| 79 | error.SetErrorString("empty property list"); |
| 80 | return error; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | size_t |
Zachary Turner | 067d1db | 2016-11-16 21:45:04 +0000 | [diff] [blame] | 84 | Properties::Apropos(llvm::StringRef keyword, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | std::vector<const Property *> &matching_properties) const { |
| 86 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 87 | if (properties_sp) { |
| 88 | properties_sp->Apropos(keyword, matching_properties); |
| 89 | } |
| 90 | return matching_properties.size(); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 91 | } |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 92 | |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 93 | lldb::OptionValuePropertiesSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | Properties::GetSubProperty(const ExecutionContext *exe_ctx, |
| 95 | const ConstString &name) { |
| 96 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 97 | if (properties_sp) |
| 98 | return properties_sp->GetSubProperty(exe_ctx, name); |
| 99 | return lldb::OptionValuePropertiesSP(); |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | const char *Properties::GetExperimentalSettingsName() { return "experimental"; } |
| 103 | |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 104 | bool Properties::IsSettingExperimental(llvm::StringRef setting) { |
| 105 | if (setting.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | return false; |
| 107 | |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 108 | llvm::StringRef experimental = GetExperimentalSettingsName(); |
| 109 | size_t dot_pos = setting.find_first_of('.'); |
| 110 | return setting.take_front(dot_pos) == experimental; |
Jim Ingham | 8b57dcf | 2016-07-06 01:27:33 +0000 | [diff] [blame] | 111 | } |