File indexing completed on 2024-06-16 04:23:17
0001 /* 0002 SPDX-FileCopyrightText: 2006 Roberto Raggi <roberto@kdevelop.org> 0003 SPDX-FileCopyrightText: 2006 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 "typesystem.h" 0010 #include "typeregister.h" 0011 #include "integraltype.h" 0012 #include "structuretype.h" 0013 0014 namespace KDevelop { 0015 AbstractTypeData::AbstractTypeData() 0016 : m_alignOfExponent(AbstractTypeData::MaxAlignOfExponent) 0017 , inRepository(false) 0018 { 0019 initializeAppendedLists(true); 0020 } 0021 0022 uint AbstractTypeData::classSize() const 0023 { 0024 return TypeSystem::self().dataClassSize(*this); 0025 } 0026 0027 unsigned int AbstractTypeData::itemSize() const 0028 { 0029 return TypeSystem::self().dynamicSize(*this); 0030 } 0031 0032 unsigned int AbstractTypeData::hash() const 0033 { 0034 AbstractType::Ptr type(TypeSystem::self().create(const_cast<AbstractTypeData*>(this))); 0035 return type->hash(); 0036 } 0037 0038 AbstractTypeData::AbstractTypeData(const AbstractTypeData& rhs) 0039 : m_sizeOf(rhs.m_sizeOf) 0040 , m_alignOfExponent(rhs.m_alignOfExponent) 0041 , m_modifiers(rhs.m_modifiers) 0042 , refCount(0) 0043 , inRepository(false) 0044 { 0045 initializeAppendedLists(!rhs.m_dynamic); //This type will be dynamic exactly if the copied one is not. 0046 typeClassId = rhs.typeClassId; 0047 } 0048 0049 AbstractTypeData::~AbstractTypeData() 0050 { 0051 freeAppendedLists(); 0052 } 0053 0054 IntegralTypeData::IntegralTypeData() 0055 0056 { 0057 } 0058 0059 IntegralTypeData::IntegralTypeData(const IntegralTypeData& rhs) 0060 : AbstractTypeData(rhs) 0061 , m_dataType(rhs.m_dataType) 0062 { 0063 } 0064 0065 PointerTypeData::PointerTypeData() 0066 { 0067 } 0068 0069 PointerTypeData::PointerTypeData(const PointerTypeData& rhs) 0070 : AbstractTypeData(rhs) 0071 , m_baseType(rhs.m_baseType) 0072 { 0073 } 0074 0075 ReferenceTypeData::ReferenceTypeData() : m_isRValue(false) 0076 { 0077 } 0078 0079 ReferenceTypeData::ReferenceTypeData(const ReferenceTypeData& rhs) 0080 : AbstractTypeData(rhs) 0081 , m_baseType(rhs.m_baseType) 0082 , m_isRValue(rhs.m_isRValue) 0083 { 0084 } 0085 0086 FunctionTypeData::FunctionTypeData() 0087 { 0088 initializeAppendedLists(m_dynamic); 0089 } 0090 0091 FunctionTypeData::~FunctionTypeData() 0092 { 0093 freeAppendedLists(); 0094 } 0095 0096 FunctionTypeData::FunctionTypeData(const FunctionTypeData& rhs) 0097 : AbstractTypeData(rhs) 0098 , m_returnType(rhs.m_returnType) 0099 { 0100 initializeAppendedLists(m_dynamic); 0101 copyListsFrom(rhs); 0102 } 0103 0104 void FunctionTypeData::operator=(const FunctionTypeData& rhs) 0105 { 0106 Q_UNUSED(rhs) 0107 } 0108 0109 StructureTypeData::StructureTypeData() 0110 { 0111 } 0112 0113 StructureTypeData::StructureTypeData(const StructureTypeData& rhs) 0114 : MergeIdentifiedType<AbstractType>::Data(rhs) 0115 { 0116 } 0117 0118 ConstantIntegralTypeData::ConstantIntegralTypeData() 0119 0120 { 0121 } 0122 0123 ArrayTypeData::ArrayTypeData() 0124 0125 { 0126 } 0127 0128 ArrayTypeData::ArrayTypeData(const ArrayTypeData& rhs) 0129 : AbstractTypeData(rhs) 0130 , m_dimension(rhs.m_dimension) 0131 , m_elementType(rhs.m_elementType) 0132 { 0133 Q_ASSERT(m_dimension == rhs.m_dimension); 0134 } 0135 0136 DelayedTypeData::DelayedTypeData() 0137 { 0138 } 0139 0140 DelayedTypeData::DelayedTypeData(const DelayedTypeData& rhs) 0141 : AbstractTypeData(rhs) 0142 , m_identifier(rhs.m_identifier) 0143 , m_kind(rhs.m_kind) 0144 { 0145 } 0146 0147 bool SimpleTypeVisitor::preVisit(const AbstractType*) 0148 { 0149 return true; 0150 } 0151 0152 void SimpleTypeVisitor::postVisit(const AbstractType*) 0153 { 0154 } 0155 0156 void SimpleTypeVisitor::visit(const IntegralType* type) 0157 { 0158 visit(( AbstractType* )type); 0159 } 0160 0161 bool SimpleTypeVisitor::visit(const PointerType* type) 0162 { 0163 return visit(( AbstractType* )type); 0164 } 0165 0166 void SimpleTypeVisitor::endVisit(const PointerType* type) 0167 { 0168 visit(( AbstractType* )type); 0169 } 0170 0171 bool SimpleTypeVisitor::visit(const ReferenceType* type) 0172 { 0173 return visit(( AbstractType* )type); 0174 } 0175 0176 void SimpleTypeVisitor::endVisit(const ReferenceType* type) 0177 { 0178 visit(( AbstractType* )type); 0179 } 0180 0181 bool SimpleTypeVisitor::visit(const FunctionType* type) 0182 { 0183 return visit(( AbstractType* )type); 0184 } 0185 0186 void SimpleTypeVisitor::endVisit(const FunctionType* type) 0187 { 0188 visit(( AbstractType* )type); 0189 } 0190 0191 bool SimpleTypeVisitor::visit(const StructureType* type) 0192 { 0193 return visit(( AbstractType* )type); 0194 } 0195 0196 void SimpleTypeVisitor::endVisit(const StructureType* type) 0197 { 0198 visit(( AbstractType* )type); 0199 } 0200 0201 bool SimpleTypeVisitor::visit(const ArrayType* type) 0202 { 0203 return visit(( AbstractType* )type); 0204 } 0205 0206 void SimpleTypeVisitor::endVisit(const ArrayType* type) 0207 { 0208 visit(( AbstractType* )type); 0209 } 0210 0211 TypeVisitor::~TypeVisitor() 0212 { 0213 } 0214 0215 TypePtr<KDevelop::AbstractType> TypeExchanger::exchange(const TypePtr<KDevelop::AbstractType>& type) 0216 { 0217 const_cast<AbstractType*>(type.data())->exchangeTypes(this); 0218 return type; 0219 } 0220 0221 TypePtr<KDevelop::AbstractType> SimpleTypeExchanger::exchange(const TypePtr<KDevelop::AbstractType>& type) 0222 { 0223 if (type && type->equals(m_replace.data())) 0224 return m_replaceWith; 0225 else 0226 return TypeExchanger::exchange(type); 0227 } 0228 0229 SimpleTypeExchanger::SimpleTypeExchanger(const TypePtr<KDevelop::AbstractType>& replace, 0230 const TypePtr<KDevelop::AbstractType>& replaceWith) 0231 : m_replace(replace) 0232 , m_replaceWith(replaceWith) 0233 { 0234 } 0235 }