• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/language/duchain

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • language
  • duchain
  • types
abstracttype.h
Go to the documentation of this file.
1 /* This file is part of KDevelop
2  Copyright 2006 Roberto Raggi <[email protected]>
3  Copyright 2006-2008 Hamish Rodda <[email protected]>
4  Copyright 2007-2008 David Nolden <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef KDEVPLATFORM_ABSTRACTTYPE_H
22 #define KDEVPLATFORM_ABSTRACTTYPE_H
23 
24 #include "typepointer.h"
25 #include <language/languageexport.h>
26 
27 class QString;
28 
29 namespace KDevelop {
30 class AbstractTypeData;
31 
32 class IndexedType;
33 
34 class TypeVisitor;
35 class TypeExchanger;
36 
38 #define TYPE_DECLARE_DATA(Class) \
39  inline Class ## Data * d_func_dynamic() { makeDynamic(); return reinterpret_cast<Class ## Data*>(d_ptr); } \
40  inline const Class ## Data* d_func() const { return reinterpret_cast<const Class ## Data*>(d_ptr); }
41 
43 #define TYPE_D(Class) const Class ## Data * const d = d_func()
44 #define TYPE_D_DYNAMIC(Class) Class ## Data * const d = d_func_dynamic()
45 
87 class KDEVPLATFORMLANGUAGE_EXPORT AbstractType
88  : public QSharedData
89 {
90 public:
91  using Ptr = TypePtr<AbstractType>;
92 
102  enum CommonModifiers : quint32 {
103  NoModifiers = 0,
104 
105  ConstModifier = 1 << 0,
106  VolatileModifier = 1 << 1,
107  TransientModifier = 1 << 2,
108  NewModifier = 1 << 3,
109  SealedModifier = 1 << 4,
110  UnsafeModifier = 1 << 5,
111  FixedModifier = 1 << 6,
112  ShortModifier = 1 << 7,
113  LongModifier = 1 << 8,
114  LongLongModifier = 1 << 9,
115  SignedModifier = 1 << 10,
116  UnsignedModifier = 1 << 11,
117 
118  LanguageSpecificModifier = 1 << 12
119  };
120 
122  AbstractType();
124  explicit AbstractType(AbstractTypeData& dd);
126  virtual ~AbstractType ();
127 
128  AbstractType(const AbstractType& rhs) = delete;
129  AbstractType& operator=(const AbstractType& rhs) = delete;
130 
136  quint32 modifiers() const;
137 
143  void setModifiers(quint32 modifiers);
144 
148  int64_t sizeOf() const;
149 
153  void setSizeOf(int64_t sizeOf);
154 
158  int64_t alignOf() const;
159 
165  void setAlignOf(int64_t alignedTo);
166 
173  void accept(TypeVisitor* v) const;
174 
181  static void acceptType(AbstractType::Ptr type, TypeVisitor* v);
182 
188  virtual QString toString() const;
189 
192  void makeDynamic();
193 
196  virtual bool equals(const AbstractType* rhs) const;
197 
201  virtual AbstractType* clone() const = 0;
202 
208  virtual uint hash() const;
209 
211  IndexedType indexed() const;
212 
214  enum WhichType : quint8 {
215  TypeAbstract ,
216  TypeIntegral ,
217  TypePointer ,
218  TypeReference ,
219  TypeFunction ,
220  TypeStructure ,
221  TypeArray ,
222  TypeDelayed ,
223  TypeEnumeration ,
224  TypeEnumerator ,
225  TypeAlias ,
226  TypeUnsure
227  };
228 
234  virtual WhichType whichType() const;
235 
236  enum {
237  Identity = 1
238  };
239 
246  virtual void exchangeTypes(TypeExchanger* exchanger);
247 
257  template <class Type>
258  static typename Type::Data& copyData(const typename Type::Data& rhs)
259  {
260  uint size;
261  if (!rhs.m_dynamic)
262  size = sizeof(typename Type::Data); //Create a dynamic data instance
263  else
264  size = rhs.dynamicSize(); //Create a constant data instance, that holds all the data embedded.
265 
266  typename Type::Data& ret(*new (new char[size]) typename Type::Data(rhs));
267  ret.template setTypeClassId<Type>();
268  return ret;
269  }
270 
274  template <class DataType>
275  static DataType& copyDataDirectly(const DataType& rhs)
276  {
277  uint size;
278  if (!rhs.m_dynamic)
279  size = sizeof(DataType); //Create a dynamic data instance
280  else
281  size = rhs.dynamicSize(); //Create a constant data instance, that holds all the data embedded.
282 
283  return *new (new char[size]) DataType(rhs);
284  }
285 
291  template <class Type>
292  static typename Type::Data& createData()
293  {
294  typename Type::Data& ret(*new (new char[sizeof(typename Type::Data)]) typename Type::Data());
295  ret.template setTypeClassId<Type>();
296  return ret;
297  }
298 
299  using Data = AbstractTypeData;
300 
301 protected:
307  virtual void accept0 (TypeVisitor* v) const = 0;
308 
310  QString toString(bool spaceOnLeft) const;
311 
312  AbstractTypeData* d_ptr;
313 
314  TYPE_DECLARE_DATA(AbstractType)
315 
316  friend class AbstractTypeDataRequest;
317 };
318 
322 template <class To>
323 inline To fastCast(AbstractType* from)
324 {
325  return dynamic_cast<To>(from);
326 }
327 
328 template <class To>
329 inline const To fastCast(const AbstractType* from)
330 {
331  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
332 }
333 }
334 
335 #endif
QSharedData
TYPE_DECLARE_DATA
#define TYPE_DECLARE_DATA(Class)
This macro is used to declare type-specific data-access functions within subclasses of AbstractType.
Definition: abstracttype.h:38
AbstractTypeData
KDevelop::AbstractType::copyData
static Type::Data & copyData(const typename Type::Data &rhs)
Method to create copies of internal type data.
Definition: abstracttype.h:258
KDevelop::TypePtr< AbstractType >
KDevelop::fastCast
To fastCast(AbstractType *from)
You can use these instead of dynamic_cast, for basic types it has better performance because it check...
Definition: abstracttype.h:323
QString
KDevelop::AbstractType::copyDataDirectly
static DataType & copyDataDirectly(const DataType &rhs)
As above, but does not support copying data into a lower class(Should not be used while cloning)
Definition: abstracttype.h:275
KDevelop::TypeVisitor
Definition: typesystem.h:41
KDevelop::TypeExchanger
A class that can be used to walk through all types that are references from one type,...
Definition: typesystem.h:103
KDevelop::IndexedType
Indexed type pointer.
Definition: indexedtype.h:36
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
KDevelop::AbstractType::CommonModifiers
CommonModifiers
An enumeration of common modifiers for data types.
Definition: abstracttype.h:102
KDevelop::AbstractType::d_ptr
AbstractTypeData * d_ptr
Definition: abstracttype.h:312
KDevelop::AbstractType::WhichType
WhichType
Enumeration of major data types.
Definition: abstracttype.h:214
KDevelop::AbstractType::createData
static Type::Data & createData()
Method to create internal data structures.
Definition: abstracttype.h:292
KDevelop::AbstractType
Base class for all types.
Definition: abstracttype.h:87
typepointer.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 09:40:52 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/language/duchain

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

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal