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/Interpreter/Property.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/UserSettingsController.h"
17 #include "lldb/Host/StringConvert.h"
18 #include "lldb/Interpreter/CommandInterpreter.h"
19 #include "lldb/Interpreter/OptionValues.h"
20 #include "lldb/Target/Language.h"
23 using namespace lldb_private;
25 Property::Property(const PropertyDefinition &definition)
26 : m_name(definition.name), m_description(definition.description),
27 m_value_sp(), m_is_global(definition.global) {
28 switch (definition.type) {
29 case OptionValue::eTypeInvalid:
30 case OptionValue::eTypeProperties:
32 case OptionValue::eTypeArch:
33 // "definition.default_uint_value" is not used
34 // "definition.default_cstr_value" as a string value that represents the
35 // default string value for the architecture/triple
36 m_value_sp.reset(new OptionValueArch(definition.default_cstr_value));
39 case OptionValue::eTypeArgs:
40 // "definition.default_uint_value" is always a OptionValue::Type
41 m_value_sp.reset(new OptionValueArgs());
44 case OptionValue::eTypeArray:
45 // "definition.default_uint_value" is always a OptionValue::Type
46 m_value_sp.reset(new OptionValueArray(OptionValue::ConvertTypeToMask(
47 (OptionValue::Type)definition.default_uint_value)));
50 case OptionValue::eTypeBoolean:
51 // "definition.default_uint_value" is the default boolean value if
52 // "definition.default_cstr_value" is NULL, otherwise interpret
53 // "definition.default_cstr_value" as a string value that represents the
55 if (definition.default_cstr_value)
56 m_value_sp.reset(new OptionValueBoolean(Args::StringToBoolean(
57 llvm::StringRef(definition.default_cstr_value), false, nullptr)));
60 new OptionValueBoolean(definition.default_uint_value != 0));
63 case OptionValue::eTypeChar: {
64 llvm::StringRef s(definition.default_cstr_value ? definition.default_cstr_value : "");
65 m_value_sp = std::make_shared<OptionValueChar>(Args::StringToChar(s, '\0', nullptr));
68 case OptionValue::eTypeDictionary:
69 // "definition.default_uint_value" is always a OptionValue::Type
70 m_value_sp.reset(new OptionValueDictionary(OptionValue::ConvertTypeToMask(
71 (OptionValue::Type)definition.default_uint_value)));
74 case OptionValue::eTypeEnum:
75 // "definition.default_uint_value" is the default enumeration value if
76 // "definition.default_cstr_value" is NULL, otherwise interpret
77 // "definition.default_cstr_value" as a string value that represents the
81 OptionValueEnumeration *enum_value = new OptionValueEnumeration(
82 definition.enum_values, definition.default_uint_value);
83 m_value_sp.reset(enum_value);
84 if (definition.default_cstr_value) {
87 llvm::StringRef(definition.default_cstr_value))
89 enum_value->SetDefaultValue(enum_value->GetCurrentValue());
90 // Call Clear() since we don't want the value to appear as
91 // having been set since we called SetValueFromString() above.
92 // Clear will set the current value to the default and clear
93 // the boolean that says that the value has been set.
100 case OptionValue::eTypeFileSpec: {
101 // "definition.default_uint_value" represents if the
102 // "definition.default_cstr_value" should
103 // be resolved or not
104 const bool resolve = definition.default_uint_value != 0;
105 m_value_sp.reset(new OptionValueFileSpec(
106 FileSpec(definition.default_cstr_value, resolve), resolve));
110 case OptionValue::eTypeFileSpecList:
111 // "definition.default_uint_value" is not used for a
112 // OptionValue::eTypeFileSpecList
113 m_value_sp.reset(new OptionValueFileSpecList());
116 case OptionValue::eTypeFormat:
117 // "definition.default_uint_value" is the default format enumeration value
119 // "definition.default_cstr_value" is NULL, otherwise interpret
120 // "definition.default_cstr_value" as a string value that represents the
124 Format new_format = eFormatInvalid;
125 if (definition.default_cstr_value)
126 Args::StringToFormat(definition.default_cstr_value, new_format,
129 new_format = (Format)definition.default_uint_value;
130 m_value_sp.reset(new OptionValueFormat(new_format));
134 case OptionValue::eTypeLanguage:
135 // "definition.default_uint_value" is the default language enumeration value
137 // "definition.default_cstr_value" is NULL, otherwise interpret
138 // "definition.default_cstr_value" as a string value that represents the
142 LanguageType new_lang = eLanguageTypeUnknown;
143 if (definition.default_cstr_value)
144 Language::GetLanguageTypeFromString(
145 llvm::StringRef(definition.default_cstr_value));
147 new_lang = (LanguageType)definition.default_uint_value;
148 m_value_sp.reset(new OptionValueLanguage(new_lang));
152 case OptionValue::eTypeFormatEntity:
153 // "definition.default_cstr_value" as a string value that represents the
156 new OptionValueFormatEntity(definition.default_cstr_value));
159 case OptionValue::eTypePathMap:
160 // "definition.default_uint_value" tells us if notifications should occur
164 new OptionValuePathMappings(definition.default_uint_value != 0));
167 case OptionValue::eTypeRegex:
168 // "definition.default_uint_value" is used to the regular expression flags
169 // "definition.default_cstr_value" the default regular expression value
171 m_value_sp.reset(new OptionValueRegex(definition.default_cstr_value));
174 case OptionValue::eTypeSInt64:
175 // "definition.default_uint_value" is the default integer value if
176 // "definition.default_cstr_value" is NULL, otherwise interpret
177 // "definition.default_cstr_value" as a string value that represents the
180 m_value_sp.reset(new OptionValueSInt64(
181 definition.default_cstr_value
182 ? StringConvert::ToSInt64(definition.default_cstr_value)
183 : definition.default_uint_value));
186 case OptionValue::eTypeUInt64:
187 // "definition.default_uint_value" is the default unsigned integer value if
188 // "definition.default_cstr_value" is NULL, otherwise interpret
189 // "definition.default_cstr_value" as a string value that represents the
192 m_value_sp.reset(new OptionValueUInt64(
193 definition.default_cstr_value
194 ? StringConvert::ToUInt64(definition.default_cstr_value)
195 : definition.default_uint_value));
198 case OptionValue::eTypeUUID:
199 // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
200 // "definition.default_cstr_value" can contain a default UUID value
203 if (definition.default_cstr_value)
204 uuid.SetFromCString(definition.default_cstr_value);
205 m_value_sp.reset(new OptionValueUUID(uuid));
209 case OptionValue::eTypeString:
210 // "definition.default_uint_value" can contain the string option flags OR'ed
212 // "definition.default_cstr_value" can contain a default string value
214 OptionValueString *string_value =
215 new OptionValueString(definition.default_cstr_value);
216 if (definition.default_uint_value != 0)
217 string_value->GetOptions().Reset(definition.default_uint_value);
218 m_value_sp.reset(string_value);
224 Property::Property(const ConstString &name, const ConstString &desc,
225 bool is_global, const lldb::OptionValueSP &value_sp)
226 : m_name(name), m_description(desc), m_value_sp(value_sp),
227 m_is_global(is_global) {}
229 bool Property::DumpQualifiedName(Stream &strm) const {
231 if (m_value_sp->DumpQualifiedName(strm))
239 void Property::Dump(const ExecutionContext *exe_ctx, Stream &strm,
240 uint32_t dump_mask) const {
242 const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription;
243 const bool transparent = m_value_sp->ValueIsTransparent();
244 if (dump_desc || !transparent) {
245 if ((dump_mask & OptionValue::eDumpOptionName) && m_name) {
246 DumpQualifiedName(strm);
247 if (dump_mask & ~OptionValue::eDumpOptionName)
252 llvm::StringRef desc = GetDescription();
254 strm << "-- " << desc;
256 if (transparent && (dump_mask == (OptionValue::eDumpOptionName |
257 OptionValue::eDumpOptionDescription)))
260 m_value_sp->DumpValue(exe_ctx, strm, dump_mask);
264 void Property::DumpDescription(CommandInterpreter &interpreter, Stream &strm,
265 uint32_t output_width,
266 bool display_qualified_name) const {
269 llvm::StringRef desc = GetDescription();
274 StreamString qualified_name;
275 const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
276 if (sub_properties) {
279 if (m_value_sp->DumpQualifiedName(qualified_name))
280 strm.Printf("'%s' variables:\n\n", qualified_name.GetData());
281 sub_properties->DumpAllDescriptions(interpreter, strm);
283 if (display_qualified_name) {
284 StreamString qualified_name;
285 DumpQualifiedName(qualified_name);
286 interpreter.OutputFormattedHelpText(strm, qualified_name.GetString(),
287 "--", desc, output_width);
289 interpreter.OutputFormattedHelpText(strm, m_name.GetStringRef(), "--",
295 void Property::SetValueChangedCallback(OptionValueChangedCallback callback,
298 m_value_sp->SetValueChangedCallback(callback, baton);