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