1 //===-- OptionValue.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Interpreter/OptionValue.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/StringList.h"
17 #include "lldb/Interpreter/OptionValues.h"
20 using namespace lldb_private;
23 //-------------------------------------------------------------------------
24 // Get this value as a uint64_t value if it is encoded as a boolean,
25 // uint64_t or int64_t. Other types will cause "fail_value" to be
27 //-------------------------------------------------------------------------
29 OptionValue::GetUInt64Value (uint64_t fail_value, bool *success_ptr)
35 case OptionValue::eTypeBoolean: return static_cast<OptionValueBoolean *>(this)->GetCurrentValue();
36 case OptionValue::eTypeSInt64: return static_cast<OptionValueSInt64 *>(this)->GetCurrentValue();
37 case OptionValue::eTypeUInt64: return static_cast<OptionValueUInt64 *>(this)->GetCurrentValue();
47 OptionValue::SetSubValue (const ExecutionContext *exe_ctx,
48 VarSetOperationType op,
53 error.SetErrorStringWithFormat("SetSubValue is not supported");
59 OptionValue::GetAsBoolean ()
61 if (GetType () == OptionValue::eTypeBoolean)
62 return static_cast<OptionValueBoolean *>(this);
66 const OptionValueBoolean *
67 OptionValue::GetAsBoolean () const
69 if (GetType () == OptionValue::eTypeBoolean)
70 return static_cast<const OptionValueBoolean *>(this);
74 const OptionValueChar *
75 OptionValue::GetAsChar () const
77 if (GetType () == OptionValue::eTypeChar)
78 return static_cast<const OptionValueChar *>(this);
83 OptionValue::GetAsChar ()
85 if (GetType () == OptionValue::eTypeChar)
86 return static_cast<OptionValueChar *>(this);
91 OptionValue::GetAsFileSpec ()
93 if (GetType () == OptionValue::eTypeFileSpec)
94 return static_cast<OptionValueFileSpec *>(this);
99 const OptionValueFileSpec *
100 OptionValue::GetAsFileSpec () const
102 if (GetType () == OptionValue::eTypeFileSpec)
103 return static_cast<const OptionValueFileSpec *>(this);
108 OptionValueFileSpecList *
109 OptionValue::GetAsFileSpecList ()
111 if (GetType () == OptionValue::eTypeFileSpecList)
112 return static_cast<OptionValueFileSpecList *>(this);
117 const OptionValueFileSpecList *
118 OptionValue::GetAsFileSpecList () const
120 if (GetType () == OptionValue::eTypeFileSpecList)
121 return static_cast<const OptionValueFileSpecList *>(this);
127 OptionValue::GetAsArch ()
129 if (GetType () == OptionValue::eTypeArch)
130 return static_cast<OptionValueArch *>(this);
135 const OptionValueArch *
136 OptionValue::GetAsArch () const
138 if (GetType () == OptionValue::eTypeArch)
139 return static_cast<const OptionValueArch *>(this);
144 OptionValue::GetAsArray ()
146 if (GetType () == OptionValue::eTypeArray)
147 return static_cast<OptionValueArray *>(this);
152 const OptionValueArray *
153 OptionValue::GetAsArray () const
155 if (GetType () == OptionValue::eTypeArray)
156 return static_cast<const OptionValueArray *>(this);
161 OptionValue::GetAsArgs ()
163 if (GetType () == OptionValue::eTypeArgs)
164 return static_cast<OptionValueArgs *>(this);
169 const OptionValueArgs *
170 OptionValue::GetAsArgs () const
172 if (GetType () == OptionValue::eTypeArgs)
173 return static_cast<const OptionValueArgs *>(this);
177 OptionValueDictionary *
178 OptionValue::GetAsDictionary ()
180 if (GetType () == OptionValue::eTypeDictionary)
181 return static_cast<OptionValueDictionary *>(this);
185 const OptionValueDictionary *
186 OptionValue::GetAsDictionary () const
188 if (GetType () == OptionValue::eTypeDictionary)
189 return static_cast<const OptionValueDictionary *>(this);
193 OptionValueEnumeration *
194 OptionValue::GetAsEnumeration ()
196 if (GetType () == OptionValue::eTypeEnum)
197 return static_cast<OptionValueEnumeration *>(this);
201 const OptionValueEnumeration *
202 OptionValue::GetAsEnumeration () const
204 if (GetType () == OptionValue::eTypeEnum)
205 return static_cast<const OptionValueEnumeration *>(this);
210 OptionValue::GetAsFormat ()
212 if (GetType () == OptionValue::eTypeFormat)
213 return static_cast<OptionValueFormat *>(this);
217 const OptionValueFormat *
218 OptionValue::GetAsFormat () const
220 if (GetType () == OptionValue::eTypeFormat)
221 return static_cast<const OptionValueFormat *>(this);
225 OptionValueLanguage *
226 OptionValue::GetAsLanguage ()
228 if (GetType () == OptionValue::eTypeLanguage)
229 return static_cast<OptionValueLanguage *>(this);
233 const OptionValueLanguage *
234 OptionValue::GetAsLanguage () const
236 if (GetType () == OptionValue::eTypeLanguage)
237 return static_cast<const OptionValueLanguage *>(this);
241 OptionValueFormatEntity *
242 OptionValue::GetAsFormatEntity ()
244 if (GetType () == OptionValue::eTypeFormatEntity)
245 return static_cast<OptionValueFormatEntity *>(this);
249 const OptionValueFormatEntity *
250 OptionValue::GetAsFormatEntity () const
252 if (GetType () == OptionValue::eTypeFormatEntity)
253 return static_cast<const OptionValueFormatEntity *>(this);
257 OptionValuePathMappings *
258 OptionValue::GetAsPathMappings ()
260 if (GetType () == OptionValue::eTypePathMap)
261 return static_cast<OptionValuePathMappings *>(this);
265 const OptionValuePathMappings *
266 OptionValue::GetAsPathMappings () const
268 if (GetType () == OptionValue::eTypePathMap)
269 return static_cast<const OptionValuePathMappings *>(this);
273 OptionValueProperties *
274 OptionValue::GetAsProperties ()
276 if (GetType () == OptionValue::eTypeProperties)
277 return static_cast<OptionValueProperties *>(this);
281 const OptionValueProperties *
282 OptionValue::GetAsProperties () const
284 if (GetType () == OptionValue::eTypeProperties)
285 return static_cast<const OptionValueProperties *>(this);
290 OptionValue::GetAsRegex ()
292 if (GetType () == OptionValue::eTypeRegex)
293 return static_cast<OptionValueRegex *>(this);
297 const OptionValueRegex *
298 OptionValue::GetAsRegex () const
300 if (GetType () == OptionValue::eTypeRegex)
301 return static_cast<const OptionValueRegex *>(this);
306 OptionValue::GetAsSInt64 ()
308 if (GetType () == OptionValue::eTypeSInt64)
309 return static_cast<OptionValueSInt64 *>(this);
313 const OptionValueSInt64 *
314 OptionValue::GetAsSInt64 () const
316 if (GetType () == OptionValue::eTypeSInt64)
317 return static_cast<const OptionValueSInt64 *>(this);
322 OptionValue::GetAsString ()
324 if (GetType () == OptionValue::eTypeString)
325 return static_cast<OptionValueString *>(this);
329 const OptionValueString *
330 OptionValue::GetAsString () const
332 if (GetType () == OptionValue::eTypeString)
333 return static_cast<const OptionValueString *>(this);
338 OptionValue::GetAsUInt64 ()
340 if (GetType () == OptionValue::eTypeUInt64)
341 return static_cast<OptionValueUInt64 *>(this);
345 const OptionValueUInt64 *
346 OptionValue::GetAsUInt64 () const
348 if (GetType () == OptionValue::eTypeUInt64)
349 return static_cast<const OptionValueUInt64 *>(this);
354 OptionValue::GetAsUUID ()
356 if (GetType () == OptionValue::eTypeUUID)
357 return static_cast<OptionValueUUID *>(this);
362 const OptionValueUUID *
363 OptionValue::GetAsUUID () const
365 if (GetType () == OptionValue::eTypeUUID)
366 return static_cast<const OptionValueUUID *>(this);
372 OptionValue::GetBooleanValue (bool fail_value) const
374 const OptionValueBoolean *option_value = GetAsBoolean ();
376 return option_value->GetCurrentValue();
381 OptionValue::SetBooleanValue (bool new_value)
383 OptionValueBoolean *option_value = GetAsBoolean ();
386 option_value->SetCurrentValue(new_value);
393 OptionValue::GetCharValue(char fail_value) const
395 const OptionValueChar *option_value = GetAsChar();
397 return option_value->GetCurrentValue();
402 OptionValue::SetCharValue(char new_value)
404 OptionValueChar *option_value = GetAsChar();
407 option_value->SetCurrentValue(new_value);
414 OptionValue::GetEnumerationValue (int64_t fail_value) const
416 const OptionValueEnumeration *option_value = GetAsEnumeration();
418 return option_value->GetCurrentValue();
423 OptionValue::SetEnumerationValue (int64_t value)
425 OptionValueEnumeration *option_value = GetAsEnumeration();
428 option_value->SetCurrentValue(value);
435 OptionValue::GetFileSpecValue () const
437 const OptionValueFileSpec *option_value = GetAsFileSpec ();
439 return option_value->GetCurrentValue();
445 OptionValue::SetFileSpecValue (const FileSpec &file_spec)
447 OptionValueFileSpec *option_value = GetAsFileSpec ();
450 option_value->SetCurrentValue(file_spec, false);
457 OptionValue::GetFileSpecListValue () const
459 const OptionValueFileSpecList *option_value = GetAsFileSpecList ();
461 return option_value->GetCurrentValue();
462 return FileSpecList();
467 OptionValue::GetFormatValue (lldb::Format fail_value) const
469 const OptionValueFormat *option_value = GetAsFormat ();
471 return option_value->GetCurrentValue();
476 OptionValue::SetFormatValue (lldb::Format new_value)
478 OptionValueFormat *option_value = GetAsFormat ();
481 option_value->SetCurrentValue(new_value);
488 OptionValue::GetLanguageValue (lldb::LanguageType fail_value) const
490 const OptionValueLanguage *option_value = GetAsLanguage ();
492 return option_value->GetCurrentValue();
497 OptionValue::SetLanguageValue (lldb::LanguageType new_language)
499 OptionValueLanguage *option_value = GetAsLanguage ();
502 option_value->SetCurrentValue(new_language);
508 const FormatEntity::Entry *
509 OptionValue::GetFormatEntity () const
511 const OptionValueFormatEntity *option_value = GetAsFormatEntity();
513 return &option_value->GetCurrentValue();
517 const RegularExpression *
518 OptionValue::GetRegexValue () const
520 const OptionValueRegex *option_value = GetAsRegex ();
522 return option_value->GetCurrentValue();
528 OptionValue::GetSInt64Value (int64_t fail_value) const
530 const OptionValueSInt64 *option_value = GetAsSInt64 ();
532 return option_value->GetCurrentValue();
537 OptionValue::SetSInt64Value (int64_t new_value)
539 OptionValueSInt64 *option_value = GetAsSInt64 ();
542 option_value->SetCurrentValue(new_value);
549 OptionValue::GetStringValue (const char *fail_value) const
551 const OptionValueString *option_value = GetAsString ();
553 return option_value->GetCurrentValue();
558 OptionValue::SetStringValue (const char *new_value)
560 OptionValueString *option_value = GetAsString ();
563 option_value->SetCurrentValue(new_value);
570 OptionValue::GetUInt64Value (uint64_t fail_value) const
572 const OptionValueUInt64 *option_value = GetAsUInt64 ();
574 return option_value->GetCurrentValue();
579 OptionValue::SetUInt64Value (uint64_t new_value)
581 OptionValueUInt64 *option_value = GetAsUInt64 ();
584 option_value->SetCurrentValue(new_value);
591 OptionValue::GetUUIDValue () const
593 const OptionValueUUID *option_value = GetAsUUID();
595 return option_value->GetCurrentValue();
600 OptionValue::SetUUIDValue (const UUID &uuid)
602 OptionValueUUID *option_value = GetAsUUID();
605 option_value->SetCurrentValue(uuid);
612 OptionValue::GetBuiltinTypeAsCString (Type t)
616 case eTypeInvalid: return "invalid";
617 case eTypeArch: return "arch";
618 case eTypeArgs: return "arguments";
619 case eTypeArray: return "array";
620 case eTypeBoolean: return "boolean";
623 case eTypeDictionary: return "dictionary";
624 case eTypeEnum: return "enum";
625 case eTypeFileSpec: return "file";
626 case eTypeFileSpecList: return "file-list";
627 case eTypeFormat: return "format";
628 case eTypeFormatEntity: return "format-string";
629 case eTypeLanguage: return "language";
630 case eTypePathMap: return "path-map";
631 case eTypeProperties: return "properties";
632 case eTypeRegex: return "regex";
633 case eTypeSInt64: return "int";
634 case eTypeString: return "string";
635 case eTypeUInt64: return "unsigned";
636 case eTypeUUID: return "uuid";
643 OptionValue::CreateValueFromCStringForTypeMask (const char *value_cstr, uint32_t type_mask, Error &error)
645 // If only 1 bit is set in the type mask for a dictionary or array
646 // then we know how to decode a value from a cstring
647 lldb::OptionValueSP value_sp;
650 case 1u << eTypeArch: value_sp.reset(new OptionValueArch()); break;
651 case 1u << eTypeBoolean: value_sp.reset(new OptionValueBoolean(false)); break;
652 case 1u << eTypeChar: value_sp.reset(new OptionValueChar('\0')); break;
653 case 1u << eTypeFileSpec: value_sp.reset(new OptionValueFileSpec()); break;
654 case 1u << eTypeFormat: value_sp.reset(new OptionValueFormat(eFormatInvalid)); break;
655 case 1u << eTypeFormatEntity: value_sp.reset(new OptionValueFormatEntity(NULL)); break;
656 case 1u << eTypeLanguage: value_sp.reset(new OptionValueLanguage(eLanguageTypeUnknown)); break;
657 case 1u << eTypeSInt64: value_sp.reset(new OptionValueSInt64()); break;
658 case 1u << eTypeString: value_sp.reset(new OptionValueString()); break;
659 case 1u << eTypeUInt64: value_sp.reset(new OptionValueUInt64()); break;
660 case 1u << eTypeUUID: value_sp.reset(new OptionValueUUID()); break;
664 error = value_sp->SetValueFromString (value_cstr, eVarSetOperationAssign);
666 error.SetErrorString("unsupported type mask");
671 OptionValue::DumpQualifiedName (Stream &strm) const
673 bool dumped_something = false;
674 lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
677 if (m_parent_sp->DumpQualifiedName(strm))
678 dumped_something = true;
680 ConstString name (GetName());
683 if (dumped_something)
686 dumped_something = true;
689 return dumped_something;
693 OptionValue::AutoComplete (CommandInterpreter &interpreter,
695 int match_start_point,
696 int max_return_elements,
700 word_complete = false;
702 return matches.GetSize();
706 OptionValue::SetValueFromString (llvm::StringRef value, VarSetOperationType op)
711 case eVarSetOperationReplace:
712 error.SetErrorStringWithFormat ("%s objects do not support the 'replace' operation", GetTypeAsCString());
714 case eVarSetOperationInsertBefore:
715 error.SetErrorStringWithFormat ("%s objects do not support the 'insert-before' operation", GetTypeAsCString());
717 case eVarSetOperationInsertAfter:
718 error.SetErrorStringWithFormat ("%s objects do not support the 'insert-after' operation", GetTypeAsCString());
720 case eVarSetOperationRemove:
721 error.SetErrorStringWithFormat ("%s objects do not support the 'remove' operation", GetTypeAsCString());
723 case eVarSetOperationAppend:
724 error.SetErrorStringWithFormat ("%s objects do not support the 'append' operation", GetTypeAsCString());
726 case eVarSetOperationClear:
727 error.SetErrorStringWithFormat ("%s objects do not support the 'clear' operation", GetTypeAsCString());
729 case eVarSetOperationAssign:
730 error.SetErrorStringWithFormat ("%s objects do not support the 'assign' operation", GetTypeAsCString());
732 case eVarSetOperationInvalid:
733 error.SetErrorStringWithFormat ("invalid operation performed on a %s object", GetTypeAsCString());