1 //===-- OptionValueProperties.h ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_OptionValueProperties_h_
11 #define liblldb_OptionValueProperties_h_
17 // Other libraries and framework includes
19 #include "lldb/Core/FormatEntity.h"
20 #include "lldb/Core/UniqueCStringMap.h"
21 #include "lldb/Interpreter/OptionValue.h"
22 #include "lldb/Interpreter/Property.h"
23 #include "lldb/Utility/ConstString.h"
25 namespace lldb_private {
27 class OptionValueProperties
29 public std::enable_shared_from_this<OptionValueProperties> {
31 OptionValueProperties()
32 : OptionValue(), m_name(), m_properties(), m_name_to_index() {}
34 OptionValueProperties(const ConstString &name);
36 OptionValueProperties(const OptionValueProperties &global_properties);
38 ~OptionValueProperties() override = default;
40 Type GetType() const override { return eTypeProperties; }
42 bool Clear() override;
44 lldb::OptionValueSP DeepCopy() const override;
47 SetValueFromString(llvm::StringRef value,
48 VarSetOperationType op = eVarSetOperationAssign) override;
50 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
51 uint32_t dump_mask) override;
53 ConstString GetName() const override { return m_name; }
55 virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx,
56 Stream &strm, llvm::StringRef property_path,
59 virtual void DumpAllDescriptions(CommandInterpreter &interpreter,
62 void Apropos(llvm::StringRef keyword,
63 std::vector<const Property *> &matching_properties) const;
65 void Initialize(const PropertyDefinition *setting_definitions);
68 // GetQualifiedName (Stream &strm);
70 //---------------------------------------------------------------------
71 // Subclass specific functions
72 //---------------------------------------------------------------------
74 virtual size_t GetNumProperties() const;
76 //---------------------------------------------------------------------
77 // Get the index of a property given its exact name in this property
78 // collection, "name" can't be a path to a property path that refers
79 // to a property within a property
80 //---------------------------------------------------------------------
81 virtual uint32_t GetPropertyIndex(const ConstString &name) const;
83 //---------------------------------------------------------------------
84 // Get a property by exact name exists in this property collection, name
85 // can not be a path to a property path that refers to a property within
87 //---------------------------------------------------------------------
88 virtual const Property *GetProperty(const ExecutionContext *exe_ctx,
90 const ConstString &name) const;
92 virtual const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx,
96 //---------------------------------------------------------------------
97 // Property can be be a property path like
98 // "target.process.extra-startup-command"
99 //---------------------------------------------------------------------
100 virtual const Property *GetPropertyAtPath(const ExecutionContext *exe_ctx,
102 llvm::StringRef property_path) const;
104 virtual lldb::OptionValueSP
105 GetPropertyValueAtIndex(const ExecutionContext *exe_ctx, bool will_modify,
108 virtual lldb::OptionValueSP GetValueForKey(const ExecutionContext *exe_ctx,
109 const ConstString &key,
110 bool value_will_be_modified) const;
112 lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
113 llvm::StringRef name,
114 bool value_will_be_modified,
115 Status &error) const override;
117 Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op,
118 llvm::StringRef path, llvm::StringRef value) override;
120 virtual bool PredicateMatches(const ExecutionContext *exe_ctx,
121 llvm::StringRef predicate) const {
126 GetPropertyAtIndexAsOptionValueArch(const ExecutionContext *exe_ctx,
129 OptionValueLanguage *
130 GetPropertyAtIndexAsOptionValueLanguage(const ExecutionContext *exe_ctx,
133 bool GetPropertyAtIndexAsArgs(const ExecutionContext *exe_ctx, uint32_t idx,
136 bool SetPropertyAtIndexFromArgs(const ExecutionContext *exe_ctx, uint32_t idx,
139 bool GetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx,
140 uint32_t idx, bool fail_value) const;
142 bool SetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx,
143 uint32_t idx, bool new_value);
145 OptionValueDictionary *
146 GetPropertyAtIndexAsOptionValueDictionary(const ExecutionContext *exe_ctx,
149 int64_t GetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx,
151 int64_t fail_value) const;
153 bool SetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx,
154 uint32_t idx, int64_t new_value);
156 const FormatEntity::Entry *
157 GetPropertyAtIndexAsFormatEntity(const ExecutionContext *exe_ctx,
160 const RegularExpression *
161 GetPropertyAtIndexAsOptionValueRegex(const ExecutionContext *exe_ctx,
165 GetPropertyAtIndexAsOptionValueSInt64(const ExecutionContext *exe_ctx,
168 int64_t GetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx,
169 uint32_t idx, int64_t fail_value) const;
171 bool SetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx, uint32_t idx,
174 uint64_t GetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx,
175 uint32_t idx, uint64_t fail_value) const;
177 bool SetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx, uint32_t idx,
180 llvm::StringRef GetPropertyAtIndexAsString(const ExecutionContext *exe_ctx,
182 llvm::StringRef fail_value) const;
184 bool SetPropertyAtIndexAsString(const ExecutionContext *exe_ctx, uint32_t idx,
185 llvm::StringRef new_value);
188 GetPropertyAtIndexAsOptionValueString(const ExecutionContext *exe_ctx,
189 bool will_modify, uint32_t idx) const;
191 OptionValueFileSpec *
192 GetPropertyAtIndexAsOptionValueFileSpec(const ExecutionContext *exe_ctx,
193 bool will_modify, uint32_t idx) const;
195 FileSpec GetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx,
198 bool SetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx,
199 uint32_t idx, const FileSpec &file_spec);
201 OptionValuePathMappings *GetPropertyAtIndexAsOptionValuePathMappings(
202 const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
204 OptionValueFileSpecList *GetPropertyAtIndexAsOptionValueFileSpecList(
205 const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
207 void AppendProperty(const ConstString &name, const ConstString &desc,
208 bool is_global, const lldb::OptionValueSP &value_sp);
210 lldb::OptionValuePropertiesSP GetSubProperty(const ExecutionContext *exe_ctx,
211 const ConstString &name);
213 void SetValueChangedCallback(uint32_t property_idx,
214 OptionValueChangedCallback callback,
218 Property *ProtectedGetPropertyAtIndex(uint32_t idx) {
219 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
222 const Property *ProtectedGetPropertyAtIndex(uint32_t idx) const {
223 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
226 typedef UniqueCStringMap<size_t> NameToIndex;
229 std::vector<Property> m_properties;
230 NameToIndex m_name_to_index;
233 } // namespace lldb_private
235 #endif // liblldb_OptionValueProperties_h_