language/duchain
abstracttype.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ABSTRACTTYPE_H
00022 #define ABSTRACTTYPE_H
00023
00024 #include <QtCore/QString>
00025 #include "typepointer.h"
00026 #include "../../languageexport.h"
00027
00028 namespace KDevelop
00029 {
00030 class AbstractTypeData;
00031
00032 class IndexedType;
00033
00034 class TypeVisitor;
00035 class TypeExchanger;
00036
00037 #define TYPE_DECLARE_DATA(Class) \
00038 inline Class##Data* d_func_dynamic() { makeDynamic(); return reinterpret_cast<Class##Data *>(d_ptr); } \
00039 inline const Class##Data* d_func() const { return reinterpret_cast<const Class##Data *>(d_ptr); }
00040
00041 #define TYPE_D(Class) const Class##Data * const d = d_func()
00042 #define TYPE_D_DYNAMIC(Class) Class##Data * const d = d_func_dynamic()
00043
00081 class KDEVPLATFORMLANGUAGE_EXPORT AbstractType : public TypeShared
00082 {
00083 public:
00084 typedef TypePtr<AbstractType> Ptr;
00085
00095 enum CommonModifiers {
00096 NoModifiers = 0,
00097 ConstModifier = 1 << 0,
00098 VolatileModifier = 1 << 1,
00099 TransientModifier = 1 << 2,
00100 NewModifier = 1 << 3,
00101 SealedModifier = 1 << 4,
00102 UnsafeModifier = 1 << 5,
00103 FixedModifier = 1 << 6,
00104 ShortModifier = 1 << 7,
00105 LongModifier = 1 << 8,
00106 LongLongModifier = 1 << 9,
00107 SignedModifier = 1 << 10,
00108 UnsignedModifier = 1 << 11,
00109 LanguageSpecificModifier = 1 << 12
00110 };
00111
00113 AbstractType();
00115 AbstractType(AbstractTypeData& dd);
00117 virtual ~AbstractType ();
00118
00124 quint64 modifiers() const;
00125
00131 void setModifiers(quint64 modifiers);
00132
00139 void accept(TypeVisitor *v) const;
00140
00147 static void acceptType(AbstractType::Ptr type, TypeVisitor *v);
00148
00154 virtual QString toString() const;
00155
00158 void makeDynamic();
00159
00162 virtual bool equals(const AbstractType* rhs) const;
00163
00167 virtual AbstractType* clone() const = 0;
00168
00174 virtual uint hash() const;
00175
00177 IndexedType indexed() const;
00178
00180 enum WhichType {
00181 TypeAbstract ,
00182 TypeIntegral ,
00183 TypePointer ,
00184 TypeReference ,
00185 TypeFunction ,
00186 TypeStructure ,
00187 TypeArray ,
00188 TypeDelayed ,
00189 TypeEnumeration ,
00190 TypeEnumerator ,
00191 TypeAlias ,
00192 TypeUnsure
00193 };
00194
00200 virtual WhichType whichType() const;
00201
00202 enum {
00203 Identity = 1
00204 };
00205
00212 virtual void exchangeTypes( TypeExchanger* exchanger );
00213
00223 template<class Type>
00224 static typename Type::Data& copyData(const typename Type::Data& rhs) {
00225 size_t size;
00226 if(!rhs.m_dynamic)
00227 size = sizeof(typename Type::Data);
00228 else
00229 size = rhs.dynamicSize();
00230
00231 typename Type::Data& ret(*new (new char[size]) typename Type::Data(rhs));
00232 ret.template setTypeClassId<Type>();
00233 return ret;
00234 }
00235
00239 template<class DataType>
00240 static DataType& copyDataDirectly(const DataType& rhs) {
00241 size_t size;
00242 if(!rhs.m_dynamic)
00243 size = sizeof(DataType);
00244 else
00245 size = rhs.dynamicSize();
00246
00247 return *new (new char[size]) DataType(rhs);
00248 }
00249
00255 template<class Type>
00256 static typename Type::Data& createData() {
00257 typename Type::Data& ret(*new (new char[sizeof(typename Type::Data)]) typename Type::Data());
00258 ret.template setTypeClassId<Type>();
00259 return ret;
00260 }
00261
00262 typedef AbstractTypeData Data;
00263
00264 protected:
00270 virtual void accept0 (TypeVisitor *v) const = 0;
00271
00273 QString toString(bool spaceOnLeft) const;
00274
00275 AbstractTypeData* d_ptr;
00276
00277 TYPE_DECLARE_DATA(AbstractType)
00278
00279 friend class AbstractTypeDataRequest;
00280
00281 private:
00282 AbstractType(const AbstractType& rhs);
00283 };
00284
00285 template <class T>
00286 uint qHash(const TypePtr<T>& type) { return (uint)((size_t)type.unsafeData()); }
00287
00288
00293 template<class To>
00294 inline To fastCast(AbstractType* from) {
00295 return dynamic_cast<To>(from);
00296 }
00297
00298 template<class To>
00299 inline const To fastCast(const AbstractType* from) {
00300 return const_cast<const To>(fastCast<To>(const_cast<AbstractType*>(from)));
00301 }
00302
00303 }
00304
00305 #endif
00306
00307