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

language/duchain

instantiationinformation.cpp

00001 /* This file is part of KDevelop
00002     Copyright 2007-2009 David Nolden <david.nolden.kdevelop@art-master.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "./instantiationinformation.h"
00020 #include "identifier.h"
00021 #include "repositories/itemrepository.h"
00022 #include "types/typeutils.h"
00023 #include <typeinfo>
00024 #include "types/typealiastype.h"
00025 #include "repositories/typerepository.h"
00026 
00027 
00028 namespace KDevelop {
00029 
00030 DEFINE_LIST_MEMBER_HASH(InstantiationInformation, templateParameters, IndexedType)
00031 
00032 QualifiedIdentifier InstantiationInformation::applyToIdentifier(const QualifiedIdentifier& id) const {
00033   QualifiedIdentifier ret;
00034   if(id.count() > 1) {
00035     ret = id;
00036     ret.pop();
00037     if(previousInstantiationInformation.index())
00038       ret = previousInstantiationInformation.information().applyToIdentifier(ret);
00039   }
00040 
00041   Identifier lastId(id.last());
00042 
00043   KDevVarLengthArray<IndexedTypeIdentifier> oldTemplateIdentifiers;
00044   for(uint a = 0; a < lastId.templateIdentifiersCount(); ++a)
00045     oldTemplateIdentifiers.append(lastId.templateIdentifier(a)); 
00046   lastId.clearTemplateIdentifiers();
00047 
00048   for(uint a = 0; a < templateParametersSize(); ++a) {
00049     if(templateParameters()[a].abstractType()) {
00050       lastId.appendTemplateIdentifier(IndexedTypeIdentifier(templateParameters()[a].abstractType()->toString(), true));
00051     }else{
00052       lastId.appendTemplateIdentifier((uint) oldTemplateIdentifiers.size() > a ? oldTemplateIdentifiers[a] : IndexedTypeIdentifier());
00053     }
00054   }
00055 
00056   for(int a = templateParametersSize(); a < oldTemplateIdentifiers.size(); ++a)
00057     lastId.appendTemplateIdentifier(oldTemplateIdentifiers[a]);
00058 
00059   ret.push(lastId);
00060   return ret;
00061 }
00062 
00063 void InstantiationInformation::addTemplateParameter(KDevelop::AbstractType::Ptr type) {
00064   templateParametersList().append(type->indexed());
00065 }
00066 
00067 QString InstantiationInformation::toString(bool local) const {
00068     QString ret;
00069     if(previousInstantiationInformation.index() && !local)
00070         ret = previousInstantiationInformation.information().toString() + "::";
00071     ret += '<';
00072     for(uint a = 0; a < templateParametersSize(); ++a) {
00073         if(a)
00074             ret += ", ";
00075         if(templateParameters()[a].abstractType())
00076           ret += templateParameters()[a].abstractType()->toString();
00077     }
00078     ret += '>';
00079     return ret;
00080 }
00081 
00082 InstantiationInformation::InstantiationInformation() : m_refCount(0) {
00083   initializeAppendedLists();
00084 }
00085 
00086 InstantiationInformation::InstantiationInformation(const InstantiationInformation& rhs, bool dynamic) : previousInstantiationInformation(rhs.previousInstantiationInformation), m_refCount(0) {
00087   initializeAppendedLists(dynamic);
00088   copyListsFrom(rhs);
00089 }
00090 
00091 InstantiationInformation::~InstantiationInformation() {
00092   freeAppendedLists();
00093 }
00094 
00095 InstantiationInformation& InstantiationInformation::operator=(const InstantiationInformation& rhs) {
00096   previousInstantiationInformation = rhs.previousInstantiationInformation;
00097   copyListsFrom(rhs);
00098   return *this;
00099 }
00100 
00101 bool InstantiationInformation::operator==(const InstantiationInformation& rhs) const {
00102   if(!(previousInstantiationInformation == rhs.previousInstantiationInformation))
00103     return false;
00104   return listsEqual(rhs);
00105 }
00106 
00107 uint InstantiationInformation::hash() const {
00108   uint ret = 0;
00109   FOREACH_FUNCTION(const IndexedType& param, templateParameters) {
00110     ret = (ret + param.hash()) * 117;
00111   }
00112 
00113   return (ret + previousInstantiationInformation.index()) * 31;
00114 }
00115 
00116 AbstractRepositoryManager* returnTypeRepository() {
00117   return typeRepositoryManager();
00118 }
00119 
00120 KDevelop::RepositoryManager<KDevelop::ItemRepository<InstantiationInformation, AppendedListItemRequest<InstantiationInformation> > > instantiationInformationRepository("Instantiation Information Repository", 1, &returnTypeRepository);
00121 
00122 const uint standardInstantiationInformationIndex = instantiationInformationRepository->index( InstantiationInformation() );
00123 
00124 IndexedInstantiationInformation::IndexedInstantiationInformation() : m_index(0) {
00125 }
00126 
00127 IndexedInstantiationInformation::IndexedInstantiationInformation(uint index) : m_index(index) {
00128   if(m_index == standardInstantiationInformationIndex)
00129     m_index = 0;
00130   
00131   if(m_index && shouldDoDUChainReferenceCounting(this))
00132   {
00133     QMutexLocker lock(instantiationInformationRepository->mutex());
00134     increase(instantiationInformationRepository->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
00135   }
00136 }
00137 
00138 IndexedInstantiationInformation::IndexedInstantiationInformation(const IndexedInstantiationInformation& rhs) : m_index(rhs.m_index) {
00139   if(m_index && shouldDoDUChainReferenceCounting(this))
00140   {
00141     QMutexLocker lock(instantiationInformationRepository->mutex());
00142     increase(instantiationInformationRepository->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
00143   }
00144 }
00145 
00146 IndexedInstantiationInformation& IndexedInstantiationInformation::operator=(const IndexedInstantiationInformation& rhs) {
00147 
00148   if(m_index && shouldDoDUChainReferenceCounting(this))
00149   {
00150     QMutexLocker lock(instantiationInformationRepository->mutex());
00151     decrease(instantiationInformationRepository->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
00152   }
00153   
00154   m_index = rhs.m_index;
00155   
00156   if(m_index && shouldDoDUChainReferenceCounting(this))
00157   {
00158     QMutexLocker lock(instantiationInformationRepository->mutex());
00159     increase(instantiationInformationRepository->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
00160   }
00161   return *this;
00162 }
00163 
00164 IndexedInstantiationInformation::~IndexedInstantiationInformation() {
00165   if(m_index && shouldDoDUChainReferenceCounting(this))
00166   {
00167     QMutexLocker lock(instantiationInformationRepository->mutex());
00168     decrease(instantiationInformationRepository->dynamicItemFromIndexSimple(m_index)->m_refCount, m_index);
00169   }
00170 }
00171 
00172 bool IndexedInstantiationInformation::isValid() const {
00173   return m_index;
00174 }
00175 
00176 const InstantiationInformation& IndexedInstantiationInformation::information() const {
00177   return *instantiationInformationRepository->itemFromIndex(m_index ? m_index : standardInstantiationInformationIndex);
00178 }
00179 
00180 IndexedInstantiationInformation InstantiationInformation::indexed() const {
00181   return IndexedInstantiationInformation(instantiationInformationRepository->index(*this));
00182 }
00183 }

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