1 //===-- Mangled.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_Mangled_h_
11 #define liblldb_Mangled_h_
12 #if defined(__cplusplus)
15 #include "lldb/lldb-private.h"
16 #include "lldb/Core/ConstString.h"
19 namespace lldb_private {
21 //----------------------------------------------------------------------
22 /// @class Mangled Mangled.h "lldb/Core/Mangled.h"
23 /// @brief A class that handles mangled names.
25 /// Designed to handle mangled names. The demangled version of any names
26 /// will be computed when the demangled name is accessed through the
27 /// Demangled() acccessor. This class can also tokenize the demangled
28 /// version of the name for powerful searches. Functions and symbols
29 /// could make instances of this class for their mangled names. Uniqued
30 /// string pools are used for the mangled, demangled, and token string
31 /// values to allow for faster comparisons and for efficient memory use.
32 //----------------------------------------------------------------------
41 ePreferDemangledWithoutArguments
44 //----------------------------------------------------------------------
45 /// Default constructor.
47 /// Initialize with both mangled and demangled names empty.
48 //----------------------------------------------------------------------
51 //----------------------------------------------------------------------
52 /// Construct with name.
54 /// Constructor with an optional string and a boolean indicating if it is
55 /// the mangled version.
58 /// The already const name to copy into this object.
60 /// @param[in] is_mangled
61 /// If \b true then \a name is a mangled name, if \b false then
62 /// \a name is demangled.
63 //----------------------------------------------------------------------
65 Mangled (const ConstString &name, bool is_mangled);
67 //----------------------------------------------------------------------
68 /// Construct with name.
70 /// Constructor with an optional string and auto-detect if \a name is
74 /// The already const name to copy into this object.
75 //----------------------------------------------------------------------
77 Mangled (const ConstString &name);
79 //----------------------------------------------------------------------
82 /// Releases its ref counts on the mangled and demangled strings that
83 /// live in the global string pool.
84 //----------------------------------------------------------------------
87 //----------------------------------------------------------------------
88 /// Convert to pointer operator.
90 /// This allows code to check a Mangled object to see if it contains
91 /// a valid mangled name using code such as:
94 /// Mangled mangled(...);
100 /// A pointer to this object if either the mangled or unmangled
101 /// name is set, NULL otherwise.
102 //----------------------------------------------------------------------
106 //----------------------------------------------------------------------
107 /// Logical NOT operator.
109 /// This allows code to check a Mangled object to see if it contains
110 /// an empty mangled name using code such as:
113 /// Mangled mangled(...);
119 /// Returns \b true if the object has an empty mangled and
120 /// unmangled name, \b false otherwise.
121 //----------------------------------------------------------------------
125 //----------------------------------------------------------------------
126 /// Clear the mangled and demangled values.
127 //----------------------------------------------------------------------
131 //----------------------------------------------------------------------
132 /// Compare the mangled string values
134 /// Compares the Mangled::GetName() string in \a lhs and \a rhs.
137 /// A const reference to the Left Hand Side object to compare.
140 /// A const reference to the Right Hand Side object to compare.
143 /// @li -1 if \a lhs is less than \a rhs
144 /// @li 0 if \a lhs is equal to \a rhs
145 /// @li 1 if \a lhs is greater than \a rhs
146 //----------------------------------------------------------------------
148 Compare (const Mangled& lhs, const Mangled& rhs);
150 //----------------------------------------------------------------------
151 /// Dump a description of this object to a Stream \a s.
153 /// Dump a Mangled object to stream \a s. We don't force our
154 /// demangled name to be computed currently (we don't use the accessor).
157 /// The stream to which to dump the object description.
158 //----------------------------------------------------------------------
160 Dump (Stream *s) const;
162 //----------------------------------------------------------------------
163 /// Dump a debug description of this object to a Stream \a s.
166 /// The stream to which to dump the object description.
167 //----------------------------------------------------------------------
169 DumpDebug (Stream *s) const;
171 //----------------------------------------------------------------------
172 /// Demangled name get accessor.
175 /// A const reference to the demangled name string object.
176 //----------------------------------------------------------------------
178 GetDemangledName () const;
181 SetDemangledName (const ConstString &name)
187 SetMangledName (const ConstString &name)
192 //----------------------------------------------------------------------
193 /// Mangled name get accessor.
196 /// A reference to the mangled name string object.
197 //----------------------------------------------------------------------
204 //----------------------------------------------------------------------
205 /// Mangled name get accessor.
208 /// A const reference to the mangled name string object.
209 //----------------------------------------------------------------------
211 GetMangledName () const
216 //----------------------------------------------------------------------
217 /// Best name get accessor.
219 /// @param[in] preference
220 /// Which name would you prefer to get?
223 /// A const reference to the preferred name string object if this
224 /// object has a valid name of that kind, else a const reference to the
225 /// other name is returned.
226 //----------------------------------------------------------------------
228 GetName (NamePreference preference = ePreferDemangled) const;
230 //----------------------------------------------------------------------
231 /// Check if "name" matches either the mangled or demangled name.
234 /// A name to match against both strings.
237 /// \b True if \a name matches either name, \b false otherwise.
238 //----------------------------------------------------------------------
240 NameMatches (const ConstString &name) const
242 if (m_mangled == name)
244 return GetDemangledName () == name;
248 NameMatches (const RegularExpression& regex) const;
250 //----------------------------------------------------------------------
251 /// Get the memory cost of this object.
253 /// Return the size in bytes that this object takes in memory. This
254 /// returns the size in bytes of this object, not any shared string
255 /// values it may refer to.
258 /// The number of bytes that this object occupies in memory.
260 /// @see ConstString::StaticMemorySize ()
261 //----------------------------------------------------------------------
265 //----------------------------------------------------------------------
266 /// Set the string value in this object.
268 /// If \a is_mangled is \b true, then the mangled named is set to \a
269 /// name, else the demangled name is set to \a name.
272 /// The already const version of the name for this object.
274 /// @param[in] is_mangled
275 /// If \b true then \a name is a mangled name, if \b false then
276 /// \a name is demangled.
277 //----------------------------------------------------------------------
279 SetValue (const ConstString &name, bool is_mangled);
281 //----------------------------------------------------------------------
282 /// Set the string value in this object.
284 /// This version auto detects if the string is mangled by inspecting the
285 /// string value and looking for common mangling prefixes.
288 /// The already const version of the name for this object.
289 //----------------------------------------------------------------------
291 SetValue (const ConstString &name);
294 //----------------------------------------------------------------------
295 /// Mangled member variables.
296 //----------------------------------------------------------------------
297 ConstString m_mangled; ///< The mangled version of the name
298 mutable ConstString m_demangled; ///< Mutable so we can get it on demand with a const version of this object
302 Stream& operator << (Stream& s, const Mangled& obj);
304 } // namespace lldb_private
306 #endif // #if defined(__cplusplus)
307 #endif // liblldb_Mangled_h_