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