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 OptionValuePathMappings *
226 OptionValue::GetAsPathMappings ()
228 if (GetType () == OptionValue::eTypePathMap)
229 return static_cast<OptionValuePathMappings *>(this);
233 const OptionValuePathMappings *
234 OptionValue::GetAsPathMappings () const
236 if (GetType () == OptionValue::eTypePathMap)
237 return static_cast<const OptionValuePathMappings *>(this);
241 OptionValueProperties *
242 OptionValue::GetAsProperties ()
244 if (GetType () == OptionValue::eTypeProperties)
245 return static_cast<OptionValueProperties *>(this);
249 const OptionValueProperties *
250 OptionValue::GetAsProperties () const
252 if (GetType () == OptionValue::eTypeProperties)
253 return static_cast<const OptionValueProperties *>(this);
258 OptionValue::GetAsRegex ()
260 if (GetType () == OptionValue::eTypeRegex)
261 return static_cast<OptionValueRegex *>(this);
265 const OptionValueRegex *
266 OptionValue::GetAsRegex () const
268 if (GetType () == OptionValue::eTypeRegex)
269 return static_cast<const OptionValueRegex *>(this);
274 OptionValue::GetAsSInt64 ()
276 if (GetType () == OptionValue::eTypeSInt64)
277 return static_cast<OptionValueSInt64 *>(this);
281 const OptionValueSInt64 *
282 OptionValue::GetAsSInt64 () const
284 if (GetType () == OptionValue::eTypeSInt64)
285 return static_cast<const OptionValueSInt64 *>(this);
290 OptionValue::GetAsString ()
292 if (GetType () == OptionValue::eTypeString)
293 return static_cast<OptionValueString *>(this);
297 const OptionValueString *
298 OptionValue::GetAsString () const
300 if (GetType () == OptionValue::eTypeString)
301 return static_cast<const OptionValueString *>(this);
306 OptionValue::GetAsUInt64 ()
308 if (GetType () == OptionValue::eTypeUInt64)
309 return static_cast<OptionValueUInt64 *>(this);
313 const OptionValueUInt64 *
314 OptionValue::GetAsUInt64 () const
316 if (GetType () == OptionValue::eTypeUInt64)
317 return static_cast<const OptionValueUInt64 *>(this);
322 OptionValue::GetAsUUID ()
324 if (GetType () == OptionValue::eTypeUUID)
325 return static_cast<OptionValueUUID *>(this);
330 const OptionValueUUID *
331 OptionValue::GetAsUUID () const
333 if (GetType () == OptionValue::eTypeUUID)
334 return static_cast<const OptionValueUUID *>(this);
340 OptionValue::GetBooleanValue (bool fail_value) const
342 const OptionValueBoolean *option_value = GetAsBoolean ();
344 return option_value->GetCurrentValue();
349 OptionValue::SetBooleanValue (bool new_value)
351 OptionValueBoolean *option_value = GetAsBoolean ();
354 option_value->SetCurrentValue(new_value);
361 OptionValue::GetCharValue(char fail_value) const
363 const OptionValueChar *option_value = GetAsChar();
365 return option_value->GetCurrentValue();
370 OptionValue::SetCharValue(char new_value)
372 OptionValueChar *option_value = GetAsChar();
375 option_value->SetCurrentValue(new_value);
382 OptionValue::GetEnumerationValue (int64_t fail_value) const
384 const OptionValueEnumeration *option_value = GetAsEnumeration();
386 return option_value->GetCurrentValue();
391 OptionValue::SetEnumerationValue (int64_t value)
393 OptionValueEnumeration *option_value = GetAsEnumeration();
396 option_value->SetCurrentValue(value);
403 OptionValue::GetFileSpecValue () const
405 const OptionValueFileSpec *option_value = GetAsFileSpec ();
407 return option_value->GetCurrentValue();
413 OptionValue::SetFileSpecValue (const FileSpec &file_spec)
415 OptionValueFileSpec *option_value = GetAsFileSpec ();
418 option_value->SetCurrentValue(file_spec, false);
425 OptionValue::GetFileSpecListValue () const
427 const OptionValueFileSpecList *option_value = GetAsFileSpecList ();
429 return option_value->GetCurrentValue();
430 return FileSpecList();
435 OptionValue::GetFormatValue (lldb::Format fail_value) const
437 const OptionValueFormat *option_value = GetAsFormat ();
439 return option_value->GetCurrentValue();
444 OptionValue::SetFormatValue (lldb::Format new_value)
446 OptionValueFormat *option_value = GetAsFormat ();
449 option_value->SetCurrentValue(new_value);
455 const RegularExpression *
456 OptionValue::GetRegexValue () const
458 const OptionValueRegex *option_value = GetAsRegex ();
460 return option_value->GetCurrentValue();
466 OptionValue::GetSInt64Value (int64_t fail_value) const
468 const OptionValueSInt64 *option_value = GetAsSInt64 ();
470 return option_value->GetCurrentValue();
475 OptionValue::SetSInt64Value (int64_t new_value)
477 OptionValueSInt64 *option_value = GetAsSInt64 ();
480 option_value->SetCurrentValue(new_value);
487 OptionValue::GetStringValue (const char *fail_value) const
489 const OptionValueString *option_value = GetAsString ();
491 return option_value->GetCurrentValue();
496 OptionValue::SetStringValue (const char *new_value)
498 OptionValueString *option_value = GetAsString ();
501 option_value->SetCurrentValue(new_value);
508 OptionValue::GetUInt64Value (uint64_t fail_value) const
510 const OptionValueUInt64 *option_value = GetAsUInt64 ();
512 return option_value->GetCurrentValue();
517 OptionValue::SetUInt64Value (uint64_t new_value)
519 OptionValueUInt64 *option_value = GetAsUInt64 ();
522 option_value->SetCurrentValue(new_value);
529 OptionValue::GetUUIDValue () const
531 const OptionValueUUID *option_value = GetAsUUID();
533 return option_value->GetCurrentValue();
538 OptionValue::SetUUIDValue (const UUID &uuid)
540 OptionValueUUID *option_value = GetAsUUID();
543 option_value->SetCurrentValue(uuid);
550 OptionValue::GetBuiltinTypeAsCString (Type t)
554 case eTypeInvalid: return "invalid";
555 case eTypeArch: return "arch";
556 case eTypeArgs: return "arguments";
557 case eTypeArray: return "array";
558 case eTypeBoolean: return "boolean";
561 case eTypeDictionary: return "dictionary";
562 case eTypeEnum: return "enum";
563 case eTypeFileSpec: return "file";
564 case eTypeFileSpecList: return "file-list";
565 case eTypeFormat: return "format";
566 case eTypePathMap: return "path-map";
567 case eTypeProperties: return "properties";
568 case eTypeRegex: return "regex";
569 case eTypeSInt64: return "int";
570 case eTypeString: return "string";
571 case eTypeUInt64: return "unsigned";
572 case eTypeUUID: return "uuid";
579 OptionValue::CreateValueFromCStringForTypeMask (const char *value_cstr, uint32_t type_mask, Error &error)
581 // If only 1 bit is set in the type mask for a dictionary or array
582 // then we know how to decode a value from a cstring
583 lldb::OptionValueSP value_sp;
586 case 1u << eTypeArch: value_sp.reset(new OptionValueArch()); break;
587 case 1u << eTypeBoolean: value_sp.reset(new OptionValueBoolean(false)); break;
588 case 1u << eTypeChar: value_sp.reset(new OptionValueChar('\0')); break;
589 case 1u << eTypeFileSpec: value_sp.reset(new OptionValueFileSpec()); break;
590 case 1u << eTypeFormat: value_sp.reset(new OptionValueFormat(eFormatInvalid)); break;
591 case 1u << eTypeSInt64: value_sp.reset(new OptionValueSInt64()); break;
592 case 1u << eTypeString: value_sp.reset(new OptionValueString()); break;
593 case 1u << eTypeUInt64: value_sp.reset(new OptionValueUInt64()); break;
594 case 1u << eTypeUUID: value_sp.reset(new OptionValueUUID()); break;
598 error = value_sp->SetValueFromCString (value_cstr, eVarSetOperationAssign);
600 error.SetErrorString("unsupported type mask");
605 OptionValue::DumpQualifiedName (Stream &strm) const
607 bool dumped_something = false;
608 lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
611 if (m_parent_sp->DumpQualifiedName(strm))
612 dumped_something = true;
614 ConstString name (GetName());
617 if (dumped_something)
620 dumped_something = true;
623 return dumped_something;
627 OptionValue::AutoComplete (CommandInterpreter &interpreter,
629 int match_start_point,
630 int max_return_elements,
634 word_complete = false;
636 return matches.GetSize();
640 OptionValue::SetValueFromCString (const char *value, VarSetOperationType op)
645 case eVarSetOperationReplace:
646 error.SetErrorStringWithFormat ("%s objects do not support the 'replace' operation", GetTypeAsCString());
648 case eVarSetOperationInsertBefore:
649 error.SetErrorStringWithFormat ("%s objects do not support the 'insert-before' operation", GetTypeAsCString());
651 case eVarSetOperationInsertAfter:
652 error.SetErrorStringWithFormat ("%s objects do not support the 'insert-after' operation", GetTypeAsCString());
654 case eVarSetOperationRemove:
655 error.SetErrorStringWithFormat ("%s objects do not support the 'remove' operation", GetTypeAsCString());
657 case eVarSetOperationAppend:
658 error.SetErrorStringWithFormat ("%s objects do not support the 'append' operation", GetTypeAsCString());
660 case eVarSetOperationClear:
661 error.SetErrorStringWithFormat ("%s objects do not support the 'clear' operation", GetTypeAsCString());
663 case eVarSetOperationAssign:
664 error.SetErrorStringWithFormat ("%s objects do not support the 'assign' operation", GetTypeAsCString());
666 case eVarSetOperationInvalid:
667 error.SetErrorStringWithFormat ("invalid operation performed on a %s object", GetTypeAsCString());