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 (lldb::LanguageType language) const;
187 //----------------------------------------------------------------------
188 /// Display demangled name get accessor.
191 /// A const reference to the display demangled name string object.
192 //----------------------------------------------------------------------
194 GetDisplayDemangledName (lldb::LanguageType language) const;
197 SetDemangledName (const ConstString &name)
203 SetMangledName (const ConstString &name)
208 //----------------------------------------------------------------------
209 /// Mangled name get accessor.
212 /// A reference to the mangled name string object.
213 //----------------------------------------------------------------------
220 //----------------------------------------------------------------------
221 /// Mangled name get accessor.
224 /// A const reference to the mangled name string object.
225 //----------------------------------------------------------------------
227 GetMangledName () const
232 //----------------------------------------------------------------------
233 /// Best name get accessor.
235 /// @param[in] preference
236 /// Which name would you prefer to get?
239 /// A const reference to the preferred name string object if this
240 /// object has a valid name of that kind, else a const reference to the
241 /// other name is returned.
242 //----------------------------------------------------------------------
244 GetName (lldb::LanguageType language, NamePreference preference = ePreferDemangled) const;
246 //----------------------------------------------------------------------
247 /// Check if "name" matches either the mangled or demangled name.
250 /// A name to match against both strings.
253 /// \b True if \a name matches either name, \b false otherwise.
254 //----------------------------------------------------------------------
256 NameMatches (const ConstString &name, lldb::LanguageType language) const
258 if (m_mangled == name)
260 return GetDemangledName (language) == name;
264 NameMatches (const RegularExpression& regex, lldb::LanguageType language) const;
266 //----------------------------------------------------------------------
267 /// Get the memory cost of this object.
269 /// Return the size in bytes that this object takes in memory. This
270 /// returns the size in bytes of this object, not any shared string
271 /// values it may refer to.
274 /// The number of bytes that this object occupies in memory.
276 /// @see ConstString::StaticMemorySize ()
277 //----------------------------------------------------------------------
281 //----------------------------------------------------------------------
282 /// Set the string value in this object.
284 /// If \a is_mangled is \b true, then the mangled named is set to \a
285 /// name, else the demangled name is set to \a name.
288 /// The already const version of the name for this object.
290 /// @param[in] is_mangled
291 /// If \b true then \a name is a mangled name, if \b false then
292 /// \a name is demangled.
293 //----------------------------------------------------------------------
295 SetValue (const ConstString &name, bool is_mangled);
297 //----------------------------------------------------------------------
298 /// Set the string value in this object.
300 /// This version auto detects if the string is mangled by inspecting the
301 /// string value and looking for common mangling prefixes.
304 /// The already const version of the name for this object.
305 //----------------------------------------------------------------------
307 SetValue (const ConstString &name);
309 //----------------------------------------------------------------------
310 /// Try to guess the language from the mangling.
312 /// For a mangled name to have a language it must have both a mangled
313 /// and a demangled name and it can be guessed from the mangling what
314 /// the language is. Note: this will return C++ for any language that
315 /// uses Itanium ABI mangling.
317 /// Standard C function names will return eLanguageTypeUnknown because
318 /// they aren't mangled and it isn't clear what language the name
319 /// represents (there will be no mangled name).
322 /// The language for the mangled/demangled name, eLanguageTypeUnknown
323 /// if there is no mangled or demangled counterpart.
324 //----------------------------------------------------------------------
326 GuessLanguage () const;
329 //----------------------------------------------------------------------
330 /// Mangled member variables.
331 //----------------------------------------------------------------------
332 ConstString m_mangled; ///< The mangled version of the name
333 mutable ConstString m_demangled; ///< Mutable so we can get it on demand with a const version of this object
337 Stream& operator << (Stream& s, const Mangled& obj);
339 } // namespace lldb_private
341 #endif // #if defined(__cplusplus)
342 #endif // liblldb_Mangled_h_