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

language/duchain

functiondefinition.cpp

00001 /* This file is part of KDevelop
00002     Copyright 2008 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 "functiondefinition.h"
00020 #include "duchainregister.h"
00021 #include "definitions.h"
00022 
00023 namespace KDevelop {
00024 REGISTER_DUCHAIN_ITEM(FunctionDefinition);
00025 
00026 FunctionDefinition::FunctionDefinition(FunctionDefinitionData& data) : FunctionDeclaration(data)
00027 {
00028 }
00029 
00030 FunctionDefinition::FunctionDefinition(const SimpleRange& range, DUContext* context)
00031   : FunctionDeclaration(*new FunctionDefinitionData, range)
00032 {
00033   d_func_dynamic()->setClassId(this);
00034   if( context )
00035     setContext( context );
00036 }
00037 
00038 FunctionDefinition::FunctionDefinition(const FunctionDefinition& rhs) : FunctionDeclaration(*new FunctionDefinitionData(*rhs.d_func())) {
00039 }
00040 
00041 FunctionDefinition::~FunctionDefinition() {
00042   if(!topContext()->isOnDisk())
00043     DUChain::definitions()->removeDefinition(d_func()->m_declaration, this);
00044 }
00045 
00046 Declaration* FunctionDefinition::declaration(TopDUContext* topContext) const
00047 {
00048   ENSURE_CAN_READ
00049   
00050   KDevVarLengthArray<Declaration*> declarations = d_func()->m_declaration.getDeclarations(topContext ? topContext : this->topContext());
00051   
00052   FOREACH_ARRAY(Declaration* decl, declarations) {
00053     if(!dynamic_cast<FunctionDefinition*>(decl))
00054       return decl;
00055   }
00056   
00057   return 0;
00058 }
00059 
00060 bool FunctionDefinition::hasDeclaration() const
00061 {
00062   return d_func()->m_declaration.isValid();
00063 }
00064 
00065 void FunctionDefinition::setDeclaration(Declaration* declaration)
00066 {
00067   ENSURE_CAN_WRITE
00068 
00069   if(declaration) {
00070     DUChain::definitions()->addDefinition(declaration->id(), this);
00071     d_func_dynamic()->m_declaration = declaration->id();
00072   }else{
00073     if(d_func()->m_declaration.isValid()) {
00074       DUChain::definitions()->removeDefinition(d_func()->m_declaration, this);
00075       d_func_dynamic()->m_declaration = DeclarationId();
00076     }
00077   }
00078 }
00079 
00080 FunctionDefinition* FunctionDefinition::definition(const Declaration* decl)
00081 {
00082   ENSURE_CHAIN_READ_LOCKED
00083   KDevVarLengthArray<IndexedDeclaration> allDefinitions = DUChain::definitions()->definitions(decl->id());
00084   FOREACH_ARRAY(IndexedDeclaration decl, allDefinitions) {
00085     if(decl.data()) 
00086       return dynamic_cast<FunctionDefinition*>(decl.data());
00087   }
00088   return 0;
00089 }
00090 
00091 Declaration* FunctionDefinition::clonePrivate() const
00092 {
00093   return new FunctionDefinition(*new FunctionDefinitionData(*d_func()));
00094 }
00095 
00096 }

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