Warning, file /kdevelop/kdev-python/duchain/types/indexedcontainer.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2011 Sven Brauch <svenbrauch@googlemail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "indexedcontainer.h" 0008 #include "types/unsuretype.h" 0009 #include "helpers.h" 0010 0011 #include <language/duchain/types/typeregister.h> 0012 #include <language/duchain/duchain.h> 0013 #include <language/duchain/duchainlock.h> 0014 0015 #include <KLocalizedString> 0016 0017 using namespace KDevelop; 0018 0019 namespace Python { 0020 0021 DEFINE_LIST_MEMBER_HASH(IndexedContainerData, m_values, IndexedType) 0022 REGISTER_TYPE(IndexedContainer); 0023 0024 IndexedContainer::IndexedContainer() : KDevelop::StructureType(createData<IndexedContainer>()) 0025 { 0026 0027 } 0028 0029 IndexedContainer::IndexedContainer(const IndexedContainer& rhs) 0030 : StructureType(copyData<IndexedContainer>(*rhs.d_func())) 0031 { 0032 0033 } 0034 0035 IndexedContainer::IndexedContainer(IndexedContainerData& data) 0036 : StructureType(data) 0037 { 0038 0039 } 0040 0041 void IndexedContainer::addEntry(AbstractType::Ptr typeToAdd) 0042 { 0043 Q_ASSERT(typeToAdd && "trying to add a null type to indexedContainer"); 0044 d_func_dynamic()->m_valuesList().append(typeToAdd->indexed()); 0045 } 0046 0047 const IndexedType& IndexedContainer::typeAt(int index) const 0048 { 0049 Q_ASSERT((uint) index < d_func()->m_valuesSize()); 0050 return d_func()->m_values()[index]; 0051 } 0052 0053 void IndexedContainer::replaceType(int index, AbstractType::Ptr newType) 0054 { 0055 Q_ASSERT((uint) index < d_func()->m_valuesSize()); 0056 d_func_dynamic()->m_valuesList()[index] = newType->indexed(); 0057 } 0058 0059 KDevelop::AbstractType* IndexedContainer::clone() const 0060 { 0061 IndexedContainer* n = new IndexedContainer(*this); 0062 return n; 0063 } 0064 0065 QString IndexedContainer::toString() const 0066 { 0067 QString prefix = KDevelop::StructureType::toString(); 0068 QStringList typesArray; 0069 for ( int i = 0; i < typesCount(); i++ ) { 0070 if ( i >= 5 ) { 0071 // Don't print more than five types explicitly 0072 typesArray << "..."; 0073 break; 0074 } 0075 typesArray << typeAt(i).abstractType()->toString(); 0076 } 0077 const QString contentType = QStringLiteral("(") + typesArray.join(", ") + ")"; 0078 return i18nc("as in list of int, set of string", "%1 of %2", prefix, contentType); 0079 } 0080 0081 AbstractType::Ptr IndexedContainer::asUnsureType() const 0082 { 0083 AbstractType::Ptr unsure = AbstractType::Ptr(new UnsureType); 0084 for ( int i = 0; i < typesCount(); i++ ) { 0085 unsure = Helper::mergeTypes(unsure, typeAt(i).abstractType()); 0086 } 0087 return unsure; 0088 } 0089 0090 QString IndexedContainer::containerToString() const 0091 { 0092 return KDevelop::StructureType::toString(); 0093 } 0094 0095 int IndexedContainer::typesCount() const 0096 { 0097 return d_func()->m_valuesSize(); 0098 } 0099 0100 bool IndexedContainer::equals(const AbstractType* rhs) const 0101 { 0102 if ( this == rhs ) { 0103 return true; 0104 } 0105 if ( ! KDevelop::StructureType::equals(rhs) ) { 0106 return false; 0107 } 0108 const IndexedContainer* c = dynamic_cast<const IndexedContainer*>(rhs); 0109 if ( ! c ) { 0110 return false; 0111 } 0112 if ( typesCount() != c->typesCount() ) { 0113 return false; 0114 } 0115 for ( int i = 0; i < typesCount(); i++ ) { 0116 if ( c->typeAt(i) != typeAt(i) ) { 0117 return false; 0118 } 0119 } 0120 return true; 0121 } 0122 0123 uint IndexedContainer::hash() const 0124 { 0125 uint h = StructureType::hash(); 0126 for ( uint i = 0; i < d_func()->m_valuesSize(); i++ ) { 0127 h += i*d_func()->m_values()[i]; 0128 } 0129 return h; 0130 } 0131 0132 }