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

language/duchain

classdeclaration.cpp

00001 /* This file is part of KDevelop
00002     Copyright 2007 David Nolden <david.nolden@kdevelop.org>
00003     Copyright 2009 Lior Mualem <lior.m.kde@gmail.com>
00004     
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "classdeclaration.h"
00021 #include <language/duchain/identifier.h>
00022 #include <language/duchain/declaration.h>
00023 #include <language/duchain/appendedlist.h>
00024 #include <language/duchain/duchainregister.h>
00025 
00026 
00027 namespace KDevelop {
00028 
00029 DEFINE_LIST_MEMBER_HASH(ClassDeclarationData, baseClasses, BaseClassInstance)
00030 
00031 
00032 ClassDeclaration::ClassDeclaration(const KDevelop::SimpleRange& range, DUContext* context)
00033   : ClassMemberDeclaration(*new ClassDeclarationData, range)
00034 {
00035   d_func_dynamic()->setClassId(this);
00036   setContext(context);
00037 }
00038 
00039 ClassDeclaration::ClassDeclaration( ClassDeclarationData& data, const KDevelop::SimpleRange& range, DUContext* context )
00040   : ClassMemberDeclaration( data, range )
00041 {
00042   setContext(context);
00043 }
00044 
00045 ClassDeclaration::ClassDeclaration(ClassDeclarationData& data)
00046   : ClassMemberDeclaration(data)
00047 {
00048 }
00049 
00050 REGISTER_DUCHAIN_ITEM(ClassDeclaration);
00051 
00052 void ClassDeclaration::clearBaseClasses() {
00053   d_func_dynamic()->baseClassesList().clear();
00054 }
00055 
00056 uint ClassDeclaration::baseClassesSize() const {
00057   return d_func()->baseClassesSize();
00058 }
00059 
00060 const BaseClassInstance* ClassDeclaration::baseClasses() const {
00061   return d_func()->baseClasses();
00062 }
00063 
00064 void ClassDeclaration::addBaseClass(BaseClassInstance klass) {
00065   d_func_dynamic()->baseClassesList().append(klass);
00066 }
00067 
00068 void ClassDeclaration::replaceBaseClass(uint n, BaseClassInstance klass) {
00069   Q_ASSERT(n <= d_func()->baseClassesSize());
00070   d_func_dynamic()->baseClassesList()[n] = klass;
00071 }
00072 
00073 ClassDeclaration::~ClassDeclaration()
00074 {
00075 }
00076 
00077 ClassDeclaration::ClassDeclaration(const ClassDeclaration& rhs) : ClassMemberDeclaration(*new ClassDeclarationData(*rhs.d_func())) {
00078   d_func_dynamic()->setClassId(this);
00079 }
00080 
00081 Declaration* ClassDeclaration::clonePrivate() const {
00082   return new ClassDeclaration(*this);
00083 }
00084 
00085 bool ClassDeclaration::isPublicBaseClass( ClassDeclaration* base, const KDevelop::TopDUContext* topContext, int* baseConversionLevels ) const {
00086   if( baseConversionLevels )
00087     *baseConversionLevels = 0;
00088 
00089   if( indexedType() == base->indexedType() )
00090     return true;
00091 
00092   FOREACH_FUNCTION(const BaseClassInstance& b, baseClasses)
00093   {
00094     if( baseConversionLevels )
00095       ++ (*baseConversionLevels);
00096     //kDebug(9007) << "public base of" << c->toString() << "is" << b.baseClass->toString();
00097     if( b.access != KDevelop::Declaration::Private ) {
00098       int nextBaseConversion = 0;
00099       if( StructureType::Ptr c = b.baseClass.type<StructureType>() ) {
00100         ClassDeclaration* decl = dynamic_cast<ClassDeclaration*>(c->declaration(topContext));
00101         if( decl && decl->isPublicBaseClass( base, topContext, &nextBaseConversion ) ) {
00102           if ( baseConversionLevels )
00103             *baseConversionLevels += nextBaseConversion;
00104           return true;
00105         }
00106       }
00107     }
00108     if( baseConversionLevels )
00109       -- (*baseConversionLevels);
00110   }
00111   return false;
00112 }
00113 
00114 QString ClassDeclaration::toString() const {
00115   QString ret;
00116   switch ( classModifier() ) {
00117     case ClassDeclarationData::None:
00118       //nothing
00119       break;
00120     case ClassDeclarationData::Abstract:
00121       ret += "abstract ";
00122       break;
00123     case ClassDeclarationData::Final:
00124       ret += "final ";
00125       break;
00126   }
00127   switch ( classType() ) {
00128     case ClassDeclarationData::Class:
00129       ret += "class ";
00130       break;
00131     case ClassDeclarationData::Interface:
00132       ret += "interface ";
00133       break;
00134     case ClassDeclarationData::Union:
00135       ret += "union ";
00136       break;
00137     case ClassDeclarationData::Struct:
00138       ret += "struct ";
00139       break;
00140   }
00141   return ret + identifier().toString();
00142 }
00143 
00144 ClassDeclarationData::ClassType ClassDeclaration::classType() const {
00145   return d_func()->m_classType;
00146 }
00147 
00148 void ClassDeclaration::setClassType(ClassDeclarationData::ClassType type) {
00149   d_func_dynamic()->m_classType = type;
00150 }
00151 
00152 ClassDeclarationData::ClassModifier ClassDeclaration::classModifier() const {
00153   return d_func()->m_classModifier;
00154 }
00155 
00156 void ClassDeclaration::setClassModifier(ClassDeclarationData::ClassModifier modifier) {
00157   d_func_dynamic()->m_classModifier = modifier;
00158 }
00159 
00160 
00161 /*
00162 class TBase
00163 {
00164   public:
00165     void DoSomething();
00166 };
00167 
00168 template<class T>
00169 class Deriv : public T
00170 {
00171   public:
00172     void DoSomethingElse();
00173 };
00174 
00175 void F()
00176 {
00177   Deriv<TBase> g;
00178   g.DoSomethingElse();
00179 }
00180 */
00181 }

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