blob: c3f363b059880af5788489d2be15272c43699fab [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- 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 Clayton67cc0632012-08-22 17:17:09 +000016#include "lldb/Interpreter/OptionValues.h"
Zachary Turner573ab902017-03-21 18:25:04 +000017#include "lldb/Utility/StringList.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000018
19using namespace lldb;
20using namespace lldb_private;
21
Greg Clayton67cc0632012-08-22 17:17:09 +000022//-------------------------------------------------------------------------
Adrian Prantl05097242018-04-30 16:49:04 +000023// 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 Clayton67cc0632012-08-22 17:17:09 +000025//-------------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000026uint64_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 Clayton67cc0632012-08-22 17:17:09 +000042}
43
Zachary Turner97206d52017-05-12 04:51:55 +000044Status OptionValue::SetSubValue(const ExecutionContext *exe_ctx,
45 VarSetOperationType op, llvm::StringRef name,
46 llvm::StringRef value) {
47 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 error.SetErrorStringWithFormat("SetSubValue is not supported");
49 return error;
Greg Clayton67cc0632012-08-22 17:17:09 +000050}
51
Kate Stoneb9c1b512016-09-06 20:57:50 +000052OptionValueBoolean *OptionValue::GetAsBoolean() {
53 if (GetType() == OptionValue::eTypeBoolean)
54 return static_cast<OptionValueBoolean *>(this);
55 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000056}
57
Kate Stoneb9c1b512016-09-06 20:57:50 +000058const OptionValueBoolean *OptionValue::GetAsBoolean() const {
59 if (GetType() == OptionValue::eTypeBoolean)
60 return static_cast<const OptionValueBoolean *>(this);
61 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064const OptionValueChar *OptionValue::GetAsChar() const {
65 if (GetType() == OptionValue::eTypeChar)
66 return static_cast<const OptionValueChar *>(this);
67 return nullptr;
Zachary Turner3e7442b2015-01-12 20:44:02 +000068}
69
Kate Stoneb9c1b512016-09-06 20:57:50 +000070OptionValueChar *OptionValue::GetAsChar() {
71 if (GetType() == OptionValue::eTypeChar)
72 return static_cast<OptionValueChar *>(this);
73 return nullptr;
Zachary Turner3e7442b2015-01-12 20:44:02 +000074}
Greg Clayton67cc0632012-08-22 17:17:09 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076OptionValueFileSpec *OptionValue::GetAsFileSpec() {
77 if (GetType() == OptionValue::eTypeFileSpec)
78 return static_cast<OptionValueFileSpec *>(this);
79 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000080}
81
Kate Stoneb9c1b512016-09-06 20:57:50 +000082const OptionValueFileSpec *OptionValue::GetAsFileSpec() const {
83 if (GetType() == OptionValue::eTypeFileSpec)
84 return static_cast<const OptionValueFileSpec *>(this);
85 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000086}
87
Kate Stoneb9c1b512016-09-06 20:57:50 +000088OptionValueFileSpecList *OptionValue::GetAsFileSpecList() {
89 if (GetType() == OptionValue::eTypeFileSpecList)
90 return static_cast<OptionValueFileSpecList *>(this);
91 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000092}
93
Kate Stoneb9c1b512016-09-06 20:57:50 +000094const OptionValueFileSpecList *OptionValue::GetAsFileSpecList() const {
95 if (GetType() == OptionValue::eTypeFileSpecList)
96 return static_cast<const OptionValueFileSpecList *>(this);
97 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000098}
99
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100OptionValueArch *OptionValue::GetAsArch() {
101 if (GetType() == OptionValue::eTypeArch)
102 return static_cast<OptionValueArch *>(this);
103 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000104}
105
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106const OptionValueArch *OptionValue::GetAsArch() const {
107 if (GetType() == OptionValue::eTypeArch)
108 return static_cast<const OptionValueArch *>(this);
109 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000110}
111
Kate Stoneb9c1b512016-09-06 20:57:50 +0000112OptionValueArray *OptionValue::GetAsArray() {
113 if (GetType() == OptionValue::eTypeArray)
114 return static_cast<OptionValueArray *>(this);
115 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000116}
117
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118const OptionValueArray *OptionValue::GetAsArray() const {
119 if (GetType() == OptionValue::eTypeArray)
120 return static_cast<const OptionValueArray *>(this);
121 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000122}
123
Kate Stoneb9c1b512016-09-06 20:57:50 +0000124OptionValueArgs *OptionValue::GetAsArgs() {
125 if (GetType() == OptionValue::eTypeArgs)
126 return static_cast<OptionValueArgs *>(this);
127 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000128}
129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130const OptionValueArgs *OptionValue::GetAsArgs() const {
131 if (GetType() == OptionValue::eTypeArgs)
132 return static_cast<const OptionValueArgs *>(this);
133 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000134}
135
Kate Stoneb9c1b512016-09-06 20:57:50 +0000136OptionValueDictionary *OptionValue::GetAsDictionary() {
137 if (GetType() == OptionValue::eTypeDictionary)
138 return static_cast<OptionValueDictionary *>(this);
139 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000140}
141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142const OptionValueDictionary *OptionValue::GetAsDictionary() const {
143 if (GetType() == OptionValue::eTypeDictionary)
144 return static_cast<const OptionValueDictionary *>(this);
145 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000146}
147
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148OptionValueEnumeration *OptionValue::GetAsEnumeration() {
149 if (GetType() == OptionValue::eTypeEnum)
150 return static_cast<OptionValueEnumeration *>(this);
151 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000152}
153
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154const OptionValueEnumeration *OptionValue::GetAsEnumeration() const {
155 if (GetType() == OptionValue::eTypeEnum)
156 return static_cast<const OptionValueEnumeration *>(this);
157 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000158}
159
Kate Stoneb9c1b512016-09-06 20:57:50 +0000160OptionValueFormat *OptionValue::GetAsFormat() {
161 if (GetType() == OptionValue::eTypeFormat)
162 return static_cast<OptionValueFormat *>(this);
163 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000164}
165
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166const OptionValueFormat *OptionValue::GetAsFormat() const {
167 if (GetType() == OptionValue::eTypeFormat)
168 return static_cast<const OptionValueFormat *>(this);
169 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000170}
171
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172OptionValueLanguage *OptionValue::GetAsLanguage() {
173 if (GetType() == OptionValue::eTypeLanguage)
174 return static_cast<OptionValueLanguage *>(this);
175 return NULL;
Enrico Granata8fdf7852015-02-20 19:46:30 +0000176}
177
Kate Stoneb9c1b512016-09-06 20:57:50 +0000178const OptionValueLanguage *OptionValue::GetAsLanguage() const {
179 if (GetType() == OptionValue::eTypeLanguage)
180 return static_cast<const OptionValueLanguage *>(this);
181 return NULL;
Enrico Granata8fdf7852015-02-20 19:46:30 +0000182}
183
Kate Stoneb9c1b512016-09-06 20:57:50 +0000184OptionValueFormatEntity *OptionValue::GetAsFormatEntity() {
185 if (GetType() == OptionValue::eTypeFormatEntity)
186 return static_cast<OptionValueFormatEntity *>(this);
187 return nullptr;
Greg Clayton554f68d2015-02-04 22:00:53 +0000188}
189
Kate Stoneb9c1b512016-09-06 20:57:50 +0000190const OptionValueFormatEntity *OptionValue::GetAsFormatEntity() const {
191 if (GetType() == OptionValue::eTypeFormatEntity)
192 return static_cast<const OptionValueFormatEntity *>(this);
193 return nullptr;
Greg Clayton554f68d2015-02-04 22:00:53 +0000194}
195
Kate Stoneb9c1b512016-09-06 20:57:50 +0000196OptionValuePathMappings *OptionValue::GetAsPathMappings() {
197 if (GetType() == OptionValue::eTypePathMap)
198 return static_cast<OptionValuePathMappings *>(this);
199 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000200}
201
Kate Stoneb9c1b512016-09-06 20:57:50 +0000202const OptionValuePathMappings *OptionValue::GetAsPathMappings() const {
203 if (GetType() == OptionValue::eTypePathMap)
204 return static_cast<const OptionValuePathMappings *>(this);
205 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000206}
207
Kate Stoneb9c1b512016-09-06 20:57:50 +0000208OptionValueProperties *OptionValue::GetAsProperties() {
209 if (GetType() == OptionValue::eTypeProperties)
210 return static_cast<OptionValueProperties *>(this);
211 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000212}
213
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214const OptionValueProperties *OptionValue::GetAsProperties() const {
215 if (GetType() == OptionValue::eTypeProperties)
216 return static_cast<const OptionValueProperties *>(this);
217 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000218}
219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220OptionValueRegex *OptionValue::GetAsRegex() {
221 if (GetType() == OptionValue::eTypeRegex)
222 return static_cast<OptionValueRegex *>(this);
223 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000224}
225
Kate Stoneb9c1b512016-09-06 20:57:50 +0000226const OptionValueRegex *OptionValue::GetAsRegex() const {
227 if (GetType() == OptionValue::eTypeRegex)
228 return static_cast<const OptionValueRegex *>(this);
229 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000230}
231
Kate Stoneb9c1b512016-09-06 20:57:50 +0000232OptionValueSInt64 *OptionValue::GetAsSInt64() {
233 if (GetType() == OptionValue::eTypeSInt64)
234 return static_cast<OptionValueSInt64 *>(this);
235 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000236}
237
Kate Stoneb9c1b512016-09-06 20:57:50 +0000238const OptionValueSInt64 *OptionValue::GetAsSInt64() const {
239 if (GetType() == OptionValue::eTypeSInt64)
240 return static_cast<const OptionValueSInt64 *>(this);
241 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000242}
243
Kate Stoneb9c1b512016-09-06 20:57:50 +0000244OptionValueString *OptionValue::GetAsString() {
245 if (GetType() == OptionValue::eTypeString)
246 return static_cast<OptionValueString *>(this);
247 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000248}
249
Kate Stoneb9c1b512016-09-06 20:57:50 +0000250const OptionValueString *OptionValue::GetAsString() const {
251 if (GetType() == OptionValue::eTypeString)
252 return static_cast<const OptionValueString *>(this);
253 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000254}
255
Kate Stoneb9c1b512016-09-06 20:57:50 +0000256OptionValueUInt64 *OptionValue::GetAsUInt64() {
257 if (GetType() == OptionValue::eTypeUInt64)
258 return static_cast<OptionValueUInt64 *>(this);
259 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000260}
261
Kate Stoneb9c1b512016-09-06 20:57:50 +0000262const OptionValueUInt64 *OptionValue::GetAsUInt64() const {
263 if (GetType() == OptionValue::eTypeUInt64)
264 return static_cast<const OptionValueUInt64 *>(this);
265 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000266}
267
Kate Stoneb9c1b512016-09-06 20:57:50 +0000268OptionValueUUID *OptionValue::GetAsUUID() {
269 if (GetType() == OptionValue::eTypeUUID)
270 return static_cast<OptionValueUUID *>(this);
271 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000272}
273
Kate Stoneb9c1b512016-09-06 20:57:50 +0000274const OptionValueUUID *OptionValue::GetAsUUID() const {
275 if (GetType() == OptionValue::eTypeUUID)
276 return static_cast<const OptionValueUUID *>(this);
277 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000278}
279
Kate Stoneb9c1b512016-09-06 20:57:50 +0000280bool 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 Clayton67cc0632012-08-22 17:17:09 +0000285}
286
Kate Stoneb9c1b512016-09-06 20:57:50 +0000287bool 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 Clayton67cc0632012-08-22 17:17:09 +0000294}
295
Kate Stoneb9c1b512016-09-06 20:57:50 +0000296char 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 Turner3e7442b2015-01-12 20:44:02 +0000301}
302
Kate Stoneb9c1b512016-09-06 20:57:50 +0000303char 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 Turner3e7442b2015-01-12 20:44:02 +0000310}
311
Kate Stoneb9c1b512016-09-06 20:57:50 +0000312int64_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 Clayton67cc0632012-08-22 17:17:09 +0000317}
318
Kate Stoneb9c1b512016-09-06 20:57:50 +0000319bool 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 Clayton67cc0632012-08-22 17:17:09 +0000326}
327
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328FileSpec OptionValue::GetFileSpecValue() const {
329 const OptionValueFileSpec *option_value = GetAsFileSpec();
330 if (option_value)
331 return option_value->GetCurrentValue();
332 return FileSpec();
Greg Clayton67cc0632012-08-22 17:17:09 +0000333}
334
Kate Stoneb9c1b512016-09-06 20:57:50 +0000335bool 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 Clayton67cc0632012-08-22 17:17:09 +0000342}
343
Kate Stoneb9c1b512016-09-06 20:57:50 +0000344FileSpecList OptionValue::GetFileSpecListValue() const {
345 const OptionValueFileSpecList *option_value = GetAsFileSpecList();
346 if (option_value)
347 return option_value->GetCurrentValue();
348 return FileSpecList();
Greg Clayton67cc0632012-08-22 17:17:09 +0000349}
350
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351lldb::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 Clayton67cc0632012-08-22 17:17:09 +0000356}
357
Kate Stoneb9c1b512016-09-06 20:57:50 +0000358bool 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 Clayton67cc0632012-08-22 17:17:09 +0000365}
366
Enrico Granata8fdf7852015-02-20 19:46:30 +0000367lldb::LanguageType
Kate Stoneb9c1b512016-09-06 20:57:50 +0000368OptionValue::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 Granata8fdf7852015-02-20 19:46:30 +0000373}
374
Kate Stoneb9c1b512016-09-06 20:57:50 +0000375bool 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 Granata8fdf7852015-02-20 19:46:30 +0000382}
383
Kate Stoneb9c1b512016-09-06 20:57:50 +0000384const FormatEntity::Entry *OptionValue::GetFormatEntity() const {
385 const OptionValueFormatEntity *option_value = GetAsFormatEntity();
386 if (option_value)
387 return &option_value->GetCurrentValue();
388 return nullptr;
Greg Clayton554f68d2015-02-04 22:00:53 +0000389}
390
Kate Stoneb9c1b512016-09-06 20:57:50 +0000391const RegularExpression *OptionValue::GetRegexValue() const {
392 const OptionValueRegex *option_value = GetAsRegex();
393 if (option_value)
394 return option_value->GetCurrentValue();
395 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000396}
397
Kate Stoneb9c1b512016-09-06 20:57:50 +0000398int64_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 Clayton67cc0632012-08-22 17:17:09 +0000403}
404
Kate Stoneb9c1b512016-09-06 20:57:50 +0000405bool 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 Clayton67cc0632012-08-22 17:17:09 +0000412}
413
Zachary Turner31d97a52016-11-17 18:08:12 +0000414llvm::StringRef OptionValue::GetStringValue(llvm::StringRef fail_value) const {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415 const OptionValueString *option_value = GetAsString();
416 if (option_value)
Zachary Turner31d97a52016-11-17 18:08:12 +0000417 return option_value->GetCurrentValueAsRef();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000418 return fail_value;
Greg Clayton67cc0632012-08-22 17:17:09 +0000419}
420
Zachary Turner514d8cd2016-09-23 18:06:53 +0000421bool OptionValue::SetStringValue(llvm::StringRef new_value) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000422 OptionValueString *option_value = GetAsString();
423 if (option_value) {
Zachary Turner514d8cd2016-09-23 18:06:53 +0000424 option_value->SetCurrentValue(new_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000425 return true;
426 }
427 return false;
Greg Clayton67cc0632012-08-22 17:17:09 +0000428}
429
Kate Stoneb9c1b512016-09-06 20:57:50 +0000430uint64_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 Clayton67cc0632012-08-22 17:17:09 +0000435}
436
Kate Stoneb9c1b512016-09-06 20:57:50 +0000437bool 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 Clayton67cc0632012-08-22 17:17:09 +0000444}
445
Kate Stoneb9c1b512016-09-06 20:57:50 +0000446UUID OptionValue::GetUUIDValue() const {
447 const OptionValueUUID *option_value = GetAsUUID();
448 if (option_value)
449 return option_value->GetCurrentValue();
450 return UUID();
Greg Clayton67cc0632012-08-22 17:17:09 +0000451}
452
Kate Stoneb9c1b512016-09-06 20:57:50 +0000453bool 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 Clayton67cc0632012-08-22 17:17:09 +0000460}
461
Kate Stoneb9c1b512016-09-06 20:57:50 +0000462const 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 Clayton67cc0632012-08-22 17:17:09 +0000506}
507
Kate Stoneb9c1b512016-09-06 20:57:50 +0000508lldb::OptionValueSP OptionValue::CreateValueFromCStringForTypeMask(
Zachary Turner97206d52017-05-12 04:51:55 +0000509 const char *value_cstr, uint32_t type_mask, Status &error) {
Adrian Prantl05097242018-04-30 16:49:04 +0000510 // 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 Stoneb9c1b512016-09-06 20:57:50 +0000512 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 Clayton67cc0632012-08-22 17:17:09 +0000548
Kate Stoneb9c1b512016-09-06 20:57:50 +0000549 if (value_sp)
Zachary Turner8cef4b02016-09-23 17:48:13 +0000550 error = value_sp->SetValueFromString(
551 llvm::StringRef::withNullAsEmpty(value_cstr), eVarSetOperationAssign);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000552 else
553 error.SetErrorString("unsupported type mask");
554 return value_sp;
555}
Greg Clayton67cc0632012-08-22 17:17:09 +0000556
Kate Stoneb9c1b512016-09-06 20:57:50 +0000557bool 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 Clayton67cc0632012-08-22 17:17:09 +0000568 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000569 dumped_something = true;
570 strm << name;
571 }
572 return dumped_something;
Greg Clayton67cc0632012-08-22 17:17:09 +0000573}
574
Zachary Turner4aa87532016-11-17 01:37:42 +0000575size_t OptionValue::AutoComplete(CommandInterpreter &interpreter,
Raphael Isemanna2e76c02018-07-13 18:28:14 +0000576 CompletionRequest &request) {
577 request.SetWordComplete(false);
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +0000578 return request.GetNumberOfMatches();
Greg Clayton67cc0632012-08-22 17:17:09 +0000579}
580
Zachary Turner97206d52017-05-12 04:51:55 +0000581Status OptionValue::SetValueFromString(llvm::StringRef value,
582 VarSetOperationType op) {
583 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000584 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 Clayton67cc0632012-08-22 17:17:09 +0000622}