language/duchain
arraytype.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "arraytype.h"
00022
00023 #include "../indexedstring.h"
00024 #include "../repositories/typerepository.h"
00025 #include "typesystemdata.h"
00026 #include "typeregister.h"
00027 #include "typesystem.h"
00028
00029 namespace KDevelop
00030 {
00031
00032 REGISTER_TYPE(ArrayType);
00033
00034 ArrayType::ArrayType(const ArrayType& rhs) : AbstractType(copyData<ArrayType>(*rhs.d_func())) {
00035 }
00036
00037 ArrayType::ArrayType(ArrayTypeData& data) : AbstractType(data) {
00038 }
00039
00040 AbstractType* ArrayType::clone() const {
00041 return new ArrayType(*this);
00042 }
00043
00044 bool ArrayType::equals(const AbstractType* _rhs) const
00045 {
00046 if (!AbstractType::equals(_rhs))
00047 return false;
00048
00049 Q_ASSERT(fastCast<const ArrayType*>(_rhs));
00050
00051 const ArrayType* rhs = static_cast<const ArrayType*>(_rhs);
00052
00053 TYPE_D(ArrayType);
00054 if( d->m_dimension != rhs->d_func()->m_dimension )
00055 return false;
00056
00057 return d->m_elementType == rhs->d_func()->m_elementType;
00058 }
00059
00060 ArrayType::ArrayType()
00061 : AbstractType(createData<ArrayType>())
00062 {
00063 }
00064
00065 ArrayType::~ArrayType()
00066 {
00067 }
00068
00069 int ArrayType::dimension () const
00070 {
00071 return d_func()->m_dimension;
00072 }
00073
00074 void ArrayType::setDimension(int dimension)
00075 {
00076 d_func_dynamic()->m_dimension = dimension;
00077 }
00078
00079 AbstractType::Ptr ArrayType::elementType () const
00080 {
00081 return d_func()->m_elementType.abstractType();
00082 }
00083
00084 void ArrayType::setElementType(AbstractType::Ptr type)
00085 {
00086 d_func_dynamic()->m_elementType = type->indexed();
00087 }
00088
00089 QString ArrayType::toString() const
00090 {
00091 return QString("%1[%2]").arg(elementType() ? elementType()->toString() : QString("<notype>")).arg(d_func()->m_dimension);
00092 }
00093
00094 void ArrayType::accept0 (TypeVisitor *v) const
00095 {
00096 if (v->visit (this))
00097 {
00098 acceptType (d_func()->m_elementType.abstractType(), v);
00099 }
00100
00101 v->endVisit (this);
00102 }
00103
00104 void ArrayType::exchangeTypes( TypeExchanger* exchanger )
00105 {
00106 TYPE_D_DYNAMIC(ArrayType);
00107 d->m_elementType = exchanger->exchange( d->m_elementType.abstractType() )->indexed();
00108 }
00109
00110 AbstractType::WhichType ArrayType::whichType() const
00111 {
00112 return TypeArray;
00113 }
00114
00115 uint ArrayType::hash() const
00116 {
00117 return AbstractType::hash() + (elementType() ? elementType()->hash() : 0) * 47 + 117* dimension();
00118 }
00119
00120 }
00121
00122