1 //===-- OptionValue.h --------------------------------------*- 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 #ifndef liblldb_OptionValue_h_
11 #define liblldb_OptionValue_h_
15 // Other libraries and framework includes
17 #include "lldb/lldb-defines.h"
18 #include "lldb/Core/ConstString.h"
19 #include "lldb/Core/Error.h"
20 #include "lldb/Core/FormatEntity.h"
22 namespace lldb_private {
24 //---------------------------------------------------------------------
26 //---------------------------------------------------------------------
55 eDumpOptionName = (1u << 0),
56 eDumpOptionType = (1u << 1),
57 eDumpOptionValue = (1u << 2),
58 eDumpOptionDescription = (1u << 3),
59 eDumpOptionRaw = (1u << 4),
60 eDumpGroupValue = (eDumpOptionName | eDumpOptionType | eDumpOptionValue),
61 eDumpGroupHelp = (eDumpOptionName | eDumpOptionType | eDumpOptionDescription)
68 m_value_was_set (false)
72 OptionValue (const OptionValue &rhs) :
73 m_callback (rhs.m_callback),
74 m_baton (rhs.m_baton),
75 m_value_was_set (rhs.m_value_was_set)
79 virtual ~OptionValue ()
82 //-----------------------------------------------------------------
83 // Subclasses should override these functions
84 //-----------------------------------------------------------------
88 // If this value is always hidden, the avoid showing any info on this
89 // value, just show the info for the child values.
91 ValueIsTransparent () const
93 return GetType() == eTypeProperties;
97 GetTypeAsCString () const
99 return GetBuiltinTypeAsCString(GetType());
104 GetBuiltinTypeAsCString (Type t);
107 DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) = 0;
110 SetValueFromString (llvm::StringRef value, VarSetOperationType op = eVarSetOperationAssign);
115 virtual lldb::OptionValueSP
116 DeepCopy () const = 0;
119 AutoComplete (CommandInterpreter &interpreter,
121 int match_start_point,
122 int max_return_elements,
124 StringList &matches);
126 //-----------------------------------------------------------------
127 // Subclasses can override these functions
128 //-----------------------------------------------------------------
129 virtual lldb::OptionValueSP
130 GetSubValue (const ExecutionContext *exe_ctx,
135 error.SetErrorStringWithFormat("'%s' is not a value subvalue", name);
136 return lldb::OptionValueSP();
140 SetSubValue (const ExecutionContext *exe_ctx,
141 VarSetOperationType op,
146 IsAggregateValue () const
154 return ConstString();
158 DumpQualifiedName (Stream &strm) const;
159 //-----------------------------------------------------------------
160 // Subclasses should NOT override these functions as they use the
161 // above functions to implement functionality
162 //-----------------------------------------------------------------
166 return 1u << GetType();
170 ConvertTypeToMask (OptionValue::Type type)
175 static OptionValue::Type
176 ConvertTypeMaskToType (uint32_t type_mask)
178 // If only one bit is set, then return an appropriate enumeration
181 case 1u << eTypeArch: return eTypeArch;
182 case 1u << eTypeArgs: return eTypeArgs;
183 case 1u << eTypeArray: return eTypeArray;
184 case 1u << eTypeBoolean: return eTypeBoolean;
185 case 1u << eTypeChar: return eTypeChar;
186 case 1u << eTypeDictionary: return eTypeDictionary;
187 case 1u << eTypeEnum: return eTypeEnum;
188 case 1u << eTypeFileSpec: return eTypeFileSpec;
189 case 1u << eTypeFileSpecList: return eTypeFileSpecList;
190 case 1u << eTypeFormat: return eTypeFormat;
191 case 1u << eTypeLanguage: return eTypeLanguage;
192 case 1u << eTypePathMap: return eTypePathMap;
193 case 1u << eTypeProperties: return eTypeProperties;
194 case 1u << eTypeRegex: return eTypeRegex;
195 case 1u << eTypeSInt64: return eTypeSInt64;
196 case 1u << eTypeString: return eTypeString;
197 case 1u << eTypeUInt64: return eTypeUInt64;
198 case 1u << eTypeUUID: return eTypeUUID;
200 // Else return invalid
204 static lldb::OptionValueSP
205 CreateValueFromCStringForTypeMask (const char *value_cstr,
209 // Get this value as a uint64_t value if it is encoded as a boolean,
210 // uint64_t or int64_t. Other types will cause "fail_value" to be
213 GetUInt64Value (uint64_t fail_value, bool *success_ptr);
218 const OptionValueArch *
224 const OptionValueArray *
230 const OptionValueArgs *
239 const OptionValueBoolean *
240 GetAsBoolean () const;
242 const OptionValueChar *
245 OptionValueDictionary *
248 const OptionValueDictionary *
249 GetAsDictionary () const;
251 OptionValueEnumeration *
254 const OptionValueEnumeration *
255 GetAsEnumeration () const;
257 OptionValueFileSpec *
260 const OptionValueFileSpec *
261 GetAsFileSpec () const;
263 OptionValueFileSpecList *
264 GetAsFileSpecList ();
266 const OptionValueFileSpecList *
267 GetAsFileSpecList () const;
272 const OptionValueFormat *
273 GetAsFormat () const;
275 OptionValueLanguage *
278 const OptionValueLanguage *
279 GetAsLanguage () const;
281 OptionValuePathMappings *
282 GetAsPathMappings ();
284 const OptionValuePathMappings *
285 GetAsPathMappings () const;
287 OptionValueProperties *
290 const OptionValueProperties *
291 GetAsProperties () const;
296 const OptionValueRegex *
302 const OptionValueSInt64 *
303 GetAsSInt64 () const;
308 const OptionValueString *
309 GetAsString () const;
314 const OptionValueUInt64 *
315 GetAsUInt64 () const;
320 const OptionValueUUID *
323 OptionValueFormatEntity *
324 GetAsFormatEntity ();
326 const OptionValueFormatEntity *
327 GetAsFormatEntity () const;
330 GetBooleanValue (bool fail_value = false) const;
333 SetBooleanValue (bool new_value);
335 char GetCharValue(char fail_value) const;
337 char SetCharValue(char new_value);
340 GetEnumerationValue (int64_t fail_value = -1) const;
343 SetEnumerationValue (int64_t value);
346 GetFileSpecValue () const;
349 SetFileSpecValue (const FileSpec &file_spec);
352 GetFileSpecListValue () const;
355 GetFormatValue (lldb::Format fail_value = lldb::eFormatDefault) const;
358 SetFormatValue (lldb::Format new_value);
361 GetLanguageValue (lldb::LanguageType fail_value = lldb::eLanguageTypeUnknown) const;
364 SetLanguageValue (lldb::LanguageType new_language);
366 const FormatEntity::Entry *
367 GetFormatEntity () const;
369 const RegularExpression *
370 GetRegexValue () const;
373 GetSInt64Value (int64_t fail_value = 0) const;
376 SetSInt64Value (int64_t new_value);
379 GetStringValue (const char *fail_value = NULL) const;
382 SetStringValue (const char *new_value);
385 GetUInt64Value (uint64_t fail_value = 0) const;
388 SetUInt64Value (uint64_t new_value);
391 GetUUIDValue () const;
394 SetUUIDValue (const UUID &uuid);
397 OptionWasSet () const
399 return m_value_was_set;
405 m_value_was_set = true;
409 SetParent (const lldb::OptionValueSP &parent_sp)
411 m_parent_wp = parent_sp;
415 SetValueChangedCallback (OptionValueChangedCallback callback,
418 assert (m_callback == NULL);
419 m_callback = callback;
424 NotifyValueChanged ()
427 m_callback (m_baton, this);
430 lldb::OptionValueWP m_parent_wp;
431 OptionValueChangedCallback m_callback;
433 bool m_value_was_set; // This can be used to see if a value has been set
434 // by a call to SetValueFromCString(). It is often
435 // handy to know if an option value was set from
436 // the command line or as a setting, versus if we
437 // just have the default value that was already
438 // populated in the option value.
442 } // namespace lldb_private
444 #endif // liblldb_OptionValue_h_