]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionValue.cpp
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionValue.cpp
1 //===-- 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
19 using namespace lldb;
20 using namespace lldb_private;
21
22
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 
26 // returned
27 //-------------------------------------------------------------------------
28 uint64_t
29 OptionValue::GetUInt64Value (uint64_t fail_value, bool *success_ptr)
30 {
31     if (success_ptr)
32         *success_ptr = true;
33     switch (GetType())
34     {
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();
38     default: 
39         break;
40     }
41     if (success_ptr)
42         *success_ptr = false;
43     return fail_value;
44 }
45
46 Error
47 OptionValue::SetSubValue (const ExecutionContext *exe_ctx,
48                           VarSetOperationType op,
49                           const char *name,
50                           const char *value)
51 {
52     Error error;
53     error.SetErrorStringWithFormat("SetSubValue is not supported");
54     return error;
55 }
56
57
58 OptionValueBoolean *
59 OptionValue::GetAsBoolean ()
60 {
61     if (GetType () == OptionValue::eTypeBoolean)
62         return static_cast<OptionValueBoolean *>(this);
63     return nullptr;
64 }
65
66 const OptionValueBoolean *
67 OptionValue::GetAsBoolean () const
68 {
69     if (GetType () == OptionValue::eTypeBoolean)
70         return static_cast<const OptionValueBoolean *>(this);
71     return nullptr;
72 }
73
74 const OptionValueChar *
75 OptionValue::GetAsChar () const
76 {
77     if (GetType () == OptionValue::eTypeChar)
78         return static_cast<const OptionValueChar *>(this);
79     return nullptr;
80 }
81
82 OptionValueChar *
83 OptionValue::GetAsChar ()
84 {
85     if (GetType () == OptionValue::eTypeChar)
86         return static_cast<OptionValueChar *>(this);
87     return nullptr;
88 }
89
90 OptionValueFileSpec *
91 OptionValue::GetAsFileSpec ()
92 {
93     if (GetType () == OptionValue::eTypeFileSpec)
94         return static_cast<OptionValueFileSpec *>(this);
95     return nullptr;
96     
97 }
98
99 const OptionValueFileSpec *
100 OptionValue::GetAsFileSpec () const
101 {
102     if (GetType () == OptionValue::eTypeFileSpec)
103         return static_cast<const OptionValueFileSpec *>(this);
104     return nullptr;
105     
106 }
107
108 OptionValueFileSpecList *
109 OptionValue::GetAsFileSpecList ()
110 {
111     if (GetType () == OptionValue::eTypeFileSpecList)
112         return static_cast<OptionValueFileSpecList *>(this);
113     return nullptr;
114     
115 }
116
117 const OptionValueFileSpecList *
118 OptionValue::GetAsFileSpecList () const
119 {
120     if (GetType () == OptionValue::eTypeFileSpecList)
121         return static_cast<const OptionValueFileSpecList *>(this);
122     return nullptr;
123     
124 }
125
126 OptionValueArch *
127 OptionValue::GetAsArch ()
128 {
129     if (GetType () == OptionValue::eTypeArch)
130         return static_cast<OptionValueArch *>(this);
131     return nullptr;
132 }
133
134
135 const OptionValueArch *
136 OptionValue::GetAsArch () const
137 {
138     if (GetType () == OptionValue::eTypeArch)
139         return static_cast<const OptionValueArch *>(this);
140     return nullptr;
141 }
142
143 OptionValueArray *
144 OptionValue::GetAsArray ()
145 {
146     if (GetType () == OptionValue::eTypeArray)
147         return static_cast<OptionValueArray *>(this);
148     return nullptr;
149 }
150
151
152 const OptionValueArray *
153 OptionValue::GetAsArray () const
154 {
155     if (GetType () == OptionValue::eTypeArray)
156         return static_cast<const OptionValueArray *>(this);
157     return nullptr;
158 }
159
160 OptionValueArgs *
161 OptionValue::GetAsArgs ()
162 {
163     if (GetType () == OptionValue::eTypeArgs)
164         return static_cast<OptionValueArgs *>(this);
165     return nullptr;
166 }
167
168
169 const OptionValueArgs *
170 OptionValue::GetAsArgs () const
171 {
172     if (GetType () == OptionValue::eTypeArgs)
173         return static_cast<const OptionValueArgs *>(this);
174     return nullptr;
175 }
176
177 OptionValueDictionary *
178 OptionValue::GetAsDictionary ()
179 {
180     if (GetType () == OptionValue::eTypeDictionary)
181         return static_cast<OptionValueDictionary *>(this);
182     return nullptr;
183 }
184
185 const OptionValueDictionary *
186 OptionValue::GetAsDictionary () const
187 {
188     if (GetType () == OptionValue::eTypeDictionary)
189         return static_cast<const OptionValueDictionary *>(this);
190     return nullptr;
191 }
192
193 OptionValueEnumeration *
194 OptionValue::GetAsEnumeration ()
195 {
196     if (GetType () == OptionValue::eTypeEnum)
197         return static_cast<OptionValueEnumeration *>(this);
198     return nullptr;
199 }
200
201 const OptionValueEnumeration *
202 OptionValue::GetAsEnumeration () const
203 {
204     if (GetType () == OptionValue::eTypeEnum)
205         return static_cast<const OptionValueEnumeration *>(this);
206     return nullptr;
207 }
208
209 OptionValueFormat *
210 OptionValue::GetAsFormat ()
211 {
212     if (GetType () == OptionValue::eTypeFormat)
213         return static_cast<OptionValueFormat *>(this);
214     return nullptr;
215 }
216
217 const OptionValueFormat *
218 OptionValue::GetAsFormat () const
219 {
220     if (GetType () == OptionValue::eTypeFormat)
221         return static_cast<const OptionValueFormat *>(this);
222     return nullptr;
223 }
224
225 OptionValuePathMappings *
226 OptionValue::GetAsPathMappings ()
227 {
228     if (GetType () == OptionValue::eTypePathMap)
229         return static_cast<OptionValuePathMappings *>(this);
230     return nullptr;
231 }
232
233 const OptionValuePathMappings *
234 OptionValue::GetAsPathMappings () const
235 {
236     if (GetType () == OptionValue::eTypePathMap)
237         return static_cast<const OptionValuePathMappings *>(this);
238     return nullptr;
239 }
240
241 OptionValueProperties *
242 OptionValue::GetAsProperties ()
243 {
244     if (GetType () == OptionValue::eTypeProperties)
245         return static_cast<OptionValueProperties *>(this);
246     return nullptr;
247 }
248
249 const OptionValueProperties *
250 OptionValue::GetAsProperties () const
251 {
252     if (GetType () == OptionValue::eTypeProperties)
253         return static_cast<const OptionValueProperties *>(this);
254     return nullptr;
255 }
256
257 OptionValueRegex *
258 OptionValue::GetAsRegex ()
259 {
260     if (GetType () == OptionValue::eTypeRegex)
261         return static_cast<OptionValueRegex *>(this);
262     return nullptr;
263 }
264
265 const OptionValueRegex *
266 OptionValue::GetAsRegex () const
267 {
268     if (GetType () == OptionValue::eTypeRegex)
269         return static_cast<const OptionValueRegex *>(this);
270     return nullptr;
271 }
272
273 OptionValueSInt64 *
274 OptionValue::GetAsSInt64 ()
275 {
276     if (GetType () == OptionValue::eTypeSInt64)
277         return static_cast<OptionValueSInt64 *>(this);
278     return nullptr;
279 }
280
281 const OptionValueSInt64 *
282 OptionValue::GetAsSInt64 () const
283 {
284     if (GetType () == OptionValue::eTypeSInt64)
285         return static_cast<const OptionValueSInt64 *>(this);
286     return nullptr;
287 }
288
289 OptionValueString *
290 OptionValue::GetAsString ()
291 {
292     if (GetType () == OptionValue::eTypeString)
293         return static_cast<OptionValueString *>(this);
294     return nullptr;
295 }
296
297 const OptionValueString *
298 OptionValue::GetAsString () const
299 {
300     if (GetType () == OptionValue::eTypeString)
301         return static_cast<const OptionValueString *>(this);
302     return nullptr;
303 }
304
305 OptionValueUInt64 *
306 OptionValue::GetAsUInt64 ()
307 {
308     if (GetType () == OptionValue::eTypeUInt64)
309         return static_cast<OptionValueUInt64 *>(this);
310     return nullptr;
311 }
312
313 const OptionValueUInt64 *
314 OptionValue::GetAsUInt64 () const
315 {
316     if (GetType () == OptionValue::eTypeUInt64)
317         return static_cast<const OptionValueUInt64 *>(this);
318     return nullptr;
319 }
320
321 OptionValueUUID *
322 OptionValue::GetAsUUID ()
323 {
324     if (GetType () == OptionValue::eTypeUUID)
325         return static_cast<OptionValueUUID *>(this);
326     return nullptr;
327     
328 }
329
330 const OptionValueUUID *
331 OptionValue::GetAsUUID () const
332 {
333     if (GetType () == OptionValue::eTypeUUID)
334         return static_cast<const OptionValueUUID *>(this);
335     return nullptr;
336     
337 }
338
339 bool
340 OptionValue::GetBooleanValue (bool fail_value) const
341 {
342     const OptionValueBoolean *option_value = GetAsBoolean ();
343     if (option_value)
344         return option_value->GetCurrentValue();
345     return fail_value;
346 }
347
348 bool
349 OptionValue::SetBooleanValue (bool new_value)
350 {
351     OptionValueBoolean *option_value = GetAsBoolean ();
352     if (option_value)
353     {
354         option_value->SetCurrentValue(new_value);
355         return true;
356     }
357     return false;
358 }
359
360 char
361 OptionValue::GetCharValue(char fail_value) const
362 {
363     const OptionValueChar *option_value = GetAsChar();
364     if (option_value)
365         return option_value->GetCurrentValue();
366     return fail_value;
367 }
368
369 char
370 OptionValue::SetCharValue(char new_value)
371 {
372     OptionValueChar *option_value = GetAsChar();
373     if (option_value)
374     {
375         option_value->SetCurrentValue(new_value);
376         return true;
377     }
378     return false;
379 }
380
381 int64_t
382 OptionValue::GetEnumerationValue (int64_t fail_value) const
383 {
384     const OptionValueEnumeration *option_value = GetAsEnumeration();
385     if (option_value)
386         return option_value->GetCurrentValue();
387     return fail_value;
388 }
389
390 bool
391 OptionValue::SetEnumerationValue (int64_t value)
392 {
393     OptionValueEnumeration *option_value = GetAsEnumeration();
394     if (option_value)
395     {
396         option_value->SetCurrentValue(value);
397         return true;
398     }
399     return false;
400 }
401
402 FileSpec
403 OptionValue::GetFileSpecValue () const
404 {
405     const OptionValueFileSpec *option_value = GetAsFileSpec ();
406     if (option_value)
407         return option_value->GetCurrentValue();
408     return FileSpec();
409 }
410
411
412 bool
413 OptionValue::SetFileSpecValue (const FileSpec &file_spec)
414 {
415     OptionValueFileSpec *option_value = GetAsFileSpec ();
416     if (option_value)
417     {
418         option_value->SetCurrentValue(file_spec, false);
419         return true;
420     }
421     return false;
422 }
423
424 FileSpecList
425 OptionValue::GetFileSpecListValue () const
426 {
427     const OptionValueFileSpecList *option_value = GetAsFileSpecList ();
428     if (option_value)
429         return option_value->GetCurrentValue();
430     return FileSpecList();
431 }
432
433
434 lldb::Format
435 OptionValue::GetFormatValue (lldb::Format fail_value) const
436 {
437     const OptionValueFormat *option_value = GetAsFormat ();
438     if (option_value)
439         return option_value->GetCurrentValue();
440     return fail_value;
441 }
442
443 bool
444 OptionValue::SetFormatValue (lldb::Format new_value)
445 {
446     OptionValueFormat *option_value = GetAsFormat ();
447     if (option_value)
448     {
449         option_value->SetCurrentValue(new_value);
450         return true;
451     }
452     return false;
453 }
454
455 const RegularExpression *
456 OptionValue::GetRegexValue () const
457 {
458     const OptionValueRegex *option_value = GetAsRegex ();
459     if (option_value)
460         return option_value->GetCurrentValue();
461     return nullptr;
462 }
463
464
465 int64_t
466 OptionValue::GetSInt64Value (int64_t fail_value) const
467 {
468     const OptionValueSInt64 *option_value = GetAsSInt64 ();
469     if (option_value)
470         return option_value->GetCurrentValue();
471     return fail_value;
472 }
473
474 bool
475 OptionValue::SetSInt64Value (int64_t new_value)
476 {
477     OptionValueSInt64 *option_value = GetAsSInt64 ();
478     if (option_value)
479     {
480         option_value->SetCurrentValue(new_value);
481         return true;
482     }
483     return false;
484 }
485
486 const char *
487 OptionValue::GetStringValue (const char *fail_value) const
488 {
489     const OptionValueString *option_value = GetAsString ();
490     if (option_value)
491         return option_value->GetCurrentValue();
492     return fail_value;
493 }
494
495 bool
496 OptionValue::SetStringValue (const char *new_value)
497 {
498     OptionValueString *option_value = GetAsString ();
499     if (option_value)
500     {
501         option_value->SetCurrentValue(new_value);
502         return true;
503     }
504     return false;
505 }
506
507 uint64_t
508 OptionValue::GetUInt64Value (uint64_t fail_value) const
509 {
510     const OptionValueUInt64 *option_value = GetAsUInt64 ();
511     if (option_value)
512         return option_value->GetCurrentValue();
513     return fail_value;
514 }
515
516 bool
517 OptionValue::SetUInt64Value (uint64_t new_value)
518 {
519     OptionValueUInt64 *option_value = GetAsUInt64 ();
520     if (option_value)
521     {
522         option_value->SetCurrentValue(new_value);
523         return true;
524     }
525     return false;
526 }
527
528 UUID
529 OptionValue::GetUUIDValue () const
530 {
531     const OptionValueUUID *option_value = GetAsUUID();
532     if (option_value)
533         return option_value->GetCurrentValue();
534     return UUID();
535 }
536
537 bool
538 OptionValue::SetUUIDValue (const UUID &uuid)
539 {
540     OptionValueUUID *option_value = GetAsUUID();
541     if (option_value)
542     {
543         option_value->SetCurrentValue(uuid);
544         return true;
545     }
546     return false;
547 }
548
549 const char *
550 OptionValue::GetBuiltinTypeAsCString (Type t)
551 {
552     switch (t)
553     {
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";
559         case eTypeChar:
560             return "char";
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";
573     }
574     return nullptr;
575 }
576
577
578 lldb::OptionValueSP
579 OptionValue::CreateValueFromCStringForTypeMask (const char *value_cstr, uint32_t type_mask, Error &error)
580 {
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;
584     switch (type_mask)
585     {
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;
595     }
596
597     if (value_sp)
598         error = value_sp->SetValueFromCString (value_cstr, eVarSetOperationAssign);
599     else
600         error.SetErrorString("unsupported type mask");
601     return value_sp;
602 }
603
604 bool
605 OptionValue::DumpQualifiedName (Stream &strm) const
606 {
607     bool dumped_something = false;
608     lldb::OptionValueSP m_parent_sp(m_parent_wp.lock());
609     if (m_parent_sp)
610     {
611         if (m_parent_sp->DumpQualifiedName(strm))
612             dumped_something = true;
613     }
614     ConstString name (GetName());
615     if (name)
616     {
617         if (dumped_something)
618             strm.PutChar('.');
619         else
620             dumped_something = true;
621         strm << name;
622     }
623     return dumped_something;
624 }
625
626 size_t
627 OptionValue::AutoComplete (CommandInterpreter &interpreter,
628                            const char *s,
629                            int match_start_point,
630                            int max_return_elements,
631                            bool &word_complete,
632                            StringList &matches)
633 {
634     word_complete = false;
635     matches.Clear();
636     return matches.GetSize();
637 }
638
639 Error
640 OptionValue::SetValueFromCString (const char *value, VarSetOperationType op)
641 {
642     Error error;
643     switch (op)
644     {
645     case eVarSetOperationReplace:
646         error.SetErrorStringWithFormat ("%s objects do not support the 'replace' operation", GetTypeAsCString());
647         break;
648     case eVarSetOperationInsertBefore:
649         error.SetErrorStringWithFormat ("%s objects do not support the 'insert-before' operation", GetTypeAsCString());
650         break;
651     case eVarSetOperationInsertAfter:
652         error.SetErrorStringWithFormat ("%s objects do not support the 'insert-after' operation", GetTypeAsCString());
653         break;
654     case eVarSetOperationRemove:
655         error.SetErrorStringWithFormat ("%s objects do not support the 'remove' operation", GetTypeAsCString());
656         break;
657     case eVarSetOperationAppend:
658         error.SetErrorStringWithFormat ("%s objects do not support the 'append' operation", GetTypeAsCString());
659         break;
660     case eVarSetOperationClear:
661         error.SetErrorStringWithFormat ("%s objects do not support the 'clear' operation", GetTypeAsCString());
662         break;
663     case eVarSetOperationAssign:
664         error.SetErrorStringWithFormat ("%s objects do not support the 'assign' operation", GetTypeAsCString());
665         break;
666     case eVarSetOperationInvalid:
667         error.SetErrorStringWithFormat ("invalid operation performed on a %s object", GetTypeAsCString());
668         break;
669     }
670     return error;
671 }
672