blob: 7e7dc010997c80926129bc02d1e40b244f852365 [file] [log] [blame]
Greg Clayton73844aa2012-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
10#include "lldb/Interpreter/Property.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/UserSettingsController.h"
17#include "lldb/Interpreter/Args.h"
18#include "lldb/Interpreter/CommandInterpreter.h"
19#include "lldb/Interpreter/OptionValues.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
24Property::Property (const PropertyDefinition &definition) :
25 m_name (definition.name),
26 m_description (definition.description),
27 m_value_sp (),
28 m_is_global (definition.global)
29{
30 switch (definition.type)
31 {
32 case OptionValue::eTypeInvalid:
33 case OptionValue::eTypeProperties:
34 break;
35 case OptionValue::eTypeArch:
36 // "definition.default_uint_value" is not used
37 // "definition.default_cstr_value" as a string value that represents the default string value for the architecture/triple
38 m_value_sp.reset (new OptionValueArch(definition.default_cstr_value));
39 break;
40
41 case OptionValue::eTypeArgs:
42 // "definition.default_uint_value" is always a OptionValue::Type
43 m_value_sp.reset (new OptionValueArgs());
44 break;
45
46 case OptionValue::eTypeArray:
47 // "definition.default_uint_value" is always a OptionValue::Type
48 m_value_sp.reset (new OptionValueArray(OptionValue::ConvertTypeToMask((OptionValue::Type)definition.default_uint_value)));
49 break;
50
51 case OptionValue::eTypeBoolean:
52 // "definition.default_uint_value" is the default boolean value if
53 // "definition.default_cstr_value" is NULL, otherwise interpret
54 // "definition.default_cstr_value" as a string value that represents the default
55 // value.
56 if (definition.default_cstr_value)
57 m_value_sp.reset (new OptionValueBoolean(Args::StringToBoolean (definition.default_cstr_value, false, NULL)));
58 else
59 m_value_sp.reset (new OptionValueBoolean(definition.default_uint_value != 0));
60 break;
61
62 case OptionValue::eTypeDictionary:
63 // "definition.default_uint_value" is always a OptionValue::Type
64 m_value_sp.reset (new OptionValueDictionary(OptionValue::ConvertTypeToMask((OptionValue::Type)definition.default_uint_value)));
65 break;
66
67 case OptionValue::eTypeEnum:
68 // "definition.default_uint_value" is the default enumeration value if
69 // "definition.default_cstr_value" is NULL, otherwise interpret
70 // "definition.default_cstr_value" as a string value that represents the default
71 // value.
72 {
73 OptionValueEnumeration *enum_value = new OptionValueEnumeration(definition.enum_values, definition.default_uint_value);
74 m_value_sp.reset (enum_value);
75 if (definition.default_cstr_value)
76 {
77 if (enum_value->SetValueFromCString(definition.default_cstr_value).Success())
78 {
79 enum_value->SetDefaultValue(enum_value->GetCurrentValue());
80 // Call Clear() since we don't want the value to appear as
81 // having been set since we called SetValueFromCString() above.
82 // Clear will set the current value to the default and clear
83 // the boolean that says that the value has been set.
84 enum_value->Clear();
85 }
86 }
87 }
88 break;
89
90 case OptionValue::eTypeFileSpec:
91 // "definition.default_uint_value" represents if the "definition.default_cstr_value" should
92 // be resolved or not
93 m_value_sp.reset (new OptionValueFileSpec(FileSpec(definition.default_cstr_value, definition.default_uint_value != 0)));
94 break;
95
96 case OptionValue::eTypeFileSpecList:
97 // "definition.default_uint_value" is not used for a OptionValue::eTypeFileSpecList
98 m_value_sp.reset (new OptionValueFileSpecList());
99 break;
100
101 case OptionValue::eTypeFormat:
102 // "definition.default_uint_value" is the default format enumeration value if
103 // "definition.default_cstr_value" is NULL, otherwise interpret
104 // "definition.default_cstr_value" as a string value that represents the default
105 // value.
106 {
107 Format new_format = eFormatInvalid;
108 if (definition.default_cstr_value)
109 Args::StringToFormat (definition.default_cstr_value, new_format, NULL);
110 else
111 new_format = (Format)definition.default_uint_value;
112 m_value_sp.reset (new OptionValueFormat(new_format));
113 }
114 break;
115
116 case OptionValue::eTypePathMap:
117 // "definition.default_uint_value" tells us if notifications should occur for
118 // path mappings
119 m_value_sp.reset (new OptionValuePathMappings(definition.default_uint_value != 0));
120 break;
121
122 case OptionValue::eTypeRegex:
123 // "definition.default_uint_value" is used to the regular expression flags
124 // "definition.default_cstr_value" the default regular expression value
125 // value.
126 m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value, definition.default_uint_value));
127 break;
128
129 case OptionValue::eTypeSInt64:
130 // "definition.default_uint_value" is the default integer value if
131 // "definition.default_cstr_value" is NULL, otherwise interpret
132 // "definition.default_cstr_value" as a string value that represents the default
133 // value.
134 m_value_sp.reset (new OptionValueSInt64(definition.default_cstr_value ? Args::StringToSInt64 (definition.default_cstr_value) : definition.default_uint_value));
135 break;
136
137 case OptionValue::eTypeUInt64:
138 // "definition.default_uint_value" is the default unsigned integer value if
139 // "definition.default_cstr_value" is NULL, otherwise interpret
140 // "definition.default_cstr_value" as a string value that represents the default
141 // value.
142 m_value_sp.reset (new OptionValueUInt64(definition.default_cstr_value ? Args::StringToUInt64 (definition.default_cstr_value) : definition.default_uint_value));
143 break;
144
145 case OptionValue::eTypeUUID:
146 // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
147 // "definition.default_cstr_value" can contain a default UUID value
148 {
149 UUID uuid;
150 if (definition.default_cstr_value)
151 uuid.SetfromCString (definition.default_cstr_value);
152 m_value_sp.reset (new OptionValueUUID(uuid));
153 }
154 break;
155
156 case OptionValue::eTypeString:
157 // "definition.default_uint_value" is not used for a OptionValueFileSpecList
158 // "definition.default_cstr_value" can contain a default string value
159 m_value_sp.reset (new OptionValueString(definition.default_cstr_value));
160 break;
161 }
162}
163
164Property::Property (const ConstString &name,
165 const ConstString &desc,
166 bool is_global,
167 const lldb::OptionValueSP &value_sp) :
168 m_name (name),
169 m_description (desc),
170 m_value_sp (value_sp),
171 m_is_global (is_global)
172{
173}
174
175bool
176Property::DumpQualifiedName(Stream &strm) const
177{
178 if (m_name)
179 {
180 if (m_value_sp->DumpQualifiedName(strm))
181 strm.PutChar('.');
182 strm << m_name;
183 return true;
184 }
185 return false;
186}
187
188
189void
190Property::Dump (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) const
191{
192 if (m_value_sp)
193 {
194 const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription;
195 const bool transparent = m_value_sp->ValueIsTransparent ();
196 if (dump_desc || !transparent)
197 {
198 if ((dump_mask & OptionValue::eDumpOptionName) && m_name)
199 {
200 DumpQualifiedName(strm);
201 if (dump_mask & ~OptionValue::eDumpOptionName)
202 strm.PutChar(' ');
203 }
204 }
205 if (dump_desc)
206 {
207 const char *desc = GetDescription();
208 if (desc)
209 strm.Printf ("-- %s", desc);
210
211 if (transparent && (dump_mask == (OptionValue::eDumpOptionName | OptionValue::eDumpOptionDescription)))
212 strm.EOL();
213 }
214 m_value_sp->DumpValue(exe_ctx, strm, dump_mask);
215 }
216}
217
218
219void
220Property::DumpDescription (CommandInterpreter &interpreter,
221 Stream &strm,
222 uint32_t output_width,
223 bool display_qualified_name) const
224{
225 if (m_value_sp)
226 {
227 const char *desc = GetDescription();
228
229 if (desc)
230 {
231 StreamString qualified_name;
232 const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
233 if (sub_properties)
234 {
235 strm.EOL();
236
237 if (m_value_sp->DumpQualifiedName(qualified_name))
238 strm.Printf("'%s' variables:\n\n", qualified_name.GetString().c_str());
239 sub_properties->DumpAllDescriptions(interpreter, strm);
240 }
241 else
242 {
243 if (desc)
244 {
245 if (display_qualified_name)
246 {
247 StreamString qualified_name;
248 DumpQualifiedName(qualified_name);
249 interpreter.OutputFormattedHelpText (strm,
250 qualified_name.GetString().c_str(),
251 "--",
252 desc,
253 output_width);
254 }
255 else
256 {
257 interpreter.OutputFormattedHelpText (strm,
258 m_name.GetCString(),
259 "--",
260 desc,
261 output_width);
262 }
263 }
264 }
265 }
266 }
267}
268