blob: cde255acef7af5c8976bf246d49e0c907bf5441d [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
Greg Clayton554f68d2015-02-04 22:00:53 +0000125 case OptionValue::eTypeFormatEntity:
126 // "definition.default_cstr_value" as a string value that represents the default
127 m_value_sp.reset (new OptionValueFormatEntity(definition.default_cstr_value));
128 break;
129
Greg Clayton67cc0632012-08-22 17:17:09 +0000130 case OptionValue::eTypePathMap:
131 // "definition.default_uint_value" tells us if notifications should occur for
132 // path mappings
133 m_value_sp.reset (new OptionValuePathMappings(definition.default_uint_value != 0));
134 break;
135
136 case OptionValue::eTypeRegex:
137 // "definition.default_uint_value" is used to the regular expression flags
138 // "definition.default_cstr_value" the default regular expression value
139 // value.
Greg Clayton7bd4c602015-01-21 21:51:02 +0000140 m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value));
Greg Clayton67cc0632012-08-22 17:17:09 +0000141 break;
142
143 case OptionValue::eTypeSInt64:
144 // "definition.default_uint_value" is the default integer value if
145 // "definition.default_cstr_value" is NULL, otherwise interpret
146 // "definition.default_cstr_value" as a string value that represents the default
147 // value.
Vince Harron5275aaa2015-01-15 20:08:35 +0000148 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 +0000149 break;
150
151 case OptionValue::eTypeUInt64:
152 // "definition.default_uint_value" is the default unsigned integer value if
153 // "definition.default_cstr_value" is NULL, otherwise interpret
154 // "definition.default_cstr_value" as a string value that represents the default
155 // value.
Vince Harron5275aaa2015-01-15 20:08:35 +0000156 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 +0000157 break;
158
159 case OptionValue::eTypeUUID:
160 // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
161 // "definition.default_cstr_value" can contain a default UUID value
Greg Clayton554f68d2015-02-04 22:00:53 +0000162 {
163 UUID uuid;
164 if (definition.default_cstr_value)
165 uuid.SetFromCString (definition.default_cstr_value);
166 m_value_sp.reset (new OptionValueUUID(uuid));
167 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000168 break;
169
170 case OptionValue::eTypeString:
Greg Clayton4c054102012-09-01 00:38:36 +0000171 // "definition.default_uint_value" can contain the string option flags OR'ed together
Greg Clayton67cc0632012-08-22 17:17:09 +0000172 // "definition.default_cstr_value" can contain a default string value
Greg Clayton4c054102012-09-01 00:38:36 +0000173 {
174 OptionValueString *string_value = new OptionValueString(definition.default_cstr_value);
175 if (definition.default_uint_value != 0)
176 string_value->GetOptions().Reset(definition.default_uint_value);
177 m_value_sp.reset (string_value);
178 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000179 break;
180 }
181}
182
183Property::Property (const ConstString &name,
184 const ConstString &desc,
185 bool is_global,
186 const lldb::OptionValueSP &value_sp) :
187 m_name (name),
188 m_description (desc),
189 m_value_sp (value_sp),
190 m_is_global (is_global)
191{
192}
193
194bool
195Property::DumpQualifiedName(Stream &strm) const
196{
197 if (m_name)
198 {
199 if (m_value_sp->DumpQualifiedName(strm))
200 strm.PutChar('.');
201 strm << m_name;
202 return true;
203 }
204 return false;
205}
206
207
208void
209Property::Dump (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) const
210{
211 if (m_value_sp)
212 {
213 const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription;
214 const bool transparent = m_value_sp->ValueIsTransparent ();
215 if (dump_desc || !transparent)
216 {
217 if ((dump_mask & OptionValue::eDumpOptionName) && m_name)
218 {
219 DumpQualifiedName(strm);
220 if (dump_mask & ~OptionValue::eDumpOptionName)
221 strm.PutChar(' ');
222 }
223 }
224 if (dump_desc)
225 {
226 const char *desc = GetDescription();
227 if (desc)
228 strm.Printf ("-- %s", desc);
229
230 if (transparent && (dump_mask == (OptionValue::eDumpOptionName | OptionValue::eDumpOptionDescription)))
231 strm.EOL();
232 }
233 m_value_sp->DumpValue(exe_ctx, strm, dump_mask);
234 }
235}
236
237
238void
239Property::DumpDescription (CommandInterpreter &interpreter,
240 Stream &strm,
241 uint32_t output_width,
242 bool display_qualified_name) const
243{
244 if (m_value_sp)
245 {
246 const char *desc = GetDescription();
247
248 if (desc)
249 {
250 StreamString qualified_name;
251 const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
252 if (sub_properties)
253 {
254 strm.EOL();
255
256 if (m_value_sp->DumpQualifiedName(qualified_name))
257 strm.Printf("'%s' variables:\n\n", qualified_name.GetString().c_str());
258 sub_properties->DumpAllDescriptions(interpreter, strm);
259 }
260 else
261 {
262 if (desc)
263 {
264 if (display_qualified_name)
265 {
266 StreamString qualified_name;
267 DumpQualifiedName(qualified_name);
268 interpreter.OutputFormattedHelpText (strm,
269 qualified_name.GetString().c_str(),
270 "--",
271 desc,
272 output_width);
273 }
274 else
275 {
276 interpreter.OutputFormattedHelpText (strm,
277 m_name.GetCString(),
278 "--",
279 desc,
280 output_width);
281 }
282 }
283 }
284 }
285 }
286}
287
Greg Clayton332e8b12015-01-13 21:13:08 +0000288
289void
290Property::SetValueChangedCallback (OptionValueChangedCallback callback, void *baton)
291{
292 if (m_value_sp)
293 m_value_sp->SetValueChangedCallback (callback, baton);
294}
295
296