Cleaned up the lldb_private::Mangled class to get rid of the tokenizing code that has bit rotted and isn't being used. Also cleaned up the API to the "lldb_private::Mangled" to always take "const ConstString &" arguments instead of both "const ConstString &" and "const char *".
llvm-svn: 160466
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 73e45d6..200f8ba 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -43,20 +43,6 @@
// Constructor with an optional string and a boolean indicating if it is
// the mangled version.
//----------------------------------------------------------------------
-Mangled::Mangled (const char *s, bool mangled) :
- m_mangled(),
- m_demangled()
-{
- if (s && s[0])
- {
- SetValue(s, mangled);
- }
-}
-
-//----------------------------------------------------------------------
-// Constructor with an optional string and a boolean indicating if it is
-// the mangled version.
-//----------------------------------------------------------------------
Mangled::Mangled (const ConstString &s, bool mangled) :
m_mangled(),
m_demangled()
@@ -65,22 +51,10 @@
SetValue(s, mangled);
}
-//----------------------------------------------------------------------
-// Constructor with an optional string where we try and auto detect if
-// the name is mangled or not by inspecting the string value
-//----------------------------------------------------------------------
-Mangled::Mangled (const char *s) :
+Mangled::Mangled (const ConstString &s) :
m_mangled(),
m_demangled()
{
- if (s && s[0])
- SetValue(ConstString(s));
-}
-
-Mangled::Mangled (const ConstString &s) :
-m_mangled(),
-m_demangled()
-{
if (s)
SetValue(s);
}
@@ -147,29 +121,6 @@
// demangled name is set.
//----------------------------------------------------------------------
void
-Mangled::SetValue (const char *s, bool mangled)
-{
- if (s)
- {
- if (mangled)
- {
- m_demangled.Clear();
- m_mangled.SetCString (s);
- }
- else
- {
- m_demangled.SetCString(s);
- m_mangled.Clear();
- }
- }
- else
- {
- m_demangled.Clear();
- m_mangled.Clear();
- }
-}
-
-void
Mangled::SetValue (const ConstString &s, bool mangled)
{
if (s)
@@ -298,22 +249,6 @@
}
//----------------------------------------------------------------------
-// Generate the tokens from the demangled name.
-//
-// Returns the number of tokens that were parsed.
-//----------------------------------------------------------------------
-size_t
-Mangled::GetTokens (Mangled::TokenList &tokens) const
-{
- tokens.Clear();
- const ConstString& demangled = GetDemangledName();
- if (demangled && !demangled.IsEmpty())
- tokens.Parse(demangled.AsCString());
-
- return tokens.Size();
-}
-
-//----------------------------------------------------------------------
// Dump a Mangled object to stream "s". We don't force our
// demangled name to be computed currently (we don't use the accessor).
//----------------------------------------------------------------------
@@ -371,459 +306,3 @@
s << ", demangled = <error>";
return s;
}
-
-
-
-
-#pragma mark Mangled::Token
-
-//--------------------------------------------------------------
-// Default constructor
-//--------------------------------------------------------------
-Mangled::Token::Token () :
- type(eInvalid),
- value()
-{
-}
-
-//--------------------------------------------------------------
-// Equal to operator
-//--------------------------------------------------------------
-bool
-Mangled::Token::operator== (const Token& rhs) const
-{
- return type == rhs.type && value == rhs.value;
-}
-
-//--------------------------------------------------------------
-// Dump the token to a stream "s"
-//--------------------------------------------------------------
-void
-Mangled::Token::Dump (Stream *s) const
-{
- switch (type)
- {
- case eInvalid: s->PutCString("invalid "); break;
- case eNameSpace: s->PutCString("namespace "); break;
- case eMethodName: s->PutCString("method "); break;
- case eType: s->PutCString("type "); break;
- case eTemplate: s->PutCString("template "); break;
- case eTemplateBeg: s->PutCString("template < "); break;
- case eTemplateEnd: s->PutCString("template > "); break;
- case eParamsBeg: s->PutCString("params ( "); break;
- case eParamsEnd: s->PutCString("params ) "); break;
- case eQualifier: s->PutCString("qualifier "); break;
- case eError: s->PutCString("ERROR "); break;
- default:
- s->Printf("type = %i", type);
- break;
- }
- value.DumpDebug(s);
-}
-
-//--------------------------------------------------------------
-// Returns true if this token is a wildcard
-//--------------------------------------------------------------
-bool
-Mangled::Token::IsWildcard () const
-{
- static ConstString g_wildcard_str("*");
- return value == g_wildcard_str;
-}
-
-
-//----------------------------------------------------------------------
-// Dump "obj" to the supplied stream "s"
-//----------------------------------------------------------------------
-Stream&
-lldb_private::operator << (Stream& s, const Mangled::Token& obj)
-{
- obj.Dump(&s);
- return s;
-}
-
-
-#pragma mark Mangled::TokenList
-//----------------------------------------------------------------------
-// Mangled::TokenList
-//----------------------------------------------------------------------
-
-//--------------------------------------------------------------
-// Default constructor. If demangled is non-NULL and not-empty
-// the token list will parse up the demangled string it is
-// given, else the object will initialize an empty token list.
-//--------------------------------------------------------------
-Mangled::TokenList::TokenList (const char *demangled) :
- m_tokens()
-{
- if (demangled && demangled[0])
- {
- Parse(demangled);
- }
-}
-
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-Mangled::TokenList::~TokenList ()
-{
-}
-
-//----------------------------------------------------------------------
-// Parses "demangled" into tokens. This allows complex
-// comparisons to be done. Comparisons can include wildcards at
-// the namespace, method name, template, and template and
-// parameter type levels.
-//
-// Example queries include:
-// "std::basic_string<*>" // Find all std::basic_string variants
-// "std::basic_string<*>::erase(*)" // Find all std::basic_string::erase variants with any number of parameters
-// "*::clear()" // Find all functions with a method name of
-// // "clear" that are in any namespace that
-// // have no parameters
-// "::printf" // Find the printf function in the global namespace
-// "printf" // Ditto
-// "foo::*(int)" // Find all functions in the class or namespace "foo" that take a single integer argument
-//
-// Returns the number of tokens that were decoded, or zero when
-// we fail.
-//----------------------------------------------------------------------
-size_t
-Mangled::TokenList::Parse (const char *s)
-{
- m_tokens.clear();
-
- Token token;
- token.type = eNameSpace;
-
- TokenType max_type = eInvalid;
- const char *p = s;
- size_t span = 0;
- size_t sep_size = 0;
-
- while (*p != '\0')
- {
- p = p + span + sep_size;
- while (isspace(*p))
- ++p;
-
- if (*p == '\0')
- break;
-
- span = strcspn(p, ":<>(),");
- sep_size = 1;
- token.type = eInvalid;
- switch (p[span])
- {
- case '\0':
- break;
-
- case ':':
- if (p[span+1] == ':')
- {
- sep_size = 2;
- if (span > 0)
- {
- token.type = eNameSpace;
- token.value.SetCStringWithLength (p, span);
- m_tokens.push_back(token);
- }
- else
- continue;
- }
- break;
-
- case '(':
- if (span > 0)
- {
- token.type = eMethodName;
- token.value.SetCStringWithLength (p, span);
- m_tokens.push_back(token);
- }
-
- token.type = eParamsBeg;
- token.value.Clear();
- m_tokens.push_back(token);
- break;
-
- case ',':
- if (span > 0)
- {
- token.type = eType;
- token.value.SetCStringWithLength (p, span);
- m_tokens.push_back(token);
- }
- else
- {
- continue;
- }
- break;
-
- case ')':
- if (span > 0)
- {
- token.type = eType;
- token.value.SetCStringWithLength (p, span);
- m_tokens.push_back(token);
- }
-
- token.type = eParamsEnd;
- token.value.Clear();
- m_tokens.push_back(token);
- break;
-
- case '<':
- if (span > 0)
- {
- token.type = eTemplate;
- token.value.SetCStringWithLength (p, span);
- m_tokens.push_back(token);
- }
-
- token.type = eTemplateBeg;
- token.value.Clear();
- m_tokens.push_back(token);
- break;
-
- case '>':
- if (span > 0)
- {
- token.type = eType;
- token.value.SetCStringWithLength (p, span);
- m_tokens.push_back(token);
- }
-
- token.type = eTemplateEnd;
- token.value.Clear();
- m_tokens.push_back(token);
- break;
- }
-
- if (max_type < token.type)
- max_type = token.type;
-
- if (token.type == eInvalid)
- {
- if (max_type >= eParamsEnd)
- {
- token.type = eQualifier;
- token.value.SetCString(p);
- m_tokens.push_back(token);
- }
- else if (max_type >= eParamsBeg)
- {
- token.type = eType;
- token.value.SetCString(p);
- m_tokens.push_back(token);
- }
- else
- {
- token.type = eMethodName;
- token.value.SetCString(p);
- m_tokens.push_back(token);
- }
- break;
- }
- }
- return m_tokens.size();
-}
-
-
-//----------------------------------------------------------------------
-// Clear the token list.
-//----------------------------------------------------------------------
-void
-Mangled::TokenList::Clear ()
-{
- m_tokens.clear();
-}
-
-//----------------------------------------------------------------------
-// Dump the token list to the stream "s"
-//----------------------------------------------------------------------
-void
-Mangled::TokenList::Dump (Stream *s) const
-{
- collection::const_iterator pos;
- collection::const_iterator beg = m_tokens.begin();
- collection::const_iterator end = m_tokens.end();
- for (pos = beg; pos != end; ++pos)
- {
- s->Indent("token[");
- *s << (uint32_t)std::distance(beg, pos) << "] = " << *pos << "\n";
- }
-}
-
-//----------------------------------------------------------------------
-// Find the first token in the list that has "token_type" as its
-// type
-//----------------------------------------------------------------------
-const Mangled::Token *
-Mangled::TokenList::Find (TokenType token_type) const
-{
- collection::const_iterator pos;
- collection::const_iterator beg = m_tokens.begin();
- collection::const_iterator end = m_tokens.end();
- for (pos = beg; pos != end; ++pos)
- {
- if (pos->type == token_type)
- return &(*pos);
- }
- return NULL;
-}
-
-//----------------------------------------------------------------------
-// Return the token at index "idx", or NULL if the index is
-// out of range.
-//----------------------------------------------------------------------
-const Mangled::Token *
-Mangled::TokenList::GetTokenAtIndex (uint32_t idx) const
-{
- if (idx < m_tokens.size())
- return &m_tokens[idx];
- return NULL;
-}
-
-
-//----------------------------------------------------------------------
-// Given a token list, see if it matches this object's tokens.
-// "token_list" can contain wild card values to enable powerful
-// matching. Matching the std::string::erase(*) example that was
-// tokenized above we could use a token list such as:
-//
-// token name
-// ----------- ----------------------------------------
-// eNameSpace "std"
-// eTemplate "basic_string"
-// eTemplateBeg
-// eInvalid "*"
-// eTemplateEnd
-// eMethodName "erase"
-// eParamsBeg
-// eInvalid "*"
-// eParamsEnd
-//
-// Returns true if it "token_list" matches this object's tokens,
-// false otherwise.
-//----------------------------------------------------------------------
-bool
-Mangled::TokenList::MatchesQuery (const Mangled::TokenList &match) const
-{
- size_t match_count = 0;
- collection::const_iterator pos;
- collection::const_iterator pos_end = m_tokens.end();
-
- collection::const_iterator match_pos;
- collection::const_iterator match_pos_end = match.m_tokens.end();
- collection::const_iterator match_wildcard_pos = match_pos_end;
- collection::const_iterator match_next_pos = match_pos_end;
-
- size_t template_scope_depth = 0;
-
- for (pos = m_tokens.begin(), match_pos = match.m_tokens.begin();
- pos != pos_end && match_pos != match_pos_end;
- ++match_pos)
- {
- match_next_pos = match_pos + 1;
- // Is this a wildcard?
- if (match_pos->IsWildcard())
- {
- if (match_wildcard_pos != match_pos_end)
- return false; // Can't have two wildcards in effect at once.
-
- match_wildcard_pos = match_pos;
- // Are we at the end of the MATCH token list?
- if (match_next_pos == match_pos_end)
- {
- // There is nothing more to match, return if we have any matches so far...
- return match_count > 0;
- }
- }
-
- if (match_pos->type == eInvalid || match_pos->type == eError)
- {
- return false;
- }
- else
- {
- if (match_pos->type == eTemplateBeg)
- {
- ++template_scope_depth;
- }
- else if (match_pos->type == eTemplateEnd)
- {
- assert(template_scope_depth > 0);
- --template_scope_depth;
- }
-
- // Do we have a wildcard going right now?
- if (match_wildcard_pos == match_pos_end)
- {
- // No wildcard matching right now, just check and see if things match
- if (*pos == *match_pos)
- ++match_count;
- else
- return false;
- }
- else
- {
- // We have a wildcard match going
-
- // For template types we need to make sure to match the template depths...
- const size_t start_wildcard_template_scope_depth = template_scope_depth;
- size_t curr_wildcard_template_scope_depth = template_scope_depth;
- while (pos != pos_end)
- {
- if (match_wildcard_pos->type == eNameSpace && pos->type == eParamsBeg)
- return false;
-
- if (start_wildcard_template_scope_depth == curr_wildcard_template_scope_depth)
- {
- if (*pos == *match_next_pos)
- {
- ++match_count;
- match_pos = match_next_pos;
- match_wildcard_pos = match_pos_end;
- break;
- }
- }
- if (pos->type == eTemplateBeg)
- ++curr_wildcard_template_scope_depth;
- else if (pos->type == eTemplateEnd)
- --curr_wildcard_template_scope_depth;
-
-
- ++pos;
- }
- }
- }
-
- if (pos != pos_end)
- ++pos;
- }
- if (match_pos != match_pos_end)
- return false;
-
- return match_count > 0;
-}
-
-
-//----------------------------------------------------------------------
-// Return the number of tokens in the token collection
-//----------------------------------------------------------------------
-size_t
-Mangled::TokenList::Size () const
-{
- return m_tokens.size();
-}
-
-
-//----------------------------------------------------------------------
-// Stream out the tokens
-//----------------------------------------------------------------------
-Stream&
-lldb_private::operator << (Stream& s, const Mangled::TokenList& obj)
-{
- obj.Dump(&s);
- return s;
-}