blob: 492a8017c6069b764e213591d618858adc82dfe8 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- Property.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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton67cc0632012-08-22 17:17:09 +000012#include "lldb/Interpreter/Property.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/UserSettingsController.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000019#include "lldb/Host/StringConvert.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000020#include "lldb/Interpreter/CommandInterpreter.h"
21#include "lldb/Interpreter/OptionValues.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26Property::Property (const PropertyDefinition &definition) :
27 m_name (definition.name),
28 m_description (definition.description),
29 m_value_sp (),
30 m_is_global (definition.global)
31{
32 switch (definition.type)
33 {
34 case OptionValue::eTypeInvalid:
35 case OptionValue::eTypeProperties:
36 break;
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));
41 break;
42
43 case OptionValue::eTypeArgs:
44 // "definition.default_uint_value" is always a OptionValue::Type
45 m_value_sp.reset (new OptionValueArgs());
46 break;
47
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)));
51 break;
52
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
57 // value.
58 if (definition.default_cstr_value)
Ed Masted78c9572014-04-20 00:31:37 +000059 m_value_sp.reset (new OptionValueBoolean(Args::StringToBoolean (definition.default_cstr_value, false, nullptr)));
Greg Clayton67cc0632012-08-22 17:17:09 +000060 else
61 m_value_sp.reset (new OptionValueBoolean(definition.default_uint_value != 0));
62 break;
Zachary Turner3e7442b2015-01-12 20:44:02 +000063
64 case OptionValue::eTypeChar:
65 m_value_sp.reset(new OptionValueChar(Args::StringToChar(definition.default_cstr_value, '\0', nullptr)));
66 break;
67
Greg Clayton67cc0632012-08-22 17:17:09 +000068 case OptionValue::eTypeDictionary:
69 // "definition.default_uint_value" is always a OptionValue::Type
70 m_value_sp.reset (new OptionValueDictionary(OptionValue::ConvertTypeToMask((OptionValue::Type)definition.default_uint_value)));
71 break;
72
73 case OptionValue::eTypeEnum:
74 // "definition.default_uint_value" is the default enumeration value if
75 // "definition.default_cstr_value" is NULL, otherwise interpret
76 // "definition.default_cstr_value" as a string value that represents the default
77 // value.
78 {
79 OptionValueEnumeration *enum_value = new OptionValueEnumeration(definition.enum_values, definition.default_uint_value);
80 m_value_sp.reset (enum_value);
81 if (definition.default_cstr_value)
82 {
Pavel Labathc95f7e22015-02-20 11:14:59 +000083 if (enum_value->SetValueFromString(definition.default_cstr_value).Success())
Greg Clayton67cc0632012-08-22 17:17:09 +000084 {
85 enum_value->SetDefaultValue(enum_value->GetCurrentValue());
86 // Call Clear() since we don't want the value to appear as
Pavel Labathc95f7e22015-02-20 11:14:59 +000087 // having been set since we called SetValueFromString() above.
Greg Clayton67cc0632012-08-22 17:17:09 +000088 // Clear will set the current value to the default and clear
89 // the boolean that says that the value has been set.
90 enum_value->Clear();
91 }
92 }
93 }
94 break;
95
96 case OptionValue::eTypeFileSpec:
Vince Harron1f4706c2015-02-18 23:12:26 +000097 {
Greg Clayton67cc0632012-08-22 17:17:09 +000098 // "definition.default_uint_value" represents if the "definition.default_cstr_value" should
99 // be resolved or not
Vince Harron1f4706c2015-02-18 23:12:26 +0000100 const bool resolve = definition.default_uint_value != 0;
101 m_value_sp.reset (new OptionValueFileSpec(FileSpec(definition.default_cstr_value, resolve), resolve));
Greg Clayton67cc0632012-08-22 17:17:09 +0000102 break;
Vince Harron1f4706c2015-02-18 23:12:26 +0000103 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000104
105 case OptionValue::eTypeFileSpecList:
106 // "definition.default_uint_value" is not used for a OptionValue::eTypeFileSpecList
107 m_value_sp.reset (new OptionValueFileSpecList());
108 break;
109
110 case OptionValue::eTypeFormat:
111 // "definition.default_uint_value" is the default format enumeration value if
112 // "definition.default_cstr_value" is NULL, otherwise interpret
113 // "definition.default_cstr_value" as a string value that represents the default
114 // value.
Greg Clayton554f68d2015-02-04 22:00:53 +0000115 {
116 Format new_format = eFormatInvalid;
117 if (definition.default_cstr_value)
118 Args::StringToFormat (definition.default_cstr_value, new_format, nullptr);
119 else
120 new_format = (Format)definition.default_uint_value;
121 m_value_sp.reset (new OptionValueFormat(new_format));
122 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000123 break;
124
Enrico Granata8fdf7852015-02-20 19:46:30 +0000125 case OptionValue::eTypeLanguage:
126 // "definition.default_uint_value" is the default language enumeration value if
127 // "definition.default_cstr_value" is NULL, otherwise interpret
128 // "definition.default_cstr_value" as a string value that represents the default
129 // value.
130 {
131 LanguageType new_lang = eLanguageTypeUnknown;
132 if (definition.default_cstr_value)
133 LanguageRuntime::GetLanguageTypeFromString(definition.default_cstr_value);
134 else
135 new_lang = (LanguageType)definition.default_uint_value;
136 m_value_sp.reset (new OptionValueLanguage(new_lang));
137 }
138 break;
139
Greg Clayton554f68d2015-02-04 22:00:53 +0000140 case OptionValue::eTypeFormatEntity:
141 // "definition.default_cstr_value" as a string value that represents the default
142 m_value_sp.reset (new OptionValueFormatEntity(definition.default_cstr_value));
143 break;
144
Greg Clayton67cc0632012-08-22 17:17:09 +0000145 case OptionValue::eTypePathMap:
146 // "definition.default_uint_value" tells us if notifications should occur for
147 // path mappings
148 m_value_sp.reset (new OptionValuePathMappings(definition.default_uint_value != 0));
149 break;
150
151 case OptionValue::eTypeRegex:
152 // "definition.default_uint_value" is used to the regular expression flags
153 // "definition.default_cstr_value" the default regular expression value
154 // value.
Greg Clayton7bd4c602015-01-21 21:51:02 +0000155 m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value));
Greg Clayton67cc0632012-08-22 17:17:09 +0000156 break;
157
158 case OptionValue::eTypeSInt64:
159 // "definition.default_uint_value" is the default integer value if
160 // "definition.default_cstr_value" is NULL, otherwise interpret
161 // "definition.default_cstr_value" as a string value that represents the default
162 // value.
Vince Harron5275aaa2015-01-15 20:08:35 +0000163 m_value_sp.reset (new OptionValueSInt64(definition.default_cstr_value ? StringConvert::ToSInt64 (definition.default_cstr_value) : definition.default_uint_value));
Greg Clayton67cc0632012-08-22 17:17:09 +0000164 break;
165
166 case OptionValue::eTypeUInt64:
167 // "definition.default_uint_value" is the default unsigned integer value if
168 // "definition.default_cstr_value" is NULL, otherwise interpret
169 // "definition.default_cstr_value" as a string value that represents the default
170 // value.
Vince Harron5275aaa2015-01-15 20:08:35 +0000171 m_value_sp.reset (new OptionValueUInt64(definition.default_cstr_value ? StringConvert::ToUInt64 (definition.default_cstr_value) : definition.default_uint_value));
Greg Clayton67cc0632012-08-22 17:17:09 +0000172 break;
173
174 case OptionValue::eTypeUUID:
175 // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
176 // "definition.default_cstr_value" can contain a default UUID value
Greg Clayton554f68d2015-02-04 22:00:53 +0000177 {
178 UUID uuid;
179 if (definition.default_cstr_value)
180 uuid.SetFromCString (definition.default_cstr_value);
181 m_value_sp.reset (new OptionValueUUID(uuid));
182 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000183 break;
184
185 case OptionValue::eTypeString:
Greg Clayton4c054102012-09-01 00:38:36 +0000186 // "definition.default_uint_value" can contain the string option flags OR'ed together
Greg Clayton67cc0632012-08-22 17:17:09 +0000187 // "definition.default_cstr_value" can contain a default string value
Greg Clayton4c054102012-09-01 00:38:36 +0000188 {
189 OptionValueString *string_value = new OptionValueString(definition.default_cstr_value);
190 if (definition.default_uint_value != 0)
191 string_value->GetOptions().Reset(definition.default_uint_value);
192 m_value_sp.reset (string_value);
193 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000194 break;
195 }
196}
197
198Property::Property (const ConstString &name,
199 const ConstString &desc,
200 bool is_global,
201 const lldb::OptionValueSP &value_sp) :
202 m_name (name),
203 m_description (desc),
204 m_value_sp (value_sp),
205 m_is_global (is_global)
206{
207}
208
209bool
210Property::DumpQualifiedName(Stream &strm) const
211{
212 if (m_name)
213 {
214 if (m_value_sp->DumpQualifiedName(strm))
215 strm.PutChar('.');
216 strm << m_name;
217 return true;
218 }
219 return false;
220}
221
222
223void
224Property::Dump (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) const
225{
226 if (m_value_sp)
227 {
228 const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription;
229 const bool transparent = m_value_sp->ValueIsTransparent ();
230 if (dump_desc || !transparent)
231 {
232 if ((dump_mask & OptionValue::eDumpOptionName) && m_name)
233 {
234 DumpQualifiedName(strm);
235 if (dump_mask & ~OptionValue::eDumpOptionName)
236 strm.PutChar(' ');
237 }
238 }
239 if (dump_desc)
240 {
241 const char *desc = GetDescription();
242 if (desc)
243 strm.Printf ("-- %s", desc);
244
245 if (transparent && (dump_mask == (OptionValue::eDumpOptionName | OptionValue::eDumpOptionDescription)))
246 strm.EOL();
247 }
248 m_value_sp->DumpValue(exe_ctx, strm, dump_mask);
249 }
250}
251
252
253void
254Property::DumpDescription (CommandInterpreter &interpreter,
255 Stream &strm,
256 uint32_t output_width,
257 bool display_qualified_name) const
258{
259 if (m_value_sp)
260 {
261 const char *desc = GetDescription();
262
263 if (desc)
264 {
265 StreamString qualified_name;
266 const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
267 if (sub_properties)
268 {
269 strm.EOL();
270
271 if (m_value_sp->DumpQualifiedName(qualified_name))
272 strm.Printf("'%s' variables:\n\n", qualified_name.GetString().c_str());
273 sub_properties->DumpAllDescriptions(interpreter, strm);
274 }
275 else
276 {
277 if (desc)
278 {
279 if (display_qualified_name)
280 {
281 StreamString qualified_name;
282 DumpQualifiedName(qualified_name);
283 interpreter.OutputFormattedHelpText (strm,
284 qualified_name.GetString().c_str(),
285 "--",
286 desc,
287 output_width);
288 }
289 else
290 {
291 interpreter.OutputFormattedHelpText (strm,
292 m_name.GetCString(),
293 "--",
294 desc,
295 output_width);
296 }
297 }
298 }
299 }
300 }
301}
302
Greg Clayton332e8b12015-01-13 21:13:08 +0000303
304void
305Property::SetValueChangedCallback (OptionValueChangedCallback callback, void *baton)
306{
307 if (m_value_sp)
308 m_value_sp->SetValueChangedCallback (callback, baton);
309}
310
311