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"
21 namespace lldb_private {
23 //---------------------------------------------------------------------
25 //---------------------------------------------------------------------
50 eDumpOptionName = (1u << 0),
51 eDumpOptionType = (1u << 1),
52 eDumpOptionValue = (1u << 2),
53 eDumpOptionDescription = (1u << 3),
54 eDumpOptionRaw = (1u << 4),
55 eDumpGroupValue = (eDumpOptionName | eDumpOptionType | eDumpOptionValue),
56 eDumpGroupHelp = (eDumpOptionName | eDumpOptionType | eDumpOptionDescription)
61 m_value_was_set (false)
65 OptionValue (const OptionValue &rhs) :
66 m_value_was_set (rhs.m_value_was_set)
70 virtual ~OptionValue ()
73 //-----------------------------------------------------------------
74 // Subclasses should override these functions
75 //-----------------------------------------------------------------
79 // If this value is always hidden, the avoid showing any info on this
80 // value, just show the info for the child values.
82 ValueIsTransparent () const
84 return GetType() == eTypeProperties;
88 GetTypeAsCString () const
90 return GetBuiltinTypeAsCString(GetType());
95 GetBuiltinTypeAsCString (Type t);
98 DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) = 0;
101 SetValueFromCString (const char *value, VarSetOperationType op = eVarSetOperationAssign);
106 virtual lldb::OptionValueSP
107 DeepCopy () const = 0;
110 AutoComplete (CommandInterpreter &interpreter,
112 int match_start_point,
113 int max_return_elements,
115 StringList &matches);
117 //-----------------------------------------------------------------
118 // Subclasses can override these functions
119 //-----------------------------------------------------------------
120 virtual lldb::OptionValueSP
121 GetSubValue (const ExecutionContext *exe_ctx,
126 error.SetErrorStringWithFormat("'%s' is not a value subvalue", name);
127 return lldb::OptionValueSP();
131 SetSubValue (const ExecutionContext *exe_ctx,
132 VarSetOperationType op,
137 IsAggregateValue () const
145 return ConstString();
149 DumpQualifiedName (Stream &strm) const;
150 //-----------------------------------------------------------------
151 // Subclasses should NOT override these functions as they use the
152 // above functions to implement functionality
153 //-----------------------------------------------------------------
157 return 1u << GetType();
161 ConvertTypeToMask (OptionValue::Type type)
166 static OptionValue::Type
167 ConvertTypeMaskToType (uint32_t type_mask)
169 // If only one bit is set, then return an appropriate enumeration
172 case 1u << eTypeArch: return eTypeArch;
173 case 1u << eTypeArgs: return eTypeArgs;
174 case 1u << eTypeArray: return eTypeArray;
175 case 1u << eTypeBoolean: return eTypeBoolean;
176 case 1u << eTypeDictionary: return eTypeDictionary;
177 case 1u << eTypeEnum: return eTypeEnum;
178 case 1u << eTypeFileSpec: return eTypeFileSpec;
179 case 1u << eTypeFileSpecList: return eTypeFileSpecList;
180 case 1u << eTypeFormat: return eTypeFormat;
181 case 1u << eTypePathMap: return eTypePathMap;
182 case 1u << eTypeProperties: return eTypeProperties;
183 case 1u << eTypeRegex: return eTypeRegex;
184 case 1u << eTypeSInt64: return eTypeSInt64;
185 case 1u << eTypeString: return eTypeString;
186 case 1u << eTypeUInt64: return eTypeUInt64;
187 case 1u << eTypeUUID: return eTypeUUID;
189 // Else return invalid
193 static lldb::OptionValueSP
194 CreateValueFromCStringForTypeMask (const char *value_cstr,
198 // Get this value as a uint64_t value if it is encoded as a boolean,
199 // uint64_t or int64_t. Other types will cause "fail_value" to be
202 GetUInt64Value (uint64_t fail_value, bool *success_ptr);
207 const OptionValueArch *
213 const OptionValueArray *
219 const OptionValueArgs *
225 const OptionValueBoolean *
226 GetAsBoolean () const;
228 OptionValueDictionary *
231 const OptionValueDictionary *
232 GetAsDictionary () const;
234 OptionValueEnumeration *
237 const OptionValueEnumeration *
238 GetAsEnumeration () const;
240 OptionValueFileSpec *
243 const OptionValueFileSpec *
244 GetAsFileSpec () const;
246 OptionValueFileSpecList *
247 GetAsFileSpecList ();
249 const OptionValueFileSpecList *
250 GetAsFileSpecList () const;
255 const OptionValueFormat *
256 GetAsFormat () const;
258 OptionValuePathMappings *
259 GetAsPathMappings ();
261 const OptionValuePathMappings *
262 GetAsPathMappings () const;
264 OptionValueProperties *
267 const OptionValueProperties *
268 GetAsProperties () const;
273 const OptionValueRegex *
279 const OptionValueSInt64 *
280 GetAsSInt64 () const;
285 const OptionValueString *
286 GetAsString () const;
291 const OptionValueUInt64 *
292 GetAsUInt64 () const;
297 const OptionValueUUID *
301 GetBooleanValue (bool fail_value = false) const;
304 SetBooleanValue (bool new_value);
307 GetEnumerationValue (int64_t fail_value = -1) const;
310 SetEnumerationValue (int64_t value);
313 GetFileSpecValue () const;
316 SetFileSpecValue (const FileSpec &file_spec);
319 GetFileSpecListValue () const;
322 GetFormatValue (lldb::Format fail_value = lldb::eFormatDefault) const;
325 SetFormatValue (lldb::Format new_value);
327 const RegularExpression *
328 GetRegexValue () const;
331 GetSInt64Value (int64_t fail_value = 0) const;
334 SetSInt64Value (int64_t new_value);
337 GetStringValue (const char *fail_value = NULL) const;
340 SetStringValue (const char *new_value);
343 GetUInt64Value (uint64_t fail_value = 0) const;
346 SetUInt64Value (uint64_t new_value);
349 GetUUIDValue () const;
352 SetUUIDValue (const UUID &uuid);
355 OptionWasSet () const
357 return m_value_was_set;
363 m_value_was_set = true;
367 SetParent (const lldb::OptionValueSP &parent_sp)
369 m_parent_wp = parent_sp;
372 lldb::OptionValueWP m_parent_wp;
373 bool m_value_was_set; // This can be used to see if a value has been set
374 // by a call to SetValueFromCString(). It is often
375 // handy to know if an option value was set from
376 // the command line or as a setting, versus if we
377 // just have the default value that was already
378 // populated in the option value.
382 } // namespace lldb_private
384 #endif // liblldb_OptionValue_h_