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