1254721Semaste//===-- OptionValue.h --------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#ifndef liblldb_OptionValue_h_
11254721Semaste#define liblldb_OptionValue_h_
12254721Semaste
13254721Semaste// C Includes
14254721Semaste// C++ Includes
15254721Semaste// Other libraries and framework includes
16254721Semaste// Project includes
17254721Semaste#include "lldb/lldb-defines.h"
18254721Semaste#include "lldb/Core/ConstString.h"
19254721Semaste#include "lldb/Core/Error.h"
20254721Semaste
21254721Semastenamespace lldb_private {
22254721Semaste
23254721Semaste    //---------------------------------------------------------------------
24254721Semaste    // OptionValue
25254721Semaste    //---------------------------------------------------------------------
26254721Semaste    class OptionValue
27254721Semaste    {
28254721Semaste    public:
29254721Semaste        typedef enum {
30254721Semaste            eTypeInvalid = 0,
31254721Semaste            eTypeArch,
32254721Semaste            eTypeArgs,
33254721Semaste            eTypeArray,
34254721Semaste            eTypeBoolean,
35254721Semaste            eTypeDictionary,
36254721Semaste            eTypeEnum,
37254721Semaste            eTypeFileSpec,
38254721Semaste            eTypeFileSpecList,
39254721Semaste            eTypeFormat,
40254721Semaste            eTypePathMap,
41254721Semaste            eTypeProperties,
42254721Semaste            eTypeRegex,
43254721Semaste            eTypeSInt64,
44254721Semaste            eTypeString,
45254721Semaste            eTypeUInt64,
46254721Semaste            eTypeUUID
47254721Semaste        } Type;
48254721Semaste
49254721Semaste        enum {
50254721Semaste            eDumpOptionName         = (1u << 0),
51254721Semaste            eDumpOptionType         = (1u << 1),
52254721Semaste            eDumpOptionValue        = (1u << 2),
53254721Semaste            eDumpOptionDescription  = (1u << 3),
54254721Semaste            eDumpOptionRaw          = (1u << 4),
55254721Semaste            eDumpGroupValue         = (eDumpOptionName | eDumpOptionType | eDumpOptionValue),
56254721Semaste            eDumpGroupHelp          = (eDumpOptionName | eDumpOptionType | eDumpOptionDescription)
57254721Semaste        };
58254721Semaste
59254721Semaste
60254721Semaste        OptionValue () :
61254721Semaste            m_value_was_set (false)
62254721Semaste        {
63254721Semaste        }
64254721Semaste
65254721Semaste        OptionValue (const OptionValue &rhs) :
66254721Semaste            m_value_was_set (rhs.m_value_was_set)
67254721Semaste        {
68254721Semaste        }
69254721Semaste
70254721Semaste        virtual ~OptionValue ()
71254721Semaste        {
72254721Semaste        }
73254721Semaste        //-----------------------------------------------------------------
74254721Semaste        // Subclasses should override these functions
75254721Semaste        //-----------------------------------------------------------------
76254721Semaste        virtual Type
77254721Semaste        GetType () const = 0;
78254721Semaste
79254721Semaste        // If this value is always hidden, the avoid showing any info on this
80254721Semaste        // value, just show the info for the child values.
81254721Semaste        virtual bool
82254721Semaste        ValueIsTransparent () const
83254721Semaste        {
84254721Semaste            return GetType() == eTypeProperties;
85254721Semaste        }
86254721Semaste
87254721Semaste        virtual const char *
88254721Semaste        GetTypeAsCString () const
89254721Semaste        {
90254721Semaste            return GetBuiltinTypeAsCString(GetType());
91254721Semaste        }
92254721Semaste
93254721Semaste
94254721Semaste        static const char *
95254721Semaste        GetBuiltinTypeAsCString (Type t);
96254721Semaste
97254721Semaste        virtual void
98254721Semaste        DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) = 0;
99254721Semaste
100254721Semaste        virtual Error
101254721Semaste        SetValueFromCString (const char *value, VarSetOperationType op = eVarSetOperationAssign);
102254721Semaste
103254721Semaste        virtual bool
104254721Semaste        Clear () = 0;
105254721Semaste
106254721Semaste        virtual lldb::OptionValueSP
107254721Semaste        DeepCopy () const = 0;
108254721Semaste
109254721Semaste        virtual size_t
110254721Semaste        AutoComplete (CommandInterpreter &interpreter,
111254721Semaste                      const char *s,
112254721Semaste                      int match_start_point,
113254721Semaste                      int max_return_elements,
114254721Semaste                      bool &word_complete,
115254721Semaste                      StringList &matches);
116254721Semaste
117254721Semaste        //-----------------------------------------------------------------
118254721Semaste        // Subclasses can override these functions
119254721Semaste        //-----------------------------------------------------------------
120254721Semaste        virtual lldb::OptionValueSP
121254721Semaste        GetSubValue (const ExecutionContext *exe_ctx,
122254721Semaste                     const char *name,
123254721Semaste                     bool will_modify,
124254721Semaste                     Error &error) const
125254721Semaste        {
126254721Semaste            error.SetErrorStringWithFormat("'%s' is not a value subvalue", name);
127254721Semaste            return lldb::OptionValueSP();
128254721Semaste        }
129254721Semaste
130254721Semaste        virtual Error
131254721Semaste        SetSubValue (const ExecutionContext *exe_ctx,
132254721Semaste                     VarSetOperationType op,
133254721Semaste                     const char *name,
134254721Semaste                     const char *value);
135254721Semaste
136254721Semaste        virtual bool
137254721Semaste        IsAggregateValue () const
138254721Semaste        {
139254721Semaste            return false;
140254721Semaste        }
141254721Semaste
142254721Semaste        virtual ConstString
143254721Semaste        GetName() const
144254721Semaste        {
145254721Semaste            return ConstString();
146254721Semaste        }
147254721Semaste
148254721Semaste        virtual bool
149254721Semaste        DumpQualifiedName (Stream &strm) const;
150254721Semaste        //-----------------------------------------------------------------
151254721Semaste        // Subclasses should NOT override these functions as they use the
152254721Semaste        // above functions to implement functionality
153254721Semaste        //-----------------------------------------------------------------
154254721Semaste        uint32_t
155254721Semaste        GetTypeAsMask ()
156254721Semaste        {
157254721Semaste            return 1u << GetType();
158254721Semaste        }
159254721Semaste
160254721Semaste        static uint32_t
161254721Semaste        ConvertTypeToMask (OptionValue::Type type)
162254721Semaste        {
163254721Semaste            return 1u << type;
164254721Semaste        }
165254721Semaste
166254721Semaste        static OptionValue::Type
167254721Semaste        ConvertTypeMaskToType (uint32_t type_mask)
168254721Semaste        {
169254721Semaste            // If only one bit is set, then return an appropriate enumeration
170254721Semaste            switch (type_mask)
171254721Semaste            {
172254721Semaste                case 1u << eTypeArch:           return eTypeArch;
173254721Semaste                case 1u << eTypeArgs:           return eTypeArgs;
174254721Semaste                case 1u << eTypeArray:          return eTypeArray;
175254721Semaste                case 1u << eTypeBoolean:        return eTypeBoolean;
176254721Semaste                case 1u << eTypeDictionary:     return eTypeDictionary;
177254721Semaste                case 1u << eTypeEnum:           return eTypeEnum;
178254721Semaste                case 1u << eTypeFileSpec:       return eTypeFileSpec;
179254721Semaste                case 1u << eTypeFileSpecList:   return eTypeFileSpecList;
180254721Semaste                case 1u << eTypeFormat:         return eTypeFormat;
181254721Semaste                case 1u << eTypePathMap:        return eTypePathMap;
182254721Semaste                case 1u << eTypeProperties:     return eTypeProperties;
183254721Semaste                case 1u << eTypeRegex:          return eTypeRegex;
184254721Semaste                case 1u << eTypeSInt64:         return eTypeSInt64;
185254721Semaste                case 1u << eTypeString:         return eTypeString;
186254721Semaste                case 1u << eTypeUInt64:         return eTypeUInt64;
187254721Semaste                case 1u << eTypeUUID:           return eTypeUUID;
188254721Semaste            }
189254721Semaste            // Else return invalid
190254721Semaste            return eTypeInvalid;
191254721Semaste        }
192254721Semaste
193254721Semaste        static lldb::OptionValueSP
194254721Semaste        CreateValueFromCStringForTypeMask (const char *value_cstr,
195254721Semaste                                           uint32_t type_mask,
196254721Semaste                                           Error &error);
197254721Semaste
198254721Semaste        // Get this value as a uint64_t value if it is encoded as a boolean,
199254721Semaste        // uint64_t or int64_t. Other types will cause "fail_value" to be
200254721Semaste        // returned
201254721Semaste        uint64_t
202254721Semaste        GetUInt64Value (uint64_t fail_value, bool *success_ptr);
203254721Semaste
204254721Semaste        OptionValueArch *
205254721Semaste        GetAsArch ();
206254721Semaste
207254721Semaste        const OptionValueArch *
208254721Semaste        GetAsArch () const;
209254721Semaste
210254721Semaste        OptionValueArray *
211254721Semaste        GetAsArray ();
212254721Semaste
213254721Semaste        const OptionValueArray *
214254721Semaste        GetAsArray () const;
215254721Semaste
216254721Semaste        OptionValueArgs *
217254721Semaste        GetAsArgs ();
218254721Semaste
219254721Semaste        const OptionValueArgs *
220254721Semaste        GetAsArgs () const;
221254721Semaste
222254721Semaste        OptionValueBoolean *
223254721Semaste        GetAsBoolean ();
224254721Semaste
225254721Semaste        const OptionValueBoolean *
226254721Semaste        GetAsBoolean () const;
227254721Semaste
228254721Semaste        OptionValueDictionary *
229254721Semaste        GetAsDictionary ();
230254721Semaste
231254721Semaste        const OptionValueDictionary *
232254721Semaste        GetAsDictionary () const;
233254721Semaste
234254721Semaste        OptionValueEnumeration *
235254721Semaste        GetAsEnumeration ();
236254721Semaste
237254721Semaste        const OptionValueEnumeration *
238254721Semaste        GetAsEnumeration () const;
239254721Semaste
240254721Semaste        OptionValueFileSpec *
241254721Semaste        GetAsFileSpec ();
242254721Semaste
243254721Semaste        const OptionValueFileSpec *
244254721Semaste        GetAsFileSpec () const;
245254721Semaste
246254721Semaste        OptionValueFileSpecList *
247254721Semaste        GetAsFileSpecList ();
248254721Semaste
249254721Semaste        const OptionValueFileSpecList *
250254721Semaste        GetAsFileSpecList () const;
251254721Semaste
252254721Semaste        OptionValueFormat *
253254721Semaste        GetAsFormat ();
254254721Semaste
255254721Semaste        const OptionValueFormat *
256254721Semaste        GetAsFormat () const;
257254721Semaste
258254721Semaste        OptionValuePathMappings *
259254721Semaste        GetAsPathMappings ();
260254721Semaste
261254721Semaste        const OptionValuePathMappings *
262254721Semaste        GetAsPathMappings () const;
263254721Semaste
264254721Semaste        OptionValueProperties *
265254721Semaste        GetAsProperties ();
266254721Semaste
267254721Semaste        const OptionValueProperties *
268254721Semaste        GetAsProperties () const;
269254721Semaste
270254721Semaste        OptionValueRegex *
271254721Semaste        GetAsRegex ();
272254721Semaste
273254721Semaste        const OptionValueRegex *
274254721Semaste        GetAsRegex () const;
275254721Semaste
276254721Semaste        OptionValueSInt64 *
277254721Semaste        GetAsSInt64 ();
278254721Semaste
279254721Semaste        const OptionValueSInt64 *
280254721Semaste        GetAsSInt64 () const;
281254721Semaste
282254721Semaste        OptionValueString *
283254721Semaste        GetAsString ();
284254721Semaste
285254721Semaste        const OptionValueString *
286254721Semaste        GetAsString () const;
287254721Semaste
288254721Semaste        OptionValueUInt64 *
289254721Semaste        GetAsUInt64 ();
290254721Semaste
291254721Semaste        const OptionValueUInt64 *
292254721Semaste        GetAsUInt64 () const;
293254721Semaste
294254721Semaste        OptionValueUUID *
295254721Semaste        GetAsUUID ();
296254721Semaste
297254721Semaste        const OptionValueUUID *
298254721Semaste        GetAsUUID () const;
299254721Semaste
300254721Semaste        bool
301254721Semaste        GetBooleanValue (bool fail_value = false) const;
302254721Semaste
303254721Semaste        bool
304254721Semaste        SetBooleanValue (bool new_value);
305254721Semaste
306254721Semaste        int64_t
307254721Semaste        GetEnumerationValue (int64_t fail_value = -1) const;
308254721Semaste
309254721Semaste        bool
310254721Semaste        SetEnumerationValue (int64_t value);
311254721Semaste
312254721Semaste        FileSpec
313254721Semaste        GetFileSpecValue () const;
314254721Semaste
315254721Semaste        bool
316254721Semaste        SetFileSpecValue (const FileSpec &file_spec);
317254721Semaste
318254721Semaste        FileSpecList
319254721Semaste        GetFileSpecListValue () const;
320254721Semaste
321254721Semaste        lldb::Format
322254721Semaste        GetFormatValue (lldb::Format fail_value = lldb::eFormatDefault) const;
323254721Semaste
324254721Semaste        bool
325254721Semaste        SetFormatValue (lldb::Format new_value);
326254721Semaste
327254721Semaste        const RegularExpression *
328254721Semaste        GetRegexValue () const;
329254721Semaste
330254721Semaste        int64_t
331254721Semaste        GetSInt64Value (int64_t fail_value = 0) const;
332254721Semaste
333254721Semaste        bool
334254721Semaste        SetSInt64Value (int64_t new_value);
335254721Semaste
336254721Semaste        const char *
337254721Semaste        GetStringValue (const char *fail_value = NULL) const;
338254721Semaste
339254721Semaste        bool
340254721Semaste        SetStringValue (const char *new_value);
341254721Semaste
342254721Semaste        uint64_t
343254721Semaste        GetUInt64Value (uint64_t fail_value = 0) const;
344254721Semaste
345254721Semaste        bool
346254721Semaste        SetUInt64Value (uint64_t new_value);
347254721Semaste
348254721Semaste        UUID
349254721Semaste        GetUUIDValue () const;
350254721Semaste
351254721Semaste        bool
352254721Semaste        SetUUIDValue (const UUID &uuid);
353254721Semaste
354254721Semaste        bool
355254721Semaste        OptionWasSet () const
356254721Semaste        {
357254721Semaste            return m_value_was_set;
358254721Semaste        }
359254721Semaste
360254721Semaste        void
361254721Semaste        SetOptionWasSet ()
362254721Semaste        {
363254721Semaste            m_value_was_set = true;
364254721Semaste        }
365254721Semaste
366254721Semaste        void
367254721Semaste        SetParent (const lldb::OptionValueSP &parent_sp)
368254721Semaste        {
369254721Semaste            m_parent_wp = parent_sp;
370254721Semaste        }
371254721Semaste    protected:
372254721Semaste        lldb::OptionValueWP m_parent_wp;
373254721Semaste        bool m_value_was_set; // This can be used to see if a value has been set
374254721Semaste                              // by a call to SetValueFromCString(). It is often
375254721Semaste                              // handy to know if an option value was set from
376254721Semaste                              // the command line or as a setting, versus if we
377254721Semaste                              // just have the default value that was already
378254721Semaste                              // populated in the option value.
379254721Semaste
380254721Semaste    };
381254721Semaste
382254721Semaste} // namespace lldb_private
383254721Semaste
384254721Semaste#endif  // liblldb_OptionValue_h_
385