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 //----------------------------------------------------------------------
43 //----------------------------------------------------------------------
44 /// Default constructor.
46 /// Initialize with both mangled and demangled names empty.
47 //----------------------------------------------------------------------
50 //----------------------------------------------------------------------
51 /// Construct with name.
53 /// Constructor with an optional string and a boolean indicating if it is
54 /// the mangled version.
57 /// The already const name to copy into this object.
59 /// @param[in] is_mangled
60 /// If \b true then \a name is a mangled name, if \b false then
61 /// \a name is demangled.
62 //----------------------------------------------------------------------
64 Mangled (const ConstString &name, bool is_mangled);
66 //----------------------------------------------------------------------
67 /// Construct with name.
69 /// Constructor with an optional string and auto-detect if \a name is
73 /// The already const name to copy into this object.
74 //----------------------------------------------------------------------
76 Mangled (const ConstString &name);
78 //----------------------------------------------------------------------
81 /// Releases its ref counts on the mangled and demangled strings that
82 /// live in the global string pool.
83 //----------------------------------------------------------------------
86 //----------------------------------------------------------------------
87 /// Convert to pointer operator.
89 /// This allows code to check a Mangled object to see if it contains
90 /// a valid mangled name using code such as:
93 /// Mangled mangled(...);
99 /// A pointer to this object if either the mangled or unmangled
100 /// name is set, NULL otherwise.
101 //----------------------------------------------------------------------
105 //----------------------------------------------------------------------
106 /// Logical NOT operator.
108 /// This allows code to check a Mangled object to see if it contains
109 /// an empty mangled name using code such as:
112 /// Mangled mangled(...);
118 /// Returns \b true if the object has an empty mangled and
119 /// unmangled name, \b false otherwise.
120 //----------------------------------------------------------------------
124 //----------------------------------------------------------------------
125 /// Clear the mangled and demangled values.
126 //----------------------------------------------------------------------
130 //----------------------------------------------------------------------
131 /// Compare the mangled string values
133 /// Compares the Mangled::GetName() string in \a lhs and \a rhs.
136 /// A const reference to the Left Hand Side object to compare.
139 /// A const reference to the Right Hand Side object to compare.
142 /// @li -1 if \a lhs is less than \a rhs
143 /// @li 0 if \a lhs is equal to \a rhs
144 /// @li 1 if \a lhs is greater than \a rhs
145 //----------------------------------------------------------------------
147 Compare (const Mangled& lhs, const Mangled& rhs);
149 //----------------------------------------------------------------------
150 /// Dump a description of this object to a Stream \a s.
152 /// Dump a Mangled object to stream \a s. We don't force our
153 /// demangled name to be computed currently (we don't use the accessor).
156 /// The stream to which to dump the object descripton.
157 //----------------------------------------------------------------------
159 Dump (Stream *s) const;
161 //----------------------------------------------------------------------
162 /// Dump a debug description of this object to a Stream \a s.
165 /// The stream to which to dump the object descripton.
166 //----------------------------------------------------------------------
168 DumpDebug (Stream *s) const;
170 //----------------------------------------------------------------------
171 /// Demangled name get accessor.
174 /// A const reference to the demangled name string object.
175 //----------------------------------------------------------------------
177 GetDemangledName () const;
180 SetDemangledName (const ConstString &name)
186 SetMangledName (const ConstString &name)
191 //----------------------------------------------------------------------
192 /// Mangled name get accessor.
195 /// A reference to the mangled name string object.
196 //----------------------------------------------------------------------
203 //----------------------------------------------------------------------
204 /// Mangled name get accessor.
207 /// A const reference to the mangled name string object.
208 //----------------------------------------------------------------------
210 GetMangledName () const
215 //----------------------------------------------------------------------
216 /// Best name get accessor.
218 /// @param[in] preference
219 /// Which name would you prefer to get?
222 /// A const reference to the the preferred name string object if this
223 /// object has a valid name of that kind, else a const reference to the
224 /// other name is returned.
225 //----------------------------------------------------------------------
227 GetName (NamePreference preference = ePreferDemangled) const;
229 //----------------------------------------------------------------------
230 /// Check if "name" matches either the mangled or demangled name.
233 /// A name to match against both strings.
236 /// \b True if \a name matches either name, \b false otherwise.
237 //----------------------------------------------------------------------
239 NameMatches (const ConstString &name) const
241 if (m_mangled == name)
243 return GetDemangledName () == name;
247 NameMatches (const RegularExpression& regex) const;
249 //----------------------------------------------------------------------
250 /// Get the memory cost of this object.
252 /// Return the size in bytes that this object takes in memory. This
253 /// returns the size in bytes of this object, not any shared string
254 /// values it may refer to.
257 /// The number of bytes that this object occupies in memory.
259 /// @see ConstString::StaticMemorySize ()
260 //----------------------------------------------------------------------
264 //----------------------------------------------------------------------
265 /// Set the string value in this object.
267 /// If \a is_mangled is \b true, then the mangled named is set to \a
268 /// name, else the demangled name is set to \a name.
271 /// The already const version of the name for this object.
273 /// @param[in] is_mangled
274 /// If \b true then \a name is a mangled name, if \b false then
275 /// \a name is demangled.
276 //----------------------------------------------------------------------
278 SetValue (const ConstString &name, bool is_mangled);
280 //----------------------------------------------------------------------
281 /// Set the string value in this object.
283 /// This version auto detects if the string is mangled by inspecting the
284 /// string value and looking for common mangling prefixes.
287 /// The already const version of the name for this object.
288 //----------------------------------------------------------------------
290 SetValue (const ConstString &name);
293 //----------------------------------------------------------------------
294 /// Mangled member variables.
295 //----------------------------------------------------------------------
296 ConstString m_mangled; ///< The mangled version of the name
297 mutable ConstString m_demangled; ///< Mutable so we can get it on demand with a const version of this object
301 Stream& operator << (Stream& s, const Mangled& obj);
303 } // namespace lldb_private
305 #endif // #if defined(__cplusplus)
306 #endif // liblldb_Mangled_h_