]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Interpreter/OptionValue.h
MFV r329760: 7638 Refactor spa_load_impl into several functions
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Interpreter / OptionValue.h
1 //===-- OptionValue.h -------------------------------------------*- 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 #ifndef liblldb_OptionValue_h_
11 #define liblldb_OptionValue_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Core/FormatEntity.h"
18 #include "lldb/Utility/ConstString.h"
19 #include "lldb/Utility/Status.h"
20 #include "lldb/lldb-defines.h"
21 #include "lldb/lldb-private-enumerations.h"
22 #include "lldb/lldb-private-interfaces.h"
23
24 namespace lldb_private {
25
26 //---------------------------------------------------------------------
27 // OptionValue
28 //---------------------------------------------------------------------
29 class OptionValue {
30 public:
31   typedef enum {
32     eTypeInvalid = 0,
33     eTypeArch,
34     eTypeArgs,
35     eTypeArray,
36     eTypeBoolean,
37     eTypeChar,
38     eTypeDictionary,
39     eTypeEnum,
40     eTypeFileSpec,
41     eTypeFileSpecList,
42     eTypeFormat,
43     eTypeLanguage,
44     eTypePathMap,
45     eTypeProperties,
46     eTypeRegex,
47     eTypeSInt64,
48     eTypeString,
49     eTypeUInt64,
50     eTypeUUID,
51     eTypeFormatEntity
52   } Type;
53
54   enum {
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 =
62         (eDumpOptionName | eDumpOptionType | eDumpOptionDescription)
63   };
64
65   OptionValue()
66       : m_callback(nullptr), m_baton(nullptr), m_value_was_set(false) {}
67
68   OptionValue(const OptionValue &rhs)
69       : m_callback(rhs.m_callback), m_baton(rhs.m_baton),
70         m_value_was_set(rhs.m_value_was_set) {}
71
72   virtual ~OptionValue() = default;
73
74   //-----------------------------------------------------------------
75   // Subclasses should override these functions
76   //-----------------------------------------------------------------
77   virtual Type GetType() const = 0;
78
79   // If this value is always hidden, the avoid showing any info on this
80   // value, just show the info for the child values.
81   virtual bool ValueIsTransparent() const {
82     return GetType() == eTypeProperties;
83   }
84
85   virtual const char *GetTypeAsCString() const {
86     return GetBuiltinTypeAsCString(GetType());
87   }
88
89   static const char *GetBuiltinTypeAsCString(Type t);
90
91   virtual void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
92                          uint32_t dump_mask) = 0;
93
94   virtual Status
95   SetValueFromString(llvm::StringRef value,
96                      VarSetOperationType op = eVarSetOperationAssign);
97
98   virtual bool Clear() = 0;
99
100   virtual lldb::OptionValueSP DeepCopy() const = 0;
101
102   virtual size_t AutoComplete(CommandInterpreter &interpreter,
103                               llvm::StringRef s, int match_start_point,
104                               int max_return_elements, bool &word_complete,
105                               StringList &matches);
106
107   //-----------------------------------------------------------------
108   // Subclasses can override these functions
109   //-----------------------------------------------------------------
110   virtual lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
111                                           llvm::StringRef name,
112                                           bool will_modify,
113                                           Status &error) const {
114     error.SetErrorStringWithFormat("'%s' is not a value subvalue", name.str().c_str());
115     return lldb::OptionValueSP();
116   }
117
118   virtual Status SetSubValue(const ExecutionContext *exe_ctx,
119                              VarSetOperationType op, llvm::StringRef name,
120                              llvm::StringRef value);
121
122   virtual bool IsAggregateValue() const { return false; }
123
124   virtual ConstString GetName() const { return ConstString(); }
125
126   virtual bool DumpQualifiedName(Stream &strm) const;
127
128   //-----------------------------------------------------------------
129   // Subclasses should NOT override these functions as they use the
130   // above functions to implement functionality
131   //-----------------------------------------------------------------
132   uint32_t GetTypeAsMask() { return 1u << GetType(); }
133
134   static uint32_t ConvertTypeToMask(OptionValue::Type type) {
135     return 1u << type;
136   }
137
138   static OptionValue::Type ConvertTypeMaskToType(uint32_t type_mask) {
139     // If only one bit is set, then return an appropriate enumeration
140     switch (type_mask) {
141     case 1u << eTypeArch:
142       return eTypeArch;
143     case 1u << eTypeArgs:
144       return eTypeArgs;
145     case 1u << eTypeArray:
146       return eTypeArray;
147     case 1u << eTypeBoolean:
148       return eTypeBoolean;
149     case 1u << eTypeChar:
150       return eTypeChar;
151     case 1u << eTypeDictionary:
152       return eTypeDictionary;
153     case 1u << eTypeEnum:
154       return eTypeEnum;
155     case 1u << eTypeFileSpec:
156       return eTypeFileSpec;
157     case 1u << eTypeFileSpecList:
158       return eTypeFileSpecList;
159     case 1u << eTypeFormat:
160       return eTypeFormat;
161     case 1u << eTypeLanguage:
162       return eTypeLanguage;
163     case 1u << eTypePathMap:
164       return eTypePathMap;
165     case 1u << eTypeProperties:
166       return eTypeProperties;
167     case 1u << eTypeRegex:
168       return eTypeRegex;
169     case 1u << eTypeSInt64:
170       return eTypeSInt64;
171     case 1u << eTypeString:
172       return eTypeString;
173     case 1u << eTypeUInt64:
174       return eTypeUInt64;
175     case 1u << eTypeUUID:
176       return eTypeUUID;
177     }
178     // Else return invalid
179     return eTypeInvalid;
180   }
181
182   static lldb::OptionValueSP
183   CreateValueFromCStringForTypeMask(const char *value_cstr, uint32_t type_mask,
184                                     Status &error);
185
186   // Get this value as a uint64_t value if it is encoded as a boolean,
187   // uint64_t or int64_t. Other types will cause "fail_value" to be
188   // returned
189   uint64_t GetUInt64Value(uint64_t fail_value, bool *success_ptr);
190
191   OptionValueArch *GetAsArch();
192
193   const OptionValueArch *GetAsArch() const;
194
195   OptionValueArray *GetAsArray();
196
197   const OptionValueArray *GetAsArray() const;
198
199   OptionValueArgs *GetAsArgs();
200
201   const OptionValueArgs *GetAsArgs() const;
202
203   OptionValueBoolean *GetAsBoolean();
204
205   OptionValueChar *GetAsChar();
206
207   const OptionValueBoolean *GetAsBoolean() const;
208
209   const OptionValueChar *GetAsChar() const;
210
211   OptionValueDictionary *GetAsDictionary();
212
213   const OptionValueDictionary *GetAsDictionary() const;
214
215   OptionValueEnumeration *GetAsEnumeration();
216
217   const OptionValueEnumeration *GetAsEnumeration() const;
218
219   OptionValueFileSpec *GetAsFileSpec();
220
221   const OptionValueFileSpec *GetAsFileSpec() const;
222
223   OptionValueFileSpecList *GetAsFileSpecList();
224
225   const OptionValueFileSpecList *GetAsFileSpecList() const;
226
227   OptionValueFormat *GetAsFormat();
228
229   const OptionValueFormat *GetAsFormat() const;
230
231   OptionValueLanguage *GetAsLanguage();
232
233   const OptionValueLanguage *GetAsLanguage() const;
234
235   OptionValuePathMappings *GetAsPathMappings();
236
237   const OptionValuePathMappings *GetAsPathMappings() const;
238
239   OptionValueProperties *GetAsProperties();
240
241   const OptionValueProperties *GetAsProperties() const;
242
243   OptionValueRegex *GetAsRegex();
244
245   const OptionValueRegex *GetAsRegex() const;
246
247   OptionValueSInt64 *GetAsSInt64();
248
249   const OptionValueSInt64 *GetAsSInt64() const;
250
251   OptionValueString *GetAsString();
252
253   const OptionValueString *GetAsString() const;
254
255   OptionValueUInt64 *GetAsUInt64();
256
257   const OptionValueUInt64 *GetAsUInt64() const;
258
259   OptionValueUUID *GetAsUUID();
260
261   const OptionValueUUID *GetAsUUID() const;
262
263   OptionValueFormatEntity *GetAsFormatEntity();
264
265   const OptionValueFormatEntity *GetAsFormatEntity() const;
266
267   bool GetBooleanValue(bool fail_value = false) const;
268
269   bool SetBooleanValue(bool new_value);
270
271   char GetCharValue(char fail_value) const;
272
273   char SetCharValue(char new_value);
274
275   int64_t GetEnumerationValue(int64_t fail_value = -1) const;
276
277   bool SetEnumerationValue(int64_t value);
278
279   FileSpec GetFileSpecValue() const;
280
281   bool SetFileSpecValue(const FileSpec &file_spec);
282
283   FileSpecList GetFileSpecListValue() const;
284
285   lldb::Format
286   GetFormatValue(lldb::Format fail_value = lldb::eFormatDefault) const;
287
288   bool SetFormatValue(lldb::Format new_value);
289
290   lldb::LanguageType GetLanguageValue(
291       lldb::LanguageType fail_value = lldb::eLanguageTypeUnknown) const;
292
293   bool SetLanguageValue(lldb::LanguageType new_language);
294
295   const FormatEntity::Entry *GetFormatEntity() const;
296
297   const RegularExpression *GetRegexValue() const;
298
299   int64_t GetSInt64Value(int64_t fail_value = 0) const;
300
301   bool SetSInt64Value(int64_t new_value);
302
303   llvm::StringRef GetStringValue(llvm::StringRef fail_value) const;
304   llvm::StringRef GetStringValue() const { return GetStringValue(llvm::StringRef()); }
305
306   bool SetStringValue(llvm::StringRef new_value);
307
308   uint64_t GetUInt64Value(uint64_t fail_value = 0) const;
309
310   bool SetUInt64Value(uint64_t new_value);
311
312   UUID GetUUIDValue() const;
313
314   bool SetUUIDValue(const UUID &uuid);
315
316   bool OptionWasSet() const { return m_value_was_set; }
317
318   void SetOptionWasSet() { m_value_was_set = true; }
319
320   void SetParent(const lldb::OptionValueSP &parent_sp) {
321     m_parent_wp = parent_sp;
322   }
323
324   void SetValueChangedCallback(OptionValueChangedCallback callback,
325                                void *baton) {
326     assert(m_callback == nullptr);
327     m_callback = callback;
328     m_baton = baton;
329   }
330
331   void NotifyValueChanged() {
332     if (m_callback)
333       m_callback(m_baton, this);
334   }
335
336 protected:
337   lldb::OptionValueWP m_parent_wp;
338   OptionValueChangedCallback m_callback;
339   void *m_baton;
340   bool m_value_was_set; // This can be used to see if a value has been set
341                         // by a call to SetValueFromCString(). It is often
342                         // handy to know if an option value was set from
343                         // the command line or as a setting, versus if we
344                         // just have the default value that was already
345                         // populated in the option value.
346 };
347
348 } // namespace lldb_private
349
350 #endif // liblldb_OptionValue_h_