• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

abstracttype.h

00001 /* This file is part of KDevelop
00002     Copyright 2006 Roberto Raggi <roberto@kdevelop.org>
00003     Copyright 2006-2008 Hamish Rodda <rodda@kde.org>
00004     Copyright 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
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 //TODO make this support 64 bit values
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); //Create a dynamic data instance
00228     else
00229       size = rhs.dynamicSize(); //Create a constant data instance, that holds all the data embedded.
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); //Create a dynamic data instance
00244     else
00245       size = rhs.dynamicSize(); //Create a constant data instance, that holds all the data embedded.
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))); //Hack so we don't need to define the functions twice, once for const, and once for not const
00301 }
00302 
00303 }
00304 
00305 #endif
00306 
00307 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal