[Lldb-commits] [lldb] r250567 - Move TypeSummaryImpl over to LLVM-style RTTI for subclassing
Enrico Granata via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 16 15:51:56 PDT 2015
Author: enrico
Date: Fri Oct 16 17:51:56 2015
New Revision: 250567
URL: http://llvm.org/viewvc/llvm-project?rev=250567&view=rev
Log:
Move TypeSummaryImpl over to LLVM-style RTTI for subclassing
Modified:
lldb/trunk/include/lldb/DataFormatters/TypeSummary.h
lldb/trunk/source/API/SBTypeSummary.cpp
lldb/trunk/source/DataFormatters/TypeSummary.cpp
Modified: lldb/trunk/include/lldb/DataFormatters/TypeSummary.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeSummary.h?rev=250567&r1=250566&r2=250567&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/TypeSummary.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/TypeSummary.h Fri Oct 16 17:51:56 2015
@@ -61,6 +61,19 @@ namespace lldb_private {
class TypeSummaryImpl
{
public:
+ enum class Kind
+ {
+ eSummaryString,
+ eScript,
+ eCallback
+ };
+
+ Kind
+ GetKind () const
+ {
+ return m_kind;
+ }
+
class Flags
{
public:
@@ -260,16 +273,6 @@ namespace lldb_private {
uint32_t m_flags;
};
- typedef enum Type
- {
- eTypeUnknown,
- eTypeString,
- eTypeScript,
- eTypeCallback
- } Type;
-
- TypeSummaryImpl (const TypeSummaryImpl::Flags& flags);
-
bool
Cascades () const
{
@@ -397,12 +400,6 @@ namespace lldb_private {
virtual std::string
GetDescription () = 0;
- virtual bool
- IsScripted () = 0;
-
- virtual Type
- GetType () = 0;
-
uint32_t&
GetRevision ()
{
@@ -417,7 +414,11 @@ namespace lldb_private {
uint32_t m_my_revision;
Flags m_flags;
+ TypeSummaryImpl (Kind kind,
+ const TypeSummaryImpl::Flags& flags);
+
private:
+ Kind m_kind;
DISALLOW_COPY_AND_ASSIGN(TypeSummaryImpl);
};
@@ -452,16 +453,9 @@ namespace lldb_private {
std::string
GetDescription() override;
- bool
- IsScripted() override
- {
- return false;
- }
-
- Type
- GetType() override
+ static bool classof(const TypeSummaryImpl* S)
{
- return TypeSummaryImpl::eTypeString;
+ return S->GetKind() == Kind::eSummaryString;
}
private:
@@ -523,16 +517,9 @@ namespace lldb_private {
std::string
GetDescription() override;
- bool
- IsScripted() override
- {
- return false;
- }
-
- Type
- GetType() override
+ static bool classof(const TypeSummaryImpl* S)
{
- return TypeSummaryImpl::eTypeCallback;
+ return S->GetKind() == Kind::eCallback;
}
typedef std::shared_ptr<CXXFunctionSummaryFormat> SharedPointer;
@@ -595,16 +582,9 @@ namespace lldb_private {
std::string
GetDescription() override;
- bool
- IsScripted() override
- {
- return true;
- }
-
- Type
- GetType() override
+ static bool classof(const TypeSummaryImpl* S)
{
- return TypeSummaryImpl::eTypeScript;
+ return S->GetKind() == Kind::eScript;
}
typedef std::shared_ptr<ScriptSummaryFormat> SharedPointer;
Modified: lldb/trunk/source/API/SBTypeSummary.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTypeSummary.cpp?rev=250567&r1=250566&r2=250567&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTypeSummary.cpp (original)
+++ lldb/trunk/source/API/SBTypeSummary.cpp Fri Oct 16 17:51:56 2015
@@ -12,6 +12,8 @@
#include "lldb/API/SBValue.h"
#include "lldb/DataFormatters/DataVisualization.h"
+#include "llvm/Support/Casting.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -164,9 +166,8 @@ SBTypeSummary::IsFunctionCode()
{
if (!IsValid())
return false;
- if (m_opaque_sp->IsScripted())
+ if (ScriptSummaryFormat* script_summary_ptr = llvm::dyn_cast<ScriptSummaryFormat>(m_opaque_sp.get()))
{
- ScriptSummaryFormat* script_summary_ptr = (ScriptSummaryFormat*)m_opaque_sp.get();
const char* ftext = script_summary_ptr->GetPythonScript();
return (ftext && *ftext != 0);
}
@@ -178,9 +179,8 @@ SBTypeSummary::IsFunctionName()
{
if (!IsValid())
return false;
- if (m_opaque_sp->IsScripted())
+ if (ScriptSummaryFormat* script_summary_ptr = llvm::dyn_cast<ScriptSummaryFormat>(m_opaque_sp.get()))
{
- ScriptSummaryFormat* script_summary_ptr = (ScriptSummaryFormat*)m_opaque_sp.get();
const char* ftext = script_summary_ptr->GetPythonScript();
return (!ftext || *ftext == 0);
}
@@ -193,10 +193,7 @@ SBTypeSummary::IsSummaryString()
if (!IsValid())
return false;
- if (m_opaque_sp->GetType() == lldb_private::TypeSummaryImpl::eTypeCallback)
- return false;
-
- return !m_opaque_sp->IsScripted();
+ return m_opaque_sp->GetKind() == TypeSummaryImpl::Kind::eSummaryString;
}
const char*
@@ -204,22 +201,17 @@ SBTypeSummary::GetData ()
{
if (!IsValid())
return NULL;
- if (m_opaque_sp->GetType() == lldb_private::TypeSummaryImpl::eTypeCallback)
- return NULL;
- if (m_opaque_sp->IsScripted())
+ if (ScriptSummaryFormat* script_summary_ptr = llvm::dyn_cast<ScriptSummaryFormat>(m_opaque_sp.get()))
{
- ScriptSummaryFormat* script_summary_ptr = (ScriptSummaryFormat*)m_opaque_sp.get();
const char* fname = script_summary_ptr->GetFunctionName();
const char* ftext = script_summary_ptr->GetPythonScript();
if (ftext && *ftext)
return ftext;
return fname;
}
- else
- {
- StringSummaryFormat* string_summary_ptr = (StringSummaryFormat*)m_opaque_sp.get();
+ else if (StringSummaryFormat* string_summary_ptr = llvm::dyn_cast<StringSummaryFormat>(m_opaque_sp.get()))
return string_summary_ptr->GetSummaryString();
- }
+ return nullptr;
}
uint32_t
@@ -243,9 +235,10 @@ SBTypeSummary::SetSummaryString (const c
{
if (!IsValid())
return;
- if (m_opaque_sp->IsScripted() || (m_opaque_sp->GetType() == lldb_private::TypeSummaryImpl::eTypeCallback))
+ if (!llvm::isa<StringSummaryFormat>(m_opaque_sp.get()))
ChangeSummaryType(false);
- ((StringSummaryFormat*)m_opaque_sp.get())->SetSummaryString(data);
+ if (StringSummaryFormat* string_summary_ptr = llvm::dyn_cast<StringSummaryFormat>(m_opaque_sp.get()))
+ string_summary_ptr->SetSummaryString(data);
}
void
@@ -253,9 +246,10 @@ SBTypeSummary::SetFunctionName (const ch
{
if (!IsValid())
return;
- if (!m_opaque_sp->IsScripted())
+ if (!llvm::isa<ScriptSummaryFormat>(m_opaque_sp.get()))
ChangeSummaryType(true);
- ((ScriptSummaryFormat*)m_opaque_sp.get())->SetFunctionName(data);
+ if (ScriptSummaryFormat* script_summary_ptr = llvm::dyn_cast<ScriptSummaryFormat>(m_opaque_sp.get()))
+ script_summary_ptr->SetFunctionName(data);
}
void
@@ -263,9 +257,10 @@ SBTypeSummary::SetFunctionCode (const ch
{
if (!IsValid())
return;
- if (!m_opaque_sp->IsScripted())
+ if (!llvm::isa<ScriptSummaryFormat>(m_opaque_sp.get()))
ChangeSummaryType(true);
- ((ScriptSummaryFormat*)m_opaque_sp.get())->SetPythonScript(data);
+ if (ScriptSummaryFormat* script_summary_ptr = llvm::dyn_cast<ScriptSummaryFormat>(m_opaque_sp.get()))
+ script_summary_ptr->SetPythonScript(data);
}
bool
@@ -314,33 +309,26 @@ SBTypeSummary::IsEqualTo (lldb::SBTypeSu
if (IsValid() == false)
return !rhs.IsValid();
- if (m_opaque_sp->GetType() != rhs.m_opaque_sp->GetType())
+ if (m_opaque_sp->GetKind() != rhs.m_opaque_sp->GetKind())
return false;
- if (m_opaque_sp->GetType() == lldb_private::TypeSummaryImpl::eTypeCallback)
+ switch (m_opaque_sp->GetKind())
{
- lldb_private::CXXFunctionSummaryFormat *self_cxx = (lldb_private::CXXFunctionSummaryFormat*)m_opaque_sp.get();
- lldb_private::CXXFunctionSummaryFormat *other_cxx = (lldb_private::CXXFunctionSummaryFormat*)rhs.m_opaque_sp.get();
- return (self_cxx == other_cxx);
+ case TypeSummaryImpl::Kind::eCallback:
+ return llvm::dyn_cast<CXXFunctionSummaryFormat>(m_opaque_sp.get()) == llvm::dyn_cast<CXXFunctionSummaryFormat>(rhs.m_opaque_sp.get());
+ case TypeSummaryImpl::Kind::eScript:
+ if (IsFunctionCode() != rhs.IsFunctionCode())
+ return false;
+ if (IsFunctionName() != rhs.IsFunctionName())
+ return false;
+ return GetOptions() == rhs.GetOptions();
+ case TypeSummaryImpl::Kind::eSummaryString:
+ if (IsSummaryString() != rhs.IsSummaryString())
+ return false;
+ return GetOptions() == rhs.GetOptions();
}
- if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
- return false;
-
- if (IsFunctionCode() != rhs.IsFunctionCode())
- return false;
-
- if (IsSummaryString() != rhs.IsSummaryString())
- return false;
-
- if (IsFunctionName() != rhs.IsFunctionName())
- return false;
-
- if ( GetData() == NULL || rhs.GetData() == NULL || strcmp(GetData(), rhs.GetData()) )
- return false;
-
- return GetOptions() == rhs.GetOptions();
-
+ return false;
}
bool
@@ -379,29 +367,27 @@ SBTypeSummary::CopyOnWrite_Impl()
TypeSummaryImplSP new_sp;
- if (m_opaque_sp->GetType() == lldb_private::TypeSummaryImpl::eTypeCallback)
+ if (CXXFunctionSummaryFormat* current_summary_ptr = llvm::dyn_cast<CXXFunctionSummaryFormat>(m_opaque_sp.get()))
{
- CXXFunctionSummaryFormat* current_summary_ptr = (CXXFunctionSummaryFormat*)m_opaque_sp.get();
new_sp = TypeSummaryImplSP(new CXXFunctionSummaryFormat(GetOptions(),
current_summary_ptr->m_impl,
current_summary_ptr->m_description.c_str()));
}
- else if (m_opaque_sp->IsScripted())
+ else if (ScriptSummaryFormat* current_summary_ptr = llvm::dyn_cast<ScriptSummaryFormat>(m_opaque_sp.get()))
{
- ScriptSummaryFormat* current_summary_ptr = (ScriptSummaryFormat*)m_opaque_sp.get();
new_sp = TypeSummaryImplSP(new ScriptSummaryFormat(GetOptions(),
current_summary_ptr->GetFunctionName(),
current_summary_ptr->GetPythonScript()));
}
- else {
- StringSummaryFormat* current_summary_ptr = (StringSummaryFormat*)m_opaque_sp.get();
+ else if (StringSummaryFormat* current_summary_ptr = llvm::dyn_cast<StringSummaryFormat>(m_opaque_sp.get()))
+ {
new_sp = TypeSummaryImplSP(new StringSummaryFormat(GetOptions(),
current_summary_ptr->GetSummaryString()));
}
-
+
SetSP(new_sp);
- return true;
+ return nullptr != new_sp.get();
}
bool
@@ -412,9 +398,9 @@ SBTypeSummary::ChangeSummaryType (bool w
TypeSummaryImplSP new_sp;
- if (want_script == m_opaque_sp->IsScripted())
+ if (want_script == (m_opaque_sp->GetKind() == TypeSummaryImpl::Kind::eScript))
{
- if (m_opaque_sp->GetType() == lldb_private::TypeSummaryImpl::eTypeCallback && !want_script)
+ if (m_opaque_sp->GetKind() == lldb_private::TypeSummaryImpl::Kind::eCallback && !want_script)
new_sp = TypeSummaryImplSP(new StringSummaryFormat(GetOptions(), ""));
else
return CopyOnWrite_Impl();
Modified: lldb/trunk/source/DataFormatters/TypeSummary.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/TypeSummary.cpp?rev=250567&r1=250566&r2=250567&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/TypeSummary.cpp (original)
+++ lldb/trunk/source/DataFormatters/TypeSummary.cpp Fri Oct 16 17:51:56 2015
@@ -76,15 +76,17 @@ TypeSummaryOptions::SetCapping (lldb::Ty
return *this;
}
-TypeSummaryImpl::TypeSummaryImpl (const TypeSummaryImpl::Flags& flags) :
-m_flags(flags)
+TypeSummaryImpl::TypeSummaryImpl (Kind kind,
+ const TypeSummaryImpl::Flags& flags) :
+ m_flags(flags),
+ m_kind(kind)
{
}
StringSummaryFormat::StringSummaryFormat (const TypeSummaryImpl::Flags& flags,
const char *format_cstr) :
- TypeSummaryImpl(flags),
+ TypeSummaryImpl(Kind::eSummaryString,flags),
m_format_str()
{
SetSummaryString (format_cstr);
@@ -170,7 +172,7 @@ StringSummaryFormat::GetDescription ()
CXXFunctionSummaryFormat::CXXFunctionSummaryFormat (const TypeSummaryImpl::Flags& flags,
Callback impl,
const char* description) :
-TypeSummaryImpl(flags),
+ TypeSummaryImpl(Kind::eCallback,flags),
m_impl(impl),
m_description(description ? description : "")
{
@@ -208,10 +210,10 @@ CXXFunctionSummaryFormat::GetDescription
ScriptSummaryFormat::ScriptSummaryFormat (const TypeSummaryImpl::Flags& flags,
const char * function_name,
const char * python_script) :
-TypeSummaryImpl(flags),
-m_function_name(),
-m_python_script(),
-m_script_function_sp()
+ TypeSummaryImpl(Kind::eScript,flags),
+ m_function_name(),
+ m_python_script(),
+ m_script_function_sp()
{
if (function_name)
m_function_name.assign(function_name);
More information about the lldb-commits
mailing list