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

language/duchain

forwarddeclaration.cpp

00001 /* This file is part of KDevelop
00002     Copyright 2006 Hamish Rodda <rodda@kde.org>
00003     Copyright 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
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 "forwarddeclaration.h"
00021 
00022 #include <ktexteditor/smartrange.h>
00023 #include <ktexteditor/document.h>
00024 #include <klocale.h>
00025 
00026 #include "duchain.h"
00027 #include "duchainlock.h"
00028 #include "ducontext.h"
00029 #include "use.h"
00030 #include "duchainregister.h"
00031 #include "types/identifiedtype.h"
00032 
00033 using namespace KTextEditor;
00034 
00035 namespace KDevelop
00036 {
00037 REGISTER_DUCHAIN_ITEM(ForwardDeclaration);
00038 
00039 ForwardDeclaration::ForwardDeclaration(const ForwardDeclaration& rhs) : Declaration(*new ForwardDeclarationData(*rhs.d_func())) {
00040   setSmartRange(rhs.smartRange(), DocumentRangeObject::DontOwn);
00041 }
00042 
00043 ForwardDeclaration::ForwardDeclaration(ForwardDeclarationData& data) : Declaration(data) {
00044 }
00045 
00046 ForwardDeclaration::ForwardDeclaration(const SimpleRange& range, DUContext* context )
00047   : Declaration(*new ForwardDeclarationData, range)
00048 {
00049   d_func_dynamic()->setClassId(this);
00050   if( context )
00051     setContext( context );
00052 }
00053 
00054 ForwardDeclaration::~ForwardDeclaration()
00055 {
00056 }
00057   
00058 QString ForwardDeclaration::toString() const
00059 {
00060   if(context() )
00061     return qualifiedIdentifier().toString();
00062   else
00063     return i18n("context-free forward-declaration %1", identifier().toString());
00064 }
00065 
00066 Declaration * ForwardDeclaration::resolve(const TopDUContext* topContext) const
00067 {
00068   ENSURE_CAN_READ
00069 
00070   //If we've got a type assigned, that counts as a way of resolution.
00071   AbstractType::Ptr t = abstractType();
00072   IdentifiedType* idType = dynamic_cast<IdentifiedType*>(t.unsafeData());
00073   if( idType  ) {
00074     Declaration* decl = idType->declaration(topContext);
00075     if(decl && !decl->isForwardDeclaration())
00076       return decl;
00077     else
00078       return 0;
00079   }
00080   
00081   if(!topContext)
00082       topContext = this->topContext();
00083   
00084   QualifiedIdentifier globalIdentifier = qualifiedIdentifier();
00085   globalIdentifier.setExplicitlyGlobal(true);
00086 
00087   //We've got to use DUContext::DirectQualifiedLookup so C++ works correctly.
00088   QList<Declaration*> declarations = topContext->findDeclarations(globalIdentifier, SimpleCursor::invalid(), AbstractType::Ptr(), 0, DUContext::DirectQualifiedLookup);
00089 
00090   foreach(Declaration* decl, declarations) {
00091     if( !decl->isForwardDeclaration() )
00092       return decl;
00093   }
00094 
00095   return 0;
00096 }
00097 
00098 DUContext * ForwardDeclaration::logicalInternalContext(const TopDUContext* topContext) const
00099 {
00100   ENSURE_CAN_READ
00101   Declaration* resolved = resolve(topContext);
00102   if(resolved && resolved != this)
00103     return resolved->logicalInternalContext(topContext);
00104   else
00105     return Declaration::logicalInternalContext(topContext);
00106 }
00107 
00108 bool ForwardDeclaration::isForwardDeclaration() const
00109 {
00110   return true;
00111 }
00112 
00113 Declaration* ForwardDeclaration::clonePrivate() const {
00114   return new ForwardDeclaration(*this);
00115 }
00116 
00117 }
00118 
00119 // 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