1 //===-- OptionValueProperties.h ---------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_OptionValueProperties_h_
10 #define liblldb_OptionValueProperties_h_
14 #include "lldb/Core/FormatEntity.h"
15 #include "lldb/Core/UniqueCStringMap.h"
16 #include "lldb/Interpreter/OptionValue.h"
17 #include "lldb/Interpreter/Property.h"
18 #include "lldb/Utility/ConstString.h"
20 namespace lldb_private {
22 class OptionValueProperties
24 public std::enable_shared_from_this<OptionValueProperties> {
26 OptionValueProperties()
27 : OptionValue(), m_name(), m_properties(), m_name_to_index() {}
29 OptionValueProperties(ConstString name);
31 OptionValueProperties(const OptionValueProperties &global_properties);
33 ~OptionValueProperties() override = default;
35 Type GetType() const override { return eTypeProperties; }
37 bool Clear() override;
39 lldb::OptionValueSP DeepCopy() const override;
42 SetValueFromString(llvm::StringRef value,
43 VarSetOperationType op = eVarSetOperationAssign) override;
45 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
46 uint32_t dump_mask) override;
48 ConstString GetName() const override { return m_name; }
50 virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx,
51 Stream &strm, llvm::StringRef property_path,
54 virtual void DumpAllDescriptions(CommandInterpreter &interpreter,
57 void Apropos(llvm::StringRef keyword,
58 std::vector<const Property *> &matching_properties) const;
60 void Initialize(const PropertyDefinitions &setting_definitions);
63 // GetQualifiedName (Stream &strm);
65 // Subclass specific functions
67 virtual size_t GetNumProperties() const;
69 // Get the index of a property given its exact name in this property
70 // collection, "name" can't be a path to a property path that refers to a
71 // property within a property
72 virtual uint32_t GetPropertyIndex(ConstString name) const;
74 // Get a property by exact name exists in this property collection, name can
75 // not be a path to a property path that refers to a property within a
77 virtual const Property *GetProperty(const ExecutionContext *exe_ctx,
79 ConstString name) const;
81 virtual const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx,
85 // Property can be be a property path like
86 // "target.process.extra-startup-command"
87 virtual const Property *GetPropertyAtPath(const ExecutionContext *exe_ctx,
89 llvm::StringRef property_path) const;
91 virtual lldb::OptionValueSP
92 GetPropertyValueAtIndex(const ExecutionContext *exe_ctx, bool will_modify,
95 virtual lldb::OptionValueSP GetValueForKey(const ExecutionContext *exe_ctx,
97 bool value_will_be_modified) const;
99 lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
100 llvm::StringRef name,
101 bool value_will_be_modified,
102 Status &error) const override;
104 Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op,
105 llvm::StringRef path, llvm::StringRef value) override;
107 virtual bool PredicateMatches(const ExecutionContext *exe_ctx,
108 llvm::StringRef predicate) const {
113 GetPropertyAtIndexAsOptionValueArch(const ExecutionContext *exe_ctx,
116 OptionValueLanguage *
117 GetPropertyAtIndexAsOptionValueLanguage(const ExecutionContext *exe_ctx,
120 bool GetPropertyAtIndexAsArgs(const ExecutionContext *exe_ctx, uint32_t idx,
123 bool SetPropertyAtIndexFromArgs(const ExecutionContext *exe_ctx, uint32_t idx,
126 bool GetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx,
127 uint32_t idx, bool fail_value) const;
129 bool SetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx,
130 uint32_t idx, bool new_value);
132 OptionValueDictionary *
133 GetPropertyAtIndexAsOptionValueDictionary(const ExecutionContext *exe_ctx,
136 int64_t GetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx,
138 int64_t fail_value) const;
140 bool SetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx,
141 uint32_t idx, int64_t new_value);
143 const FormatEntity::Entry *
144 GetPropertyAtIndexAsFormatEntity(const ExecutionContext *exe_ctx,
147 const RegularExpression *
148 GetPropertyAtIndexAsOptionValueRegex(const ExecutionContext *exe_ctx,
152 GetPropertyAtIndexAsOptionValueSInt64(const ExecutionContext *exe_ctx,
155 int64_t GetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx,
156 uint32_t idx, int64_t fail_value) const;
158 bool SetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx, uint32_t idx,
161 uint64_t GetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx,
162 uint32_t idx, uint64_t fail_value) const;
164 bool SetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx, uint32_t idx,
167 llvm::StringRef GetPropertyAtIndexAsString(const ExecutionContext *exe_ctx,
169 llvm::StringRef fail_value) const;
171 bool SetPropertyAtIndexAsString(const ExecutionContext *exe_ctx, uint32_t idx,
172 llvm::StringRef new_value);
175 GetPropertyAtIndexAsOptionValueString(const ExecutionContext *exe_ctx,
176 bool will_modify, uint32_t idx) const;
178 OptionValueFileSpec *
179 GetPropertyAtIndexAsOptionValueFileSpec(const ExecutionContext *exe_ctx,
180 bool will_modify, uint32_t idx) const;
182 FileSpec GetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx,
185 bool SetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx,
186 uint32_t idx, const FileSpec &file_spec);
188 OptionValuePathMappings *GetPropertyAtIndexAsOptionValuePathMappings(
189 const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
191 OptionValueFileSpecList *GetPropertyAtIndexAsOptionValueFileSpecList(
192 const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const;
194 void AppendProperty(ConstString name, ConstString desc,
195 bool is_global, const lldb::OptionValueSP &value_sp);
197 lldb::OptionValuePropertiesSP GetSubProperty(const ExecutionContext *exe_ctx,
200 void SetValueChangedCallback(uint32_t property_idx,
201 OptionValueChangedCallback callback,
205 Property *ProtectedGetPropertyAtIndex(uint32_t idx) {
206 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
209 const Property *ProtectedGetPropertyAtIndex(uint32_t idx) const {
210 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
213 typedef UniqueCStringMap<size_t> NameToIndex;
216 std::vector<Property> m_properties;
217 NameToIndex m_name_to_index;
220 } // namespace lldb_private
222 #endif // liblldb_OptionValueProperties_h_