blob: 0497ee1c15d7c15022ca9e24194027f11afac895 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- OptionValueProperties.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/OptionValueProperties.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Flags.h"
17#include "lldb/Core/Stream.h"
18#include "lldb/Core/StringList.h"
19#include "lldb/Core/UserSettingsController.h"
20#include "lldb/Interpreter/Args.h"
21#include "lldb/Interpreter/OptionValues.h"
22#include "lldb/Interpreter/Property.h"
23
24using namespace lldb;
25using namespace lldb_private;
26
27
28OptionValueProperties::OptionValueProperties (const ConstString &name) :
Greg Clayton03da4cc2013-04-19 21:31:16 +000029 OptionValue (),
30 m_name (name),
31 m_properties (),
32 m_name_to_index ()
Greg Clayton67cc0632012-08-22 17:17:09 +000033{
34}
35
36OptionValueProperties::OptionValueProperties (const OptionValueProperties &global_properties) :
Greg Clayton03da4cc2013-04-19 21:31:16 +000037 OptionValue (global_properties),
Saleem Abdulrasoole0147292014-06-13 03:30:45 +000038 std::enable_shared_from_this<OptionValueProperties> (),
Greg Clayton67cc0632012-08-22 17:17:09 +000039 m_name (global_properties.m_name),
40 m_properties (global_properties.m_properties),
41 m_name_to_index (global_properties.m_name_to_index)
42{
43 // We now have an exact copy of "global_properties". We need to now
44 // find all non-global settings and copy the property values so that
45 // all non-global settings get new OptionValue instances created for
46 // them.
47 const size_t num_properties = m_properties.size();
48 for (size_t i=0; i<num_properties; ++i)
49 {
Bruce Mitchener6a7f3332014-06-27 02:42:12 +000050 // Duplicate any values that are not global when constructing properties from
Greg Clayton67cc0632012-08-22 17:17:09 +000051 // a global copy
52 if (m_properties[i].IsGlobal() == false)
53 {
54 lldb::OptionValueSP new_value_sp (m_properties[i].GetValue()->DeepCopy());
55 m_properties[i].SetOptionValue(new_value_sp);
56 }
57 }
58}
59
60
61
62size_t
63OptionValueProperties::GetNumProperties() const
64{
65 return m_properties.size();
66}
67
68
69void
70OptionValueProperties::Initialize (const PropertyDefinition *defs)
71{
72 for (size_t i=0; defs[i].name; ++i)
73 {
74 Property property(defs[i]);
75 assert(property.IsValid());
76 m_name_to_index.Append(property.GetName().GetCString(),m_properties.size());
77 property.GetValue()->SetParent(shared_from_this());
78 m_properties.push_back(property);
79 }
80 m_name_to_index.Sort();
81}
82
83void
84OptionValueProperties::AppendProperty(const ConstString &name,
85 const ConstString &desc,
86 bool is_global,
87 const OptionValueSP &value_sp)
88{
89 Property property(name, desc, is_global, value_sp);
90 m_name_to_index.Append(name.GetCString(),m_properties.size());
91 m_properties.push_back(property);
92 value_sp->SetParent (shared_from_this());
93 m_name_to_index.Sort();
94}
95
96
97
98//bool
99//OptionValueProperties::GetQualifiedName (Stream &strm)
100//{
101// bool dumped_something = false;
102//// lldb::OptionValuePropertiesSP parent_sp(GetParent ());
103//// if (parent_sp)
104//// {
105//// parent_sp->GetQualifiedName (strm);
106//// strm.PutChar('.');
107//// dumped_something = true;
108//// }
109// if (m_name)
110// {
111// strm << m_name;
112// dumped_something = true;
113// }
114// return dumped_something;
115//}
116//
117lldb::OptionValueSP
118OptionValueProperties::GetValueForKey (const ExecutionContext *exe_ctx,
119 const ConstString &key,
120 bool will_modify) const
121{
122 lldb::OptionValueSP value_sp;
123 size_t idx = m_name_to_index.Find (key.GetCString(), SIZE_MAX);
124 if (idx < m_properties.size())
125 value_sp = GetPropertyAtIndex(exe_ctx, will_modify, idx)->GetValue();
126 return value_sp;
127}
128
129lldb::OptionValueSP
130OptionValueProperties::GetSubValue (const ExecutionContext *exe_ctx,
131 const char *name,
132 bool will_modify,
133 Error &error) const
134{
135 lldb::OptionValueSP value_sp;
136
137 if (name && name[0])
138 {
Ed Masted78c9572014-04-20 00:31:37 +0000139 const char *sub_name = nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000140 ConstString key;
141 size_t key_len = ::strcspn (name, ".[{");
142
143 if (name[key_len])
144 {
145 key.SetCStringWithLength (name, key_len);
146 sub_name = name + key_len;
147 }
148 else
149 key.SetCString (name);
150
151 value_sp = GetValueForKey (exe_ctx, key, will_modify);
152 if (sub_name && value_sp)
153 {
154 switch (sub_name[0])
155 {
156 case '.':
157 return value_sp->GetSubValue (exe_ctx, sub_name + 1, will_modify, error);
158
159 case '{':
160 // Predicate matching for predicates like
161 // "<setting-name>{<predicate>}"
162 // strings are parsed by the current OptionValueProperties subclass
163 // to mean whatever they want to. For instance a subclass of
164 // OptionValueProperties for a lldb_private::Target might implement:
165 // "target.run-args{arch==i386}" -- only set run args if the arch is i386
166 // "target.run-args{path=/tmp/a/b/c/a.out}" -- only set run args if the path matches
Bruce Mitchener6a7f3332014-06-27 02:42:12 +0000167 // "target.run-args{basename==test&&arch==x86_64}" -- only set run args if executable basename is "test" and arch is "x86_64"
Greg Clayton67cc0632012-08-22 17:17:09 +0000168 if (sub_name[1])
169 {
170 const char *predicate_start = sub_name + 1;
171 const char *predicate_end = strchr(predicate_start, '}');
172 if (predicate_end)
173 {
174 std::string predicate(predicate_start, predicate_end);
175 if (PredicateMatches(exe_ctx, predicate.c_str()))
176 {
177 if (predicate_end[1])
178 {
179 // Still more subvalue string to evaluate
180 return value_sp->GetSubValue (exe_ctx, predicate_end + 1, will_modify, error);
181 }
182 else
183 {
184 // We have a match!
185 break;
186 }
187 }
188 }
189 }
190 // Predicate didn't match or wasn't correctly formed
191 value_sp.reset();
192 break;
193
194 case '[':
195 // Array or dictionary access for subvalues like:
196 // "[12]" -- access 12th array element
197 // "['hello']" -- dictionary access of key named hello
198 return value_sp->GetSubValue (exe_ctx, sub_name, will_modify, error);
199
200 default:
201 value_sp.reset();
202 break;
203 }
204 }
205 }
206 return value_sp;
207}
208
209Error
210OptionValueProperties::SetSubValue (const ExecutionContext *exe_ctx,
211 VarSetOperationType op,
212 const char *name,
213 const char *value)
214{
215 Error error;
216 const bool will_modify = true;
217 lldb::OptionValueSP value_sp (GetSubValue (exe_ctx, name, will_modify, error));
218 if (value_sp)
219 error = value_sp->SetValueFromCString(value, op);
220 else
221 {
Ed Masted78c9572014-04-20 00:31:37 +0000222 if (error.AsCString() == nullptr)
Greg Clayton67cc0632012-08-22 17:17:09 +0000223 error.SetErrorStringWithFormat("invalid value path '%s'", name);
224 }
225 return error;
226}
227
228
229ConstString
230OptionValueProperties::GetPropertyNameAtIndex (uint32_t idx) const
231{
Ed Masted78c9572014-04-20 00:31:37 +0000232 const Property *property = GetPropertyAtIndex(nullptr, false, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000233 if (property)
234 return property->GetName();
235 return ConstString();
236
237}
238
239const char *
240OptionValueProperties::GetPropertyDescriptionAtIndex (uint32_t idx) const
241{
Ed Masted78c9572014-04-20 00:31:37 +0000242 const Property *property = GetPropertyAtIndex(nullptr, false, idx);
Greg Clayton67cc0632012-08-22 17:17:09 +0000243 if (property)
244 return property->GetDescription();
Ed Masted78c9572014-04-20 00:31:37 +0000245 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000246}
247
248uint32_t
249OptionValueProperties::GetPropertyIndex (const ConstString &name) const
250{
251 return m_name_to_index.Find (name.GetCString(), SIZE_MAX);
252}
253
254const Property *
255OptionValueProperties::GetProperty (const ExecutionContext *exe_ctx, bool will_modify, const ConstString &name) const
256{
257 return GetPropertyAtIndex (exe_ctx, will_modify, m_name_to_index.Find (name.GetCString(), SIZE_MAX));
258}
259
260const Property *
261OptionValueProperties::GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
262{
263 return ProtectedGetPropertyAtIndex (idx);
264}
265
266lldb::OptionValueSP
267OptionValueProperties::GetPropertyValueAtIndex (const ExecutionContext *exe_ctx,
268 bool will_modify,
269 uint32_t idx) const
270{
271 const Property *setting = GetPropertyAtIndex (exe_ctx, will_modify, idx);
272 if (setting)
273 return setting->GetValue();
274 return OptionValueSP();
275}
276
277OptionValuePathMappings *
278OptionValueProperties::GetPropertyAtIndexAsOptionValuePathMappings (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
279{
280 OptionValueSP value_sp(GetPropertyValueAtIndex (exe_ctx, will_modify, idx));
281 if (value_sp)
282 return value_sp->GetAsPathMappings();
Ed Masted78c9572014-04-20 00:31:37 +0000283 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000284}
285
286OptionValueFileSpecList *
287OptionValueProperties::GetPropertyAtIndexAsOptionValueFileSpecList (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
288{
289 OptionValueSP value_sp(GetPropertyValueAtIndex (exe_ctx, will_modify, idx));
290 if (value_sp)
291 return value_sp->GetAsFileSpecList();
Ed Masted78c9572014-04-20 00:31:37 +0000292 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000293}
294
295OptionValueArch *
296OptionValueProperties::GetPropertyAtIndexAsOptionValueArch (const ExecutionContext *exe_ctx, uint32_t idx) const
297{
298 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
299 if (property)
300 return property->GetValue()->GetAsArch();
Ed Masted78c9572014-04-20 00:31:37 +0000301 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000302}
303
304bool
305OptionValueProperties::GetPropertyAtIndexAsArgs (const ExecutionContext *exe_ctx, uint32_t idx, Args &args) const
306{
307 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
308 if (property)
309 {
310 OptionValue *value = property->GetValue().get();
311 if (value)
312 {
313 const OptionValueArray *array = value->GetAsArray();
314 if (array)
315 return array->GetArgs(args);
316 else
317 {
318 const OptionValueDictionary *dict = value->GetAsDictionary();
319 if (dict)
320 return dict->GetArgs(args);
321 }
322 }
323 }
324 return false;
325}
326
327bool
328OptionValueProperties::SetPropertyAtIndexFromArgs (const ExecutionContext *exe_ctx, uint32_t idx, const Args &args)
329{
330 const Property *property = GetPropertyAtIndex (exe_ctx, true, idx);
331 if (property)
332 {
333 OptionValue *value = property->GetValue().get();
334 if (value)
335 {
336 OptionValueArray *array = value->GetAsArray();
337 if (array)
338 return array->SetArgs(args, eVarSetOperationAssign).Success();
339 else
340 {
341 OptionValueDictionary *dict = value->GetAsDictionary();
342 if (dict)
343 return dict->SetArgs(args, eVarSetOperationAssign).Success();
344 }
345 }
346 }
347 return false;
348}
349
350bool
351OptionValueProperties::GetPropertyAtIndexAsBoolean (const ExecutionContext *exe_ctx, uint32_t idx, bool fail_value) const
352{
353 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
354 if (property)
355 {
356 OptionValue *value = property->GetValue().get();
357 if (value)
358 return value->GetBooleanValue(fail_value);
359 }
360 return fail_value;
361}
362
363bool
364OptionValueProperties::SetPropertyAtIndexAsBoolean (const ExecutionContext *exe_ctx, uint32_t idx, bool new_value)
365{
366 const Property *property = GetPropertyAtIndex (exe_ctx, true, idx);
367 if (property)
368 {
369 OptionValue *value = property->GetValue().get();
370 if (value)
371 {
372 value->SetBooleanValue(new_value);
373 return true;
374 }
375 }
376 return false;
377}
378
379OptionValueDictionary *
380OptionValueProperties::GetPropertyAtIndexAsOptionValueDictionary (const ExecutionContext *exe_ctx, uint32_t idx) const
381{
382 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
383 if (property)
384 return property->GetValue()->GetAsDictionary();
Ed Masted78c9572014-04-20 00:31:37 +0000385 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000386}
387
388int64_t
389OptionValueProperties::GetPropertyAtIndexAsEnumeration (const ExecutionContext *exe_ctx, uint32_t idx, int64_t fail_value) const
390{
391 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
392 if (property)
393 {
394 OptionValue *value = property->GetValue().get();
395 if (value)
396 return value->GetEnumerationValue(fail_value);
397 }
398 return fail_value;
399}
400
401bool
402OptionValueProperties::SetPropertyAtIndexAsEnumeration (const ExecutionContext *exe_ctx, uint32_t idx, int64_t new_value)
403{
404 const Property *property = GetPropertyAtIndex (exe_ctx, true, idx);
405 if (property)
406 {
407 OptionValue *value = property->GetValue().get();
408 if (value)
409 return value->SetEnumerationValue(new_value);
410 }
411 return false;
412}
413
414
Greg Clayton6920b522012-08-22 18:39:03 +0000415OptionValueFileSpec *
416OptionValueProperties::GetPropertyAtIndexAsOptionValueFileSpec (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
417{
418 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
419 if (property)
420 {
421 OptionValue *value = property->GetValue().get();
422 if (value)
423 return value->GetAsFileSpec();
424 }
Ed Masted78c9572014-04-20 00:31:37 +0000425 return nullptr;
Greg Clayton6920b522012-08-22 18:39:03 +0000426}
427
428
Greg Clayton67cc0632012-08-22 17:17:09 +0000429FileSpec
430OptionValueProperties::GetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx) const
431{
432 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
433 if (property)
434 {
435 OptionValue *value = property->GetValue().get();
436 if (value)
437 return value->GetFileSpecValue();
438 }
439 return FileSpec();
440}
441
442
443bool
444OptionValueProperties::SetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx, const FileSpec &new_file_spec)
445{
446 const Property *property = GetPropertyAtIndex (exe_ctx, true, idx);
447 if (property)
448 {
449 OptionValue *value = property->GetValue().get();
450 if (value)
451 return value->SetFileSpecValue(new_file_spec);
452 }
453 return false;
454}
455
456const RegularExpression *
457OptionValueProperties::GetPropertyAtIndexAsOptionValueRegex (const ExecutionContext *exe_ctx, uint32_t idx) const
458{
459 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
460 if (property)
461 {
462 OptionValue *value = property->GetValue().get();
463 if (value)
464 return value->GetRegexValue();
465 }
Ed Masted78c9572014-04-20 00:31:37 +0000466 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000467}
468
469OptionValueSInt64 *
470OptionValueProperties::GetPropertyAtIndexAsOptionValueSInt64 (const ExecutionContext *exe_ctx, uint32_t idx) const
471{
472 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
473 if (property)
474 {
475 OptionValue *value = property->GetValue().get();
476 if (value)
477 return value->GetAsSInt64();
478 }
Ed Masted78c9572014-04-20 00:31:37 +0000479 return nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000480}
481
482int64_t
483OptionValueProperties::GetPropertyAtIndexAsSInt64 (const ExecutionContext *exe_ctx, uint32_t idx, int64_t fail_value) const
484{
485 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
486 if (property)
487 {
488 OptionValue *value = property->GetValue().get();
489 if (value)
490 return value->GetSInt64Value(fail_value);
491 }
492 return fail_value;
493}
494
495bool
496OptionValueProperties::SetPropertyAtIndexAsSInt64 (const ExecutionContext *exe_ctx, uint32_t idx, int64_t new_value)
497{
498 const Property *property = GetPropertyAtIndex (exe_ctx, true, idx);
499 if (property)
500 {
501 OptionValue *value = property->GetValue().get();
502 if (value)
503 return value->SetSInt64Value(new_value);
504 }
505 return false;
506}
507
508const char *
509OptionValueProperties::GetPropertyAtIndexAsString (const ExecutionContext *exe_ctx, uint32_t idx, const char *fail_value) const
510{
511 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
512 if (property)
513 {
514 OptionValue *value = property->GetValue().get();
515 if (value)
516 return value->GetStringValue(fail_value);
517 }
518 return fail_value;
519}
520
521bool
522OptionValueProperties::SetPropertyAtIndexAsString (const ExecutionContext *exe_ctx, uint32_t idx, const char *new_value)
523{
524 const Property *property = GetPropertyAtIndex (exe_ctx, true, idx);
525 if (property)
526 {
527 OptionValue *value = property->GetValue().get();
528 if (value)
529 return value->SetStringValue(new_value);
530 }
531 return false;
532}
533
Greg Clayton4c054102012-09-01 00:38:36 +0000534OptionValueString *
535OptionValueProperties::GetPropertyAtIndexAsOptionValueString (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
536{
537 OptionValueSP value_sp(GetPropertyValueAtIndex (exe_ctx, will_modify, idx));
538 if (value_sp)
539 return value_sp->GetAsString();
Ed Masted78c9572014-04-20 00:31:37 +0000540 return nullptr;
Greg Clayton4c054102012-09-01 00:38:36 +0000541}
542
543
Greg Clayton67cc0632012-08-22 17:17:09 +0000544uint64_t
545OptionValueProperties::GetPropertyAtIndexAsUInt64 (const ExecutionContext *exe_ctx, uint32_t idx, uint64_t fail_value) const
546{
547 const Property *property = GetPropertyAtIndex (exe_ctx, false, idx);
548 if (property)
549 {
550 OptionValue *value = property->GetValue().get();
551 if (value)
552 return value->GetUInt64Value(fail_value);
553 }
554 return fail_value;
555}
556
557bool
558OptionValueProperties::SetPropertyAtIndexAsUInt64 (const ExecutionContext *exe_ctx, uint32_t idx, uint64_t new_value)
559{
560 const Property *property = GetPropertyAtIndex (exe_ctx, true, idx);
561 if (property)
562 {
563 OptionValue *value = property->GetValue().get();
564 if (value)
565 return value->SetUInt64Value(new_value);
566 }
567 return false;
568}
569
570bool
571OptionValueProperties::Clear ()
572{
573 const size_t num_properties = m_properties.size();
574 for (size_t i=0; i<num_properties; ++i)
575 m_properties[i].GetValue()->Clear();
576 return true;
577}
578
579
580Error
581OptionValueProperties::SetValueFromCString (const char *value, VarSetOperationType op)
582{
583 Error error;
584
585// Args args(value_cstr);
586// const size_t argc = args.GetArgumentCount();
587 switch (op)
588 {
589 case eVarSetOperationClear:
590 Clear ();
591 break;
592
593 case eVarSetOperationReplace:
594 case eVarSetOperationAssign:
595 case eVarSetOperationRemove:
596 case eVarSetOperationInsertBefore:
597 case eVarSetOperationInsertAfter:
598 case eVarSetOperationAppend:
599 case eVarSetOperationInvalid:
600 error = OptionValue::SetValueFromCString (value, op);
601 break;
602 }
603
604 return error;
605}
606
607void
608OptionValueProperties::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
609{
610 const size_t num_properties = m_properties.size();
611 for (size_t i=0; i<num_properties; ++i)
612 {
613 const Property *property = GetPropertyAtIndex(exe_ctx, false, i);
614 if (property)
615 {
616 OptionValue *option_value = property->GetValue().get();
617 assert (option_value);
618 const bool transparent_value = option_value->ValueIsTransparent ();
619 property->Dump (exe_ctx,
620 strm,
621 dump_mask);
622 if (!transparent_value)
623 strm.EOL();
624 }
625 }
626}
627
628Error
629OptionValueProperties::DumpPropertyValue (const ExecutionContext *exe_ctx,
630 Stream &strm,
631 const char *property_path,
632 uint32_t dump_mask)
633{
634 Error error;
635 const bool will_modify = false;
636 lldb::OptionValueSP value_sp (GetSubValue (exe_ctx, property_path, will_modify, error));
637 if (value_sp)
638 {
639 if (!value_sp->ValueIsTransparent ())
640 {
641 if (dump_mask & eDumpOptionName)
642 strm.PutCString (property_path);
643 if (dump_mask & ~eDumpOptionName)
644 strm.PutChar (' ');
645 }
646 value_sp->DumpValue (exe_ctx, strm, dump_mask);
647 }
648 return error;
649}
650
651lldb::OptionValueSP
652OptionValueProperties::DeepCopy () const
653{
654 assert(!"this shouldn't happen");
Virgile Bello51d21912013-09-05 16:57:48 +0000655 return lldb::OptionValueSP();
Greg Clayton67cc0632012-08-22 17:17:09 +0000656}
657
658const Property *
659OptionValueProperties::GetPropertyAtPath (const ExecutionContext *exe_ctx,
660 bool will_modify,
661 const char *name) const
662{
Ed Masted78c9572014-04-20 00:31:37 +0000663 const Property *property = nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000664 if (name && name[0])
665 {
Ed Masted78c9572014-04-20 00:31:37 +0000666 const char *sub_name = nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000667 ConstString key;
668 size_t key_len = ::strcspn (name, ".[{");
669
670 if (name[key_len])
671 {
672 key.SetCStringWithLength (name, key_len);
673 sub_name = name + key_len;
674 }
675 else
676 key.SetCString (name);
677
678 property = GetProperty (exe_ctx, will_modify, key);
679 if (sub_name && property)
680 {
681 if (sub_name[0] == '.')
682 {
683 OptionValueProperties *sub_properties = property->GetValue()->GetAsProperties();
684 if (sub_properties)
685 return sub_properties->GetPropertyAtPath(exe_ctx, will_modify, sub_name + 1);
686 }
Ed Masted78c9572014-04-20 00:31:37 +0000687 property = nullptr;
Greg Clayton67cc0632012-08-22 17:17:09 +0000688 }
689 }
690 return property;
691}
692
693void
694OptionValueProperties::DumpAllDescriptions (CommandInterpreter &interpreter,
695 Stream &strm) const
696{
697 size_t max_name_len = 0;
698 const size_t num_properties = m_properties.size();
699 for (size_t i=0; i<num_properties; ++i)
700 {
701 const Property *property = ProtectedGetPropertyAtIndex(i);
702 if (property)
703 max_name_len = std::max<size_t>(property->GetName().GetLength(), max_name_len);
704 }
705 for (size_t i=0; i<num_properties; ++i)
706 {
707 const Property *property = ProtectedGetPropertyAtIndex(i);
708 if (property)
709 property->DumpDescription (interpreter, strm, max_name_len, false);
710 }
711}
712
713void
714OptionValueProperties::Apropos (const char *keyword, std::vector<const Property *> &matching_properties) const
715{
716 const size_t num_properties = m_properties.size();
717 StreamString strm;
718 for (size_t i=0; i<num_properties; ++i)
719 {
720 const Property *property = ProtectedGetPropertyAtIndex(i);
721 if (property)
722 {
723 const OptionValueProperties *properties = property->GetValue()->GetAsProperties();
724 if (properties)
725 {
726 properties->Apropos (keyword, matching_properties);
727 }
728 else
729 {
730 bool match = false;
731 const char *name = property->GetName().GetCString();
732 if (name && ::strcasestr(name, keyword))
733 match = true;
734 else
735 {
736 const char *desc = property->GetDescription();
737 if (desc && ::strcasestr(desc, keyword))
738 match = true;
739 }
740 if (match)
741 {
742 matching_properties.push_back (property);
743 }
744 }
745 }
746 }
747}
748
Greg Claytone8cd0c92012-10-19 18:02:49 +0000749lldb::OptionValuePropertiesSP
750OptionValueProperties::GetSubProperty (const ExecutionContext *exe_ctx,
751 const ConstString &name)
752{
753 lldb::OptionValueSP option_value_sp(GetValueForKey(exe_ctx, name, false));
754 if (option_value_sp)
755 {
756 OptionValueProperties *ov_properties = option_value_sp->GetAsProperties ();
757 if (ov_properties)
758 return ov_properties->shared_from_this();
759 }
760 return lldb::OptionValuePropertiesSP();
761}
762
763
Greg Clayton67cc0632012-08-22 17:17:09 +0000764