1 //===-- Property.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/lldb-python.h"
12 #include "lldb/Interpreter/Property.h"
16 // Other libraries and framework includes
18 #include "lldb/Core/UserSettingsController.h"
19 #include "lldb/Interpreter/Args.h"
20 #include "lldb/Interpreter/CommandInterpreter.h"
21 #include "lldb/Interpreter/OptionValues.h"
24 using namespace lldb_private;
26 Property::Property (const PropertyDefinition &definition) :
27 m_name (definition.name),
28 m_description (definition.description),
30 m_is_global (definition.global)
32 switch (definition.type)
34 case OptionValue::eTypeInvalid:
35 case OptionValue::eTypeProperties:
37 case OptionValue::eTypeArch:
38 // "definition.default_uint_value" is not used
39 // "definition.default_cstr_value" as a string value that represents the default string value for the architecture/triple
40 m_value_sp.reset (new OptionValueArch(definition.default_cstr_value));
43 case OptionValue::eTypeArgs:
44 // "definition.default_uint_value" is always a OptionValue::Type
45 m_value_sp.reset (new OptionValueArgs());
48 case OptionValue::eTypeArray:
49 // "definition.default_uint_value" is always a OptionValue::Type
50 m_value_sp.reset (new OptionValueArray(OptionValue::ConvertTypeToMask((OptionValue::Type)definition.default_uint_value)));
53 case OptionValue::eTypeBoolean:
54 // "definition.default_uint_value" is the default boolean value if
55 // "definition.default_cstr_value" is NULL, otherwise interpret
56 // "definition.default_cstr_value" as a string value that represents the default
58 if (definition.default_cstr_value)
59 m_value_sp.reset (new OptionValueBoolean(Args::StringToBoolean (definition.default_cstr_value, false, NULL)));
61 m_value_sp.reset (new OptionValueBoolean(definition.default_uint_value != 0));
64 case OptionValue::eTypeDictionary:
65 // "definition.default_uint_value" is always a OptionValue::Type
66 m_value_sp.reset (new OptionValueDictionary(OptionValue::ConvertTypeToMask((OptionValue::Type)definition.default_uint_value)));
69 case OptionValue::eTypeEnum:
70 // "definition.default_uint_value" is the default enumeration value if
71 // "definition.default_cstr_value" is NULL, otherwise interpret
72 // "definition.default_cstr_value" as a string value that represents the default
75 OptionValueEnumeration *enum_value = new OptionValueEnumeration(definition.enum_values, definition.default_uint_value);
76 m_value_sp.reset (enum_value);
77 if (definition.default_cstr_value)
79 if (enum_value->SetValueFromCString(definition.default_cstr_value).Success())
81 enum_value->SetDefaultValue(enum_value->GetCurrentValue());
82 // Call Clear() since we don't want the value to appear as
83 // having been set since we called SetValueFromCString() above.
84 // Clear will set the current value to the default and clear
85 // the boolean that says that the value has been set.
92 case OptionValue::eTypeFileSpec:
93 // "definition.default_uint_value" represents if the "definition.default_cstr_value" should
95 m_value_sp.reset (new OptionValueFileSpec(FileSpec(definition.default_cstr_value, definition.default_uint_value != 0)));
98 case OptionValue::eTypeFileSpecList:
99 // "definition.default_uint_value" is not used for a OptionValue::eTypeFileSpecList
100 m_value_sp.reset (new OptionValueFileSpecList());
103 case OptionValue::eTypeFormat:
104 // "definition.default_uint_value" is the default format enumeration value if
105 // "definition.default_cstr_value" is NULL, otherwise interpret
106 // "definition.default_cstr_value" as a string value that represents the default
109 Format new_format = eFormatInvalid;
110 if (definition.default_cstr_value)
111 Args::StringToFormat (definition.default_cstr_value, new_format, NULL);
113 new_format = (Format)definition.default_uint_value;
114 m_value_sp.reset (new OptionValueFormat(new_format));
118 case OptionValue::eTypePathMap:
119 // "definition.default_uint_value" tells us if notifications should occur for
121 m_value_sp.reset (new OptionValuePathMappings(definition.default_uint_value != 0));
124 case OptionValue::eTypeRegex:
125 // "definition.default_uint_value" is used to the regular expression flags
126 // "definition.default_cstr_value" the default regular expression value
128 m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value, definition.default_uint_value));
131 case OptionValue::eTypeSInt64:
132 // "definition.default_uint_value" is the default integer value if
133 // "definition.default_cstr_value" is NULL, otherwise interpret
134 // "definition.default_cstr_value" as a string value that represents the default
136 m_value_sp.reset (new OptionValueSInt64(definition.default_cstr_value ? Args::StringToSInt64 (definition.default_cstr_value) : definition.default_uint_value));
139 case OptionValue::eTypeUInt64:
140 // "definition.default_uint_value" is the default unsigned integer value if
141 // "definition.default_cstr_value" is NULL, otherwise interpret
142 // "definition.default_cstr_value" as a string value that represents the default
144 m_value_sp.reset (new OptionValueUInt64(definition.default_cstr_value ? Args::StringToUInt64 (definition.default_cstr_value) : definition.default_uint_value));
147 case OptionValue::eTypeUUID:
148 // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
149 // "definition.default_cstr_value" can contain a default UUID value
152 if (definition.default_cstr_value)
153 uuid.SetFromCString (definition.default_cstr_value);
154 m_value_sp.reset (new OptionValueUUID(uuid));
158 case OptionValue::eTypeString:
159 // "definition.default_uint_value" can contain the string option flags OR'ed together
160 // "definition.default_cstr_value" can contain a default string value
162 OptionValueString *string_value = new OptionValueString(definition.default_cstr_value);
163 if (definition.default_uint_value != 0)
164 string_value->GetOptions().Reset(definition.default_uint_value);
165 m_value_sp.reset (string_value);
171 Property::Property (const ConstString &name,
172 const ConstString &desc,
174 const lldb::OptionValueSP &value_sp) :
176 m_description (desc),
177 m_value_sp (value_sp),
178 m_is_global (is_global)
183 Property::DumpQualifiedName(Stream &strm) const
187 if (m_value_sp->DumpQualifiedName(strm))
197 Property::Dump (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) const
201 const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription;
202 const bool transparent = m_value_sp->ValueIsTransparent ();
203 if (dump_desc || !transparent)
205 if ((dump_mask & OptionValue::eDumpOptionName) && m_name)
207 DumpQualifiedName(strm);
208 if (dump_mask & ~OptionValue::eDumpOptionName)
214 const char *desc = GetDescription();
216 strm.Printf ("-- %s", desc);
218 if (transparent && (dump_mask == (OptionValue::eDumpOptionName | OptionValue::eDumpOptionDescription)))
221 m_value_sp->DumpValue(exe_ctx, strm, dump_mask);
227 Property::DumpDescription (CommandInterpreter &interpreter,
229 uint32_t output_width,
230 bool display_qualified_name) const
234 const char *desc = GetDescription();
238 StreamString qualified_name;
239 const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
244 if (m_value_sp->DumpQualifiedName(qualified_name))
245 strm.Printf("'%s' variables:\n\n", qualified_name.GetString().c_str());
246 sub_properties->DumpAllDescriptions(interpreter, strm);
252 if (display_qualified_name)
254 StreamString qualified_name;
255 DumpQualifiedName(qualified_name);
256 interpreter.OutputFormattedHelpText (strm,
257 qualified_name.GetString().c_str(),
264 interpreter.OutputFormattedHelpText (strm,