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