forked from OSchip/llvm-project
Move more functionality from the LanguageRuntimes to the Languages.
llvm-svn: 246616
This commit is contained in:
parent
b5c2fd7257
commit
aa816b8f3b
|
@ -25,95 +25,6 @@ class CPPLanguageRuntime :
|
|||
public LanguageRuntime
|
||||
{
|
||||
public:
|
||||
|
||||
class MethodName
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
eTypeInvalid,
|
||||
eTypeUnknownMethod,
|
||||
eTypeClassMethod,
|
||||
eTypeInstanceMethod
|
||||
};
|
||||
|
||||
MethodName () :
|
||||
m_full(),
|
||||
m_basename(),
|
||||
m_context(),
|
||||
m_arguments(),
|
||||
m_qualifiers(),
|
||||
m_type (eTypeInvalid),
|
||||
m_parsed (false),
|
||||
m_parse_error (false)
|
||||
{
|
||||
}
|
||||
|
||||
MethodName (const ConstString &s) :
|
||||
m_full(s),
|
||||
m_basename(),
|
||||
m_context(),
|
||||
m_arguments(),
|
||||
m_qualifiers(),
|
||||
m_type (eTypeInvalid),
|
||||
m_parsed (false),
|
||||
m_parse_error (false)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Clear();
|
||||
|
||||
bool
|
||||
IsValid ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
if (m_parse_error)
|
||||
return false;
|
||||
if (m_type == eTypeInvalid)
|
||||
return false;
|
||||
return (bool)m_full;
|
||||
}
|
||||
|
||||
Type
|
||||
GetType () const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
GetFullName () const
|
||||
{
|
||||
return m_full;
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
GetBasename ();
|
||||
|
||||
llvm::StringRef
|
||||
GetContext ();
|
||||
|
||||
llvm::StringRef
|
||||
GetArguments ();
|
||||
|
||||
llvm::StringRef
|
||||
GetQualifiers ();
|
||||
|
||||
protected:
|
||||
void
|
||||
Parse();
|
||||
|
||||
ConstString m_full; // Full name: "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) const"
|
||||
llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
|
||||
llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
|
||||
llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
|
||||
llvm::StringRef m_qualifiers; // Qualifiers: "const"
|
||||
Type m_type;
|
||||
bool m_parsed;
|
||||
bool m_parse_error;
|
||||
};
|
||||
|
||||
~CPPLanguageRuntime() override;
|
||||
|
||||
lldb::LanguageType
|
||||
|
@ -131,27 +42,6 @@ public:
|
|||
bool
|
||||
GetObjectDescription(Stream &str, Value &value, ExecutionContextScope *exe_scope) override;
|
||||
|
||||
static bool
|
||||
IsCPPMangledName(const char *name);
|
||||
|
||||
// Extract C++ context and identifier from a string using heuristic matching (as opposed to
|
||||
// CPPLanguageRuntime::MethodName which has to have a fully qualified C++ name with parens and arguments.
|
||||
// If the name is a lone C identifier (e.g. C) or a qualified C identifier (e.g. A::B::C) it will return true,
|
||||
// and identifier will be the identifier (C and C respectively) and the context will be "" and "A::B::" respectively.
|
||||
// If the name fails the heuristic matching for a qualified or unqualified C/C++ identifier, then it will return false
|
||||
// and identifier and context will be unchanged.
|
||||
|
||||
static bool
|
||||
ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier);
|
||||
|
||||
// in some cases, compilers will output different names for one same type. when that happens, it might be impossible
|
||||
// to construct SBType objects for a valid type, because the name that is available is not the same as the name that
|
||||
// can be used as a search key in FindTypes(). the equivalents map here is meant to return possible alternative names
|
||||
// for a type through which a search can be conducted. Currently, this is only enabled for C++ but can be extended
|
||||
// to ObjC or other languages if necessary
|
||||
static uint32_t
|
||||
FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents);
|
||||
|
||||
virtual size_t
|
||||
GetAlternateManglings(const ConstString &mangled, std::vector<ConstString> &alternates) = 0;
|
||||
|
||||
|
|
|
@ -36,109 +36,6 @@ class ObjCLanguageRuntime :
|
|||
public LanguageRuntime
|
||||
{
|
||||
public:
|
||||
class MethodName
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
eTypeUnspecified,
|
||||
eTypeClassMethod,
|
||||
eTypeInstanceMethod
|
||||
};
|
||||
|
||||
MethodName () :
|
||||
m_full(),
|
||||
m_class(),
|
||||
m_category(),
|
||||
m_selector(),
|
||||
m_type (eTypeUnspecified),
|
||||
m_category_is_valid (false)
|
||||
{
|
||||
}
|
||||
|
||||
MethodName (const char *name, bool strict) :
|
||||
m_full(),
|
||||
m_class(),
|
||||
m_category(),
|
||||
m_selector(),
|
||||
m_type (eTypeUnspecified),
|
||||
m_category_is_valid (false)
|
||||
{
|
||||
SetName (name, strict);
|
||||
}
|
||||
|
||||
void
|
||||
Clear();
|
||||
|
||||
bool
|
||||
IsValid (bool strict) const
|
||||
{
|
||||
// If "strict" is true, the name must have everything specified including
|
||||
// the leading "+" or "-" on the method name
|
||||
if (strict && m_type == eTypeUnspecified)
|
||||
return false;
|
||||
// Other than that, m_full will only be filled in if the objective C
|
||||
// name is valid.
|
||||
return (bool)m_full;
|
||||
}
|
||||
|
||||
bool
|
||||
HasCategory()
|
||||
{
|
||||
return (bool)GetCategory();
|
||||
}
|
||||
|
||||
Type
|
||||
GetType () const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
GetFullName () const
|
||||
{
|
||||
return m_full;
|
||||
}
|
||||
|
||||
ConstString
|
||||
GetFullNameWithoutCategory (bool empty_if_no_category);
|
||||
|
||||
bool
|
||||
SetName (const char *name, bool strict);
|
||||
|
||||
const ConstString &
|
||||
GetClassName ();
|
||||
|
||||
const ConstString &
|
||||
GetClassNameWithCategory ();
|
||||
|
||||
const ConstString &
|
||||
GetCategory ();
|
||||
|
||||
const ConstString &
|
||||
GetSelector ();
|
||||
|
||||
// Get all possible names for a method. Examples:
|
||||
// If name is "+[NSString(my_additions) myStringWithCString:]"
|
||||
// names[0] => "+[NSString(my_additions) myStringWithCString:]"
|
||||
// names[1] => "+[NSString myStringWithCString:]"
|
||||
// If name is specified without the leading '+' or '-' like "[NSString(my_additions) myStringWithCString:]"
|
||||
// names[0] => "+[NSString(my_additions) myStringWithCString:]"
|
||||
// names[1] => "-[NSString(my_additions) myStringWithCString:]"
|
||||
// names[2] => "+[NSString myStringWithCString:]"
|
||||
// names[3] => "-[NSString myStringWithCString:]"
|
||||
size_t
|
||||
GetFullNames (std::vector<ConstString> &names, bool append);
|
||||
protected:
|
||||
ConstString m_full; // Full name: "+[NSString(my_additions) myStringWithCString:]"
|
||||
ConstString m_class; // Class name: "NSString"
|
||||
ConstString m_class_category; // Class with category: "NSString(my_additions)"
|
||||
ConstString m_category; // Category: "my_additions"
|
||||
ConstString m_selector; // Selector: "myStringWithCString:"
|
||||
Type m_type;
|
||||
bool m_category_is_valid;
|
||||
|
||||
};
|
||||
typedef lldb::addr_t ObjCISA;
|
||||
|
||||
class ClassDescriptor;
|
||||
|
@ -451,94 +348,6 @@ public:
|
|||
return LLDB_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// Chop up an objective C function prototype.
|
||||
///
|
||||
/// Chop up an objective C function fullname and optionally fill in
|
||||
/// any non-NULL ConstString objects. If a ConstString * is NULL,
|
||||
/// then this name doesn't get filled in
|
||||
///
|
||||
/// @param[in] name
|
||||
/// A fully specified objective C function name. The string might
|
||||
/// contain a category and it includes the leading "+" or "-" and
|
||||
/// the square brackets, no types for the arguments, just the plain
|
||||
/// selector. A few examples:
|
||||
/// "-[NSStringDrawingContext init]"
|
||||
/// "-[NSStringDrawingContext addString:inRect:]"
|
||||
/// "-[NSString(NSStringDrawing) sizeWithAttributes:]"
|
||||
/// "+[NSString(NSStringDrawing) usesFontLeading]"
|
||||
///
|
||||
/// @param[out] class_name
|
||||
/// If non-NULL, this string will be filled in with the class
|
||||
/// name including the category. The examples above would return:
|
||||
/// "NSStringDrawingContext"
|
||||
/// "NSStringDrawingContext"
|
||||
/// "NSString(NSStringDrawing)"
|
||||
/// "NSString(NSStringDrawing)"
|
||||
///
|
||||
/// @param[out] selector_name
|
||||
/// If non-NULL, this string will be filled in with the selector
|
||||
/// name. The examples above would return:
|
||||
/// "init"
|
||||
/// "addString:inRect:"
|
||||
/// "sizeWithAttributes:"
|
||||
/// "usesFontLeading"
|
||||
///
|
||||
/// @param[out] name_sans_category
|
||||
/// If non-NULL, this string will be filled in with the class
|
||||
/// name _without_ the category. If there is no category, and empty
|
||||
/// string will be returned (as the result would be normally returned
|
||||
/// in the "class_name" argument). The examples above would return:
|
||||
/// <empty>
|
||||
/// <empty>
|
||||
/// "-[NSString sizeWithAttributes:]"
|
||||
/// "+[NSString usesFontLeading]"
|
||||
///
|
||||
/// @param[out] class_name_sans_category
|
||||
/// If non-NULL, this string will be filled in with the prototype
|
||||
/// name _without_ the category. If there is no category, and empty
|
||||
/// string will be returned (as this is already the value that was
|
||||
/// passed in). The examples above would return:
|
||||
/// <empty>
|
||||
/// <empty>
|
||||
/// "NSString"
|
||||
/// "NSString"
|
||||
///
|
||||
/// @return
|
||||
/// Returns the number of strings that were successfully filled
|
||||
/// in.
|
||||
//------------------------------------------------------------------
|
||||
// static uint32_t
|
||||
// ParseMethodName (const char *name,
|
||||
// ConstString *class_name, // Class name (with category if there is one)
|
||||
// ConstString *selector_name, // selector only
|
||||
// ConstString *name_sans_category, // full function name with no category (empty if no category)
|
||||
// ConstString *class_name_sans_category);// Class name without category (empty if no category)
|
||||
|
||||
static bool
|
||||
IsPossibleObjCMethodName (const char *name)
|
||||
{
|
||||
if (!name)
|
||||
return false;
|
||||
bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '[';
|
||||
bool ends_right = (name[strlen(name) - 1] == ']');
|
||||
return (starts_right && ends_right);
|
||||
}
|
||||
|
||||
static bool
|
||||
IsPossibleObjCSelector (const char *name)
|
||||
{
|
||||
if (!name)
|
||||
return false;
|
||||
|
||||
if (strchr(name, ':') == NULL)
|
||||
return true;
|
||||
else if (name[strlen(name) - 1] == ':')
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
HasNewLiteralsAndIndexing ()
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "lldb/Symbol/Function.h"
|
||||
#include "lldb/Symbol/Symbol.h"
|
||||
#include "lldb/Symbol/SymbolContext.h"
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
@ -143,7 +143,7 @@ BreakpointResolverName::BreakpointResolverName(const BreakpointResolverName &rhs
|
|||
void
|
||||
BreakpointResolverName::AddNameLookup (const ConstString &name, uint32_t name_type_mask)
|
||||
{
|
||||
ObjCLanguageRuntime::MethodName objc_method(name.GetCString(), false);
|
||||
ObjCLanguage::MethodName objc_method(name.GetCString(), false);
|
||||
if (objc_method.IsValid(false))
|
||||
{
|
||||
std::vector<ConstString> objc_names;
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include "lldb/Core/RegularExpression.h"
|
||||
#include "lldb/Core/Stream.h"
|
||||
#include "lldb/Core/Timer.h"
|
||||
#include "lldb/Target/CPPLanguageRuntime.h"
|
||||
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -94,7 +94,7 @@ get_demangled_name_without_arguments (ConstString mangled, ConstString demangled
|
|||
mangled_name_cstr[2] != 'G' && // avoid guard variables
|
||||
mangled_name_cstr[2] != 'Z')) // named local entities (if we eventually handle eSymbolTypeData, we will want this back)
|
||||
{
|
||||
CPPLanguageRuntime::MethodName cxx_method (demangled);
|
||||
CPlusPlusLanguage::MethodName cxx_method (demangled);
|
||||
if (!cxx_method.GetBasename().empty())
|
||||
{
|
||||
std::string shortname;
|
||||
|
|
|
@ -28,13 +28,13 @@
|
|||
#include "lldb/Symbol/ObjectFile.h"
|
||||
#include "lldb/Symbol/SymbolContext.h"
|
||||
#include "lldb/Symbol/SymbolVendor.h"
|
||||
#include "lldb/Target/CPPLanguageRuntime.h"
|
||||
#include "lldb/Target/Language.h"
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "lldb/Target/Process.h"
|
||||
#include "lldb/Target/SectionLoadList.h"
|
||||
#include "lldb/Target/Target.h"
|
||||
#include "lldb/Symbol/SymbolFile.h"
|
||||
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
|
||||
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
||||
|
||||
#include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"
|
||||
|
||||
|
@ -1781,11 +1781,11 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
|
|||
|
||||
if (name_type_mask & eFunctionNameTypeAuto)
|
||||
{
|
||||
if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
|
||||
if (CPlusPlusLanguage::IsCPPMangledName (name_cstr))
|
||||
lookup_name_type_mask = eFunctionNameTypeFull;
|
||||
else if ((language == eLanguageTypeUnknown ||
|
||||
Language::LanguageIsObjC(language)) &&
|
||||
ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
|
||||
ObjCLanguage::IsPossibleObjCMethodName (name_cstr))
|
||||
lookup_name_type_mask = eFunctionNameTypeFull;
|
||||
else if (Language::LanguageIsC(language))
|
||||
{
|
||||
|
@ -1795,14 +1795,14 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
|
|||
{
|
||||
if ((language == eLanguageTypeUnknown ||
|
||||
Language::LanguageIsObjC(language)) &&
|
||||
ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
|
||||
ObjCLanguage::IsPossibleObjCSelector(name_cstr))
|
||||
lookup_name_type_mask |= eFunctionNameTypeSelector;
|
||||
|
||||
CPPLanguageRuntime::MethodName cpp_method (name);
|
||||
CPlusPlusLanguage::MethodName cpp_method (name);
|
||||
basename = cpp_method.GetBasename();
|
||||
if (basename.empty())
|
||||
{
|
||||
if (CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename))
|
||||
if (CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename))
|
||||
lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
|
||||
else
|
||||
lookup_name_type_mask |= eFunctionNameTypeFull;
|
||||
|
@ -1820,7 +1820,7 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
|
|||
{
|
||||
// If they've asked for a CPP method or function name and it can't be that, we don't
|
||||
// even need to search for CPP methods or names.
|
||||
CPPLanguageRuntime::MethodName cpp_method (name);
|
||||
CPlusPlusLanguage::MethodName cpp_method (name);
|
||||
if (cpp_method.IsValid())
|
||||
{
|
||||
basename = cpp_method.GetBasename();
|
||||
|
@ -1838,13 +1838,13 @@ Module::PrepareForFunctionNameLookup (const ConstString &name,
|
|||
{
|
||||
// If the CPP method parser didn't manage to chop this up, try to fill in the base name if we can.
|
||||
// If a::b::c is passed in, we need to just look up "c", and then we'll filter the result later.
|
||||
CPPLanguageRuntime::ExtractContextAndIdentifier (name_cstr, context, basename);
|
||||
CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename);
|
||||
}
|
||||
}
|
||||
|
||||
if (lookup_name_type_mask & eFunctionNameTypeSelector)
|
||||
{
|
||||
if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
|
||||
if (!ObjCLanguage::IsPossibleObjCSelector(name_cstr))
|
||||
{
|
||||
lookup_name_type_mask &= ~(eFunctionNameTypeSelector);
|
||||
if (lookup_name_type_mask == eFunctionNameTypeNone)
|
||||
|
|
|
@ -9,8 +9,14 @@
|
|||
|
||||
#include "CPlusPlusLanguage.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
#include "lldb/Core/ConstString.h"
|
||||
#include "lldb/Core/PluginManager.h"
|
||||
#include "lldb/Core/RegularExpression.h"
|
||||
#include "lldb/Core/UniqueCStringMap.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
@ -62,3 +68,373 @@ CPlusPlusLanguage::CreateInstance (lldb::LanguageType language)
|
|||
return new CPlusPlusLanguage();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
CPlusPlusLanguage::MethodName::Clear()
|
||||
{
|
||||
m_full.Clear();
|
||||
m_basename = llvm::StringRef();
|
||||
m_context = llvm::StringRef();
|
||||
m_arguments = llvm::StringRef();
|
||||
m_qualifiers = llvm::StringRef();
|
||||
m_type = eTypeInvalid;
|
||||
m_parsed = false;
|
||||
m_parse_error = false;
|
||||
}
|
||||
|
||||
bool
|
||||
ReverseFindMatchingChars (const llvm::StringRef &s,
|
||||
const llvm::StringRef &left_right_chars,
|
||||
size_t &left_pos,
|
||||
size_t &right_pos,
|
||||
size_t pos = llvm::StringRef::npos)
|
||||
{
|
||||
assert (left_right_chars.size() == 2);
|
||||
left_pos = llvm::StringRef::npos;
|
||||
const char left_char = left_right_chars[0];
|
||||
const char right_char = left_right_chars[1];
|
||||
pos = s.find_last_of(left_right_chars, pos);
|
||||
if (pos == llvm::StringRef::npos || s[pos] == left_char)
|
||||
return false;
|
||||
right_pos = pos;
|
||||
uint32_t depth = 1;
|
||||
while (pos > 0 && depth > 0)
|
||||
{
|
||||
pos = s.find_last_of(left_right_chars, pos);
|
||||
if (pos == llvm::StringRef::npos)
|
||||
return false;
|
||||
if (s[pos] == left_char)
|
||||
{
|
||||
if (--depth == 0)
|
||||
{
|
||||
left_pos = pos;
|
||||
return left_pos < right_pos;
|
||||
}
|
||||
}
|
||||
else if (s[pos] == right_char)
|
||||
{
|
||||
++depth;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CPlusPlusLanguage::MethodName::Parse()
|
||||
{
|
||||
if (!m_parsed && m_full)
|
||||
{
|
||||
// ConstString mangled;
|
||||
// m_full.GetMangledCounterpart(mangled);
|
||||
// printf ("\n parsing = '%s'\n", m_full.GetCString());
|
||||
// if (mangled)
|
||||
// printf (" mangled = '%s'\n", mangled.GetCString());
|
||||
m_parse_error = false;
|
||||
m_parsed = true;
|
||||
llvm::StringRef full (m_full.GetCString());
|
||||
|
||||
size_t arg_start, arg_end;
|
||||
llvm::StringRef parens("()", 2);
|
||||
if (ReverseFindMatchingChars (full, parens, arg_start, arg_end))
|
||||
{
|
||||
m_arguments = full.substr(arg_start, arg_end - arg_start + 1);
|
||||
if (arg_end + 1 < full.size())
|
||||
m_qualifiers = full.substr(arg_end + 1);
|
||||
if (arg_start > 0)
|
||||
{
|
||||
size_t basename_end = arg_start;
|
||||
size_t context_start = 0;
|
||||
size_t context_end = llvm::StringRef::npos;
|
||||
if (basename_end > 0 && full[basename_end-1] == '>')
|
||||
{
|
||||
// TODO: handle template junk...
|
||||
// Templated function
|
||||
size_t template_start, template_end;
|
||||
llvm::StringRef lt_gt("<>", 2);
|
||||
if (ReverseFindMatchingChars (full, lt_gt, template_start, template_end, basename_end))
|
||||
{
|
||||
// Check for templated functions that include return type like: 'void foo<Int>()'
|
||||
context_start = full.rfind(' ', template_start);
|
||||
if (context_start == llvm::StringRef::npos)
|
||||
context_start = 0;
|
||||
|
||||
context_end = full.rfind(':', template_start);
|
||||
if (context_end == llvm::StringRef::npos || context_end < context_start)
|
||||
context_end = context_start;
|
||||
}
|
||||
else
|
||||
{
|
||||
context_end = full.rfind(':', basename_end);
|
||||
}
|
||||
}
|
||||
else if (context_end == llvm::StringRef::npos)
|
||||
{
|
||||
context_end = full.rfind(':', basename_end);
|
||||
}
|
||||
|
||||
if (context_end == llvm::StringRef::npos)
|
||||
m_basename = full.substr(0, basename_end);
|
||||
else
|
||||
{
|
||||
if (context_start < context_end)
|
||||
m_context = full.substr(context_start, context_end - 1);
|
||||
const size_t basename_begin = context_end + 1;
|
||||
m_basename = full.substr(basename_begin, basename_end - basename_begin);
|
||||
}
|
||||
m_type = eTypeUnknownMethod;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_parse_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!m_context.empty())
|
||||
// printf (" context = '%s'\n", m_context.str().c_str());
|
||||
// if (m_basename)
|
||||
// printf (" basename = '%s'\n", m_basename.GetCString());
|
||||
// if (!m_arguments.empty())
|
||||
// printf (" arguments = '%s'\n", m_arguments.str().c_str());
|
||||
// if (!m_qualifiers.empty())
|
||||
// printf ("qualifiers = '%s'\n", m_qualifiers.str().c_str());
|
||||
|
||||
// Make sure we have a valid C++ basename with optional template args
|
||||
static RegularExpression g_identifier_regex("^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$");
|
||||
std::string basename_str(m_basename.str());
|
||||
bool basename_is_valid = g_identifier_regex.Execute (basename_str.c_str(), NULL);
|
||||
if (!basename_is_valid)
|
||||
{
|
||||
// Check for C++ operators
|
||||
if (m_basename.startswith("operator"))
|
||||
{
|
||||
static RegularExpression g_operator_regex("^(operator)( ?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|\\[\\]|[\\^<>=!\\/*+-]+)(<.*>)?(\\[\\])?$");
|
||||
basename_is_valid = g_operator_regex.Execute(basename_str.c_str(), NULL);
|
||||
}
|
||||
}
|
||||
if (!basename_is_valid)
|
||||
{
|
||||
// The C++ basename doesn't match our regular expressions so this can't
|
||||
// be a valid C++ method, clear everything out and indicate an error
|
||||
m_context = llvm::StringRef();
|
||||
m_basename = llvm::StringRef();
|
||||
m_arguments = llvm::StringRef();
|
||||
m_qualifiers = llvm::StringRef();
|
||||
m_parse_error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_parse_error = true;
|
||||
// printf ("error: didn't find matching parens for arguments\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
CPlusPlusLanguage::MethodName::GetBasename ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
return m_basename;
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
CPlusPlusLanguage::MethodName::GetContext ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
return m_context;
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
CPlusPlusLanguage::MethodName::GetArguments ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
CPlusPlusLanguage::MethodName::GetQualifiers ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
return m_qualifiers;
|
||||
}
|
||||
|
||||
bool
|
||||
CPlusPlusLanguage::IsCPPMangledName (const char *name)
|
||||
{
|
||||
// FIXME, we should really run through all the known C++ Language plugins and ask each one if
|
||||
// this is a C++ mangled name, but we can put that off till there is actually more than one
|
||||
// we care about.
|
||||
|
||||
if (name && name[0] == '_' && name[1] == 'Z')
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CPlusPlusLanguage::ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
|
||||
{
|
||||
static RegularExpression g_basename_regex("^(([A-Za-z_][A-Za-z_0-9]*::)*)([A-Za-z_][A-Za-z_0-9]*)$");
|
||||
RegularExpression::Match match(4);
|
||||
if (g_basename_regex.Execute (name, &match))
|
||||
{
|
||||
match.GetMatchAtIndex(name, 1, context);
|
||||
match.GetMatchAtIndex(name, 3, identifier);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class CPPRuntimeEquivalents
|
||||
{
|
||||
public:
|
||||
CPPRuntimeEquivalents ()
|
||||
{
|
||||
|
||||
m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >").AsCString(), ConstString("basic_string<char>"));
|
||||
|
||||
// these two (with a prefixed std::) occur when c++stdlib string class occurs as a template argument in some STL container
|
||||
m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >").AsCString(), ConstString("std::basic_string<char>"));
|
||||
|
||||
m_impl.Sort();
|
||||
}
|
||||
|
||||
void
|
||||
Add (ConstString& type_name,
|
||||
ConstString& type_equivalent)
|
||||
{
|
||||
m_impl.Insert(type_name.AsCString(), type_equivalent);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
FindExactMatches (ConstString& type_name,
|
||||
std::vector<ConstString>& equivalents)
|
||||
{
|
||||
|
||||
uint32_t count = 0;
|
||||
|
||||
for (ImplData match = m_impl.FindFirstValueForName(type_name.AsCString());
|
||||
match != NULL;
|
||||
match = m_impl.FindNextValueForName(match))
|
||||
{
|
||||
equivalents.push_back(match->value);
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// partial matches can occur when a name with equivalents is a template argument.
|
||||
// e.g. we may have "class Foo" be a match for "struct Bar". if we have a typename
|
||||
// such as "class Templatized<class Foo, Anything>" we want this to be replaced with
|
||||
// "class Templatized<struct Bar, Anything>". Since partial matching is time consuming
|
||||
// once we get a partial match, we add it to the exact matches list for faster retrieval
|
||||
uint32_t
|
||||
FindPartialMatches (ConstString& type_name,
|
||||
std::vector<ConstString>& equivalents)
|
||||
{
|
||||
|
||||
uint32_t count = 0;
|
||||
|
||||
const char* type_name_cstr = type_name.AsCString();
|
||||
|
||||
size_t items_count = m_impl.GetSize();
|
||||
|
||||
for (size_t item = 0; item < items_count; item++)
|
||||
{
|
||||
const char* key_cstr = m_impl.GetCStringAtIndex(item);
|
||||
if ( strstr(type_name_cstr,key_cstr) )
|
||||
{
|
||||
count += AppendReplacements(type_name_cstr,
|
||||
key_cstr,
|
||||
equivalents);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string& replace (std::string& target,
|
||||
std::string& pattern,
|
||||
std::string& with)
|
||||
{
|
||||
size_t pos;
|
||||
size_t pattern_len = pattern.size();
|
||||
|
||||
while ( (pos = target.find(pattern)) != std::string::npos )
|
||||
target.replace(pos, pattern_len, with);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
AppendReplacements (const char* original,
|
||||
const char *matching_key,
|
||||
std::vector<ConstString>& equivalents)
|
||||
{
|
||||
|
||||
std::string matching_key_str(matching_key);
|
||||
ConstString original_const(original);
|
||||
|
||||
uint32_t count = 0;
|
||||
|
||||
for (ImplData match = m_impl.FindFirstValueForName(matching_key);
|
||||
match != NULL;
|
||||
match = m_impl.FindNextValueForName(match))
|
||||
{
|
||||
std::string target(original);
|
||||
std::string equiv_class(match->value.AsCString());
|
||||
|
||||
replace (target, matching_key_str, equiv_class);
|
||||
|
||||
ConstString target_const(target.c_str());
|
||||
|
||||
// you will most probably want to leave this off since it might make this map grow indefinitely
|
||||
#ifdef ENABLE_CPP_EQUIVALENTS_MAP_TO_GROW
|
||||
Add(original_const, target_const);
|
||||
#endif
|
||||
equivalents.push_back(target_const);
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
typedef UniqueCStringMap<ConstString> Impl;
|
||||
typedef const Impl::Entry* ImplData;
|
||||
Impl m_impl;
|
||||
};
|
||||
|
||||
static CPPRuntimeEquivalents&
|
||||
GetEquivalentsMap ()
|
||||
{
|
||||
static CPPRuntimeEquivalents g_equivalents_map;
|
||||
return g_equivalents_map;
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
CPlusPlusLanguage::FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents)
|
||||
{
|
||||
uint32_t count = GetEquivalentsMap().FindExactMatches(type_name, equivalents);
|
||||
|
||||
bool might_have_partials=
|
||||
( count == 0 ) // if we have a full name match just use it
|
||||
&& (strchr(type_name.AsCString(), '<') != NULL // we should only have partial matches when templates are involved, check that we have
|
||||
&& strchr(type_name.AsCString(), '>') != NULL); // angle brackets in the type_name before trying to scan for partial matches
|
||||
|
||||
if ( might_have_partials )
|
||||
count = GetEquivalentsMap().FindPartialMatches(type_name, equivalents);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,14 @@
|
|||
|
||||
// C Includes
|
||||
// C++ Includes
|
||||
#include <vector>
|
||||
|
||||
// Other libraries and framework includes
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
// Project includes
|
||||
#include "lldb/lldb-private.h"
|
||||
#include "lldb/Core/ConstString.h"
|
||||
#include "lldb/Target/Language.h"
|
||||
|
||||
namespace lldb_private {
|
||||
|
@ -23,6 +28,94 @@ class CPlusPlusLanguage :
|
|||
public Language
|
||||
{
|
||||
public:
|
||||
class MethodName
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
eTypeInvalid,
|
||||
eTypeUnknownMethod,
|
||||
eTypeClassMethod,
|
||||
eTypeInstanceMethod
|
||||
};
|
||||
|
||||
MethodName () :
|
||||
m_full(),
|
||||
m_basename(),
|
||||
m_context(),
|
||||
m_arguments(),
|
||||
m_qualifiers(),
|
||||
m_type (eTypeInvalid),
|
||||
m_parsed (false),
|
||||
m_parse_error (false)
|
||||
{
|
||||
}
|
||||
|
||||
MethodName (const ConstString &s) :
|
||||
m_full(s),
|
||||
m_basename(),
|
||||
m_context(),
|
||||
m_arguments(),
|
||||
m_qualifiers(),
|
||||
m_type (eTypeInvalid),
|
||||
m_parsed (false),
|
||||
m_parse_error (false)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Clear();
|
||||
|
||||
bool
|
||||
IsValid ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
if (m_parse_error)
|
||||
return false;
|
||||
if (m_type == eTypeInvalid)
|
||||
return false;
|
||||
return (bool)m_full;
|
||||
}
|
||||
|
||||
Type
|
||||
GetType () const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
GetFullName () const
|
||||
{
|
||||
return m_full;
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
GetBasename ();
|
||||
|
||||
llvm::StringRef
|
||||
GetContext ();
|
||||
|
||||
llvm::StringRef
|
||||
GetArguments ();
|
||||
|
||||
llvm::StringRef
|
||||
GetQualifiers ();
|
||||
|
||||
protected:
|
||||
void
|
||||
Parse();
|
||||
|
||||
ConstString m_full; // Full name: "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) const"
|
||||
llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
|
||||
llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
|
||||
llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
|
||||
llvm::StringRef m_qualifiers; // Qualifiers: "const"
|
||||
Type m_type;
|
||||
bool m_parsed;
|
||||
bool m_parse_error;
|
||||
};
|
||||
|
||||
virtual ~CPlusPlusLanguage() = default;
|
||||
|
||||
CPlusPlusLanguage () = default;
|
||||
|
@ -47,6 +140,28 @@ public:
|
|||
|
||||
static lldb_private::ConstString
|
||||
GetPluginNameStatic();
|
||||
|
||||
static bool
|
||||
IsCPPMangledName(const char *name);
|
||||
|
||||
// Extract C++ context and identifier from a string using heuristic matching (as opposed to
|
||||
// CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name with parens and arguments.
|
||||
// If the name is a lone C identifier (e.g. C) or a qualified C identifier (e.g. A::B::C) it will return true,
|
||||
// and identifier will be the identifier (C and C respectively) and the context will be "" and "A::B::" respectively.
|
||||
// If the name fails the heuristic matching for a qualified or unqualified C/C++ identifier, then it will return false
|
||||
// and identifier and context will be unchanged.
|
||||
|
||||
static bool
|
||||
ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier);
|
||||
|
||||
// in some cases, compilers will output different names for one same type. when that happens, it might be impossible
|
||||
// to construct SBType objects for a valid type, because the name that is available is not the same as the name that
|
||||
// can be used as a search key in FindTypes(). the equivalents map here is meant to return possible alternative names
|
||||
// for a type through which a search can be conducted. Currently, this is only enabled for C++ but can be extended
|
||||
// to ObjC or other languages if necessary
|
||||
static uint32_t
|
||||
FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents);
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// PluginInterface protocol
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "lldb/Core/ConstString.h"
|
||||
#include "lldb/Core/PluginManager.h"
|
||||
#include "lldb/Core/StreamString.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
@ -66,3 +67,234 @@ ObjCLanguage::CreateInstance (lldb::LanguageType language)
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ObjCLanguage::MethodName::Clear()
|
||||
{
|
||||
m_full.Clear();
|
||||
m_class.Clear();
|
||||
m_category.Clear();
|
||||
m_selector.Clear();
|
||||
m_type = eTypeUnspecified;
|
||||
m_category_is_valid = false;
|
||||
}
|
||||
|
||||
bool
|
||||
ObjCLanguage::MethodName::SetName (const char *name, bool strict)
|
||||
{
|
||||
Clear();
|
||||
if (name && name[0])
|
||||
{
|
||||
// If "strict" is true. then the method must be specified with a
|
||||
// '+' or '-' at the beginning. If "strict" is false, then the '+'
|
||||
// or '-' can be omitted
|
||||
bool valid_prefix = false;
|
||||
|
||||
if (name[0] == '+' || name[0] == '-')
|
||||
{
|
||||
valid_prefix = name[1] == '[';
|
||||
if (name[0] == '+')
|
||||
m_type = eTypeClassMethod;
|
||||
else
|
||||
m_type = eTypeInstanceMethod;
|
||||
}
|
||||
else if (!strict)
|
||||
{
|
||||
// "strict" is false, the name just needs to start with '['
|
||||
valid_prefix = name[0] == '[';
|
||||
}
|
||||
|
||||
if (valid_prefix)
|
||||
{
|
||||
int name_len = strlen (name);
|
||||
// Objective C methods must have at least:
|
||||
// "-[" or "+[" prefix
|
||||
// One character for a class name
|
||||
// One character for the space between the class name
|
||||
// One character for the method name
|
||||
// "]" suffix
|
||||
if (name_len >= (5 + (strict ? 1 : 0)) && name[name_len - 1] == ']')
|
||||
{
|
||||
m_full.SetCStringWithLength(name, name_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
return IsValid(strict);
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
ObjCLanguage::MethodName::GetClassName ()
|
||||
{
|
||||
if (!m_class)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
const char *full = m_full.GetCString();
|
||||
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
||||
const char *paren_pos = strchr (class_start, '(');
|
||||
if (paren_pos)
|
||||
{
|
||||
m_class.SetCStringWithLength (class_start, paren_pos - class_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No '(' was found in the full name, we can definitively say
|
||||
// that our category was valid (and empty).
|
||||
m_category_is_valid = true;
|
||||
const char *space_pos = strchr (full, ' ');
|
||||
if (space_pos)
|
||||
{
|
||||
m_class.SetCStringWithLength (class_start, space_pos - class_start);
|
||||
if (!m_class_category)
|
||||
{
|
||||
// No category in name, so we can also fill in the m_class_category
|
||||
m_class_category = m_class;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_class;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
ObjCLanguage::MethodName::GetClassNameWithCategory ()
|
||||
{
|
||||
if (!m_class_category)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
const char *full = m_full.GetCString();
|
||||
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
||||
const char *space_pos = strchr (full, ' ');
|
||||
if (space_pos)
|
||||
{
|
||||
m_class_category.SetCStringWithLength (class_start, space_pos - class_start);
|
||||
// If m_class hasn't been filled in and the class with category doesn't
|
||||
// contain a '(', then we can also fill in the m_class
|
||||
if (!m_class && strchr (m_class_category.GetCString(), '(') == NULL)
|
||||
{
|
||||
m_class = m_class_category;
|
||||
// No '(' was found in the full name, we can definitively say
|
||||
// that our category was valid (and empty).
|
||||
m_category_is_valid = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_class_category;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
ObjCLanguage::MethodName::GetSelector ()
|
||||
{
|
||||
if (!m_selector)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
const char *full = m_full.GetCString();
|
||||
const char *space_pos = strchr (full, ' ');
|
||||
if (space_pos)
|
||||
{
|
||||
++space_pos; // skip the space
|
||||
m_selector.SetCStringWithLength (space_pos, m_full.GetLength() - (space_pos - full) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_selector;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
ObjCLanguage::MethodName::GetCategory ()
|
||||
{
|
||||
if (!m_category_is_valid && !m_category)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
m_category_is_valid = true;
|
||||
const char *full = m_full.GetCString();
|
||||
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
||||
const char *open_paren_pos = strchr (class_start, '(');
|
||||
if (open_paren_pos)
|
||||
{
|
||||
++open_paren_pos; // Skip the open paren
|
||||
const char *close_paren_pos = strchr (open_paren_pos, ')');
|
||||
if (close_paren_pos)
|
||||
m_category.SetCStringWithLength (open_paren_pos, close_paren_pos - open_paren_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_category;
|
||||
}
|
||||
|
||||
ConstString
|
||||
ObjCLanguage::MethodName::GetFullNameWithoutCategory (bool empty_if_no_category)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
if (HasCategory())
|
||||
{
|
||||
StreamString strm;
|
||||
if (m_type == eTypeClassMethod)
|
||||
strm.PutChar('+');
|
||||
else if (m_type == eTypeInstanceMethod)
|
||||
strm.PutChar('-');
|
||||
strm.Printf("[%s %s]", GetClassName().GetCString(), GetSelector().GetCString());
|
||||
return ConstString(strm.GetString().c_str());
|
||||
}
|
||||
|
||||
if (!empty_if_no_category)
|
||||
{
|
||||
// Just return the full name since it doesn't have a category
|
||||
return GetFullName();
|
||||
}
|
||||
}
|
||||
return ConstString();
|
||||
}
|
||||
|
||||
size_t
|
||||
ObjCLanguage::MethodName::GetFullNames (std::vector<ConstString> &names, bool append)
|
||||
{
|
||||
if (!append)
|
||||
names.clear();
|
||||
if (IsValid(false))
|
||||
{
|
||||
StreamString strm;
|
||||
const bool is_class_method = m_type == eTypeClassMethod;
|
||||
const bool is_instance_method = m_type == eTypeInstanceMethod;
|
||||
const ConstString &category = GetCategory();
|
||||
if (is_class_method || is_instance_method)
|
||||
{
|
||||
names.push_back (m_full);
|
||||
if (category)
|
||||
{
|
||||
strm.Printf("%c[%s %s]",
|
||||
is_class_method ? '+' : '-',
|
||||
GetClassName().GetCString(),
|
||||
GetSelector().GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const ConstString &class_name = GetClassName();
|
||||
const ConstString &selector = GetSelector();
|
||||
strm.Printf("+[%s %s]", class_name.GetCString(), selector.GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
strm.Clear();
|
||||
strm.Printf("-[%s %s]", class_name.GetCString(), selector.GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
strm.Clear();
|
||||
if (category)
|
||||
{
|
||||
strm.Printf("+[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
strm.Clear();
|
||||
strm.Printf("-[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return names.size();
|
||||
}
|
||||
|
|
|
@ -12,9 +12,12 @@
|
|||
|
||||
// C Includes
|
||||
// C++ Includes
|
||||
#include <vector>
|
||||
|
||||
// Other libraries and framework includes
|
||||
// Project includes
|
||||
#include "lldb/lldb-private.h"
|
||||
#include "lldb/Core/ConstString.h"
|
||||
#include "lldb/Target/Language.h"
|
||||
|
||||
namespace lldb_private {
|
||||
|
@ -23,6 +26,110 @@ class ObjCLanguage :
|
|||
public Language
|
||||
{
|
||||
public:
|
||||
class MethodName
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
eTypeUnspecified,
|
||||
eTypeClassMethod,
|
||||
eTypeInstanceMethod
|
||||
};
|
||||
|
||||
MethodName () :
|
||||
m_full(),
|
||||
m_class(),
|
||||
m_category(),
|
||||
m_selector(),
|
||||
m_type (eTypeUnspecified),
|
||||
m_category_is_valid (false)
|
||||
{
|
||||
}
|
||||
|
||||
MethodName (const char *name, bool strict) :
|
||||
m_full(),
|
||||
m_class(),
|
||||
m_category(),
|
||||
m_selector(),
|
||||
m_type (eTypeUnspecified),
|
||||
m_category_is_valid (false)
|
||||
{
|
||||
SetName (name, strict);
|
||||
}
|
||||
|
||||
void
|
||||
Clear();
|
||||
|
||||
bool
|
||||
IsValid (bool strict) const
|
||||
{
|
||||
// If "strict" is true, the name must have everything specified including
|
||||
// the leading "+" or "-" on the method name
|
||||
if (strict && m_type == eTypeUnspecified)
|
||||
return false;
|
||||
// Other than that, m_full will only be filled in if the objective C
|
||||
// name is valid.
|
||||
return (bool)m_full;
|
||||
}
|
||||
|
||||
bool
|
||||
HasCategory()
|
||||
{
|
||||
return !GetCategory();
|
||||
}
|
||||
|
||||
Type
|
||||
GetType () const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
GetFullName () const
|
||||
{
|
||||
return m_full;
|
||||
}
|
||||
|
||||
ConstString
|
||||
GetFullNameWithoutCategory (bool empty_if_no_category);
|
||||
|
||||
bool
|
||||
SetName (const char *name, bool strict);
|
||||
|
||||
const ConstString &
|
||||
GetClassName ();
|
||||
|
||||
const ConstString &
|
||||
GetClassNameWithCategory ();
|
||||
|
||||
const ConstString &
|
||||
GetCategory ();
|
||||
|
||||
const ConstString &
|
||||
GetSelector ();
|
||||
|
||||
// Get all possible names for a method. Examples:
|
||||
// If name is "+[NSString(my_additions) myStringWithCString:]"
|
||||
// names[0] => "+[NSString(my_additions) myStringWithCString:]"
|
||||
// names[1] => "+[NSString myStringWithCString:]"
|
||||
// If name is specified without the leading '+' or '-' like "[NSString(my_additions) myStringWithCString:]"
|
||||
// names[0] => "+[NSString(my_additions) myStringWithCString:]"
|
||||
// names[1] => "-[NSString(my_additions) myStringWithCString:]"
|
||||
// names[2] => "+[NSString myStringWithCString:]"
|
||||
// names[3] => "-[NSString myStringWithCString:]"
|
||||
size_t
|
||||
GetFullNames (std::vector<ConstString> &names, bool append);
|
||||
protected:
|
||||
ConstString m_full; // Full name: "+[NSString(my_additions) myStringWithCString:]"
|
||||
ConstString m_class; // Class name: "NSString"
|
||||
ConstString m_class_category; // Class with category: "NSString(my_additions)"
|
||||
ConstString m_category; // Category: "my_additions"
|
||||
ConstString m_selector; // Selector: "myStringWithCString:"
|
||||
Type m_type;
|
||||
bool m_category_is_valid;
|
||||
|
||||
};
|
||||
|
||||
virtual ~ObjCLanguage() = default;
|
||||
|
||||
ObjCLanguage () = default;
|
||||
|
@ -48,6 +155,30 @@ public:
|
|||
static lldb_private::ConstString
|
||||
GetPluginNameStatic();
|
||||
|
||||
static bool
|
||||
IsPossibleObjCMethodName (const char *name)
|
||||
{
|
||||
if (!name)
|
||||
return false;
|
||||
bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '[';
|
||||
bool ends_right = (name[strlen(name) - 1] == ']');
|
||||
return (starts_right && ends_right);
|
||||
}
|
||||
|
||||
static bool
|
||||
IsPossibleObjCSelector (const char *name)
|
||||
{
|
||||
if (!name)
|
||||
return false;
|
||||
|
||||
if (strchr(name, ':') == NULL)
|
||||
return true;
|
||||
else if (name[strlen(name) - 1] == ':')
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// PluginInterface protocol
|
||||
//------------------------------------------------------------------
|
||||
|
|
|
@ -18,15 +18,19 @@
|
|||
#include "SymbolFileDWARFDebugMap.h"
|
||||
#include "UniqueDWARFASTType.h"
|
||||
|
||||
#include "lldb/Interpreter/Args.h"
|
||||
#include "lldb/Core/Log.h"
|
||||
#include "lldb/Core/Module.h"
|
||||
#include "lldb/Core/StreamString.h"
|
||||
#include "lldb/Core/Value.h"
|
||||
#include "lldb/Host/Host.h"
|
||||
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
|
||||
#include "lldb/Symbol/CompileUnit.h"
|
||||
#include "lldb/Symbol/Function.h"
|
||||
#include "lldb/Symbol/ObjectFile.h"
|
||||
#include "lldb/Symbol/TypeList.h"
|
||||
#include "lldb/Target/Language.h"
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
||||
|
||||
#include "clang/AST/DeclCXX.h"
|
||||
#include "clang/AST/DeclObjC.h"
|
||||
|
@ -1045,7 +1049,7 @@ DWARFASTParserClang::ParseTypeFromDWARF (const SymbolContext& sc,
|
|||
if (tag == DW_TAG_subprogram ||
|
||||
tag == DW_TAG_inlined_subroutine)
|
||||
{
|
||||
ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
|
||||
ObjCLanguage::MethodName objc_method (type_name_cstr, true);
|
||||
if (objc_method.IsValid(true))
|
||||
{
|
||||
CompilerType class_opaque_type;
|
||||
|
@ -2473,13 +2477,13 @@ DWARFASTParserClang::ParseChildMembers (const SymbolContext& sc,
|
|||
|
||||
if (prop_getter_name && prop_getter_name[0] == '-')
|
||||
{
|
||||
ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
|
||||
ObjCLanguage::MethodName prop_getter_method(prop_getter_name, true);
|
||||
prop_getter_name = prop_getter_method.GetSelector().GetCString();
|
||||
}
|
||||
|
||||
if (prop_setter_name && prop_setter_name[0] == '-')
|
||||
{
|
||||
ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
|
||||
ObjCLanguage::MethodName prop_setter_method(prop_setter_name, true);
|
||||
prop_setter_name = prop_setter_method.GetSelector().GetCString();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
#include "lldb/Core/Mangled.h"
|
||||
#include "lldb/Core/Module.h"
|
||||
#include "lldb/Core/Stream.h"
|
||||
#include "lldb/Core/StreamString.h"
|
||||
#include "lldb/Core/Timer.h"
|
||||
#include "lldb/Host/StringConvert.h"
|
||||
#include "lldb/Symbol/CompileUnit.h"
|
||||
#include "lldb/Symbol/LineTable.h"
|
||||
#include "lldb/Symbol/ObjectFile.h"
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
||||
|
||||
#include "DWARFDebugAbbrev.h"
|
||||
#include "DWARFDebugAranges.h"
|
||||
|
@ -815,9 +816,7 @@ DWARFCompileUnit::Index (const uint32_t cu_idx,
|
|||
{
|
||||
if (name)
|
||||
{
|
||||
// Note, this check is also done in ParseMethodName, but since this is a hot loop, we do the
|
||||
// simple inlined check outside the call.
|
||||
ObjCLanguageRuntime::MethodName objc_method(name, true);
|
||||
ObjCLanguage::MethodName objc_method(name, true);
|
||||
if (objc_method.IsValid(true))
|
||||
{
|
||||
ConstString objc_class_name_with_category (objc_method.GetClassNameWithCategory());
|
||||
|
|
|
@ -54,8 +54,8 @@
|
|||
#include "lldb/Symbol/SymbolVendor.h"
|
||||
#include "lldb/Symbol/VariableList.h"
|
||||
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "lldb/Target/CPPLanguageRuntime.h"
|
||||
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
|
||||
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
||||
|
||||
#include "lldb/Target/Language.h"
|
||||
|
||||
|
@ -2102,7 +2102,7 @@ SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDec
|
|||
llvm::StringRef basename;
|
||||
llvm::StringRef context;
|
||||
|
||||
if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
|
||||
if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context, basename))
|
||||
basename = name_cstr;
|
||||
|
||||
m_apple_names_ap->FindByName (basename.data(), die_offsets);
|
||||
|
@ -2531,7 +2531,7 @@ SymbolFileDWARF::FindFunctions (const ConstString &name,
|
|||
if (die)
|
||||
{
|
||||
const char *die_name = die.GetName();
|
||||
if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
|
||||
if (ObjCLanguage::IsPossibleObjCMethodName(die_name))
|
||||
{
|
||||
if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
|
||||
{
|
||||
|
|
|
@ -8,17 +8,19 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "lldb/Core/Module.h"
|
||||
#include "lldb/Core/RegularExpression.h"
|
||||
#include "lldb/Core/Section.h"
|
||||
#include "lldb/Core/Stream.h"
|
||||
#include "lldb/Core/Timer.h"
|
||||
#include "lldb/Symbol/ObjectFile.h"
|
||||
#include "lldb/Symbol/Symbol.h"
|
||||
#include "lldb/Symbol/SymbolContext.h"
|
||||
#include "lldb/Symbol/Symtab.h"
|
||||
#include "lldb/Target/CPPLanguageRuntime.h"
|
||||
#include "lldb/Target/ObjCLanguageRuntime.h"
|
||||
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
||||
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
@ -329,7 +331,7 @@ Symtab::InitNameIndexes()
|
|||
entry.cstring[2] != 'G' && // avoid guard variables
|
||||
entry.cstring[2] != 'Z')) // named local entities (if we eventually handle eSymbolTypeData, we will want this back)
|
||||
{
|
||||
CPPLanguageRuntime::MethodName cxx_method (mangled.GetDemangledName(lldb::eLanguageTypeC_plus_plus));
|
||||
CPlusPlusLanguage::MethodName cxx_method (mangled.GetDemangledName(lldb::eLanguageTypeC_plus_plus));
|
||||
entry.cstring = ConstString(cxx_method.GetBasename()).GetCString();
|
||||
if (entry.cstring && entry.cstring[0])
|
||||
{
|
||||
|
@ -392,7 +394,7 @@ Symtab::InitNameIndexes()
|
|||
|
||||
// If the demangled name turns out to be an ObjC name, and
|
||||
// is a category name, add the version without categories to the index too.
|
||||
ObjCLanguageRuntime::MethodName objc_method (entry.cstring, true);
|
||||
ObjCLanguage::MethodName objc_method (entry.cstring, true);
|
||||
if (objc_method.IsValid(true))
|
||||
{
|
||||
entry.cstring = objc_method.GetSelector().GetCString();
|
||||
|
|
|
@ -20,137 +20,6 @@
|
|||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
||||
class CPPRuntimeEquivalents
|
||||
{
|
||||
public:
|
||||
CPPRuntimeEquivalents ()
|
||||
{
|
||||
|
||||
m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >").AsCString(), ConstString("basic_string<char>"));
|
||||
|
||||
// these two (with a prefixed std::) occur when c++stdlib string class occurs as a template argument in some STL container
|
||||
m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, std::allocator<char> >").AsCString(), ConstString("std::basic_string<char>"));
|
||||
|
||||
m_impl.Sort();
|
||||
}
|
||||
|
||||
void
|
||||
Add (ConstString& type_name,
|
||||
ConstString& type_equivalent)
|
||||
{
|
||||
m_impl.Insert(type_name.AsCString(), type_equivalent);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
FindExactMatches (ConstString& type_name,
|
||||
std::vector<ConstString>& equivalents)
|
||||
{
|
||||
|
||||
uint32_t count = 0;
|
||||
|
||||
for (ImplData match = m_impl.FindFirstValueForName(type_name.AsCString());
|
||||
match != NULL;
|
||||
match = m_impl.FindNextValueForName(match))
|
||||
{
|
||||
equivalents.push_back(match->value);
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// partial matches can occur when a name with equivalents is a template argument.
|
||||
// e.g. we may have "class Foo" be a match for "struct Bar". if we have a typename
|
||||
// such as "class Templatized<class Foo, Anything>" we want this to be replaced with
|
||||
// "class Templatized<struct Bar, Anything>". Since partial matching is time consuming
|
||||
// once we get a partial match, we add it to the exact matches list for faster retrieval
|
||||
uint32_t
|
||||
FindPartialMatches (ConstString& type_name,
|
||||
std::vector<ConstString>& equivalents)
|
||||
{
|
||||
|
||||
uint32_t count = 0;
|
||||
|
||||
const char* type_name_cstr = type_name.AsCString();
|
||||
|
||||
size_t items_count = m_impl.GetSize();
|
||||
|
||||
for (size_t item = 0; item < items_count; item++)
|
||||
{
|
||||
const char* key_cstr = m_impl.GetCStringAtIndex(item);
|
||||
if ( strstr(type_name_cstr,key_cstr) )
|
||||
{
|
||||
count += AppendReplacements(type_name_cstr,
|
||||
key_cstr,
|
||||
equivalents);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string& replace (std::string& target,
|
||||
std::string& pattern,
|
||||
std::string& with)
|
||||
{
|
||||
size_t pos;
|
||||
size_t pattern_len = pattern.size();
|
||||
|
||||
while ( (pos = target.find(pattern)) != std::string::npos )
|
||||
target.replace(pos, pattern_len, with);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
AppendReplacements (const char* original,
|
||||
const char *matching_key,
|
||||
std::vector<ConstString>& equivalents)
|
||||
{
|
||||
|
||||
std::string matching_key_str(matching_key);
|
||||
ConstString original_const(original);
|
||||
|
||||
uint32_t count = 0;
|
||||
|
||||
for (ImplData match = m_impl.FindFirstValueForName(matching_key);
|
||||
match != NULL;
|
||||
match = m_impl.FindNextValueForName(match))
|
||||
{
|
||||
std::string target(original);
|
||||
std::string equiv_class(match->value.AsCString());
|
||||
|
||||
replace (target, matching_key_str, equiv_class);
|
||||
|
||||
ConstString target_const(target.c_str());
|
||||
|
||||
// you will most probably want to leave this off since it might make this map grow indefinitely
|
||||
#ifdef ENABLE_CPP_EQUIVALENTS_MAP_TO_GROW
|
||||
Add(original_const, target_const);
|
||||
#endif
|
||||
equivalents.push_back(target_const);
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
typedef UniqueCStringMap<ConstString> Impl;
|
||||
typedef const Impl::Entry* ImplData;
|
||||
Impl m_impl;
|
||||
};
|
||||
|
||||
static CPPRuntimeEquivalents&
|
||||
GetEquivalentsMap ()
|
||||
{
|
||||
static CPPRuntimeEquivalents g_equivalents_map;
|
||||
return g_equivalents_map;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Destructor
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -177,241 +46,3 @@ CPPLanguageRuntime::GetObjectDescription (Stream &str, Value &value, ExecutionCo
|
|||
// C++ has no generic way to do this.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CPPLanguageRuntime::IsCPPMangledName (const char *name)
|
||||
{
|
||||
// FIXME, we should really run through all the known C++ Language plugins and ask each one if
|
||||
// this is a C++ mangled name, but we can put that off till there is actually more than one
|
||||
// we care about.
|
||||
|
||||
if (name && name[0] == '_' && name[1] == 'Z')
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CPPLanguageRuntime::ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
|
||||
{
|
||||
static RegularExpression g_basename_regex("^(([A-Za-z_][A-Za-z_0-9]*::)*)([A-Za-z_][A-Za-z_0-9]*)$");
|
||||
RegularExpression::Match match(4);
|
||||
if (g_basename_regex.Execute (name, &match))
|
||||
{
|
||||
match.GetMatchAtIndex(name, 1, context);
|
||||
match.GetMatchAtIndex(name, 3, identifier);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
CPPLanguageRuntime::FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents)
|
||||
{
|
||||
uint32_t count = GetEquivalentsMap().FindExactMatches(type_name, equivalents);
|
||||
|
||||
bool might_have_partials=
|
||||
( count == 0 ) // if we have a full name match just use it
|
||||
&& (strchr(type_name.AsCString(), '<') != NULL // we should only have partial matches when templates are involved, check that we have
|
||||
&& strchr(type_name.AsCString(), '>') != NULL); // angle brackets in the type_name before trying to scan for partial matches
|
||||
|
||||
if ( might_have_partials )
|
||||
count = GetEquivalentsMap().FindPartialMatches(type_name, equivalents);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void
|
||||
CPPLanguageRuntime::MethodName::Clear()
|
||||
{
|
||||
m_full.Clear();
|
||||
m_basename = llvm::StringRef();
|
||||
m_context = llvm::StringRef();
|
||||
m_arguments = llvm::StringRef();
|
||||
m_qualifiers = llvm::StringRef();
|
||||
m_type = eTypeInvalid;
|
||||
m_parsed = false;
|
||||
m_parse_error = false;
|
||||
}
|
||||
|
||||
bool
|
||||
ReverseFindMatchingChars (const llvm::StringRef &s,
|
||||
const llvm::StringRef &left_right_chars,
|
||||
size_t &left_pos,
|
||||
size_t &right_pos,
|
||||
size_t pos = llvm::StringRef::npos)
|
||||
{
|
||||
assert (left_right_chars.size() == 2);
|
||||
left_pos = llvm::StringRef::npos;
|
||||
const char left_char = left_right_chars[0];
|
||||
const char right_char = left_right_chars[1];
|
||||
pos = s.find_last_of(left_right_chars, pos);
|
||||
if (pos == llvm::StringRef::npos || s[pos] == left_char)
|
||||
return false;
|
||||
right_pos = pos;
|
||||
uint32_t depth = 1;
|
||||
while (pos > 0 && depth > 0)
|
||||
{
|
||||
pos = s.find_last_of(left_right_chars, pos);
|
||||
if (pos == llvm::StringRef::npos)
|
||||
return false;
|
||||
if (s[pos] == left_char)
|
||||
{
|
||||
if (--depth == 0)
|
||||
{
|
||||
left_pos = pos;
|
||||
return left_pos < right_pos;
|
||||
}
|
||||
}
|
||||
else if (s[pos] == right_char)
|
||||
{
|
||||
++depth;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CPPLanguageRuntime::MethodName::Parse()
|
||||
{
|
||||
if (!m_parsed && m_full)
|
||||
{
|
||||
// ConstString mangled;
|
||||
// m_full.GetMangledCounterpart(mangled);
|
||||
// printf ("\n parsing = '%s'\n", m_full.GetCString());
|
||||
// if (mangled)
|
||||
// printf (" mangled = '%s'\n", mangled.GetCString());
|
||||
m_parse_error = false;
|
||||
m_parsed = true;
|
||||
llvm::StringRef full (m_full.GetCString());
|
||||
|
||||
size_t arg_start, arg_end;
|
||||
llvm::StringRef parens("()", 2);
|
||||
if (ReverseFindMatchingChars (full, parens, arg_start, arg_end))
|
||||
{
|
||||
m_arguments = full.substr(arg_start, arg_end - arg_start + 1);
|
||||
if (arg_end + 1 < full.size())
|
||||
m_qualifiers = full.substr(arg_end + 1);
|
||||
if (arg_start > 0)
|
||||
{
|
||||
size_t basename_end = arg_start;
|
||||
size_t context_start = 0;
|
||||
size_t context_end = llvm::StringRef::npos;
|
||||
if (basename_end > 0 && full[basename_end-1] == '>')
|
||||
{
|
||||
// TODO: handle template junk...
|
||||
// Templated function
|
||||
size_t template_start, template_end;
|
||||
llvm::StringRef lt_gt("<>", 2);
|
||||
if (ReverseFindMatchingChars (full, lt_gt, template_start, template_end, basename_end))
|
||||
{
|
||||
// Check for templated functions that include return type like: 'void foo<Int>()'
|
||||
context_start = full.rfind(' ', template_start);
|
||||
if (context_start == llvm::StringRef::npos)
|
||||
context_start = 0;
|
||||
|
||||
context_end = full.rfind(':', template_start);
|
||||
if (context_end == llvm::StringRef::npos || context_end < context_start)
|
||||
context_end = context_start;
|
||||
}
|
||||
else
|
||||
{
|
||||
context_end = full.rfind(':', basename_end);
|
||||
}
|
||||
}
|
||||
else if (context_end == llvm::StringRef::npos)
|
||||
{
|
||||
context_end = full.rfind(':', basename_end);
|
||||
}
|
||||
|
||||
if (context_end == llvm::StringRef::npos)
|
||||
m_basename = full.substr(0, basename_end);
|
||||
else
|
||||
{
|
||||
if (context_start < context_end)
|
||||
m_context = full.substr(context_start, context_end - 1);
|
||||
const size_t basename_begin = context_end + 1;
|
||||
m_basename = full.substr(basename_begin, basename_end - basename_begin);
|
||||
}
|
||||
m_type = eTypeUnknownMethod;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_parse_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!m_context.empty())
|
||||
// printf (" context = '%s'\n", m_context.str().c_str());
|
||||
// if (m_basename)
|
||||
// printf (" basename = '%s'\n", m_basename.GetCString());
|
||||
// if (!m_arguments.empty())
|
||||
// printf (" arguments = '%s'\n", m_arguments.str().c_str());
|
||||
// if (!m_qualifiers.empty())
|
||||
// printf ("qualifiers = '%s'\n", m_qualifiers.str().c_str());
|
||||
|
||||
// Make sure we have a valid C++ basename with optional template args
|
||||
static RegularExpression g_identifier_regex("^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$");
|
||||
std::string basename_str(m_basename.str());
|
||||
bool basename_is_valid = g_identifier_regex.Execute (basename_str.c_str(), NULL);
|
||||
if (!basename_is_valid)
|
||||
{
|
||||
// Check for C++ operators
|
||||
if (m_basename.startswith("operator"))
|
||||
{
|
||||
static RegularExpression g_operator_regex("^(operator)( ?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|\\[\\]|[\\^<>=!\\/*+-]+)(<.*>)?(\\[\\])?$");
|
||||
basename_is_valid = g_operator_regex.Execute(basename_str.c_str(), NULL);
|
||||
}
|
||||
}
|
||||
if (!basename_is_valid)
|
||||
{
|
||||
// The C++ basename doesn't match our regular expressions so this can't
|
||||
// be a valid C++ method, clear everything out and indicate an error
|
||||
m_context = llvm::StringRef();
|
||||
m_basename = llvm::StringRef();
|
||||
m_arguments = llvm::StringRef();
|
||||
m_qualifiers = llvm::StringRef();
|
||||
m_parse_error = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_parse_error = true;
|
||||
// printf ("error: didn't find matching parens for arguments\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
CPPLanguageRuntime::MethodName::GetBasename ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
return m_basename;
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
CPPLanguageRuntime::MethodName::GetContext ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
return m_context;
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
CPPLanguageRuntime::MethodName::GetArguments ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
llvm::StringRef
|
||||
CPPLanguageRuntime::MethodName::GetQualifiers ()
|
||||
{
|
||||
if (!m_parsed)
|
||||
Parse();
|
||||
return m_qualifiers;
|
||||
}
|
||||
|
||||
|
|
|
@ -157,283 +157,6 @@ ObjCLanguageRuntime::GetByteOffsetForIvar (CompilerType &parent_qual_type, const
|
|||
return LLDB_INVALID_IVAR_OFFSET;
|
||||
}
|
||||
|
||||
void
|
||||
ObjCLanguageRuntime::MethodName::Clear()
|
||||
{
|
||||
m_full.Clear();
|
||||
m_class.Clear();
|
||||
m_category.Clear();
|
||||
m_selector.Clear();
|
||||
m_type = eTypeUnspecified;
|
||||
m_category_is_valid = false;
|
||||
}
|
||||
|
||||
//bool
|
||||
//ObjCLanguageRuntime::MethodName::SetName (const char *name, bool strict)
|
||||
//{
|
||||
// Clear();
|
||||
// if (name && name[0])
|
||||
// {
|
||||
// // If "strict" is true. then the method must be specified with a
|
||||
// // '+' or '-' at the beginning. If "strict" is false, then the '+'
|
||||
// // or '-' can be omitted
|
||||
// bool valid_prefix = false;
|
||||
//
|
||||
// if (name[0] == '+' || name[0] == '-')
|
||||
// {
|
||||
// valid_prefix = name[1] == '[';
|
||||
// }
|
||||
// else if (!strict)
|
||||
// {
|
||||
// // "strict" is false, the name just needs to start with '['
|
||||
// valid_prefix = name[0] == '[';
|
||||
// }
|
||||
//
|
||||
// if (valid_prefix)
|
||||
// {
|
||||
// static RegularExpression g_regex("^([-+]?)\\[([A-Za-z_][A-Za-z_0-9]*)(\\([A-Za-z_][A-Za-z_0-9]*\\))? ([A-Za-z_][A-Za-z_0-9:]*)\\]$");
|
||||
// llvm::StringRef matches[4];
|
||||
// // Since we are using a global regular expression, we must use the threadsafe version of execute
|
||||
// if (g_regex.ExecuteThreadSafe(name, matches, 4))
|
||||
// {
|
||||
// m_full.SetCString(name);
|
||||
// if (matches[0].empty())
|
||||
// m_type = eTypeUnspecified;
|
||||
// else if (matches[0][0] == '+')
|
||||
// m_type = eTypeClassMethod;
|
||||
// else
|
||||
// m_type = eTypeInstanceMethod;
|
||||
// m_class.SetString(matches[1]);
|
||||
// m_selector.SetString(matches[3]);
|
||||
// if (!matches[2].empty())
|
||||
// m_category.SetString(matches[2]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return IsValid(strict);
|
||||
//}
|
||||
|
||||
bool
|
||||
ObjCLanguageRuntime::MethodName::SetName (const char *name, bool strict)
|
||||
{
|
||||
Clear();
|
||||
if (name && name[0])
|
||||
{
|
||||
// If "strict" is true. then the method must be specified with a
|
||||
// '+' or '-' at the beginning. If "strict" is false, then the '+'
|
||||
// or '-' can be omitted
|
||||
bool valid_prefix = false;
|
||||
|
||||
if (name[0] == '+' || name[0] == '-')
|
||||
{
|
||||
valid_prefix = name[1] == '[';
|
||||
if (name[0] == '+')
|
||||
m_type = eTypeClassMethod;
|
||||
else
|
||||
m_type = eTypeInstanceMethod;
|
||||
}
|
||||
else if (!strict)
|
||||
{
|
||||
// "strict" is false, the name just needs to start with '['
|
||||
valid_prefix = name[0] == '[';
|
||||
}
|
||||
|
||||
if (valid_prefix)
|
||||
{
|
||||
int name_len = strlen (name);
|
||||
// Objective C methods must have at least:
|
||||
// "-[" or "+[" prefix
|
||||
// One character for a class name
|
||||
// One character for the space between the class name
|
||||
// One character for the method name
|
||||
// "]" suffix
|
||||
if (name_len >= (5 + (strict ? 1 : 0)) && name[name_len - 1] == ']')
|
||||
{
|
||||
m_full.SetCStringWithLength(name, name_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
return IsValid(strict);
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
ObjCLanguageRuntime::MethodName::GetClassName ()
|
||||
{
|
||||
if (!m_class)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
const char *full = m_full.GetCString();
|
||||
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
||||
const char *paren_pos = strchr (class_start, '(');
|
||||
if (paren_pos)
|
||||
{
|
||||
m_class.SetCStringWithLength (class_start, paren_pos - class_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No '(' was found in the full name, we can definitively say
|
||||
// that our category was valid (and empty).
|
||||
m_category_is_valid = true;
|
||||
const char *space_pos = strchr (full, ' ');
|
||||
if (space_pos)
|
||||
{
|
||||
m_class.SetCStringWithLength (class_start, space_pos - class_start);
|
||||
if (!m_class_category)
|
||||
{
|
||||
// No category in name, so we can also fill in the m_class_category
|
||||
m_class_category = m_class;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_class;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
ObjCLanguageRuntime::MethodName::GetClassNameWithCategory ()
|
||||
{
|
||||
if (!m_class_category)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
const char *full = m_full.GetCString();
|
||||
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
||||
const char *space_pos = strchr (full, ' ');
|
||||
if (space_pos)
|
||||
{
|
||||
m_class_category.SetCStringWithLength (class_start, space_pos - class_start);
|
||||
// If m_class hasn't been filled in and the class with category doesn't
|
||||
// contain a '(', then we can also fill in the m_class
|
||||
if (!m_class && strchr (m_class_category.GetCString(), '(') == NULL)
|
||||
{
|
||||
m_class = m_class_category;
|
||||
// No '(' was found in the full name, we can definitively say
|
||||
// that our category was valid (and empty).
|
||||
m_category_is_valid = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_class_category;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
ObjCLanguageRuntime::MethodName::GetSelector ()
|
||||
{
|
||||
if (!m_selector)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
const char *full = m_full.GetCString();
|
||||
const char *space_pos = strchr (full, ' ');
|
||||
if (space_pos)
|
||||
{
|
||||
++space_pos; // skip the space
|
||||
m_selector.SetCStringWithLength (space_pos, m_full.GetLength() - (space_pos - full) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_selector;
|
||||
}
|
||||
|
||||
const ConstString &
|
||||
ObjCLanguageRuntime::MethodName::GetCategory ()
|
||||
{
|
||||
if (!m_category_is_valid && !m_category)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
m_category_is_valid = true;
|
||||
const char *full = m_full.GetCString();
|
||||
const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
|
||||
const char *open_paren_pos = strchr (class_start, '(');
|
||||
if (open_paren_pos)
|
||||
{
|
||||
++open_paren_pos; // Skip the open paren
|
||||
const char *close_paren_pos = strchr (open_paren_pos, ')');
|
||||
if (close_paren_pos)
|
||||
m_category.SetCStringWithLength (open_paren_pos, close_paren_pos - open_paren_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_category;
|
||||
}
|
||||
|
||||
ConstString
|
||||
ObjCLanguageRuntime::MethodName::GetFullNameWithoutCategory (bool empty_if_no_category)
|
||||
{
|
||||
if (IsValid(false))
|
||||
{
|
||||
if (HasCategory())
|
||||
{
|
||||
StreamString strm;
|
||||
if (m_type == eTypeClassMethod)
|
||||
strm.PutChar('+');
|
||||
else if (m_type == eTypeInstanceMethod)
|
||||
strm.PutChar('-');
|
||||
strm.Printf("[%s %s]", GetClassName().GetCString(), GetSelector().GetCString());
|
||||
return ConstString(strm.GetString().c_str());
|
||||
}
|
||||
|
||||
if (!empty_if_no_category)
|
||||
{
|
||||
// Just return the full name since it doesn't have a category
|
||||
return GetFullName();
|
||||
}
|
||||
}
|
||||
return ConstString();
|
||||
}
|
||||
|
||||
size_t
|
||||
ObjCLanguageRuntime::MethodName::GetFullNames (std::vector<ConstString> &names, bool append)
|
||||
{
|
||||
if (!append)
|
||||
names.clear();
|
||||
if (IsValid(false))
|
||||
{
|
||||
StreamString strm;
|
||||
const bool is_class_method = m_type == eTypeClassMethod;
|
||||
const bool is_instance_method = m_type == eTypeInstanceMethod;
|
||||
const ConstString &category = GetCategory();
|
||||
if (is_class_method || is_instance_method)
|
||||
{
|
||||
names.push_back (m_full);
|
||||
if (category)
|
||||
{
|
||||
strm.Printf("%c[%s %s]",
|
||||
is_class_method ? '+' : '-',
|
||||
GetClassName().GetCString(),
|
||||
GetSelector().GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const ConstString &class_name = GetClassName();
|
||||
const ConstString &selector = GetSelector();
|
||||
strm.Printf("+[%s %s]", class_name.GetCString(), selector.GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
strm.Clear();
|
||||
strm.Printf("-[%s %s]", class_name.GetCString(), selector.GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
strm.Clear();
|
||||
if (category)
|
||||
{
|
||||
strm.Printf("+[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
strm.Clear();
|
||||
strm.Printf("-[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
|
||||
names.push_back(ConstString(strm.GetString().c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return names.size();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ObjCLanguageRuntime::ClassDescriptor::IsPointerValid (lldb::addr_t value,
|
||||
uint32_t ptr_size,
|
||||
|
|
Loading…
Reference in New Issue