1 //===-- OptionValueProperties.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_OptionValueProperties_h_
11 #define liblldb_OptionValueProperties_h_
12 
13 #include <vector>
14 
15 #include "lldb/Core/FormatEntity.h"
16 #include "lldb/Core/UniqueCStringMap.h"
17 #include "lldb/Interpreter/OptionValue.h"
18 #include "lldb/Interpreter/Property.h"
19 #include "lldb/Utility/ConstString.h"
20 
21 namespace lldb_private {
22 
23 class OptionValueProperties
24     : public OptionValue,
25       public std::enable_shared_from_this<OptionValueProperties> {
26 public:
OptionValueProperties()27   OptionValueProperties()
28       : OptionValue(), m_name(), m_properties(), m_name_to_index() {}
29 
30   OptionValueProperties(const ConstString &name);
31 
32   OptionValueProperties(const OptionValueProperties &global_properties);
33 
34   ~OptionValueProperties() override = default;
35 
GetType()36   Type GetType() const override { return eTypeProperties; }
37 
38   bool Clear() override;
39 
40   lldb::OptionValueSP DeepCopy() const override;
41 
42   Status
43   SetValueFromString(llvm::StringRef value,
44                      VarSetOperationType op = eVarSetOperationAssign) override;
45 
46   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
47                  uint32_t dump_mask) override;
48 
GetName()49   ConstString GetName() const override { return m_name; }
50 
51   virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx,
52                                    Stream &strm, llvm::StringRef property_path,
53                                    uint32_t dump_mask);
54 
55   virtual void DumpAllDescriptions(CommandInterpreter &interpreter,
56                                    Stream &strm) const;
57 
58   void Apropos(llvm::StringRef keyword,
59                std::vector<const Property *> &matching_properties) const;
60 
61   void Initialize(const PropertyDefinitions &setting_definitions);
62 
63   //    bool
64   //    GetQualifiedName (Stream &strm);
65 
66   //---------------------------------------------------------------------
67   // Subclass specific functions
68   //---------------------------------------------------------------------
69 
70   virtual size_t GetNumProperties() const;
71 
72   //---------------------------------------------------------------------
73   // Get the index of a property given its exact name in this property
74   // collection, "name" can't be a path to a property path that refers to a
75   // property within a property
76   //---------------------------------------------------------------------
77   virtual uint32_t GetPropertyIndex(const ConstString &name) const;
78 
79   //---------------------------------------------------------------------
80   // Get a property by exact name exists in this property collection, name can
81   // not be a path to a property path that refers to a property within a
82   // property
83   //---------------------------------------------------------------------
84   virtual const Property *GetProperty(const ExecutionContext *exe_ctx,
85                                       bool will_modify,
86                                       const ConstString &name) const;
87 
88   virtual const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx,
89                                              bool will_modify,
90                                              uint32_t idx) const;
91 
92   //---------------------------------------------------------------------
93   // Property can be be a property path like
94   // "target.process.extra-startup-command"
95   //---------------------------------------------------------------------
96   virtual const Property *GetPropertyAtPath(const ExecutionContext *exe_ctx,
97                                             bool will_modify,
98     llvm::StringRef property_path) const;
99 
100   virtual lldb::OptionValueSP
101   GetPropertyValueAtIndex(const ExecutionContext *exe_ctx, bool will_modify,
102                           uint32_t idx) const;
103 
104   virtual lldb::OptionValueSP GetValueForKey(const ExecutionContext *exe_ctx,
105                                              const ConstString &key,
106                                              bool value_will_be_modified) const;
107 
108   lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
109                                   llvm::StringRef name,
110                                   bool value_will_be_modified,
111                                   Status &error) const override;
112 
113   Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op,
114                      llvm::StringRef path, llvm::StringRef value) override;
115 
PredicateMatches(const ExecutionContext * exe_ctx,llvm::StringRef predicate)116   virtual bool PredicateMatches(const ExecutionContext *exe_ctx,
117     llvm::StringRef predicate) const {
118     return false;
119   }
120 
121   OptionValueArch *
122   GetPropertyAtIndexAsOptionValueArch(const ExecutionContext *exe_ctx,
123                                       uint32_t idx) const;
124 
125   OptionValueLanguage *
126   GetPropertyAtIndexAsOptionValueLanguage(const ExecutionContext *exe_ctx,
127                                           uint32_t idx) const;
128 
129   bool GetPropertyAtIndexAsArgs(const ExecutionContext *exe_ctx, uint32_t idx,
130                                 Args &args) const;
131 
132   bool SetPropertyAtIndexFromArgs(const ExecutionContext *exe_ctx, uint32_t idx,
133                                   const Args &args);
134 
135   bool GetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx,
136                                    uint32_t idx, bool fail_value) const;
137 
138   bool SetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx,
139                                    uint32_t idx, bool new_value);
140 
141   OptionValueDictionary *
142   GetPropertyAtIndexAsOptionValueDictionary(const ExecutionContext *exe_ctx,
143                                             uint32_t idx) const;
144 
145   int64_t GetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx,
146                                           uint32_t idx,
147                                           int64_t fail_value) const;
148 
149   bool SetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx,
150                                        uint32_t idx, int64_t new_value);
151 
152   const FormatEntity::Entry *
153   GetPropertyAtIndexAsFormatEntity(const ExecutionContext *exe_ctx,
154                                    uint32_t idx);
155 
156   const RegularExpression *
157   GetPropertyAtIndexAsOptionValueRegex(const ExecutionContext *exe_ctx,
158                                        uint32_t idx) const;
159 
160   OptionValueSInt64 *
161   GetPropertyAtIndexAsOptionValueSInt64(const ExecutionContext *exe_ctx,
162                                         uint32_t idx) const;
163 
164   int64_t GetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx,
165                                      uint32_t idx, int64_t fail_value) const;
166 
167   bool SetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx, uint32_t idx,
168                                   int64_t new_value);
169 
170   uint64_t GetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx,
171                                       uint32_t idx, uint64_t fail_value) const;
172 
173   bool SetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx, uint32_t idx,
174                                   uint64_t new_value);
175 
176   llvm::StringRef GetPropertyAtIndexAsString(const ExecutionContext *exe_ctx,
177                                          uint32_t idx,
178                                          llvm::StringRef fail_value) const;
179 
180   bool SetPropertyAtIndexAsString(const ExecutionContext *exe_ctx, uint32_t idx,
181                                   llvm::StringRef new_value);
182 
183   OptionValueString *
184   GetPropertyAtIndexAsOptionValueString(const ExecutionContext *exe_ctx,
185                                         bool will_modify, uint32_t idx) const;
186 
187   OptionValueFileSpec *
188   GetPropertyAtIndexAsOptionValueFileSpec(const ExecutionContext *exe_ctx,
189                                           bool will_modify, uint32_t idx) const;
190 
191   FileSpec GetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx,
192                                         uint32_t idx) const;
193 
194   bool SetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx,
195                                     uint32_t idx, const FileSpec &file_spec);
196 
197   OptionValuePathMappings *GetPropertyAtIndexAsOptionValuePathMappings(
198       const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
199 
200   OptionValueFileSpecList *GetPropertyAtIndexAsOptionValueFileSpecList(
201       const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
202 
203   void AppendProperty(const ConstString &name, const ConstString &desc,
204                       bool is_global, const lldb::OptionValueSP &value_sp);
205 
206   lldb::OptionValuePropertiesSP GetSubProperty(const ExecutionContext *exe_ctx,
207                                                const ConstString &name);
208 
209   void SetValueChangedCallback(uint32_t property_idx,
210                                OptionValueChangedCallback callback,
211                                void *baton);
212 
213 protected:
ProtectedGetPropertyAtIndex(uint32_t idx)214   Property *ProtectedGetPropertyAtIndex(uint32_t idx) {
215     return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
216   }
217 
ProtectedGetPropertyAtIndex(uint32_t idx)218   const Property *ProtectedGetPropertyAtIndex(uint32_t idx) const {
219     return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
220   }
221 
222   typedef UniqueCStringMap<size_t> NameToIndex;
223 
224   ConstString m_name;
225   std::vector<Property> m_properties;
226   NameToIndex m_name_to_index;
227 };
228 
229 } // namespace lldb_private
230 
231 #endif // liblldb_OptionValueProperties_h_
232