Warning, file /kdevelop/kdev-python/duchain/types/hintedtype.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 "hintedtype.h"
0008 #include "helpers.h"
0009 
0010 #include <language/duchain/types/typeregister.h>
0011 #include <language/duchain/types/typesystem.h>
0012 #include <language/duchain/types/typealiastype.h>
0013 #include <language/duchain/duchain.h>
0014 #include <language/duchain/duchainlock.h>
0015 #include <language/duchain/parsingenvironment.h>
0016 
0017 #include <QDebug>
0018 #include <duchaindebug.h>
0019 
0020 #include <KLocalizedString>
0021 
0022 using namespace KDevelop;
0023 
0024 namespace Python {
0025 
0026 REGISTER_TYPE(HintedType);
0027 
0028 HintedType::HintedType() : KDevelop::TypeAliasType(createData<HintedType>())
0029 {
0030 
0031 }
0032 
0033 HintedType::HintedType(const HintedType& rhs)
0034     : TypeAliasType(copyData<HintedType>(*rhs.d_func()))
0035 {
0036 
0037 }
0038 
0039 HintedType::HintedType(TypeAliasTypeData& data): TypeAliasType(data)
0040 {
0041 
0042 }
0043 
0044 bool HintedType::isValid()
0045 {
0046     TopDUContext* creator = d_func()->m_createdByContext.data();
0047     if ( ! creator ) {
0048         return false;
0049     }
0050     ModificationRevision rev(creator->parsingEnvironmentFile()->modificationRevision());
0051     if ( d_func()->m_modificationRevision < rev ) {
0052         qCDebug(KDEV_PYTHON_DUCHAIN) << "modification revision mismatch, invalidating";
0053         return false;
0054     }
0055     return true;
0056 }
0057 
0058 void HintedType::setCreatedBy(TopDUContext* context, const ModificationRevision& revision)
0059 {
0060     d_func_dynamic()->m_createdByContext = context->indexed();
0061     d_func_dynamic()->m_modificationRevision = revision;
0062 }
0063 
0064 IndexedTopDUContext HintedType::createdBy() const
0065 {
0066     return d_func()->m_createdByContext;
0067 }
0068 
0069 
0070 KDevelop::AbstractType* HintedType::clone() const
0071 {
0072     HintedType* n = new HintedType(*this);
0073     return n;
0074 }
0075 
0076 bool HintedType::equals(const AbstractType* rhs) const
0077 {
0078     if ( this == rhs ) {
0079         return true;
0080     }
0081     if ( ! KDevelop::AbstractType::equals(rhs) ) {
0082         return false;
0083     }
0084     const HintedType* c = dynamic_cast<const HintedType*>(rhs);
0085     if ( ! c ) {
0086         return false;
0087     }
0088     if ( c->type()->indexed() != d_func()->m_type ) {
0089         return false;
0090     }
0091     if ( c->d_func()->m_modificationRevision != d_func()->m_modificationRevision ) {
0092         return false;
0093     }
0094     if ( c->d_func()->m_createdByContext != d_func()->m_createdByContext ) {
0095         return false;
0096     }
0097     return true;
0098 }
0099 
0100 uint HintedType::hash() const
0101 {
0102     return AbstractType::hash() + 1 + ( type() ? type()->hash() : 0 ) + d_func()->m_createdByContext.index()
0103                                 + d_func()->m_modificationRevision.modificationTime % 17 + (d_func()->m_modificationRevision.revision * 19) % 13;
0104 }
0105 
0106 }