• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/language/duchain

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • language
  • duchain
functiondefinition.cpp
Go to the documentation of this file.
1 /* This file is part of KDevelop
2  Copyright 2008 David Nolden <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17  */
18 
19 #include "functiondefinition.h"
20 #include "duchainregister.h"
21 #include "definitions.h"
22 
23 namespace KDevelop {
24 REGISTER_DUCHAIN_ITEM(FunctionDefinition);
25 
26 FunctionDefinition::FunctionDefinition(FunctionDefinitionData& data) : FunctionDeclaration(data)
27 {
28 }
29 
30 FunctionDefinition::FunctionDefinition(const RangeInRevision& range, DUContext* context)
31  : FunctionDeclaration(*new FunctionDefinitionData, range)
32 {
33  d_func_dynamic()->setClassId(this);
34  setDeclarationIsDefinition(true);
35  if (context)
36  setContext(context);
37 }
38 
39 FunctionDefinition::FunctionDefinition(const FunctionDefinition& rhs) : FunctionDeclaration(*new FunctionDefinitionData(
40  *rhs.d_func()))
41 {
42 }
43 
44 FunctionDefinition::~FunctionDefinition()
45 {
46  if (!topContext()->isOnDisk())
47  DUChain::definitions()->removeDefinition(d_func()->m_declaration, this);
48 }
49 
50 Declaration* FunctionDefinition::declaration(const TopDUContext* topContext) const
51 {
52  ENSURE_CAN_READ
53 
54  const KDevVarLengthArray<Declaration*> declarations = d_func()->m_declaration.declarations(
55  topContext ? topContext : this->topContext());
56 
57  for (Declaration* decl : declarations) {
58  if (!dynamic_cast<FunctionDefinition*>(decl))
59  return decl;
60  }
61 
62  return nullptr;
63 }
64 
65 bool FunctionDefinition::hasDeclaration() const
66 {
67  return d_func()->m_declaration.isValid();
68 }
69 
70 void FunctionDefinition::setDeclaration(Declaration* declaration)
71 {
72  ENSURE_CAN_WRITE
73 
74  if (declaration) {
75  DUChain::definitions()->addDefinition(declaration->id(), this);
76  d_func_dynamic()->m_declaration = declaration->id();
77  } else {
78  if (d_func()->m_declaration.isValid()) {
79  DUChain::definitions()->removeDefinition(d_func()->m_declaration, this);
80  d_func_dynamic()->m_declaration = DeclarationId();
81  }
82  }
83 }
84 
85 Declaration* FunctionDefinition::definition(const Declaration* decl)
86 {
87  ENSURE_CHAIN_READ_LOCKED
88  if (!decl) {
89  return nullptr;
90  }
91 
92  if (decl->isFunctionDeclaration() && decl->isDefinition()) {
93  return const_cast<Declaration*>(decl);
94  }
95 
96  const KDevVarLengthArray<IndexedDeclaration> allDefinitions = DUChain::definitions()->definitions(decl->id());
97  for (const IndexedDeclaration decl : allDefinitions) {
98  if (decl.data())
99  return decl.data();
100  }
101 
102  return nullptr;
103 }
104 
105 Declaration* FunctionDefinition::clonePrivate() const
106 {
107  return new FunctionDefinition(*new FunctionDefinitionData(*d_func()));
108 }
109 }
KDevelop::Definitions::addDefinition
void addDefinition(const DeclarationId &id, const IndexedDeclaration &definition)
Assigns.
Definition: definitions.cpp:180
KDevelop::FunctionDefinition::declaration
Declaration * declaration(const TopDUContext *topContext=nullptr) const
Find the declaration for this definition, if one exists.
Definition: functiondefinition.cpp:50
KDevelop::FunctionDefinition::hasDeclaration
bool hasDeclaration() const
Returns true if a Declaration has been assigned to this Definition.
Definition: functiondefinition.cpp:65
KDevelop::REGISTER_DUCHAIN_ITEM
REGISTER_DUCHAIN_ITEM(AliasDeclaration)
KDevelop::Definitions::removeDefinition
void removeDefinition(const DeclarationId &id, const IndexedDeclaration &definition)
Definition: definitions.cpp:207
KDevelop::Declaration::isFunctionDeclaration
virtual bool isFunctionDeclaration() const
Determine whether this declaration is a function declaration.
Definition: declaration.cpp:655
KDevelop::Declaration
Represents a single declaration in a definition-use chain.
Definition: declaration.h:51
ENSURE_CHAIN_READ_LOCKED
#define ENSURE_CHAIN_READ_LOCKED
Macros for ensuring the DUChain is locked properly.
Definition: duchainlock.h:37
KDevelop::IndexedDeclaration
Represents a declaration only by its global indices.
Definition: indexeddeclaration.h:33
ENSURE_CAN_WRITE
#define ENSURE_CAN_WRITE
Like the ENSURE_CHAIN_WRITE_LOCKED and .._READ_LOCKED, except that this should be used in items that ...
Definition: duchainlock.h:184
KDevelop::FunctionDefinition
A FunctionDefinition represents a function-definition that is assigned to a separate function-declara...
Definition: functiondefinition.h:35
KDevVarLengthArray
KDevelop::DUChain::definitions
static Definitions * definitions()
Returns the structure that manages mapping between definitions and declarations.
Definition: duchain.cpp:1694
KDevelop::TopDUContext
The top context in a definition-use chain for one source file.
Definition: topducontext.h:113
KDevelop::DeclarationId
Allows clearly identifying a Declaration.
Definition: declarationid.h:50
definitions.h
KDevelop::Declaration::id
virtual DeclarationId id(bool forceDirect=false) const
Definition: declaration.cpp:564
KDevelop::Definitions::definitions
KDevVarLengthArray< IndexedDeclaration > definitions(const DeclarationId &id) const
Gets all the known definitions assigned to id.
Definition: definitions.cpp:233
functiondefinition.h
KDevelop::FunctionDefinition::setDeclaration
void setDeclaration(Declaration *declaration)
Attaches this definition to the given declaration persistently.
Definition: functiondefinition.cpp:70
KDevelop::FunctionDefinitionData
Definition: functiondefinition.h:25
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
KDevelop::DUContext
A single context in source code, represented as a node in a directed acyclic graph.
Definition: ducontext.h:72
KDevelop::FunctionDeclaration
Definition: functiondeclaration.h:62
KDevelop::FunctionDefinition::definition
static Declaration * definition(const Declaration *decl)
Find the definition for the given declaration, if one exists.
Definition: functiondefinition.cpp:85
ENSURE_CAN_READ
#define ENSURE_CAN_READ
Definition: duchainlock.h:185
duchainregister.h
KDevelop::FunctionDefinition::~FunctionDefinition
~FunctionDefinition() override
Definition: functiondefinition.cpp:44
KDevelop::FunctionDefinition::FunctionDefinition
FunctionDefinition(const RangeInRevision &range, DUContext *context)
Definition: functiondefinition.cpp:30
KDevelop::Declaration::isDefinition
bool isDefinition() const
Determine whether this declaration is also a definition.
Definition: declaration.cpp:472
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Mar 4 2021 23:31:17 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/language/duchain

Skip menu "kdevplatform/language/duchain"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal