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_
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"
21 namespace lldb_private {
23 class OptionValueProperties
25 public std::enable_shared_from_this<OptionValueProperties> {
27 OptionValueProperties()
28 : OptionValue(), m_name(), m_properties(), m_name_to_index() {}
30 OptionValueProperties(const ConstString &name);
32 OptionValueProperties(const OptionValueProperties &global_properties);
34 ~OptionValueProperties() override = default;
36 Type GetType() const override { return eTypeProperties; }
38 bool Clear() override;
40 lldb::OptionValueSP DeepCopy() const override;
43 SetValueFromString(llvm::StringRef value,
44 VarSetOperationType op = eVarSetOperationAssign) override;
46 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
47 uint32_t dump_mask) override;
49 ConstString GetName() const override { return m_name; }
51 virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx,
52 Stream &strm, llvm::StringRef property_path,
55 virtual void DumpAllDescriptions(CommandInterpreter &interpreter,
58 void Apropos(llvm::StringRef keyword,
59 std::vector<const Property *> &matching_properties) const;
61 void Initialize(const PropertyDefinitions &setting_definitions);
64 // GetQualifiedName (Stream &strm);
66 //---------------------------------------------------------------------
67 // Subclass specific functions
68 //---------------------------------------------------------------------
70 virtual size_t GetNumProperties() const;
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;
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
83 //---------------------------------------------------------------------
84 virtual const Property *GetProperty(const ExecutionContext *exe_ctx,
86 const ConstString &name) const;
88 virtual const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx,
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,
98 llvm::StringRef property_path) const;
100 virtual lldb::OptionValueSP
101 GetPropertyValueAtIndex(const ExecutionContext *exe_ctx, bool will_modify,
104 virtual lldb::OptionValueSP GetValueForKey(const ExecutionContext *exe_ctx,
105 const ConstString &key,
106 bool value_will_be_modified) const;
108 lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
109 llvm::StringRef name,
110 bool value_will_be_modified,
111 Status &error) const override;
113 Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op,
114 llvm::StringRef path, llvm::StringRef value) override;
116 virtual bool PredicateMatches(const ExecutionContext *exe_ctx,
117 llvm::StringRef predicate) const {
122 GetPropertyAtIndexAsOptionValueArch(const ExecutionContext *exe_ctx,
125 OptionValueLanguage *
126 GetPropertyAtIndexAsOptionValueLanguage(const ExecutionContext *exe_ctx,
129 bool GetPropertyAtIndexAsArgs(const ExecutionContext *exe_ctx, uint32_t idx,
132 bool SetPropertyAtIndexFromArgs(const ExecutionContext *exe_ctx, uint32_t idx,
135 bool GetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx,
136 uint32_t idx, bool fail_value) const;
138 bool SetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx,
139 uint32_t idx, bool new_value);
141 OptionValueDictionary *
142 GetPropertyAtIndexAsOptionValueDictionary(const ExecutionContext *exe_ctx,
145 int64_t GetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx,
147 int64_t fail_value) const;
149 bool SetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx,
150 uint32_t idx, int64_t new_value);
152 const FormatEntity::Entry *
153 GetPropertyAtIndexAsFormatEntity(const ExecutionContext *exe_ctx,
156 const RegularExpression *
157 GetPropertyAtIndexAsOptionValueRegex(const ExecutionContext *exe_ctx,
161 GetPropertyAtIndexAsOptionValueSInt64(const ExecutionContext *exe_ctx,
164 int64_t GetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx,
165 uint32_t idx, int64_t fail_value) const;
167 bool SetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx, uint32_t idx,
170 uint64_t GetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx,
171 uint32_t idx, uint64_t fail_value) const;
173 bool SetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx, uint32_t idx,
176 llvm::StringRef GetPropertyAtIndexAsString(const ExecutionContext *exe_ctx,
178 llvm::StringRef fail_value) const;
180 bool SetPropertyAtIndexAsString(const ExecutionContext *exe_ctx, uint32_t idx,
181 llvm::StringRef new_value);
184 GetPropertyAtIndexAsOptionValueString(const ExecutionContext *exe_ctx,
185 bool will_modify, uint32_t idx) const;
187 OptionValueFileSpec *
188 GetPropertyAtIndexAsOptionValueFileSpec(const ExecutionContext *exe_ctx,
189 bool will_modify, uint32_t idx) const;
191 FileSpec GetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx,
194 bool SetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx,
195 uint32_t idx, const FileSpec &file_spec);
197 OptionValuePathMappings *GetPropertyAtIndexAsOptionValuePathMappings(
198 const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
200 OptionValueFileSpecList *GetPropertyAtIndexAsOptionValueFileSpecList(
201 const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
203 void AppendProperty(const ConstString &name, const ConstString &desc,
204 bool is_global, const lldb::OptionValueSP &value_sp);
206 lldb::OptionValuePropertiesSP GetSubProperty(const ExecutionContext *exe_ctx,
207 const ConstString &name);
209 void SetValueChangedCallback(uint32_t property_idx,
210 OptionValueChangedCallback callback,
214 Property *ProtectedGetPropertyAtIndex(uint32_t idx) {
215 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
218 const Property *ProtectedGetPropertyAtIndex(uint32_t idx) const {
219 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
222 typedef UniqueCStringMap<size_t> NameToIndex;
225 std::vector<Property> m_properties;
226 NameToIndex m_name_to_index;
229 } // namespace lldb_private
231 #endif // liblldb_OptionValueProperties_h_