Skip to content

Commit

Permalink
Delete type_sp member from TypePair
Browse files Browse the repository at this point in the history
Summary:
As discussed in the review of D59217, this member is unnecessary since
always the first thing we do is convert it to a CompilerType.

This opens up possibilities for further cleanups (e.g. the whole
TypePair class now loses purpose, since we can just pass around
CompilerType everywhere), but I did not want to do that yet, because I
am not sure if this will not introduce breakages in some of the
platforms/configurations that I am not testing on.

Reviewers: clayborg, zturner, jingham

Subscribers: jdoerfert, lldb-commits

Differential Revision: https://reviews.llvm.org/D59297

llvm-svn: 356262
  • Loading branch information
labath committed Mar 15, 2019
1 parent 373bee8 commit a933d6c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 79 deletions.
6 changes: 0 additions & 6 deletions lldb/include/lldb/DataFormatters/FormatClasses.h
Expand Up @@ -139,12 +139,6 @@ class TypeNameSpecifierImpl {
return nullptr;
}

lldb::TypeSP GetTypeSP() {
if (m_type.m_type_pair.IsValid())
return m_type.m_type_pair.GetTypeSP();
return lldb::TypeSP();
}

CompilerType GetCompilerType() {
if (m_type.m_type_pair.IsValid())
return m_type.m_type_pair.GetCompilerType();
Expand Down
78 changes: 14 additions & 64 deletions lldb/include/lldb/Symbol/Type.h
Expand Up @@ -239,19 +239,16 @@ class Type : public std::enable_shared_from_this<Type>, public UserID {

// these classes are used to back the SBType* objects

// TODO: This class is just a wrapper around CompilerType. Delete it.
class TypePair {
public:
TypePair() : compiler_type(), type_sp() {}
TypePair() : compiler_type() {}

TypePair(CompilerType type) : compiler_type(type), type_sp() {}
TypePair(CompilerType type) : compiler_type(type) {}

TypePair(lldb::TypeSP type) : compiler_type(), type_sp(type) {
compiler_type = type_sp->GetForwardCompilerType();
}
TypePair(lldb::TypeSP type) : compiler_type(type->GetForwardCompilerType()) {}

bool IsValid() const {
return compiler_type.IsValid() || (type_sp.get() != nullptr);
}
bool IsValid() const { return compiler_type.IsValid(); }

explicit operator bool() const { return IsValid(); }

Expand All @@ -261,101 +258,58 @@ class TypePair {

bool operator!=(const TypePair &rhs) const { return !(*this == rhs); }

void Clear() {
compiler_type.Clear();
type_sp.reset();
}
void Clear() { compiler_type.Clear(); }

ConstString GetName() const {
if (type_sp)
return type_sp->GetName();
if (compiler_type)
return compiler_type.GetTypeName();
return ConstString();
}

ConstString GetDisplayTypeName() const {
if (type_sp)
return type_sp->GetForwardCompilerType().GetDisplayTypeName();
if (compiler_type)
return compiler_type.GetDisplayTypeName();
return ConstString();
}

void SetType(CompilerType type) {
type_sp.reset();
compiler_type = type;
}

void SetType(lldb::TypeSP type) {
type_sp = type;
if (type_sp)
compiler_type = type_sp->GetForwardCompilerType();
else
compiler_type.Clear();
compiler_type = type->GetForwardCompilerType();
}

lldb::TypeSP GetTypeSP() const { return type_sp; }

CompilerType GetCompilerType() const { return compiler_type; }

CompilerType GetPointerType() const {
if (type_sp)
return type_sp->GetForwardCompilerType().GetPointerType();
return compiler_type.GetPointerType();
}
CompilerType GetPointerType() const { return compiler_type.GetPointerType(); }

CompilerType GetPointeeType() const {
if (type_sp)
return type_sp->GetForwardCompilerType().GetPointeeType();
return compiler_type.GetPointeeType();
}
CompilerType GetPointeeType() const { return compiler_type.GetPointeeType(); }

CompilerType GetReferenceType() const {
if (type_sp)
return type_sp->GetForwardCompilerType().GetLValueReferenceType();
else
return compiler_type.GetLValueReferenceType();
return compiler_type.GetLValueReferenceType();
}

CompilerType GetTypedefedType() const {
if (type_sp)
return type_sp->GetForwardCompilerType().GetTypedefedType();
else
return compiler_type.GetTypedefedType();
return compiler_type.GetTypedefedType();
}

CompilerType GetDereferencedType() const {
if (type_sp)
return type_sp->GetForwardCompilerType().GetNonReferenceType();
else
return compiler_type.GetNonReferenceType();
return compiler_type.GetNonReferenceType();
}

CompilerType GetUnqualifiedType() const {
if (type_sp)
return type_sp->GetForwardCompilerType().GetFullyUnqualifiedType();
else
return compiler_type.GetFullyUnqualifiedType();
return compiler_type.GetFullyUnqualifiedType();
}

CompilerType GetCanonicalType() const {
if (type_sp)
return type_sp->GetForwardCompilerType().GetCanonicalType();
return compiler_type.GetCanonicalType();
}

TypeSystem *GetTypeSystem() const { return compiler_type.GetTypeSystem(); }

lldb::ModuleSP GetModule() const {
if (type_sp)
return type_sp->GetModule();
return lldb::ModuleSP();
}

protected:
CompilerType compiler_type;
lldb::TypeSP type_sp;
};

// the two classes here are used by the public API as a backend to the SBType
Expand Down Expand Up @@ -537,8 +491,6 @@ class TypeAndOrName {

ConstString GetName() const;

lldb::TypeSP GetTypeSP() const { return m_type_pair.GetTypeSP(); }

CompilerType GetCompilerType() const { return m_type_pair.GetCompilerType(); }

void SetName(ConstString type_name);
Expand All @@ -553,11 +505,9 @@ class TypeAndOrName {

bool HasName() const;

bool HasTypeSP() const;

bool HasCompilerType() const;

bool HasType() const { return HasTypeSP() || HasCompilerType(); }
bool HasType() const { return HasCompilerType(); }

void Clear();

Expand Down
Expand Up @@ -235,16 +235,15 @@ bool ItaniumABILanguageRuntime::GetDynamicTypeAndAddress(
if (!class_type_or_name)
return false;

TypeSP type_sp = class_type_or_name.GetTypeSP();
CompilerType type = class_type_or_name.GetCompilerType();
// There can only be one type with a given name, so we've just found
// duplicate definitions, and this one will do as well as any other. We
// don't consider something to have a dynamic type if it is the same as
// the static type. So compare against the value we were handed.
if (!type_sp)
if (!type)
return true;

if (ClangASTContext::AreTypesSame(in_value.GetCompilerType(),
type_sp->GetForwardCompilerType())) {
if (ClangASTContext::AreTypesSame(in_value.GetCompilerType(), type)) {
// The dynamic type we found was the same type, so we don't have a
// dynamic type here...
return false;
Expand Down
6 changes: 1 addition & 5 deletions lldb/source/Symbol/Type.cpp
Expand Up @@ -765,10 +765,6 @@ void TypeAndOrName::Clear() {

bool TypeAndOrName::HasName() const { return (bool)m_type_name; }

bool TypeAndOrName::HasTypeSP() const {
return m_type_pair.GetTypeSP().get() != nullptr;
}

bool TypeAndOrName::HasCompilerType() const {
return m_type_pair.GetCompilerType().IsValid();
}
Expand Down Expand Up @@ -832,7 +828,7 @@ void TypeImpl::SetType(const CompilerType &compiler_type,
}

void TypeImpl::SetType(const TypePair &pair, const CompilerType &dynamic) {
m_module_wp = pair.GetModule();
m_module_wp.reset();
m_static_type = pair;
m_dynamic_type = dynamic;
}
Expand Down

0 comments on commit a933d6c

Please sign in to comment.