Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:50

0001 //===-- OptionValueProperties.h ---------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H
0010 #define LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H
0011 
0012 #include <vector>
0013 
0014 #include "lldb/Core/FormatEntity.h"
0015 #include "lldb/Core/UniqueCStringMap.h"
0016 #include "lldb/Interpreter/OptionValue.h"
0017 #include "lldb/Interpreter/Property.h"
0018 
0019 namespace lldb_private {
0020 class Properties;
0021 
0022 class OptionValueProperties
0023     : public Cloneable<OptionValueProperties, OptionValue>,
0024       public std::enable_shared_from_this<OptionValueProperties> {
0025 public:
0026   OptionValueProperties() = default;
0027 
0028   OptionValueProperties(llvm::StringRef name);
0029 
0030   ~OptionValueProperties() override = default;
0031 
0032   Type GetType() const override { return eTypeProperties; }
0033 
0034   void Clear() override;
0035 
0036   static lldb::OptionValuePropertiesSP
0037   CreateLocalCopy(const Properties &global_properties);
0038 
0039   lldb::OptionValueSP
0040   DeepCopy(const lldb::OptionValueSP &new_parent) const override;
0041 
0042   Status
0043   SetValueFromString(llvm::StringRef value,
0044                      VarSetOperationType op = eVarSetOperationAssign) override;
0045 
0046   void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
0047                  uint32_t dump_mask) override;
0048 
0049   llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override;
0050 
0051   llvm::StringRef GetName() const override { return m_name; }
0052 
0053   virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx,
0054                                    Stream &strm, llvm::StringRef property_path,
0055                                    uint32_t dump_mask, bool is_json = false);
0056 
0057   virtual void DumpAllDescriptions(CommandInterpreter &interpreter,
0058                                    Stream &strm) const;
0059 
0060   void Apropos(llvm::StringRef keyword,
0061                std::vector<const Property *> &matching_properties) const;
0062 
0063   void Initialize(const PropertyDefinitions &setting_definitions);
0064 
0065   // Subclass specific functions
0066 
0067   // Get the index of a property given its exact name in this property
0068   // collection, "name" can't be a path to a property path that refers to a
0069   // property within a property
0070   virtual size_t GetPropertyIndex(llvm::StringRef name) const;
0071 
0072   // Get a property by exact name exists in this property collection, name can
0073   // not be a path to a property path that refers to a property within a
0074   // property
0075   virtual const Property *
0076   GetProperty(llvm::StringRef name,
0077               const ExecutionContext *exe_ctx = nullptr) const;
0078 
0079   virtual const Property *
0080   GetPropertyAtIndex(size_t idx,
0081                      const ExecutionContext *exe_ctx = nullptr) const {
0082     return ProtectedGetPropertyAtIndex(idx);
0083   }
0084 
0085   // Property can be a property path like
0086   // "target.process.extra-startup-command"
0087   virtual const Property *
0088   GetPropertyAtPath(const ExecutionContext *exe_ctx,
0089                     llvm::StringRef property_path) const;
0090 
0091   virtual lldb::OptionValueSP
0092   GetPropertyValueAtIndex(size_t idx, const ExecutionContext *exe_ctx) const;
0093 
0094   virtual lldb::OptionValueSP GetValueForKey(const ExecutionContext *exe_ctx,
0095                                              llvm::StringRef key) const;
0096 
0097   lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
0098                                   llvm::StringRef name,
0099                                   Status &error) const override;
0100 
0101   Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op,
0102                      llvm::StringRef path, llvm::StringRef value) override;
0103 
0104   bool
0105   GetPropertyAtIndexAsArgs(size_t idx, Args &args,
0106                            const ExecutionContext *exe_ctx = nullptr) const;
0107 
0108   bool SetPropertyAtIndexFromArgs(size_t idx, const Args &args,
0109                                   const ExecutionContext *exe_ctx = nullptr);
0110 
0111   OptionValueDictionary *GetPropertyAtIndexAsOptionValueDictionary(
0112       size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
0113 
0114   OptionValueSInt64 *GetPropertyAtIndexAsOptionValueSInt64(
0115       size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
0116 
0117   OptionValueUInt64 *GetPropertyAtIndexAsOptionValueUInt64(
0118       size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
0119 
0120   OptionValueString *GetPropertyAtIndexAsOptionValueString(
0121       size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
0122 
0123   OptionValueFileSpec *GetPropertyAtIndexAsOptionValueFileSpec(
0124       size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
0125 
0126   OptionValuePathMappings *GetPropertyAtIndexAsOptionValuePathMappings(
0127       size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
0128 
0129   OptionValueFileSpecList *GetPropertyAtIndexAsOptionValueFileSpecList(
0130       size_t idx, const ExecutionContext *exe_ctx = nullptr) const;
0131 
0132   void AppendProperty(llvm::StringRef name, llvm::StringRef desc,
0133                       bool is_global, const lldb::OptionValueSP &value_sp);
0134 
0135   lldb::OptionValuePropertiesSP GetSubProperty(const ExecutionContext *exe_ctx,
0136                                                llvm::StringRef name);
0137 
0138   void SetValueChangedCallback(size_t property_idx,
0139                                std::function<void()> callback);
0140 
0141   template <typename T>
0142   auto GetPropertyAtIndexAs(size_t idx,
0143                             const ExecutionContext *exe_ctx = nullptr) const {
0144     if (const Property *property = GetPropertyAtIndex(idx, exe_ctx)) {
0145       if (OptionValue *value = property->GetValue().get())
0146         return value->GetValueAs<T>();
0147     }
0148     if constexpr (std::is_pointer_v<T>)
0149       return T{nullptr};
0150     else
0151       return std::optional<T>{std::nullopt};
0152   }
0153 
0154   template <typename T>
0155   bool SetPropertyAtIndex(size_t idx, T t,
0156                           const ExecutionContext *exe_ctx = nullptr) const {
0157     if (const Property *property = GetPropertyAtIndex(idx, exe_ctx)) {
0158       if (OptionValue *value = property->GetValue().get()) {
0159         value->SetValueAs(t);
0160         return true;
0161       }
0162     }
0163     return false;
0164   }
0165 
0166 protected:
0167   Property *ProtectedGetPropertyAtIndex(size_t idx) {
0168     assert(idx < m_properties.size() && "invalid property index");
0169     return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
0170   }
0171 
0172   const Property *ProtectedGetPropertyAtIndex(size_t idx) const {
0173     assert(idx < m_properties.size() && "invalid property index");
0174     return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr);
0175   }
0176 
0177   std::string m_name;
0178   std::vector<Property> m_properties;
0179   llvm::StringMap<size_t> m_name_to_index;
0180 };
0181 
0182 } // namespace lldb_private
0183 
0184 #endif // LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H