Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1 | //===-- OptionValue.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/Interpreter/OptionValue.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/OptionValues.h" |
Zachary Turner | 573ab90 | 2017-03-21 18:25:04 +0000 | [diff] [blame] | 17 | #include "lldb/Utility/StringList.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 22 | //------------------------------------------------------------------------- |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 23 | // Get this value as a uint64_t value if it is encoded as a boolean, uint64_t |
| 24 | // or int64_t. Other types will cause "fail_value" to be returned |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 25 | //------------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | uint64_t OptionValue::GetUInt64Value(uint64_t fail_value, bool *success_ptr) { |
| 27 | if (success_ptr) |
| 28 | *success_ptr = true; |
| 29 | switch (GetType()) { |
| 30 | case OptionValue::eTypeBoolean: |
| 31 | return static_cast<OptionValueBoolean *>(this)->GetCurrentValue(); |
| 32 | case OptionValue::eTypeSInt64: |
| 33 | return static_cast<OptionValueSInt64 *>(this)->GetCurrentValue(); |
| 34 | case OptionValue::eTypeUInt64: |
| 35 | return static_cast<OptionValueUInt64 *>(this)->GetCurrentValue(); |
| 36 | default: |
| 37 | break; |
| 38 | } |
| 39 | if (success_ptr) |
| 40 | *success_ptr = false; |
| 41 | return fail_value; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 44 | Status OptionValue::SetSubValue(const ExecutionContext *exe_ctx, |
| 45 | VarSetOperationType op, llvm::StringRef name, |
| 46 | llvm::StringRef value) { |
| 47 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | error.SetErrorStringWithFormat("SetSubValue is not supported"); |
| 49 | return error; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | OptionValueBoolean *OptionValue::GetAsBoolean() { |
| 53 | if (GetType() == OptionValue::eTypeBoolean) |
| 54 | return static_cast<OptionValueBoolean *>(this); |
| 55 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | const OptionValueBoolean *OptionValue::GetAsBoolean() const { |
| 59 | if (GetType() == OptionValue::eTypeBoolean) |
| 60 | return static_cast<const OptionValueBoolean *>(this); |
| 61 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | const OptionValueChar *OptionValue::GetAsChar() const { |
| 65 | if (GetType() == OptionValue::eTypeChar) |
| 66 | return static_cast<const OptionValueChar *>(this); |
| 67 | return nullptr; |
Zachary Turner | 3e7442b | 2015-01-12 20:44:02 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | OptionValueChar *OptionValue::GetAsChar() { |
| 71 | if (GetType() == OptionValue::eTypeChar) |
| 72 | return static_cast<OptionValueChar *>(this); |
| 73 | return nullptr; |
Zachary Turner | 3e7442b | 2015-01-12 20:44:02 +0000 | [diff] [blame] | 74 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | OptionValueFileSpec *OptionValue::GetAsFileSpec() { |
| 77 | if (GetType() == OptionValue::eTypeFileSpec) |
| 78 | return static_cast<OptionValueFileSpec *>(this); |
| 79 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | const OptionValueFileSpec *OptionValue::GetAsFileSpec() const { |
| 83 | if (GetType() == OptionValue::eTypeFileSpec) |
| 84 | return static_cast<const OptionValueFileSpec *>(this); |
| 85 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | OptionValueFileSpecList *OptionValue::GetAsFileSpecList() { |
| 89 | if (GetType() == OptionValue::eTypeFileSpecList) |
| 90 | return static_cast<OptionValueFileSpecList *>(this); |
| 91 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | const OptionValueFileSpecList *OptionValue::GetAsFileSpecList() const { |
| 95 | if (GetType() == OptionValue::eTypeFileSpecList) |
| 96 | return static_cast<const OptionValueFileSpecList *>(this); |
| 97 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | OptionValueArch *OptionValue::GetAsArch() { |
| 101 | if (GetType() == OptionValue::eTypeArch) |
| 102 | return static_cast<OptionValueArch *>(this); |
| 103 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | const OptionValueArch *OptionValue::GetAsArch() const { |
| 107 | if (GetType() == OptionValue::eTypeArch) |
| 108 | return static_cast<const OptionValueArch *>(this); |
| 109 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | OptionValueArray *OptionValue::GetAsArray() { |
| 113 | if (GetType() == OptionValue::eTypeArray) |
| 114 | return static_cast<OptionValueArray *>(this); |
| 115 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | const OptionValueArray *OptionValue::GetAsArray() const { |
| 119 | if (GetType() == OptionValue::eTypeArray) |
| 120 | return static_cast<const OptionValueArray *>(this); |
| 121 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | OptionValueArgs *OptionValue::GetAsArgs() { |
| 125 | if (GetType() == OptionValue::eTypeArgs) |
| 126 | return static_cast<OptionValueArgs *>(this); |
| 127 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | const OptionValueArgs *OptionValue::GetAsArgs() const { |
| 131 | if (GetType() == OptionValue::eTypeArgs) |
| 132 | return static_cast<const OptionValueArgs *>(this); |
| 133 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 136 | OptionValueDictionary *OptionValue::GetAsDictionary() { |
| 137 | if (GetType() == OptionValue::eTypeDictionary) |
| 138 | return static_cast<OptionValueDictionary *>(this); |
| 139 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | const OptionValueDictionary *OptionValue::GetAsDictionary() const { |
| 143 | if (GetType() == OptionValue::eTypeDictionary) |
| 144 | return static_cast<const OptionValueDictionary *>(this); |
| 145 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | OptionValueEnumeration *OptionValue::GetAsEnumeration() { |
| 149 | if (GetType() == OptionValue::eTypeEnum) |
| 150 | return static_cast<OptionValueEnumeration *>(this); |
| 151 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | const OptionValueEnumeration *OptionValue::GetAsEnumeration() const { |
| 155 | if (GetType() == OptionValue::eTypeEnum) |
| 156 | return static_cast<const OptionValueEnumeration *>(this); |
| 157 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | OptionValueFormat *OptionValue::GetAsFormat() { |
| 161 | if (GetType() == OptionValue::eTypeFormat) |
| 162 | return static_cast<OptionValueFormat *>(this); |
| 163 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | const OptionValueFormat *OptionValue::GetAsFormat() const { |
| 167 | if (GetType() == OptionValue::eTypeFormat) |
| 168 | return static_cast<const OptionValueFormat *>(this); |
| 169 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | OptionValueLanguage *OptionValue::GetAsLanguage() { |
| 173 | if (GetType() == OptionValue::eTypeLanguage) |
| 174 | return static_cast<OptionValueLanguage *>(this); |
| 175 | return NULL; |
Enrico Granata | 8fdf785 | 2015-02-20 19:46:30 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | const OptionValueLanguage *OptionValue::GetAsLanguage() const { |
| 179 | if (GetType() == OptionValue::eTypeLanguage) |
| 180 | return static_cast<const OptionValueLanguage *>(this); |
| 181 | return NULL; |
Enrico Granata | 8fdf785 | 2015-02-20 19:46:30 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | OptionValueFormatEntity *OptionValue::GetAsFormatEntity() { |
| 185 | if (GetType() == OptionValue::eTypeFormatEntity) |
| 186 | return static_cast<OptionValueFormatEntity *>(this); |
| 187 | return nullptr; |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | const OptionValueFormatEntity *OptionValue::GetAsFormatEntity() const { |
| 191 | if (GetType() == OptionValue::eTypeFormatEntity) |
| 192 | return static_cast<const OptionValueFormatEntity *>(this); |
| 193 | return nullptr; |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 196 | OptionValuePathMappings *OptionValue::GetAsPathMappings() { |
| 197 | if (GetType() == OptionValue::eTypePathMap) |
| 198 | return static_cast<OptionValuePathMappings *>(this); |
| 199 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 202 | const OptionValuePathMappings *OptionValue::GetAsPathMappings() const { |
| 203 | if (GetType() == OptionValue::eTypePathMap) |
| 204 | return static_cast<const OptionValuePathMappings *>(this); |
| 205 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 208 | OptionValueProperties *OptionValue::GetAsProperties() { |
| 209 | if (GetType() == OptionValue::eTypeProperties) |
| 210 | return static_cast<OptionValueProperties *>(this); |
| 211 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | const OptionValueProperties *OptionValue::GetAsProperties() const { |
| 215 | if (GetType() == OptionValue::eTypeProperties) |
| 216 | return static_cast<const OptionValueProperties *>(this); |
| 217 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | OptionValueRegex *OptionValue::GetAsRegex() { |
| 221 | if (GetType() == OptionValue::eTypeRegex) |
| 222 | return static_cast<OptionValueRegex *>(this); |
| 223 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 226 | const OptionValueRegex *OptionValue::GetAsRegex() const { |
| 227 | if (GetType() == OptionValue::eTypeRegex) |
| 228 | return static_cast<const OptionValueRegex *>(this); |
| 229 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 232 | OptionValueSInt64 *OptionValue::GetAsSInt64() { |
| 233 | if (GetType() == OptionValue::eTypeSInt64) |
| 234 | return static_cast<OptionValueSInt64 *>(this); |
| 235 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 238 | const OptionValueSInt64 *OptionValue::GetAsSInt64() const { |
| 239 | if (GetType() == OptionValue::eTypeSInt64) |
| 240 | return static_cast<const OptionValueSInt64 *>(this); |
| 241 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 244 | OptionValueString *OptionValue::GetAsString() { |
| 245 | if (GetType() == OptionValue::eTypeString) |
| 246 | return static_cast<OptionValueString *>(this); |
| 247 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 250 | const OptionValueString *OptionValue::GetAsString() const { |
| 251 | if (GetType() == OptionValue::eTypeString) |
| 252 | return static_cast<const OptionValueString *>(this); |
| 253 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 256 | OptionValueUInt64 *OptionValue::GetAsUInt64() { |
| 257 | if (GetType() == OptionValue::eTypeUInt64) |
| 258 | return static_cast<OptionValueUInt64 *>(this); |
| 259 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 262 | const OptionValueUInt64 *OptionValue::GetAsUInt64() const { |
| 263 | if (GetType() == OptionValue::eTypeUInt64) |
| 264 | return static_cast<const OptionValueUInt64 *>(this); |
| 265 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 268 | OptionValueUUID *OptionValue::GetAsUUID() { |
| 269 | if (GetType() == OptionValue::eTypeUUID) |
| 270 | return static_cast<OptionValueUUID *>(this); |
| 271 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | const OptionValueUUID *OptionValue::GetAsUUID() const { |
| 275 | if (GetType() == OptionValue::eTypeUUID) |
| 276 | return static_cast<const OptionValueUUID *>(this); |
| 277 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | bool OptionValue::GetBooleanValue(bool fail_value) const { |
| 281 | const OptionValueBoolean *option_value = GetAsBoolean(); |
| 282 | if (option_value) |
| 283 | return option_value->GetCurrentValue(); |
| 284 | return fail_value; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 287 | bool OptionValue::SetBooleanValue(bool new_value) { |
| 288 | OptionValueBoolean *option_value = GetAsBoolean(); |
| 289 | if (option_value) { |
| 290 | option_value->SetCurrentValue(new_value); |
| 291 | return true; |
| 292 | } |
| 293 | return false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | char OptionValue::GetCharValue(char fail_value) const { |
| 297 | const OptionValueChar *option_value = GetAsChar(); |
| 298 | if (option_value) |
| 299 | return option_value->GetCurrentValue(); |
| 300 | return fail_value; |
Zachary Turner | 3e7442b | 2015-01-12 20:44:02 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 303 | char OptionValue::SetCharValue(char new_value) { |
| 304 | OptionValueChar *option_value = GetAsChar(); |
| 305 | if (option_value) { |
| 306 | option_value->SetCurrentValue(new_value); |
| 307 | return true; |
| 308 | } |
| 309 | return false; |
Zachary Turner | 3e7442b | 2015-01-12 20:44:02 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 312 | int64_t OptionValue::GetEnumerationValue(int64_t fail_value) const { |
| 313 | const OptionValueEnumeration *option_value = GetAsEnumeration(); |
| 314 | if (option_value) |
| 315 | return option_value->GetCurrentValue(); |
| 316 | return fail_value; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | bool OptionValue::SetEnumerationValue(int64_t value) { |
| 320 | OptionValueEnumeration *option_value = GetAsEnumeration(); |
| 321 | if (option_value) { |
| 322 | option_value->SetCurrentValue(value); |
| 323 | return true; |
| 324 | } |
| 325 | return false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 328 | FileSpec OptionValue::GetFileSpecValue() const { |
| 329 | const OptionValueFileSpec *option_value = GetAsFileSpec(); |
| 330 | if (option_value) |
| 331 | return option_value->GetCurrentValue(); |
| 332 | return FileSpec(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 335 | bool OptionValue::SetFileSpecValue(const FileSpec &file_spec) { |
| 336 | OptionValueFileSpec *option_value = GetAsFileSpec(); |
| 337 | if (option_value) { |
| 338 | option_value->SetCurrentValue(file_spec, false); |
| 339 | return true; |
| 340 | } |
| 341 | return false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 | FileSpecList OptionValue::GetFileSpecListValue() const { |
| 345 | const OptionValueFileSpecList *option_value = GetAsFileSpecList(); |
| 346 | if (option_value) |
| 347 | return option_value->GetCurrentValue(); |
| 348 | return FileSpecList(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 351 | lldb::Format OptionValue::GetFormatValue(lldb::Format fail_value) const { |
| 352 | const OptionValueFormat *option_value = GetAsFormat(); |
| 353 | if (option_value) |
| 354 | return option_value->GetCurrentValue(); |
| 355 | return fail_value; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 358 | bool OptionValue::SetFormatValue(lldb::Format new_value) { |
| 359 | OptionValueFormat *option_value = GetAsFormat(); |
| 360 | if (option_value) { |
| 361 | option_value->SetCurrentValue(new_value); |
| 362 | return true; |
| 363 | } |
| 364 | return false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Enrico Granata | 8fdf785 | 2015-02-20 19:46:30 +0000 | [diff] [blame] | 367 | lldb::LanguageType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 368 | OptionValue::GetLanguageValue(lldb::LanguageType fail_value) const { |
| 369 | const OptionValueLanguage *option_value = GetAsLanguage(); |
| 370 | if (option_value) |
| 371 | return option_value->GetCurrentValue(); |
| 372 | return fail_value; |
Enrico Granata | 8fdf785 | 2015-02-20 19:46:30 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 375 | bool OptionValue::SetLanguageValue(lldb::LanguageType new_language) { |
| 376 | OptionValueLanguage *option_value = GetAsLanguage(); |
| 377 | if (option_value) { |
| 378 | option_value->SetCurrentValue(new_language); |
| 379 | return true; |
| 380 | } |
| 381 | return false; |
Enrico Granata | 8fdf785 | 2015-02-20 19:46:30 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 384 | const FormatEntity::Entry *OptionValue::GetFormatEntity() const { |
| 385 | const OptionValueFormatEntity *option_value = GetAsFormatEntity(); |
| 386 | if (option_value) |
| 387 | return &option_value->GetCurrentValue(); |
| 388 | return nullptr; |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 391 | const RegularExpression *OptionValue::GetRegexValue() const { |
| 392 | const OptionValueRegex *option_value = GetAsRegex(); |
| 393 | if (option_value) |
| 394 | return option_value->GetCurrentValue(); |
| 395 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | int64_t OptionValue::GetSInt64Value(int64_t fail_value) const { |
| 399 | const OptionValueSInt64 *option_value = GetAsSInt64(); |
| 400 | if (option_value) |
| 401 | return option_value->GetCurrentValue(); |
| 402 | return fail_value; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 405 | bool OptionValue::SetSInt64Value(int64_t new_value) { |
| 406 | OptionValueSInt64 *option_value = GetAsSInt64(); |
| 407 | if (option_value) { |
| 408 | option_value->SetCurrentValue(new_value); |
| 409 | return true; |
| 410 | } |
| 411 | return false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 414 | llvm::StringRef OptionValue::GetStringValue(llvm::StringRef fail_value) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 415 | const OptionValueString *option_value = GetAsString(); |
| 416 | if (option_value) |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 417 | return option_value->GetCurrentValueAsRef(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | return fail_value; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Zachary Turner | 514d8cd | 2016-09-23 18:06:53 +0000 | [diff] [blame] | 421 | bool OptionValue::SetStringValue(llvm::StringRef new_value) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 422 | OptionValueString *option_value = GetAsString(); |
| 423 | if (option_value) { |
Zachary Turner | 514d8cd | 2016-09-23 18:06:53 +0000 | [diff] [blame] | 424 | option_value->SetCurrentValue(new_value); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 425 | return true; |
| 426 | } |
| 427 | return false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 430 | uint64_t OptionValue::GetUInt64Value(uint64_t fail_value) const { |
| 431 | const OptionValueUInt64 *option_value = GetAsUInt64(); |
| 432 | if (option_value) |
| 433 | return option_value->GetCurrentValue(); |
| 434 | return fail_value; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 437 | bool OptionValue::SetUInt64Value(uint64_t new_value) { |
| 438 | OptionValueUInt64 *option_value = GetAsUInt64(); |
| 439 | if (option_value) { |
| 440 | option_value->SetCurrentValue(new_value); |
| 441 | return true; |
| 442 | } |
| 443 | return false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 446 | UUID OptionValue::GetUUIDValue() const { |
| 447 | const OptionValueUUID *option_value = GetAsUUID(); |
| 448 | if (option_value) |
| 449 | return option_value->GetCurrentValue(); |
| 450 | return UUID(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 453 | bool OptionValue::SetUUIDValue(const UUID &uuid) { |
| 454 | OptionValueUUID *option_value = GetAsUUID(); |
| 455 | if (option_value) { |
| 456 | option_value->SetCurrentValue(uuid); |
| 457 | return true; |
| 458 | } |
| 459 | return false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 462 | const char *OptionValue::GetBuiltinTypeAsCString(Type t) { |
| 463 | switch (t) { |
| 464 | case eTypeInvalid: |
| 465 | return "invalid"; |
| 466 | case eTypeArch: |
| 467 | return "arch"; |
| 468 | case eTypeArgs: |
| 469 | return "arguments"; |
| 470 | case eTypeArray: |
| 471 | return "array"; |
| 472 | case eTypeBoolean: |
| 473 | return "boolean"; |
| 474 | case eTypeChar: |
| 475 | return "char"; |
| 476 | case eTypeDictionary: |
| 477 | return "dictionary"; |
| 478 | case eTypeEnum: |
| 479 | return "enum"; |
| 480 | case eTypeFileSpec: |
| 481 | return "file"; |
| 482 | case eTypeFileSpecList: |
| 483 | return "file-list"; |
| 484 | case eTypeFormat: |
| 485 | return "format"; |
| 486 | case eTypeFormatEntity: |
| 487 | return "format-string"; |
| 488 | case eTypeLanguage: |
| 489 | return "language"; |
| 490 | case eTypePathMap: |
| 491 | return "path-map"; |
| 492 | case eTypeProperties: |
| 493 | return "properties"; |
| 494 | case eTypeRegex: |
| 495 | return "regex"; |
| 496 | case eTypeSInt64: |
| 497 | return "int"; |
| 498 | case eTypeString: |
| 499 | return "string"; |
| 500 | case eTypeUInt64: |
| 501 | return "unsigned"; |
| 502 | case eTypeUUID: |
| 503 | return "uuid"; |
| 504 | } |
| 505 | return nullptr; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 508 | lldb::OptionValueSP OptionValue::CreateValueFromCStringForTypeMask( |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 509 | const char *value_cstr, uint32_t type_mask, Status &error) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 510 | // If only 1 bit is set in the type mask for a dictionary or array then we |
| 511 | // know how to decode a value from a cstring |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 512 | lldb::OptionValueSP value_sp; |
| 513 | switch (type_mask) { |
| 514 | case 1u << eTypeArch: |
| 515 | value_sp.reset(new OptionValueArch()); |
| 516 | break; |
| 517 | case 1u << eTypeBoolean: |
| 518 | value_sp.reset(new OptionValueBoolean(false)); |
| 519 | break; |
| 520 | case 1u << eTypeChar: |
| 521 | value_sp.reset(new OptionValueChar('\0')); |
| 522 | break; |
| 523 | case 1u << eTypeFileSpec: |
| 524 | value_sp.reset(new OptionValueFileSpec()); |
| 525 | break; |
| 526 | case 1u << eTypeFormat: |
| 527 | value_sp.reset(new OptionValueFormat(eFormatInvalid)); |
| 528 | break; |
| 529 | case 1u << eTypeFormatEntity: |
| 530 | value_sp.reset(new OptionValueFormatEntity(NULL)); |
| 531 | break; |
| 532 | case 1u << eTypeLanguage: |
| 533 | value_sp.reset(new OptionValueLanguage(eLanguageTypeUnknown)); |
| 534 | break; |
| 535 | case 1u << eTypeSInt64: |
| 536 | value_sp.reset(new OptionValueSInt64()); |
| 537 | break; |
| 538 | case 1u << eTypeString: |
| 539 | value_sp.reset(new OptionValueString()); |
| 540 | break; |
| 541 | case 1u << eTypeUInt64: |
| 542 | value_sp.reset(new OptionValueUInt64()); |
| 543 | break; |
| 544 | case 1u << eTypeUUID: |
| 545 | value_sp.reset(new OptionValueUUID()); |
| 546 | break; |
| 547 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 548 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 549 | if (value_sp) |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 550 | error = value_sp->SetValueFromString( |
| 551 | llvm::StringRef::withNullAsEmpty(value_cstr), eVarSetOperationAssign); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 552 | else |
| 553 | error.SetErrorString("unsupported type mask"); |
| 554 | return value_sp; |
| 555 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 556 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 557 | bool OptionValue::DumpQualifiedName(Stream &strm) const { |
| 558 | bool dumped_something = false; |
| 559 | lldb::OptionValueSP m_parent_sp(m_parent_wp.lock()); |
| 560 | if (m_parent_sp) { |
| 561 | if (m_parent_sp->DumpQualifiedName(strm)) |
| 562 | dumped_something = true; |
| 563 | } |
| 564 | ConstString name(GetName()); |
| 565 | if (name) { |
| 566 | if (dumped_something) |
| 567 | strm.PutChar('.'); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 568 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 569 | dumped_something = true; |
| 570 | strm << name; |
| 571 | } |
| 572 | return dumped_something; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Zachary Turner | 4aa8753 | 2016-11-17 01:37:42 +0000 | [diff] [blame] | 575 | size_t OptionValue::AutoComplete(CommandInterpreter &interpreter, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 576 | CompletionRequest &request) { |
| 577 | request.SetWordComplete(false); |
Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame] | 578 | return request.GetNumberOfMatches(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 581 | Status OptionValue::SetValueFromString(llvm::StringRef value, |
| 582 | VarSetOperationType op) { |
| 583 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 584 | switch (op) { |
| 585 | case eVarSetOperationReplace: |
| 586 | error.SetErrorStringWithFormat( |
| 587 | "%s objects do not support the 'replace' operation", |
| 588 | GetTypeAsCString()); |
| 589 | break; |
| 590 | case eVarSetOperationInsertBefore: |
| 591 | error.SetErrorStringWithFormat( |
| 592 | "%s objects do not support the 'insert-before' operation", |
| 593 | GetTypeAsCString()); |
| 594 | break; |
| 595 | case eVarSetOperationInsertAfter: |
| 596 | error.SetErrorStringWithFormat( |
| 597 | "%s objects do not support the 'insert-after' operation", |
| 598 | GetTypeAsCString()); |
| 599 | break; |
| 600 | case eVarSetOperationRemove: |
| 601 | error.SetErrorStringWithFormat( |
| 602 | "%s objects do not support the 'remove' operation", GetTypeAsCString()); |
| 603 | break; |
| 604 | case eVarSetOperationAppend: |
| 605 | error.SetErrorStringWithFormat( |
| 606 | "%s objects do not support the 'append' operation", GetTypeAsCString()); |
| 607 | break; |
| 608 | case eVarSetOperationClear: |
| 609 | error.SetErrorStringWithFormat( |
| 610 | "%s objects do not support the 'clear' operation", GetTypeAsCString()); |
| 611 | break; |
| 612 | case eVarSetOperationAssign: |
| 613 | error.SetErrorStringWithFormat( |
| 614 | "%s objects do not support the 'assign' operation", GetTypeAsCString()); |
| 615 | break; |
| 616 | case eVarSetOperationInvalid: |
| 617 | error.SetErrorStringWithFormat("invalid operation performed on a %s object", |
| 618 | GetTypeAsCString()); |
| 619 | break; |
| 620 | } |
| 621 | return error; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 622 | } |