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

language/duchain

abstracttype.cpp

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 #include "abstracttype.h"
00022 
00023 #include "../indexedstring.h"
00024 #include "typesystemdata.h"
00025 #include "typeregister.h"
00026 #include "typesystem.h"
00027 #include "../repositories/typerepository.h"
00028 
00029 namespace KDevelop
00030 {
00031 
00032 //REGISTER_TYPE(AbstractType);
00033 
00034 void AbstractType::makeDynamic() {
00035   if(d_ptr->m_dynamic)
00036     return;
00037   AbstractType::Ptr newType(clone()); //While cloning, all the data is cloned as well. So we use that mechanism and steal the cloned data.
00038   Q_ASSERT(newType->equals(this));
00039   AbstractTypeData* oldData = d_ptr;
00040   d_ptr = newType->d_ptr;
00041   newType->d_ptr = oldData;
00042   Q_ASSERT(d_ptr->m_dynamic);
00043 }
00044 
00045 AbstractType::AbstractType( AbstractTypeData& dd )
00046   : d_ptr(&dd)
00047 {
00048 }
00049 
00050 quint64 AbstractType::modifiers() const
00051 {
00052   return d_func()->m_modifiers;
00053 }
00054 
00055 void AbstractType::setModifiers(quint64 modifiers)
00056 {
00057   d_func_dynamic()->m_modifiers = modifiers;
00058 }
00059 
00060 AbstractType::AbstractType()
00061   : d_ptr(&createData<AbstractType>())
00062 {
00063 }
00064 
00065 AbstractType::~AbstractType()
00066 {
00067   if(!d_ptr->inRepository) {
00068     TypeSystem::self().callDestructor(d_ptr);
00069     delete[] (char*)d_ptr;
00070   }
00071 }
00072 
00073 void AbstractType::accept(TypeVisitor *v) const
00074 {
00075   if (v->preVisit (this))
00076     this->accept0 (v);
00077 
00078   v->postVisit (this);
00079 }
00080 
00081 void AbstractType::acceptType(AbstractType::Ptr type, TypeVisitor *v)
00082 {
00083   if (! type)
00084     return;
00085 
00086   type->accept (v);
00087 }
00088 
00089 AbstractType::WhichType AbstractType::whichType() const
00090 {
00091   return TypeAbstract;
00092 }
00093 
00094 void AbstractType::exchangeTypes( TypeExchanger* /*exchanger */) {
00095 }
00096 
00097 IndexedType AbstractType::indexed() const {
00098   if(this == 0)
00099     return IndexedType();
00100   else {
00101     return IndexedType(TypeRepository::indexForType(AbstractType::Ptr(const_cast<AbstractType*>(this))));
00102   }
00103 }
00104 
00105 bool AbstractType::equals(const AbstractType* rhs) const
00106 {
00107     //kDebug() << this << rhs << modifiers() << rhs->modifiers();
00108     return d_func()->typeClassId == rhs->d_func()->typeClassId && modifiers() == rhs->modifiers();
00109 }
00110 
00111 uint AbstractType::hash() const
00112 {
00113   // TODO include other items in the hash
00114 
00115   uint hash = 0;
00116 
00117   uint mod = d_func()->m_modifiers;
00118   
00119   if (mod & ShortModifier)
00120     hash += 0x1;
00121   if (mod & LongModifier)
00122     hash += 0x2;
00123   if (mod & LongLongModifier)
00124     hash += 0x4;
00125   if (mod & SignedModifier)
00126     hash += 0x8;
00127   if (mod & UnsignedModifier)
00128     hash += 0x10;
00129 
00130   return (mod & ConstModifier ? 7 : 0) + (mod & VolatileModifier ? 3 : 0) + 83 * hash;
00131 }
00132 
00133 QString AbstractType::toString() const
00134 {
00135   return toString(false);
00136 }
00137 
00138 QString AbstractType::toString(bool spaceOnLeft) const
00139 {
00140   // TODO complete
00141   if(!spaceOnLeft) {
00142     if(modifiers() & ConstModifier) {
00143       if(modifiers() & VolatileModifier) {
00144         return "const volatile ";
00145       }else{
00146         return "const ";
00147       }
00148     }else{
00149       if(modifiers() & VolatileModifier)
00150         return "volatile ";
00151       else
00152         return QString();
00153     }
00154   }else{
00155     if(modifiers() & ConstModifier) {
00156       if(modifiers() & VolatileModifier) {
00157         return " const volatile";
00158       }else{
00159         return " const";
00160       }
00161     }else{
00162       if(modifiers() & VolatileModifier)
00163         return " volatile";
00164       else
00165         return QString();
00166     }
00167   }
00168 }
00169 
00170 }
00171 
00172 // 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