File indexing completed on 2024-06-16 04:23:17
0001 /* 0002 SPDX-FileCopyrightText: 2009 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "unsuretype.h" 0008 #include "typeregister.h" 0009 #include "typesystem.h" 0010 0011 namespace KDevelop { 0012 REGISTER_TYPE(UnsureType); 0013 DEFINE_LIST_MEMBER_HASH(UnsureTypeData, m_types, IndexedType) 0014 0015 UnsureType::UnsureType(const KDevelop::UnsureType& rhs) : AbstractType(copyData<UnsureType>(*rhs.d_func())) 0016 { 0017 } 0018 0019 UnsureType::UnsureType() : AbstractType(createData<UnsureType>()) 0020 { 0021 } 0022 0023 void UnsureType::accept0(KDevelop::TypeVisitor* v) const 0024 { 0025 FOREACH_FUNCTION(const IndexedType &type, d_func()->m_types) { 0026 AbstractType::Ptr t = type.abstractType(); 0027 v->visit(t.data()); 0028 } 0029 } 0030 0031 KDevelop::AbstractType* UnsureType::clone() const 0032 { 0033 return new UnsureType(*this); 0034 } 0035 0036 QString UnsureType::toString() const 0037 { 0038 QStringList typeNames; 0039 typeNames.reserve(d_func()->m_typesSize()); 0040 FOREACH_FUNCTION(const IndexedType &type, d_func()->m_types) { 0041 AbstractType::Ptr t = type.abstractType(); 0042 if (t) 0043 typeNames.append(t->toString()); 0044 else 0045 typeNames.append(QStringLiteral("none")); 0046 } 0047 QString ret = QLatin1String("unsure (") + typeNames.join(QLatin1String(", ")) + QLatin1Char(')'); 0048 0049 return ret; 0050 } 0051 0052 bool UnsureType::equals(const KDevelop::AbstractType* rhs) const 0053 { 0054 const auto* rhsU = dynamic_cast<const UnsureType*>(rhs); 0055 if (!rhsU) 0056 return false; 0057 if (d_func()->typeClassId != rhsU->d_func()->typeClassId) 0058 return false; 0059 if (d_func()->m_typesSize() != rhsU->d_func()->m_typesSize()) 0060 return false; 0061 0062 for (uint a = 0; a < d_func()->m_typesSize(); ++a) 0063 if (d_func()->m_types()[a] != rhsU->d_func()->m_types()[a]) 0064 return false; 0065 0066 return KDevelop::AbstractType::equals(rhs); 0067 } 0068 0069 bool UnsureType::contains(const KDevelop::AbstractType* type) const 0070 { 0071 const IndexedType indexed(type); 0072 0073 FOREACH_FUNCTION(const IndexedType& t, d_func()->m_types) { 0074 if (indexed == t) { 0075 return true; 0076 } 0077 } 0078 0079 return false; 0080 } 0081 0082 uint UnsureType::hash() const 0083 { 0084 KDevHash kdevhash(AbstractType::hash()); 0085 FOREACH_FUNCTION(const IndexedType &type, d_func()->m_types) 0086 kdevhash << type.hash(); 0087 return kdevhash << d_func()->m_typesSize(); 0088 } 0089 0090 KDevelop::AbstractType::WhichType UnsureType::whichType() const 0091 { 0092 return TypeUnsure; 0093 } 0094 0095 void UnsureType::exchangeTypes(KDevelop::TypeExchanger* exchanger) 0096 { 0097 for (uint a = 0; a < d_func()->m_typesSize(); ++a) { 0098 AbstractType::Ptr from = d_func()->m_types()[a].abstractType(); 0099 AbstractType::Ptr exchanged = exchanger->exchange(from); 0100 if (exchanged != from) 0101 d_func_dynamic()->m_typesList()[a] = exchanged->indexed(); 0102 } 0103 0104 KDevelop::AbstractType::exchangeTypes(exchanger); 0105 } 0106 0107 void UnsureType::addType(const KDevelop::IndexedType& type) 0108 { 0109 if (!d_func_dynamic()->m_typesList().contains(type)) { 0110 d_func_dynamic()->m_typesList().append(type); 0111 } 0112 } 0113 0114 void UnsureType::removeType(const KDevelop::IndexedType& type) 0115 { 0116 d_func_dynamic()->m_typesList().removeOne(type); 0117 } 0118 0119 const KDevelop::IndexedType* UnsureType::types() const 0120 { 0121 return d_func()->m_types(); 0122 } 0123 0124 uint UnsureType::typesSize() const 0125 { 0126 return d_func()->m_typesSize(); 0127 } 0128 0129 UnsureType::UnsureType(KDevelop::UnsureTypeData& data) : AbstractType(data) 0130 { 0131 } 0132 }