blob: 446fb8e656d17177b85cba1f83f2f2ea5dde9f69 [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
16#include "lldb/Core/StringList.h"
17#include "lldb/Interpreter/OptionValues.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
Greg Clayton67cc0632012-08-22 17:17:09 +000022//-------------------------------------------------------------------------
23// Get this value as a uint64_t value if it is encoded as a boolean,
Kate Stoneb9c1b512016-09-06 20:57:50 +000024// uint64_t or int64_t. Other types will cause "fail_value" to be
Greg Clayton67cc0632012-08-22 17:17:09 +000025// returned
26//-------------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000027uint64_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 Clayton67cc0632012-08-22 17:17:09 +000043}
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045Error 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 Clayton67cc0632012-08-22 17:17:09 +000051}
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053OptionValueBoolean *OptionValue::GetAsBoolean() {
54 if (GetType() == OptionValue::eTypeBoolean)
55 return static_cast<OptionValueBoolean *>(this);
56 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000057}
58
Kate Stoneb9c1b512016-09-06 20:57:50 +000059const OptionValueBoolean *OptionValue::GetAsBoolean() const {
60 if (GetType() == OptionValue::eTypeBoolean)
61 return static_cast<const OptionValueBoolean *>(this);
62 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000063}
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065const OptionValueChar *OptionValue::GetAsChar() const {
66 if (GetType() == OptionValue::eTypeChar)
67 return static_cast<const OptionValueChar *>(this);
68 return nullptr;
Zachary Turner3e7442b2015-01-12 20:44:02 +000069}
70
Kate Stoneb9c1b512016-09-06 20:57:50 +000071OptionValueChar *OptionValue::GetAsChar() {
72 if (GetType() == OptionValue::eTypeChar)
73 return static_cast<OptionValueChar *>(this);
74 return nullptr;
Zachary Turner3e7442b2015-01-12 20:44:02 +000075}
Greg Clayton67cc0632012-08-22 17:17:09 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077OptionValueFileSpec *OptionValue::GetAsFileSpec() {
78 if (GetType() == OptionValue::eTypeFileSpec)
79 return static_cast<OptionValueFileSpec *>(this);
80 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000081}
82
Kate Stoneb9c1b512016-09-06 20:57:50 +000083const OptionValueFileSpec *OptionValue::GetAsFileSpec() const {
84 if (GetType() == OptionValue::eTypeFileSpec)
85 return static_cast<const OptionValueFileSpec *>(this);
86 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000087}
88
Kate Stoneb9c1b512016-09-06 20:57:50 +000089OptionValueFileSpecList *OptionValue::GetAsFileSpecList() {
90 if (GetType() == OptionValue::eTypeFileSpecList)
91 return static_cast<OptionValueFileSpecList *>(this);
92 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000093}
94
Kate Stoneb9c1b512016-09-06 20:57:50 +000095const OptionValueFileSpecList *OptionValue::GetAsFileSpecList() const {
96 if (GetType() == OptionValue::eTypeFileSpecList)
97 return static_cast<const OptionValueFileSpecList *>(this);
98 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +000099}
100
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101OptionValueArch *OptionValue::GetAsArch() {
102 if (GetType() == OptionValue::eTypeArch)
103 return static_cast<OptionValueArch *>(this);
104 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000105}
106
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107const OptionValueArch *OptionValue::GetAsArch() const {
108 if (GetType() == OptionValue::eTypeArch)
109 return static_cast<const OptionValueArch *>(this);
110 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000111}
112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113OptionValueArray *OptionValue::GetAsArray() {
114 if (GetType() == OptionValue::eTypeArray)
115 return static_cast<OptionValueArray *>(this);
116 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000117}
118
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119const OptionValueArray *OptionValue::GetAsArray() const {
120 if (GetType() == OptionValue::eTypeArray)
121 return static_cast<const OptionValueArray *>(this);
122 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000123}
124
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125OptionValueArgs *OptionValue::GetAsArgs() {
126 if (GetType() == OptionValue::eTypeArgs)
127 return static_cast<OptionValueArgs *>(this);
128 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000129}
130
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131const OptionValueArgs *OptionValue::GetAsArgs() const {
132 if (GetType() == OptionValue::eTypeArgs)
133 return static_cast<const OptionValueArgs *>(this);
134 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000135}
136
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137OptionValueDictionary *OptionValue::GetAsDictionary() {
138 if (GetType() == OptionValue::eTypeDictionary)
139 return static_cast<OptionValueDictionary *>(this);
140 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000141}
142
Kate Stoneb9c1b512016-09-06 20:57:50 +0000143const OptionValueDictionary *OptionValue::GetAsDictionary() const {
144 if (GetType() == OptionValue::eTypeDictionary)
145 return static_cast<const OptionValueDictionary *>(this);
146 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000147}
148
Kate Stoneb9c1b512016-09-06 20:57:50 +0000149OptionValueEnumeration *OptionValue::GetAsEnumeration() {
150 if (GetType() == OptionValue::eTypeEnum)
151 return static_cast<OptionValueEnumeration *>(this);
152 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000153}
154
Kate Stoneb9c1b512016-09-06 20:57:50 +0000155const OptionValueEnumeration *OptionValue::GetAsEnumeration() const {
156 if (GetType() == OptionValue::eTypeEnum)
157 return static_cast<const OptionValueEnumeration *>(this);
158 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000159}
160
Kate Stoneb9c1b512016-09-06 20:57:50 +0000161OptionValueFormat *OptionValue::GetAsFormat() {
162 if (GetType() == OptionValue::eTypeFormat)
163 return static_cast<OptionValueFormat *>(this);
164 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000165}
166
Kate Stoneb9c1b512016-09-06 20:57:50 +0000167const OptionValueFormat *OptionValue::GetAsFormat() const {
168 if (GetType() == OptionValue::eTypeFormat)
169 return static_cast<const OptionValueFormat *>(this);
170 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000171}
172
Kate Stoneb9c1b512016-09-06 20:57:50 +0000173OptionValueLanguage *OptionValue::GetAsLanguage() {
174 if (GetType() == OptionValue::eTypeLanguage)
175 return static_cast<OptionValueLanguage *>(this);
176 return NULL;
Enrico Granata8fdf7852015-02-20 19:46:30 +0000177}
178
Kate Stoneb9c1b512016-09-06 20:57:50 +0000179const OptionValueLanguage *OptionValue::GetAsLanguage() const {
180 if (GetType() == OptionValue::eTypeLanguage)
181 return static_cast<const OptionValueLanguage *>(this);
182 return NULL;
Enrico Granata8fdf7852015-02-20 19:46:30 +0000183}
184
Kate Stoneb9c1b512016-09-06 20:57:50 +0000185OptionValueFormatEntity *OptionValue::GetAsFormatEntity() {
186 if (GetType() == OptionValue::eTypeFormatEntity)
187 return static_cast<OptionValueFormatEntity *>(this);
188 return nullptr;
Greg Clayton554f68d2015-02-04 22:00:53 +0000189}
190
Kate Stoneb9c1b512016-09-06 20:57:50 +0000191const OptionValueFormatEntity *OptionValue::GetAsFormatEntity() const {
192 if (GetType() == OptionValue::eTypeFormatEntity)
193 return static_cast<const OptionValueFormatEntity *>(this);
194 return nullptr;
Greg Clayton554f68d2015-02-04 22:00:53 +0000195}
196
Kate Stoneb9c1b512016-09-06 20:57:50 +0000197OptionValuePathMappings *OptionValue::GetAsPathMappings() {
198 if (GetType() == OptionValue::eTypePathMap)
199 return static_cast<OptionValuePathMappings *>(this);
200 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000201}
202
Kate Stoneb9c1b512016-09-06 20:57:50 +0000203const OptionValuePathMappings *OptionValue::GetAsPathMappings() const {
204 if (GetType() == OptionValue::eTypePathMap)
205 return static_cast<const OptionValuePathMappings *>(this);
206 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000207}
208
Kate Stoneb9c1b512016-09-06 20:57:50 +0000209OptionValueProperties *OptionValue::GetAsProperties() {
210 if (GetType() == OptionValue::eTypeProperties)
211 return static_cast<OptionValueProperties *>(this);
212 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000213}
214
Kate Stoneb9c1b512016-09-06 20:57:50 +0000215const OptionValueProperties *OptionValue::GetAsProperties() const {
216 if (GetType() == OptionValue::eTypeProperties)
217 return static_cast<const OptionValueProperties *>(this);
218 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000219}
220
Kate Stoneb9c1b512016-09-06 20:57:50 +0000221OptionValueRegex *OptionValue::GetAsRegex() {
222 if (GetType() == OptionValue::eTypeRegex)
223 return static_cast<OptionValueRegex *>(this);
224 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000225}
226
Kate Stoneb9c1b512016-09-06 20:57:50 +0000227const OptionValueRegex *OptionValue::GetAsRegex() const {
228 if (GetType() == OptionValue::eTypeRegex)
229 return static_cast<const OptionValueRegex *>(this);
230 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000231}
232
Kate Stoneb9c1b512016-09-06 20:57:50 +0000233OptionValueSInt64 *OptionValue::GetAsSInt64() {
234 if (GetType() == OptionValue::eTypeSInt64)
235 return static_cast<OptionValueSInt64 *>(this);
236 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000237}
238
Kate Stoneb9c1b512016-09-06 20:57:50 +0000239const OptionValueSInt64 *OptionValue::GetAsSInt64() const {
240 if (GetType() == OptionValue::eTypeSInt64)
241 return static_cast<const OptionValueSInt64 *>(this);
242 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000243}
244
Kate Stoneb9c1b512016-09-06 20:57:50 +0000245OptionValueString *OptionValue::GetAsString() {
246 if (GetType() == OptionValue::eTypeString)
247 return static_cast<OptionValueString *>(this);
248 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000249}
250
Kate Stoneb9c1b512016-09-06 20:57:50 +0000251const OptionValueString *OptionValue::GetAsString() const {
252 if (GetType() == OptionValue::eTypeString)
253 return static_cast<const OptionValueString *>(this);
254 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000255}
256
Kate Stoneb9c1b512016-09-06 20:57:50 +0000257OptionValueUInt64 *OptionValue::GetAsUInt64() {
258 if (GetType() == OptionValue::eTypeUInt64)
259 return static_cast<OptionValueUInt64 *>(this);
260 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000261}
262
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263const OptionValueUInt64 *OptionValue::GetAsUInt64() const {
264 if (GetType() == OptionValue::eTypeUInt64)
265 return static_cast<const OptionValueUInt64 *>(this);
266 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000267}
268
Kate Stoneb9c1b512016-09-06 20:57:50 +0000269OptionValueUUID *OptionValue::GetAsUUID() {
270 if (GetType() == OptionValue::eTypeUUID)
271 return static_cast<OptionValueUUID *>(this);
272 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000273}
274
Kate Stoneb9c1b512016-09-06 20:57:50 +0000275const OptionValueUUID *OptionValue::GetAsUUID() const {
276 if (GetType() == OptionValue::eTypeUUID)
277 return static_cast<const OptionValueUUID *>(this);
278 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000279}
280
Kate Stoneb9c1b512016-09-06 20:57:50 +0000281bool 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 Clayton67cc0632012-08-22 17:17:09 +0000286}
287
Kate Stoneb9c1b512016-09-06 20:57:50 +0000288bool 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 Clayton67cc0632012-08-22 17:17:09 +0000295}
296
Kate Stoneb9c1b512016-09-06 20:57:50 +0000297char 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 Turner3e7442b2015-01-12 20:44:02 +0000302}
303
Kate Stoneb9c1b512016-09-06 20:57:50 +0000304char 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 Turner3e7442b2015-01-12 20:44:02 +0000311}
312
Kate Stoneb9c1b512016-09-06 20:57:50 +0000313int64_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 Clayton67cc0632012-08-22 17:17:09 +0000318}
319
Kate Stoneb9c1b512016-09-06 20:57:50 +0000320bool 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 Clayton67cc0632012-08-22 17:17:09 +0000327}
328
Kate Stoneb9c1b512016-09-06 20:57:50 +0000329FileSpec OptionValue::GetFileSpecValue() const {
330 const OptionValueFileSpec *option_value = GetAsFileSpec();
331 if (option_value)
332 return option_value->GetCurrentValue();
333 return FileSpec();
Greg Clayton67cc0632012-08-22 17:17:09 +0000334}
335
Kate Stoneb9c1b512016-09-06 20:57:50 +0000336bool 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 Clayton67cc0632012-08-22 17:17:09 +0000343}
344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345FileSpecList OptionValue::GetFileSpecListValue() const {
346 const OptionValueFileSpecList *option_value = GetAsFileSpecList();
347 if (option_value)
348 return option_value->GetCurrentValue();
349 return FileSpecList();
Greg Clayton67cc0632012-08-22 17:17:09 +0000350}
351
Kate Stoneb9c1b512016-09-06 20:57:50 +0000352lldb::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 Clayton67cc0632012-08-22 17:17:09 +0000357}
358
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359bool 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 Clayton67cc0632012-08-22 17:17:09 +0000366}
367
Enrico Granata8fdf7852015-02-20 19:46:30 +0000368lldb::LanguageType
Kate Stoneb9c1b512016-09-06 20:57:50 +0000369OptionValue::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 Granata8fdf7852015-02-20 19:46:30 +0000374}
375
Kate Stoneb9c1b512016-09-06 20:57:50 +0000376bool 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 Granata8fdf7852015-02-20 19:46:30 +0000383}
384
Kate Stoneb9c1b512016-09-06 20:57:50 +0000385const FormatEntity::Entry *OptionValue::GetFormatEntity() const {
386 const OptionValueFormatEntity *option_value = GetAsFormatEntity();
387 if (option_value)
388 return &option_value->GetCurrentValue();
389 return nullptr;
Greg Clayton554f68d2015-02-04 22:00:53 +0000390}
391
Kate Stoneb9c1b512016-09-06 20:57:50 +0000392const RegularExpression *OptionValue::GetRegexValue() const {
393 const OptionValueRegex *option_value = GetAsRegex();
394 if (option_value)
395 return option_value->GetCurrentValue();
396 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000397}
398
Kate Stoneb9c1b512016-09-06 20:57:50 +0000399int64_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 Clayton67cc0632012-08-22 17:17:09 +0000404}
405
Kate Stoneb9c1b512016-09-06 20:57:50 +0000406bool 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 Clayton67cc0632012-08-22 17:17:09 +0000413}
414
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415const 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 Clayton67cc0632012-08-22 17:17:09 +0000420}
421
Zachary Turner514d8cd2016-09-23 18:06:53 +0000422bool OptionValue::SetStringValue(llvm::StringRef new_value) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000423 OptionValueString *option_value = GetAsString();
424 if (option_value) {
Zachary Turner514d8cd2016-09-23 18:06:53 +0000425 option_value->SetCurrentValue(new_value);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000426 return true;
427 }
428 return false;
Greg Clayton67cc0632012-08-22 17:17:09 +0000429}
430
Kate Stoneb9c1b512016-09-06 20:57:50 +0000431uint64_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 Clayton67cc0632012-08-22 17:17:09 +0000436}
437
Kate Stoneb9c1b512016-09-06 20:57:50 +0000438bool 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 Clayton67cc0632012-08-22 17:17:09 +0000445}
446
Kate Stoneb9c1b512016-09-06 20:57:50 +0000447UUID OptionValue::GetUUIDValue() const {
448 const OptionValueUUID *option_value = GetAsUUID();
449 if (option_value)
450 return option_value->GetCurrentValue();
451 return UUID();
Greg Clayton67cc0632012-08-22 17:17:09 +0000452}
453
Kate Stoneb9c1b512016-09-06 20:57:50 +0000454bool 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 Clayton67cc0632012-08-22 17:17:09 +0000461}
462
Kate Stoneb9c1b512016-09-06 20:57:50 +0000463const 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 Clayton67cc0632012-08-22 17:17:09 +0000507}
508
Kate Stoneb9c1b512016-09-06 20:57:50 +0000509lldb::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 Clayton67cc0632012-08-22 17:17:09 +0000549
Kate Stoneb9c1b512016-09-06 20:57:50 +0000550 if (value_sp)
Zachary Turner8cef4b02016-09-23 17:48:13 +0000551 error = value_sp->SetValueFromString(
552 llvm::StringRef::withNullAsEmpty(value_cstr), eVarSetOperationAssign);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000553 else
554 error.SetErrorString("unsupported type mask");
555 return value_sp;
556}
Greg Clayton67cc0632012-08-22 17:17:09 +0000557
Kate Stoneb9c1b512016-09-06 20:57:50 +0000558bool 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 Clayton67cc0632012-08-22 17:17:09 +0000569 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000570 dumped_something = true;
571 strm << name;
572 }
573 return dumped_something;
Greg Clayton67cc0632012-08-22 17:17:09 +0000574}
575
Zachary Turner4aa87532016-11-17 01:37:42 +0000576size_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 Stoneb9c1b512016-09-06 20:57:50 +0000580 word_complete = false;
581 matches.Clear();
582 return matches.GetSize();
Greg Clayton67cc0632012-08-22 17:17:09 +0000583}
584
Kate Stoneb9c1b512016-09-06 20:57:50 +0000585Error 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 Clayton67cc0632012-08-22 17:17:09 +0000626}