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