1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
SPDX-FileCopyrightText: 2011 Sven Brauch <svenbrauch@googlemail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "hintedtype.h"
#include "helpers.h"
#include <language/duchain/types/typeregister.h>
#include <language/duchain/types/typesystem.h>
#include <language/duchain/types/typealiastype.h>
#include <language/duchain/duchain.h>
#include <language/duchain/duchainlock.h>
#include <language/duchain/parsingenvironment.h>
#include <QDebug>
#include <duchaindebug.h>
#include <KLocalizedString>
using namespace KDevelop;
namespace Python {
REGISTER_TYPE(HintedType);
HintedType::HintedType() : KDevelop::TypeAliasType(createData<HintedType>())
{
}
HintedType::HintedType(const HintedType& rhs)
: TypeAliasType(copyData<HintedType>(*rhs.d_func()))
{
}
HintedType::HintedType(TypeAliasTypeData& data): TypeAliasType(data)
{
}
bool HintedType::isValid()
{
TopDUContext* creator = d_func()->m_createdByContext.data();
if ( ! creator ) {
return false;
}
ModificationRevision rev(creator->parsingEnvironmentFile()->modificationRevision());
if ( d_func()->m_modificationRevision < rev ) {
qCDebug(KDEV_PYTHON_DUCHAIN) << "modification revision mismatch, invalidating";
return false;
}
return true;
}
void HintedType::setCreatedBy(TopDUContext* context, const ModificationRevision& revision)
{
d_func_dynamic()->m_createdByContext = context->indexed();
d_func_dynamic()->m_modificationRevision = revision;
}
IndexedTopDUContext HintedType::createdBy() const
{
return d_func()->m_createdByContext;
}
KDevelop::AbstractType* HintedType::clone() const
{
HintedType* n = new HintedType(*this);
return n;
}
bool HintedType::equals(const AbstractType* rhs) const
{
if ( this == rhs ) {
return true;
}
if ( ! KDevelop::AbstractType::equals(rhs) ) {
return false;
}
const HintedType* c = dynamic_cast<const HintedType*>(rhs);
if ( ! c ) {
return false;
}
if ( c->type()->indexed() != d_func()->m_type ) {
return false;
}
if ( c->d_func()->m_modificationRevision != d_func()->m_modificationRevision ) {
return false;
}
if ( c->d_func()->m_createdByContext != d_func()->m_createdByContext ) {
return false;
}
return true;
}
uint HintedType::hash() const
{
return AbstractType::hash() + 1 + ( type() ? type()->hash() : 0 ) + d_func()->m_createdByContext.index()
+ d_func()->m_modificationRevision.modificationTime % 17 + (d_func()->m_modificationRevision.revision * 19) % 13;
}
}
|