xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Symbol/VariableList.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- VariableList.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_SYMBOL_VARIABLELIST_H
10 #define LLDB_SYMBOL_VARIABLELIST_H
11 
12 #include "lldb/Symbol/SymbolContext.h"
13 #include "lldb/Symbol/Variable.h"
14 #include "lldb/lldb-private.h"
15 
16 namespace lldb_private {
17 
18 class VariableList {
19   typedef std::vector<lldb::VariableSP> collection;
20 
21 public:
22   // Constructors and Destructors
23   //  VariableList(const SymbolContext &symbol_context);
24   VariableList();
25   virtual ~VariableList();
26 
27   VariableList(VariableList &&) = default;
28   VariableList &operator=(VariableList &&) = default;
29 
30   void AddVariable(const lldb::VariableSP &var_sp);
31 
32   bool AddVariableIfUnique(const lldb::VariableSP &var_sp);
33 
34   void AddVariables(VariableList *variable_list);
35 
36   void Clear();
37 
38   void Dump(Stream *s, bool show_context) const;
39 
40   lldb::VariableSP GetVariableAtIndex(size_t idx) const;
41 
42   lldb::VariableSP RemoveVariableAtIndex(size_t idx);
43 
44   lldb::VariableSP FindVariable(ConstString name,
45                                 bool include_static_members = true);
46 
47   lldb::VariableSP FindVariable(ConstString name,
48                                 lldb::ValueType value_type,
49                                 bool include_static_members = true);
50 
51   uint32_t FindVariableIndex(const lldb::VariableSP &var_sp);
52 
53   size_t AppendVariablesIfUnique(VariableList &var_list);
54 
55   // Returns the actual number of unique variables that were added to the list.
56   // "total_matches" will get updated with the actually number of matches that
57   // were found regardless of whether they were unique or not to allow for
58   // error conditions when nothing is found, versus conditions where any
59   // variables that match "regex" were already in "var_list".
60   size_t AppendVariablesIfUnique(const RegularExpression &regex,
61                                  VariableList &var_list, size_t &total_matches);
62 
63   size_t AppendVariablesWithScope(lldb::ValueType type, VariableList &var_list,
64                                   bool if_unique = true);
65 
66   uint32_t FindIndexForVariable(Variable *variable);
67 
68   size_t MemorySize() const;
69 
70   size_t GetSize() const;
Empty()71   bool Empty() const { return m_variables.empty(); }
72 
73   typedef collection::iterator iterator;
74   typedef collection::const_iterator const_iterator;
75 
begin()76   iterator begin() { return m_variables.begin(); }
end()77   iterator end() { return m_variables.end(); }
begin()78   const_iterator begin() const { return m_variables.begin(); }
end()79   const_iterator end() const { return m_variables.end(); }
80 
toArrayRef()81   llvm::ArrayRef<lldb::VariableSP> toArrayRef() {
82     return llvm::ArrayRef(m_variables);
83   }
84 
85 protected:
86   collection m_variables;
87 
88 private:
89   // For VariableList only
90   VariableList(const VariableList &) = delete;
91   const VariableList &operator=(const VariableList &) = delete;
92 };
93 
94 } // namespace lldb_private
95 
96 #endif // LLDB_SYMBOL_VARIABLELIST_H
97