• 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.cpp
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 #include "abstracttype.h"
22 
23 #include "typesystemdata.h"
24 #include "typeregister.h"
25 #include "typesystem.h"
26 #include "typerepository.h"
27 #include <debug.h>
28 
29 namespace KDevelop {
30 //REGISTER_TYPE(AbstractType);
31 
32 void AbstractType::makeDynamic()
33 {
34  if (d_ptr->m_dynamic)
35  return;
36  AbstractType::Ptr newType(clone()); //While cloning, all the data is cloned as well. So we use that mechanism and steal the cloned data.
37  Q_ASSERT(newType->equals(this));
38  AbstractTypeData* oldData = d_ptr;
39  d_ptr = newType->d_ptr;
40  newType->d_ptr = oldData;
41  Q_ASSERT(d_ptr->m_dynamic);
42 }
43 
44 AbstractType::AbstractType(AbstractTypeData& dd)
45  : d_ptr(&dd)
46 {
47 }
48 
49 quint32 AbstractType::modifiers() const
50 {
51  return d_func()->m_modifiers;
52 }
53 
54 void AbstractType::setModifiers(quint32 modifiers)
55 {
56  d_func_dynamic()->m_modifiers = modifiers;
57 }
58 
59 int64_t AbstractType::sizeOf() const
60 {
61  return d_func()->m_sizeOf;
62 }
63 
64 void AbstractType::setSizeOf(int64_t sizeOf)
65 {
66  d_func_dynamic()->m_sizeOf = sizeOf;
67 }
68 
69 int64_t AbstractType::alignOf() const
70 {
71  if (d_func()->m_alignOfExponent == AbstractTypeData::MaxAlignOfExponent) {
72  return -1;
73  } else {
74  return Q_INT64_C(1) << d_func()->m_alignOfExponent;
75  }
76 }
77 
78 void AbstractType::setAlignOf(int64_t alignedTo)
79 {
80  if (alignedTo <= 0) {
81  d_func_dynamic()->m_alignOfExponent = AbstractTypeData::MaxAlignOfExponent;
82  return;
83  }
84 
85  unsigned int alignOfExponent = 0;
86  while (alignedTo >>= 1)
87  alignOfExponent++;
88  d_func_dynamic()->m_alignOfExponent = alignOfExponent;
89 }
90 
91 AbstractType::AbstractType()
92  : d_ptr(&createData<AbstractType>())
93 {
94 }
95 
96 AbstractType::~AbstractType()
97 {
98  if (!d_ptr->inRepository) {
99  TypeSystem::self().callDestructor(d_ptr);
100  delete[] ( char* )d_ptr;
101  }
102 }
103 
104 void AbstractType::accept(TypeVisitor* v) const
105 {
106  if (v->preVisit(this))
107  this->accept0(v);
108 
109  v->postVisit(this);
110 }
111 
112 void AbstractType::acceptType(AbstractType::Ptr type, TypeVisitor* v)
113 {
114  if (!type)
115  return;
116 
117  type->accept(v);
118 }
119 
120 AbstractType::WhichType AbstractType::whichType() const
121 {
122  return TypeAbstract;
123 }
124 
125 void AbstractType::exchangeTypes(TypeExchanger* /*exchanger */)
126 {
127 }
128 
129 IndexedType AbstractType::indexed() const
130 {
131  return IndexedType(AbstractType::Ptr(const_cast<AbstractType*>(this)));
132 }
133 
134 bool AbstractType::equals(const AbstractType* rhs) const
135 {
136  //qCDebug(LANGUAGE) << this << rhs << modifiers() << rhs->modifiers();
137  return d_func()->typeClassId == rhs->d_func()->typeClassId && d_func()->m_modifiers == rhs->d_func()->m_modifiers
138  && d_func()->m_sizeOf == rhs->d_func()->m_sizeOf
139  && d_func()->m_alignOfExponent == rhs->d_func()->m_alignOfExponent;
140 }
141 
142 uint AbstractType::hash() const
143 {
144  return KDevHash() << d_func()->typeClassId << d_func()->m_modifiers << d_func()->m_sizeOf
145  << d_func()->m_alignOfExponent;
146 }
147 
148 QString AbstractType::toString() const
149 {
150  return toString(false);
151 }
152 
153 QString AbstractType::toString(bool spaceOnLeft) const
154 {
155  // TODO complete
156  if (!spaceOnLeft) {
157  if (modifiers() & ConstModifier) {
158  if (modifiers() & VolatileModifier) {
159  return QStringLiteral("const volatile ");
160  } else {
161  return QStringLiteral("const ");
162  }
163  } else {
164  if (modifiers() & VolatileModifier)
165  return QStringLiteral("volatile ");
166  else
167  return QString();
168  }
169  } else {
170  if (modifiers() & ConstModifier) {
171  if (modifiers() & VolatileModifier) {
172  return QStringLiteral(" const volatile");
173  } else {
174  return QStringLiteral(" const");
175  }
176  } else {
177  if (modifiers() & VolatileModifier)
178  return QStringLiteral(" volatile");
179  else
180  return QString();
181  }
182  }
183 }
184 }
KDevelop::AbstractType::VolatileModifier
Definition: abstracttype.h:106
KDevelop::AbstractType::modifiers
quint32 modifiers() const
Access the type modifiers.
Definition: abstracttype.cpp:49
KDevelop::AbstractType::setAlignOf
void setAlignOf(int64_t alignedTo)
Set the alignment to given number of bytes.
Definition: abstracttype.cpp:78
AbstractTypeData
KDevelop::TypeVisitor::preVisit
virtual bool preVisit(const AbstractType *)=0
KDevelop::AbstractType::alignOf
int64_t alignOf() const
Definition: abstracttype.cpp:69
KDevelop::AbstractType::equals
virtual bool equals(const AbstractType *rhs) const
Should return whether this type's content equals the given one Since this is used by the type-reposit...
Definition: abstracttype.cpp:134
KDevelop::TypePtr< AbstractType >
typerepository.h
KDevelop::AbstractType::whichType
virtual WhichType whichType() const
Determine which data type this abstract type represents.
Definition: abstracttype.cpp:120
KDevelop::AbstractType::toString
virtual QString toString() const
Returns this type as a string, preferably the same as it is expressed in the code.
Definition: abstracttype.cpp:148
typesystemdata.h
KDevelop::AbstractType::TypeAbstract
an abstract type
Definition: abstracttype.h:215
KDevelop::AbstractType::~AbstractType
virtual ~AbstractType()
Destructor.
Definition: abstracttype.cpp:96
KDevelop::TypeVisitor::postVisit
virtual void postVisit(const AbstractType *)=0
KDevelop::TypeSystem::callDestructor
void callDestructor(AbstractTypeData *data) const
Calls the destructor, but does not delete anything. This is needed because the data classes must not ...
Definition: typeregister.cpp:33
QString
typesystem.h
KDevelop::AbstractType::ConstModifier
Definition: abstracttype.h:105
KDevelop::AbstractType::clone
virtual AbstractType * clone() const =0
Should create a clone of the source-type, with as much data copied as possible without breaking the d...
KDevelop::TypeVisitor
Definition: typesystem.h:41
typeregister.h
KDevelop::AbstractType::AbstractType
AbstractType()
Constructor.
Definition: abstracttype.cpp:91
KDevelop::AbstractType::indexed
IndexedType indexed() const
This can also be called on zero types, those can then be reconstructed from the zero index.
Definition: abstracttype.cpp:129
KDevelop::AbstractType::exchangeTypes
virtual void exchangeTypes(TypeExchanger *exchanger)
Should, like accept0, be implemented by all types that hold references to other types.
Definition: abstracttype.cpp:125
KDevelop::TypeExchanger
A class that can be used to walk through all types that are references from one type,...
Definition: typesystem.h:103
KDevelop::AbstractType::accept0
virtual void accept0(TypeVisitor *v) const =0
Visitor method, reimplement to allow visiting of types.
abstracttype.h
KDevelop::IndexedType
Indexed type pointer.
Definition: indexedtype.h:36
KDevelop::AbstractType::acceptType
static void acceptType(AbstractType::Ptr type, TypeVisitor *v)
Convenience visitor method which can be called with a null type.
Definition: abstracttype.cpp:112
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
KDevelop::AbstractType::hash
virtual uint hash() const
A hash-value that should have the following properties:
Definition: abstracttype.cpp:142
KDevelop::AbstractType::sizeOf
int64_t sizeOf() const
Definition: abstracttype.cpp:59
KDevelop::AbstractType::makeDynamic
void makeDynamic()
Must always be called before anything in the data pointer is changed! If it's not called beforehand,...
Definition: abstracttype.cpp:32
KDevelop::TypeSystem::self
static TypeSystem & self()
Access the static TypeSystem instance.
Definition: typeregister.cpp:78
KDevelop::AbstractType::setSizeOf
void setSizeOf(int64_t sizeOf)
Set the size to given number of bytes.
Definition: abstracttype.cpp:64
KDevelop::AbstractType::d_ptr
AbstractTypeData * d_ptr
Definition: abstracttype.h:312
KDevelop::AbstractType::accept
void accept(TypeVisitor *v) const
Visitor method.
Definition: abstracttype.cpp:104
KDevelop::AbstractType::WhichType
WhichType
Enumeration of major data types.
Definition: abstracttype.h:214
KDevelop::AbstractType
Base class for all types.
Definition: abstracttype.h:87
KDevelop::AbstractType::setModifiers
void setModifiers(quint32 modifiers)
Set the type's modifiers.
Definition: abstracttype.cpp:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Apr 20 2021 23:30:11 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