labath created this revision. labath added reviewers: clayborg, jingham, zturner. Herald added subscribers: jdoerfert, dexonsmith, mehdi_amini.
After D59297 <https://reviews.llvm.org/D59297>, the TypePair class kind of lost its purpose as it was no longer a "pair". This finished the job started in that patch and deletes the class altogether. All usages have been updated to use CompilerType class directly. https://reviews.llvm.org/D59414 Files: include/lldb/DataFormatters/FormatClasses.h include/lldb/Symbol/Type.h include/lldb/lldb-forward.h source/Symbol/Type.cpp
Index: source/Symbol/Type.cpp =================================================================== --- source/Symbol/Type.cpp +++ source/Symbol/Type.cpp @@ -690,32 +690,21 @@ return ModuleSP(); } -TypeAndOrName::TypeAndOrName() : m_type_pair(), m_type_name() {} - -TypeAndOrName::TypeAndOrName(TypeSP &in_type_sp) : m_type_pair(in_type_sp) { - if (in_type_sp) +TypeAndOrName::TypeAndOrName(TypeSP &in_type_sp) { + if (in_type_sp) { + m_compiler_type = in_type_sp->GetForwardCompilerType(); m_type_name = in_type_sp->GetName(); + } } TypeAndOrName::TypeAndOrName(const char *in_type_str) : m_type_name(in_type_str) {} -TypeAndOrName::TypeAndOrName(const TypeAndOrName &rhs) - : m_type_pair(rhs.m_type_pair), m_type_name(rhs.m_type_name) {} - TypeAndOrName::TypeAndOrName(ConstString &in_type_const_string) : m_type_name(in_type_const_string) {} -TypeAndOrName &TypeAndOrName::operator=(const TypeAndOrName &rhs) { - if (this != &rhs) { - m_type_name = rhs.m_type_name; - m_type_pair = rhs.m_type_pair; - } - return *this; -} - bool TypeAndOrName::operator==(const TypeAndOrName &other) const { - if (m_type_pair != other.m_type_pair) + if (m_compiler_type != other.m_compiler_type) return false; if (m_type_name != other.m_type_name) return false; @@ -729,8 +718,8 @@ ConstString TypeAndOrName::GetName() const { if (m_type_name) return m_type_name; - if (m_type_pair) - return m_type_pair.GetName(); + if (m_compiler_type) + return m_compiler_type.GetTypeName(); return ConstString("<invalid>"); } @@ -743,30 +732,32 @@ } void TypeAndOrName::SetTypeSP(lldb::TypeSP type_sp) { - m_type_pair.SetType(type_sp); - if (m_type_pair) - m_type_name = m_type_pair.GetName(); + if (type_sp) { + m_compiler_type = type_sp->GetForwardCompilerType(); + m_type_name = type_sp->GetName(); + } else + Clear(); } void TypeAndOrName::SetCompilerType(CompilerType compiler_type) { - m_type_pair.SetType(compiler_type); - if (m_type_pair) - m_type_name = m_type_pair.GetName(); + m_compiler_type = compiler_type; + if (m_compiler_type) + m_type_name = m_compiler_type.GetTypeName(); } bool TypeAndOrName::IsEmpty() const { - return !((bool)m_type_name || (bool)m_type_pair); + return !((bool)m_type_name || (bool)m_compiler_type); } void TypeAndOrName::Clear() { m_type_name.Clear(); - m_type_pair.Clear(); + m_compiler_type.Clear(); } bool TypeAndOrName::HasName() const { return (bool)m_type_name; } bool TypeAndOrName::HasCompilerType() const { - return m_type_pair.GetCompilerType().IsValid(); + return m_compiler_type.IsValid(); } TypeImpl::TypeImpl() : m_module_wp(), m_static_type(), m_dynamic_type() {} @@ -786,7 +777,7 @@ } TypeImpl::TypeImpl(const lldb::TypeSP &type_sp, const CompilerType &dynamic) - : m_module_wp(), m_static_type(type_sp), m_dynamic_type(dynamic) { + : m_module_wp(), m_static_type(), m_dynamic_type(dynamic) { SetType(type_sp, dynamic); } @@ -796,22 +787,19 @@ SetType(static_type, dynamic_type); } -TypeImpl::TypeImpl(const TypePair &pair, const CompilerType &dynamic) - : m_module_wp(), m_static_type(), m_dynamic_type() { - SetType(pair, dynamic); -} - void TypeImpl::SetType(const lldb::TypeSP &type_sp) { - m_static_type.SetType(type_sp); - if (type_sp) + if (type_sp) { + m_static_type = type_sp->GetForwardCompilerType(); m_module_wp = type_sp->GetModule(); - else + } else { + m_static_type.Clear(); m_module_wp = lldb::ModuleWP(); + } } void TypeImpl::SetType(const CompilerType &compiler_type) { m_module_wp = lldb::ModuleWP(); - m_static_type.SetType(compiler_type); + m_static_type = compiler_type; } void TypeImpl::SetType(const lldb::TypeSP &type_sp, @@ -823,13 +811,7 @@ void TypeImpl::SetType(const CompilerType &compiler_type, const CompilerType &dynamic) { m_module_wp = lldb::ModuleWP(); - m_static_type.SetType(compiler_type); - m_dynamic_type = dynamic; -} - -void TypeImpl::SetType(const TypePair &pair, const CompilerType &dynamic) { - m_module_wp.reset(); - m_static_type = pair; + m_static_type = compiler_type; m_dynamic_type = dynamic; } @@ -900,7 +882,7 @@ if (CheckModule(module_sp)) { if (m_dynamic_type) return m_dynamic_type.GetTypeName(); - return m_static_type.GetName(); + return m_static_type.GetTypeName(); } return ConstString(); } @@ -943,10 +925,10 @@ ModuleSP module_sp; if (CheckModule(module_sp)) { if (m_dynamic_type.IsValid()) { - return TypeImpl(m_static_type.GetReferenceType(), + return TypeImpl(m_static_type.GetLValueReferenceType(), m_dynamic_type.GetLValueReferenceType()); } - return TypeImpl(m_static_type.GetReferenceType()); + return TypeImpl(m_static_type.GetLValueReferenceType()); } return TypeImpl(); } @@ -967,10 +949,10 @@ ModuleSP module_sp; if (CheckModule(module_sp)) { if (m_dynamic_type.IsValid()) { - return TypeImpl(m_static_type.GetDereferencedType(), + return TypeImpl(m_static_type.GetNonReferenceType(), m_dynamic_type.GetNonReferenceType()); } - return TypeImpl(m_static_type.GetDereferencedType()); + return TypeImpl(m_static_type.GetNonReferenceType()); } return TypeImpl(); } @@ -979,10 +961,10 @@ ModuleSP module_sp; if (CheckModule(module_sp)) { if (m_dynamic_type.IsValid()) { - return TypeImpl(m_static_type.GetUnqualifiedType(), + return TypeImpl(m_static_type.GetFullyUnqualifiedType(), m_dynamic_type.GetFullyUnqualifiedType()); } - return TypeImpl(m_static_type.GetUnqualifiedType()); + return TypeImpl(m_static_type.GetFullyUnqualifiedType()); } return TypeImpl(); } @@ -1006,7 +988,7 @@ if (m_dynamic_type.IsValid()) return m_dynamic_type; } - return m_static_type.GetCompilerType(); + return m_static_type; } return CompilerType(); } @@ -1018,7 +1000,7 @@ if (m_dynamic_type.IsValid()) return m_dynamic_type.GetTypeSystem(); } - return m_static_type.GetCompilerType().GetTypeSystem(); + return m_static_type.GetTypeSystem(); } return NULL; } @@ -1032,7 +1014,7 @@ m_dynamic_type.DumpTypeDescription(&strm); strm.Printf("\nStatic:\n"); } - m_static_type.GetCompilerType().DumpTypeDescription(&strm); + m_static_type.DumpTypeDescription(&strm); } else { strm.PutCString("Invalid TypeImpl module for type has been deleted\n"); } Index: include/lldb/lldb-forward.h =================================================================== --- include/lldb/lldb-forward.h +++ include/lldb/lldb-forward.h @@ -273,7 +273,6 @@ class TypeEnumMemberListImpl; class TypeFormatImpl; class TypeNameSpecifierImpl; -class TypePair; class TypeValidatorImpl; class UUID; class UnixSignals; Index: include/lldb/Symbol/Type.h =================================================================== --- include/lldb/Symbol/Type.h +++ include/lldb/Symbol/Type.h @@ -237,81 +237,6 @@ bool ResolveClangType(ResolveState compiler_type_resolve_state); }; -// 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() {} - - TypePair(CompilerType type) : compiler_type(type) {} - - TypePair(lldb::TypeSP type) : compiler_type(type->GetForwardCompilerType()) {} - - bool IsValid() const { return compiler_type.IsValid(); } - - explicit operator bool() const { return IsValid(); } - - bool operator==(const TypePair &rhs) const { - return compiler_type == rhs.compiler_type; - } - - bool operator!=(const TypePair &rhs) const { return !(*this == rhs); } - - void Clear() { compiler_type.Clear(); } - - ConstString GetName() const { - if (compiler_type) - return compiler_type.GetTypeName(); - return ConstString(); - } - - ConstString GetDisplayTypeName() const { - if (compiler_type) - return compiler_type.GetDisplayTypeName(); - return ConstString(); - } - - void SetType(CompilerType type) { - compiler_type = type; - } - - void SetType(lldb::TypeSP type) { - compiler_type = type->GetForwardCompilerType(); - } - - CompilerType GetCompilerType() const { return compiler_type; } - - CompilerType GetPointerType() const { return compiler_type.GetPointerType(); } - - CompilerType GetPointeeType() const { return compiler_type.GetPointeeType(); } - - CompilerType GetReferenceType() const { - return compiler_type.GetLValueReferenceType(); - } - - CompilerType GetTypedefedType() const { - return compiler_type.GetTypedefedType(); - } - - CompilerType GetDereferencedType() const { - return compiler_type.GetNonReferenceType(); - } - - CompilerType GetUnqualifiedType() const { - return compiler_type.GetFullyUnqualifiedType(); - } - - CompilerType GetCanonicalType() const { - return compiler_type.GetCanonicalType(); - } - - TypeSystem *GetTypeSystem() const { return compiler_type.GetTypeSystem(); } - -protected: - CompilerType compiler_type; -}; - // the two classes here are used by the public API as a backend to the SBType // and SBTypeList classes @@ -331,8 +256,6 @@ TypeImpl(const CompilerType &compiler_type, const CompilerType &dynamic); - TypeImpl(const TypePair &pair, const CompilerType &dynamic); - void SetType(const lldb::TypeSP &type_sp); void SetType(const CompilerType &compiler_type); @@ -341,8 +264,6 @@ void SetType(const CompilerType &compiler_type, const CompilerType &dynamic); - void SetType(const TypePair &pair, const CompilerType &dynamic); - TypeImpl &operator=(const TypeImpl &rhs); bool operator==(const TypeImpl &rhs) const; @@ -384,7 +305,7 @@ bool CheckModule(lldb::ModuleSP &module_sp) const; lldb::ModuleWP m_module_wp; - TypePair m_static_type; + CompilerType m_static_type; CompilerType m_dynamic_type; }; @@ -476,22 +397,19 @@ class TypeAndOrName { public: - TypeAndOrName(); + TypeAndOrName() = default; TypeAndOrName(lldb::TypeSP &type_sp); TypeAndOrName(const CompilerType &compiler_type); TypeAndOrName(const char *type_str); - TypeAndOrName(const TypeAndOrName &rhs); TypeAndOrName(ConstString &type_const_string); - TypeAndOrName &operator=(const TypeAndOrName &rhs); - bool operator==(const TypeAndOrName &other) const; bool operator!=(const TypeAndOrName &other) const; ConstString GetName() const; - CompilerType GetCompilerType() const { return m_type_pair.GetCompilerType(); } + CompilerType GetCompilerType() const { return m_compiler_type; } void SetName(ConstString type_name); @@ -514,7 +432,7 @@ explicit operator bool() { return !IsEmpty(); } private: - TypePair m_type_pair; + CompilerType m_compiler_type; ConstString m_type_name; }; Index: include/lldb/DataFormatters/FormatClasses.h =================================================================== --- include/lldb/DataFormatters/FormatClasses.h +++ include/lldb/DataFormatters/FormatClasses.h @@ -122,14 +122,14 @@ TypeNameSpecifierImpl(lldb::TypeSP type) : m_is_regex(false), m_type() { if (type) { m_type.m_type_name = type->GetName().GetStringRef(); - m_type.m_type_pair.SetType(type); + m_type.m_compiler_type = type->GetForwardCompilerType(); } } TypeNameSpecifierImpl(CompilerType type) : m_is_regex(false), m_type() { if (type.IsValid()) { m_type.m_type_name.assign(type.GetConstTypeName().GetCString()); - m_type.m_type_pair.SetType(type); + m_type.m_compiler_type = type; } } @@ -140,8 +140,8 @@ } CompilerType GetCompilerType() { - if (m_type.m_type_pair.IsValid()) - return m_type.m_type_pair.GetCompilerType(); + if (m_type.m_compiler_type.IsValid()) + return m_type.m_compiler_type; return CompilerType(); } @@ -149,11 +149,10 @@ private: bool m_is_regex; - // this works better than TypeAndOrName because the latter only wraps a - // TypeSP whereas TypePair can also be backed by a CompilerType + // TODO: Replace this with TypeAndOrName. struct TypeOrName { std::string m_type_name; - TypePair m_type_pair; + CompilerType m_compiler_type; }; TypeOrName m_type;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits