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);
76 OptionValue::GetAsFileSpec ()
78 if (GetType () == OptionValue::eTypeFileSpec)
79 return static_cast<OptionValueFileSpec *>(this);
84 const OptionValueFileSpec *
85 OptionValue::GetAsFileSpec () const
87 if (GetType () == OptionValue::eTypeFileSpec)
88 return static_cast<const OptionValueFileSpec *>(this);
93 OptionValueFileSpecList *
94 OptionValue::GetAsFileSpecList ()
96 if (GetType () == OptionValue::eTypeFileSpecList)
97 return static_cast<OptionValueFileSpecList *>(this);
102 const OptionValueFileSpecList *
103 OptionValue::GetAsFileSpecList () const
105 if (GetType () == OptionValue::eTypeFileSpecList)
106 return static_cast<const OptionValueFileSpecList *>(this);
112 OptionValue::GetAsArch ()
114 if (GetType () == OptionValue::eTypeArch)
115 return static_cast<OptionValueArch *>(this);
120 const OptionValueArch *
121 OptionValue::GetAsArch () const
123 if (GetType () == OptionValue::eTypeArch)
124 return static_cast<const OptionValueArch *>(this);
129 OptionValue::GetAsArray ()
131 if (GetType () == OptionValue::eTypeArray)
132 return static_cast<OptionValueArray *>(this);
137 const OptionValueArray *
138 OptionValue::GetAsArray () const
140 if (GetType () == OptionValue::eTypeArray)
141 return static_cast<const OptionValueArray *>(this);
146 OptionValue::GetAsArgs ()
148 if (GetType () == OptionValue::eTypeArgs)
149 return static_cast<OptionValueArgs *>(this);
154 const OptionValueArgs *
155 OptionValue::GetAsArgs () const
157 if (GetType () == OptionValue::eTypeArgs)
158 return static_cast<const OptionValueArgs *>(this);
162 OptionValueDictionary *
163 OptionValue::GetAsDictionary ()
165 if (GetType () == OptionValue::eTypeDictionary)
166 return static_cast<OptionValueDictionary *>(this);
170 const OptionValueDictionary *
171 OptionValue::GetAsDictionary () const
173 if (GetType () == OptionValue::eTypeDictionary)
174 return static_cast<const OptionValueDictionary *>(this);
178 OptionValueEnumeration *
179 OptionValue::GetAsEnumeration ()
181 if (GetType () == OptionValue::eTypeEnum)
182 return static_cast<OptionValueEnumeration *>(this);
186 const OptionValueEnumeration *
187 OptionValue::GetAsEnumeration () const
189 if (GetType () == OptionValue::eTypeEnum)
190 return static_cast<const OptionValueEnumeration *>(this);
195 OptionValue::GetAsFormat ()
197 if (GetType () == OptionValue::eTypeFormat)
198 return static_cast<OptionValueFormat *>(this);
202 const OptionValueFormat *
203 OptionValue::GetAsFormat () const
205 if (GetType () == OptionValue::eTypeFormat)
206 return static_cast<const OptionValueFormat *>(this);
210 OptionValuePathMappings *
211 OptionValue::GetAsPathMappings ()
213 if (GetType () == OptionValue::eTypePathMap)
214 return static_cast<OptionValuePathMappings *>(this);
218 const OptionValuePathMappings *
219 OptionValue::GetAsPathMappings () const
221 if (GetType () == OptionValue::eTypePathMap)
222 return static_cast<const OptionValuePathMappings *>(this);
226 OptionValueProperties *
227 OptionValue::GetAsProperties ()
229 if (GetType () == OptionValue::eTypeProperties)
230 return static_cast<OptionValueProperties *>(this);
234 const OptionValueProperties *
235 OptionValue::GetAsProperties () const
237 if (GetType () == OptionValue::eTypeProperties)
238 return static_cast<const OptionValueProperties *>(this);
243 OptionValue::GetAsRegex ()
245 if (GetType () == OptionValue::eTypeRegex)
246 return static_cast<OptionValueRegex *>(this);
250 const OptionValueRegex *
251 OptionValue::GetAsRegex () const
253 if (GetType () == OptionValue::eTypeRegex)
254 return static_cast<const OptionValueRegex *>(this);
259 OptionValue::GetAsSInt64 ()
261 if (GetType () == OptionValue::eTypeSInt64)
262 return static_cast<OptionValueSInt64 *>(this);
266 const OptionValueSInt64 *
267 OptionValue::GetAsSInt64 () const
269 if (GetType () == OptionValue::eTypeSInt64)
270 return static_cast<const OptionValueSInt64 *>(this);
275 OptionValue::GetAsString ()
277 if (GetType () == OptionValue::eTypeString)
278 return static_cast<OptionValueString *>(this);
282 const OptionValueString *
283 OptionValue::GetAsString () const
285 if (GetType () == OptionValue::eTypeString)
286 return static_cast<const OptionValueString *>(this);
291 OptionValue::GetAsUInt64 ()
293 if (GetType () == OptionValue::eTypeUInt64)
294 return static_cast<OptionValueUInt64 *>(this);
298 const OptionValueUInt64 *
299 OptionValue::GetAsUInt64 () const
301 if (GetType () == OptionValue::eTypeUInt64)
302 return static_cast<const OptionValueUInt64 *>(this);
307 OptionValue::GetAsUUID ()
309 if (GetType () == OptionValue::eTypeUUID)
310 return static_cast<OptionValueUUID *>(this);
315 const OptionValueUUID *
316 OptionValue::GetAsUUID () const
318 if (GetType () == OptionValue::eTypeUUID)
319 return static_cast<const OptionValueUUID *>(this);
325 OptionValue::GetBooleanValue (bool fail_value) const
327 const OptionValueBoolean *option_value = GetAsBoolean ();
329 return option_value->GetCurrentValue();
334 OptionValue::SetBooleanValue (bool new_value)
336 OptionValueBoolean *option_value = GetAsBoolean ();
339 option_value->SetCurrentValue(new_value);
346 OptionValue::GetEnumerationValue (int64_t fail_value) const
348 const OptionValueEnumeration *option_value = GetAsEnumeration();
350 return option_value->GetCurrentValue();
355 OptionValue::SetEnumerationValue (int64_t value)
357 OptionValueEnumeration *option_value = GetAsEnumeration();
360 option_value->SetCurrentValue(value);
367 OptionValue::GetFileSpecValue () const
369 const OptionValueFileSpec *option_value = GetAsFileSpec ();
371 return option_value->GetCurrentValue();
377 OptionValue::SetFileSpecValue (const FileSpec &file_spec)
379 OptionValueFileSpec *option_value = GetAsFileSpec ();
382 option_value->SetCurrentValue(file_spec, false);
389 OptionValue::GetFileSpecListValue () const
391 const OptionValueFileSpecList *option_value = GetAsFileSpecList ();
393 return option_value->GetCurrentValue();
394 return FileSpecList();
399 OptionValue::GetFormatValue (lldb::Format fail_value) const
401 const OptionValueFormat *option_value = GetAsFormat ();
403 return option_value->GetCurrentValue();
408 OptionValue::SetFormatValue (lldb::Format new_value)
410 OptionValueFormat *option_value = GetAsFormat ();
413 option_value->SetCurrentValue(new_value);
419 const RegularExpression *
420 OptionValue::GetRegexValue () const
422 const OptionValueRegex *option_value = GetAsRegex ();
424 return option_value->GetCurrentValue();
430 OptionValue::GetSInt64Value (int64_t fail_value) const
432 const OptionValueSInt64 *option_value = GetAsSInt64 ();
434 return option_value->GetCurrentValue();
439 OptionValue::SetSInt64Value (int64_t new_value)
441 OptionValueSInt64 *option_value = GetAsSInt64 ();
444 option_value->SetCurrentValue(new_value);
451 OptionValue::GetStringValue (const char *fail_value) const
453 const OptionValueString *option_value = GetAsString ();
455 return option_value->GetCurrentValue();
460 OptionValue::SetStringValue (const char *new_value)
462 OptionValueString *option_value = GetAsString ();
465 option_value->SetCurrentValue(new_value);
472 OptionValue::GetUInt64Value (uint64_t fail_value) const
474 const OptionValueUInt64 *option_value = GetAsUInt64 ();
476 return option_value->GetCurrentValue();
481 OptionValue::SetUInt64Value (uint64_t new_value)
483 OptionValueUInt64 *option_value = GetAsUInt64 ();
486 option_value->SetCurrentValue(new_value);
493 OptionValue::GetUUIDValue () const
495 const OptionValueUUID *option_value = GetAsUUID();
497 return option_value->GetCurrentValue();
502 OptionValue::SetUUIDValue (const UUID &uuid)
504 OptionValueUUID *option_value = GetAsUUID();
507 option_value->SetCurrentValue(uuid);
514 OptionValue::GetBuiltinTypeAsCString (Type t)
518 case eTypeInvalid: return "invalid";
519 case eTypeArch: return "arch";
520 case eTypeArgs: return "arguments";
521 case eTypeArray: return "array";
522 case eTypeBoolean: return "boolean";
523 case eTypeDictionary: return "dictionary";
524 case eTypeEnum: return "enum";
525 case eTypeFileSpec: return "file";
526 case eTypeFileSpecList: return "file-list";
527 case eTypeFormat: return "format";
528 case eTypePathMap: return "path-map";
529 case eTypeProperties: return "properties";
530 case eTypeRegex: return "regex";
531 case eTypeSInt64: return "int";
532 case eTypeString: return "string";
533 case eTypeUInt64: return "unsigned";
534 case eTypeUUID: return "uuid";
541 OptionValue::CreateValueFromCStringForTypeMask (const char *value_cstr, uint32_t type_mask, Error &error)
543 // If only 1 bit is set in the type mask for a dictionary or array
544 // then we know how to decode a value from a cstring
545 lldb::OptionValueSP value_sp;
548 case 1u << eTypeArch: value_sp.reset(new OptionValueArch()); break;
549 case 1u << eTypeBoolean: value_sp.reset(new OptionValueBoolean(false)); break;
550 case 1u << eTypeFileSpec: value_sp.reset(new OptionValueFileSpec()); break;
551 case 1u << eTypeFormat: value_sp.reset(new OptionValueFormat(eFormatInvalid)); break;
552 case 1u << eTypeSInt64: value_sp.reset(new OptionValueSInt64()); break;
553 case 1u << eTypeString: value_sp.reset(new OptionValueString()); break;
554 case 1u << eTypeUInt64: value_sp.reset(new OptionValueUInt64()); break;
555 case 1u << eTypeUUID: value_sp.reset(new OptionValueUUID()); break;
559 error = value_sp->SetValueFromCString (value_cstr, eVarSetOperationAssign);
561 error.SetErrorString("unsupported type mask");
566 OptionValue::DumpQualifiedName (Stream &strm) const
568 bool dumped_something = false;
569 lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
572 if (m_parent_sp->DumpQualifiedName(strm))
573 dumped_something = true;
575 ConstString name (GetName());
578 if (dumped_something)
581 dumped_something = true;
584 return dumped_something;
588 OptionValue::AutoComplete (CommandInterpreter &interpreter,
590 int match_start_point,
591 int max_return_elements,
595 word_complete = false;
597 return matches.GetSize();
601 OptionValue::SetValueFromCString (const char *value, VarSetOperationType op)
606 case eVarSetOperationReplace:
607 error.SetErrorStringWithFormat ("%s objects do not support the 'replace' operation", GetTypeAsCString());
609 case eVarSetOperationInsertBefore:
610 error.SetErrorStringWithFormat ("%s objects do not support the 'insert-before' operation", GetTypeAsCString());
612 case eVarSetOperationInsertAfter:
613 error.SetErrorStringWithFormat ("%s objects do not support the 'insert-after' operation", GetTypeAsCString());
615 case eVarSetOperationRemove:
616 error.SetErrorStringWithFormat ("%s objects do not support the 'remove' operation", GetTypeAsCString());
618 case eVarSetOperationAppend:
619 error.SetErrorStringWithFormat ("%s objects do not support the 'append' operation", GetTypeAsCString());
621 case eVarSetOperationClear:
622 error.SetErrorStringWithFormat ("%s objects do not support the 'clear' operation", GetTypeAsCString());
624 case eVarSetOperationAssign:
625 error.SetErrorStringWithFormat ("%s objects do not support the 'assign' operation", GetTypeAsCString());
627 case eVarSetOperationInvalid:
628 error.SetErrorStringWithFormat ("invalid operation performed on a %s object", GetTypeAsCString());