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 "referencetype.h" 0010 0011 #include "typeregister.h" 0012 #include "typesystem.h" 0013 #include "integraltype.h" 0014 #include "structuretype.h" 0015 0016 namespace KDevelop { 0017 REGISTER_TYPE(ReferenceType); 0018 0019 ReferenceType::ReferenceType(const ReferenceType& rhs) : AbstractType(copyData<ReferenceType>(*rhs.d_func())) 0020 { 0021 } 0022 0023 ReferenceType::ReferenceType(ReferenceTypeData& data) : AbstractType(data) 0024 { 0025 } 0026 0027 AbstractType* ReferenceType::clone() const 0028 { 0029 return new ReferenceType(*this); 0030 } 0031 0032 bool ReferenceType::equals(const AbstractType* _rhs) const 0033 { 0034 if (this == _rhs) 0035 return true; 0036 0037 if (!AbstractType::equals(_rhs)) 0038 return false; 0039 0040 Q_ASSERT(dynamic_cast<const ReferenceType*>(_rhs)); 0041 const auto* rhs = static_cast<const ReferenceType*>(_rhs); 0042 0043 return d_func()->m_baseType == rhs->d_func()->m_baseType; 0044 } 0045 0046 ReferenceType::ReferenceType() 0047 : AbstractType(createData<ReferenceType>()) 0048 { 0049 } 0050 0051 ReferenceType::~ReferenceType() 0052 { 0053 } 0054 0055 AbstractType::Ptr ReferenceType::baseType() const 0056 { 0057 return d_func()->m_baseType.abstractType(); 0058 } 0059 0060 void ReferenceType::setBaseType(const AbstractType::Ptr& type) 0061 { 0062 d_func_dynamic()->m_baseType = IndexedType(type); 0063 } 0064 0065 bool ReferenceType::isRValue() const 0066 { 0067 return d_func()->m_isRValue; 0068 } 0069 0070 void ReferenceType::setIsRValue(bool isRValue) 0071 { 0072 d_func_dynamic()->m_isRValue = isRValue; 0073 } 0074 0075 void ReferenceType::accept0(TypeVisitor* v) const 0076 { 0077 if (v->visit(this)) 0078 acceptType(d_func()->m_baseType.abstractType(), v); 0079 0080 v->endVisit(this); 0081 } 0082 0083 void ReferenceType::exchangeTypes(TypeExchanger* exchanger) 0084 { 0085 d_func_dynamic()->m_baseType = IndexedType(exchanger->exchange(d_func()->m_baseType.abstractType())); 0086 } 0087 0088 QString ReferenceType::toString() const 0089 { 0090 AbstractType::Ptr base = baseType(); 0091 QString baseString = (base ? base->toString() : QStringLiteral("<notype>")); 0092 const QLatin1String ampersands = d_func()->m_isRValue ? QLatin1String("&&") : QLatin1String("&"); 0093 if (base.dynamicCast<IntegralType>() || base.dynamicCast<StructureType>()) 0094 return AbstractType::toString(false) + baseString + ampersands; 0095 else 0096 return baseString + AbstractType::toString(true) + ampersands; 0097 } 0098 0099 AbstractType::WhichType ReferenceType::whichType() const 0100 { 0101 return TypeReference; 0102 } 0103 0104 uint ReferenceType::hash() const 0105 { 0106 return KDevHash(AbstractType::hash()) << d_func()->m_baseType.hash() << d_func()->m_isRValue; 0107 } 0108 }