File indexing completed on 2024-06-16 04:23:17

0001 /*
0002     SPDX-FileCopyrightText: 2006 Roberto Raggi <roberto@kdevelop.org>
0003     SPDX-FileCopyrightText: 2006-2008 Hamish Rodda <rodda@kde.org>
0004     SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #include "pointertype.h"
0010 
0011 #include "typeregister.h"
0012 #include "typesystem.h"
0013 
0014 namespace KDevelop {
0015 REGISTER_TYPE(PointerType);
0016 
0017 PointerType::PointerType(const PointerType& rhs) : AbstractType(copyData<PointerType>(*rhs.d_func()))
0018 {
0019 }
0020 
0021 PointerType::PointerType(PointerTypeData& data) : AbstractType(data)
0022 {
0023 }
0024 
0025 AbstractType* PointerType::clone() const
0026 {
0027     return new PointerType(*this);
0028 }
0029 
0030 bool PointerType::equals(const AbstractType* _rhs) const
0031 {
0032     if (this == _rhs)
0033         return true;
0034 
0035     if (!AbstractType::equals(_rhs))
0036         return false;
0037 
0038     Q_ASSERT(dynamic_cast<const PointerType*>(_rhs));
0039     const auto* rhs = static_cast<const PointerType*>(_rhs);
0040 
0041     return d_func()->m_baseType == rhs->d_func()->m_baseType;
0042 }
0043 
0044 PointerType::PointerType()
0045     : AbstractType(createData<PointerType>())
0046 {
0047 }
0048 
0049 void PointerType::accept0(TypeVisitor* v) const
0050 {
0051     if (v->visit(this))
0052         acceptType(d_func()->m_baseType.abstractType(), v);
0053 
0054     v->endVisit(this);
0055 }
0056 
0057 void PointerType::exchangeTypes(TypeExchanger* exchanger)
0058 {
0059     d_func_dynamic()->m_baseType = IndexedType(exchanger->exchange(d_func()->m_baseType.abstractType()));
0060 }
0061 
0062 PointerType::~PointerType()
0063 {
0064 }
0065 
0066 AbstractType::Ptr PointerType::baseType() const
0067 {
0068     return d_func()->m_baseType.abstractType();
0069 }
0070 
0071 void PointerType::setBaseType(const AbstractType::Ptr& type)
0072 {
0073     d_func_dynamic()->m_baseType = IndexedType(type);
0074 }
0075 
0076 QString PointerType::toString() const
0077 {
0078     QString baseString = (baseType() ? baseType()->toString() : QStringLiteral("<notype>"));
0079     return baseString + QLatin1Char('*') + AbstractType::toString(true);
0080 }
0081 
0082 AbstractType::WhichType PointerType::whichType() const
0083 {
0084     return TypePointer;
0085 }
0086 
0087 uint PointerType::hash() const
0088 {
0089     return KDevHash(AbstractType::hash()) << d_func()->m_baseType.hash();
0090 }
0091 }