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
46 eManglingSchemeNone = 0,
48 eManglingSchemeItanium
51 //----------------------------------------------------------------------
52 /// Default constructor.
54 /// Initialize with both mangled and demangled names empty.
55 //----------------------------------------------------------------------
58 //----------------------------------------------------------------------
59 /// Construct with name.
61 /// Constructor with an optional string and a boolean indicating if it is
62 /// the mangled version.
65 /// The already const name to copy into this object.
67 /// @param[in] is_mangled
68 /// If \b true then \a name is a mangled name, if \b false then
69 /// \a name is demangled.
70 //----------------------------------------------------------------------
72 Mangled (const ConstString &name, bool is_mangled);
74 //----------------------------------------------------------------------
75 /// Construct with name.
77 /// Constructor with an optional string and auto-detect if \a name is
81 /// The already const name to copy into this object.
82 //----------------------------------------------------------------------
84 Mangled (const ConstString &name);
86 //----------------------------------------------------------------------
89 /// Releases its ref counts on the mangled and demangled strings that
90 /// live in the global string pool.
91 //----------------------------------------------------------------------
94 //----------------------------------------------------------------------
95 /// Convert to pointer operator.
97 /// This allows code to check a Mangled object to see if it contains
98 /// a valid mangled name using code such as:
101 /// Mangled mangled(...);
107 /// A pointer to this object if either the mangled or unmangled
108 /// name is set, NULL otherwise.
109 //----------------------------------------------------------------------
113 //----------------------------------------------------------------------
114 /// Logical NOT operator.
116 /// This allows code to check a Mangled object to see if it contains
117 /// an empty mangled name using code such as:
120 /// Mangled mangled(...);
126 /// Returns \b true if the object has an empty mangled and
127 /// unmangled name, \b false otherwise.
128 //----------------------------------------------------------------------
132 //----------------------------------------------------------------------
133 /// Clear the mangled and demangled values.
134 //----------------------------------------------------------------------
138 //----------------------------------------------------------------------
139 /// Compare the mangled string values
141 /// Compares the Mangled::GetName() string in \a lhs and \a rhs.
144 /// A const reference to the Left Hand Side object to compare.
147 /// A const reference to the Right Hand Side object to compare.
150 /// @li -1 if \a lhs is less than \a rhs
151 /// @li 0 if \a lhs is equal to \a rhs
152 /// @li 1 if \a lhs is greater than \a rhs
153 //----------------------------------------------------------------------
155 Compare (const Mangled& lhs, const Mangled& rhs);
157 //----------------------------------------------------------------------
158 /// Dump a description of this object to a Stream \a s.
160 /// Dump a Mangled object to stream \a s. We don't force our
161 /// demangled name to be computed currently (we don't use the accessor).
164 /// The stream to which to dump the object description.
165 //----------------------------------------------------------------------
167 Dump (Stream *s) const;
169 //----------------------------------------------------------------------
170 /// Dump a debug description of this object to a Stream \a s.
173 /// The stream to which to dump the object description.
174 //----------------------------------------------------------------------
176 DumpDebug (Stream *s) const;
178 //----------------------------------------------------------------------
179 /// Demangled name get accessor.
182 /// A const reference to the demangled name string object.
183 //----------------------------------------------------------------------
185 GetDemangledName () const;
188 SetDemangledName (const ConstString &name)
194 SetMangledName (const ConstString &name)
199 //----------------------------------------------------------------------
200 /// Mangled name get accessor.
203 /// A reference to the mangled name string object.
204 //----------------------------------------------------------------------
211 //----------------------------------------------------------------------
212 /// Mangled name get accessor.
215 /// A const reference to the mangled name string object.
216 //----------------------------------------------------------------------
218 GetMangledName () const
223 //----------------------------------------------------------------------
224 /// Best name get accessor.
226 /// @param[in] preference
227 /// Which name would you prefer to get?
230 /// A const reference to the preferred name string object if this
231 /// object has a valid name of that kind, else a const reference to the
232 /// other name is returned.
233 //----------------------------------------------------------------------
235 GetName (NamePreference preference = ePreferDemangled) const;
237 //----------------------------------------------------------------------
238 /// Check if "name" matches either the mangled or demangled name.
241 /// A name to match against both strings.
244 /// \b True if \a name matches either name, \b false otherwise.
245 //----------------------------------------------------------------------
247 NameMatches (const ConstString &name) const
249 if (m_mangled == name)
251 return GetDemangledName () == name;
255 NameMatches (const RegularExpression& regex) const;
257 //----------------------------------------------------------------------
258 /// Get the memory cost of this object.
260 /// Return the size in bytes that this object takes in memory. This
261 /// returns the size in bytes of this object, not any shared string
262 /// values it may refer to.
265 /// The number of bytes that this object occupies in memory.
267 /// @see ConstString::StaticMemorySize ()
268 //----------------------------------------------------------------------
272 //----------------------------------------------------------------------
273 /// Set the string value in this object.
275 /// If \a is_mangled is \b true, then the mangled named is set to \a
276 /// name, else the demangled name is set to \a name.
279 /// The already const version of the name for this object.
281 /// @param[in] is_mangled
282 /// If \b true then \a name is a mangled name, if \b false then
283 /// \a name is demangled.
284 //----------------------------------------------------------------------
286 SetValue (const ConstString &name, bool is_mangled);
288 //----------------------------------------------------------------------
289 /// Set the string value in this object.
291 /// This version auto detects if the string is mangled by inspecting the
292 /// string value and looking for common mangling prefixes.
295 /// The already const version of the name for this object.
296 //----------------------------------------------------------------------
298 SetValue (const ConstString &name);
300 //----------------------------------------------------------------------
301 /// Try to guess the language from the mangling.
303 /// For a mangled name to have a language it must have both a mangled
304 /// and a demangled name and it can be guessed from the mangling what
305 /// the language is. Note: this will return C++ for any language that
306 /// uses Itanium ABI mangling.
308 /// Standard C function names will return eLanguageTypeUnknown because
309 /// they aren't mangled and it isn't clear what language the name
310 /// represents (there will be no mangled name).
313 /// The language for the mangled/demangled name, eLanguageTypeUnknown
314 /// if there is no mangled or demangled counterpart.
315 //----------------------------------------------------------------------
317 GuessLanguage () const;
320 //----------------------------------------------------------------------
321 /// Mangled member variables.
322 //----------------------------------------------------------------------
323 ConstString m_mangled; ///< The mangled version of the name
324 mutable ConstString m_demangled; ///< Mutable so we can get it on demand with a const version of this object
328 Stream& operator << (Stream& s, const Mangled& obj);
330 } // namespace lldb_private
332 #endif // #if defined(__cplusplus)
333 #endif // liblldb_Mangled_h_