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

kdevelop/kdevplatform/language/duchain

  • extragear
  • kdevelop
  • kdevelop
  • kdevplatform
  • language
  • duchain
declarationid.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 "declarationid.h"
20 
21 #include "ducontext.h"
22 #include "topducontext.h"
23 #include "duchain.h"
24 #include "declaration.h"
25 #include "persistentsymboltable.h"
26 #include "instantiationinformation.h"
27 
28 #include <util/convenientfreelist.h>
29 
30 namespace KDevelop {
31 DeclarationId::DeclarationId(const IndexedQualifiedIdentifier& id, uint additionalId,
32  const IndexedInstantiationInformation& specialization)
33  : m_indirectData{id, additionalId}
34  , m_isDirect(false)
35  , m_specialization(specialization)
36 {
37 }
38 
39 DeclarationId::DeclarationId(const IndexedDeclaration& decl,
40  const IndexedInstantiationInformation& specialization)
41  : m_directData(decl)
42  , m_isDirect(true)
43  , m_specialization(specialization)
44 {
45 }
46 
47 DeclarationId::DeclarationId(const DeclarationId& rhs)
48  : m_isDirect(rhs.m_isDirect)
49  , m_specialization(rhs.m_specialization)
50 {
51  if (!m_isDirect) {
52  // IndexedQualifiedIdentifier doesn't like zero-initialization...
53  new (&m_indirectData.identifier) IndexedQualifiedIdentifier(rhs.m_indirectData.identifier);
54  m_indirectData.additionalIdentity = rhs.m_indirectData.additionalIdentity;
55  } else {
56  m_directData = rhs.m_directData;
57  }
58 }
59 
60 DeclarationId::~DeclarationId()
61 {
62  if (!m_isDirect) {
63  m_indirectData.~Indirect();
64  }
65 }
66 
67 DeclarationId& DeclarationId::operator=(const DeclarationId& rhs)
68 {
69  if (&rhs == this)
70  return *this;
71 
72  m_isDirect = rhs.m_isDirect;
73  m_specialization = rhs.m_specialization;
74  if (!m_isDirect) {
75  m_indirectData = rhs.m_indirectData;
76  } else {
77  m_directData = rhs.m_directData;
78  }
79  return *this;
80 }
81 
82 bool DeclarationId::isDirect() const
83 {
84  return m_isDirect;
85 }
86 
87 void DeclarationId::setSpecialization(const IndexedInstantiationInformation& spec)
88 {
89  m_specialization = spec;
90 }
91 
92 IndexedInstantiationInformation DeclarationId::specialization() const
93 {
94  return m_specialization;
95 }
96 
97 KDevVarLengthArray<Declaration*> DeclarationId::declarations(const TopDUContext* top) const
98 {
99  KDevVarLengthArray<Declaration*> ret;
100 
101  if (m_isDirect == false) {
102  //Find the declaration by its qualified identifier and additionalIdentity
103  QualifiedIdentifier id(m_indirectData.identifier);
104 
105  if (top) {
106  //Do filtering
107  PersistentSymbolTable::FilteredDeclarationIterator filter =
108  PersistentSymbolTable::self().filteredDeclarations(id, top->recursiveImportIndices());
109  for (; filter; ++filter) {
110  Declaration* decl = filter->data();
111  if (decl && m_indirectData.additionalIdentity == decl->additionalIdentity()) {
112  //Hit
113  ret.append(decl);
114  }
115  }
116  } else {
117  //Just accept anything
118  PersistentSymbolTable::Declarations decls = PersistentSymbolTable::self().declarations(id);
119  PersistentSymbolTable::Declarations::Iterator decl = decls.iterator();
120  for (; decl; ++decl) {
121  const IndexedDeclaration& iDecl(*decl);
122 
124  //Don't trigger loading of top-contexts from here, it will create a lot of problems
125  if ((!DUChain::self()->isInMemory(iDecl.topContextIndex())))
126  continue;
127 
128  Declaration* decl = iDecl.data();
129  if (decl && m_indirectData.additionalIdentity == decl->additionalIdentity()) {
130  //Hit
131  ret.append(decl);
132  }
133  }
134  }
135  } else {
136  Declaration* decl = m_directData.declaration();
137  if (decl)
138  ret.append(decl);
139  }
140 
141  if (!ret.isEmpty() && m_specialization.index()) {
142  KDevVarLengthArray<Declaration*> newRet;
143  for (Declaration* decl : qAsConst(ret)) {
144  Declaration* specialized = decl->specialize(m_specialization, top ? top : decl->topContext());
145  if (specialized)
146  newRet.append(specialized);
147  }
148 
149  return newRet;
150  }
151  return ret;
152 }
153 
154 Declaration* DeclarationId::declaration(const TopDUContext* top, bool instantiateIfRequired) const
155 {
156  Declaration* ret = nullptr;
157 
158  if (m_isDirect == false) {
159  //Find the declaration by its qualified identifier and additionalIdentity
160  QualifiedIdentifier id(m_indirectData.identifier);
161 
162  if (top) {
163  //Do filtering
164  PersistentSymbolTable::FilteredDeclarationIterator filter =
165  PersistentSymbolTable::self().filteredDeclarations(id, top->recursiveImportIndices());
166  for (; filter; ++filter) {
167  Declaration* decl = filter->data();
168  if (decl && m_indirectData.additionalIdentity == decl->additionalIdentity()) {
169  //Hit
170  ret = decl;
171  if (!ret->isForwardDeclaration())
172  break;
173  }
174  }
175  } else {
176  //Just accept anything
177  PersistentSymbolTable::Declarations decls = PersistentSymbolTable::self().declarations(id);
178  PersistentSymbolTable::Declarations::Iterator decl = decls.iterator();
179  for (; decl; ++decl) {
180  const IndexedDeclaration& iDecl(*decl);
181 
183  //Don't trigger loading of top-contexts from here, it will create a lot of problems
184  if ((!DUChain::self()->isInMemory(iDecl.topContextIndex())))
185  continue;
186 
187  Declaration* decl = iDecl.data();
188  if (decl && m_indirectData.additionalIdentity == decl->additionalIdentity()) {
189  //Hit
190  ret = decl;
191  if (!ret->isForwardDeclaration())
192  break;
193  }
194  }
195  }
196  } else {
197  //Find the declaration by m_topContext and m_declaration
198  ret = m_directData.declaration();
199  }
200 
201  if (ret) {
202  if (m_specialization.isValid()) {
203  const TopDUContext* topContextForSpecialization = top;
204  if (!instantiateIfRequired)
205  topContextForSpecialization = nullptr; //If we don't want to instantiate new declarations, set the top-context to zero, so specialize(..) will only look-up
206  else if (!topContextForSpecialization)
207  topContextForSpecialization = ret->topContext();
208 
209  return ret->specialize(m_specialization, topContextForSpecialization);
210  } else {
211  return ret;
212  }
213  } else
214  return nullptr;
215 }
216 
217 QualifiedIdentifier DeclarationId::qualifiedIdentifier() const
218 {
219  if (!m_isDirect) {
220  QualifiedIdentifier baseIdentifier = m_indirectData.identifier.identifier();
221  if (!m_specialization.index())
222  return baseIdentifier;
223  return m_specialization.information().applyToIdentifier(baseIdentifier);
224  } else {
225  Declaration* decl = declaration(nullptr);
226  if (decl)
227  return decl->qualifiedIdentifier();
228 
229  return QualifiedIdentifier(i18n("(unknown direct declaration)"));
230  }
231 
232  return QualifiedIdentifier(i18n("(missing)")) + m_indirectData.identifier.identifier();
233 }
234 }
KDevelop::Declaration
Represents a single declaration in a definition-use chain.
Definition: declaration.h:51
KDevelop::DeclarationId::isDirect
bool isDirect() const
Determine whether this DeclarationId directly references a Declaration by indices, or if it uses identifiers and other data to reference the Declaration.
Definition: declarationid.cpp:82
KDevelop::IndexedDeclaration::declaration
Declaration * declaration() const
Definition: indexeddeclaration.cpp:44
KDevelop::DeclarationId::declaration
Declaration * declaration(const TopDUContext *context, bool instantiateIfRequired=true) const
Retrieve the declaration, from the perspective of context.
Definition: declarationid.cpp:154
KDevelop::DeclarationId::declarations
KDevVarLengthArray< Declaration * > declarations(const TopDUContext *context) const
Same as declaration(..), but returns all matching declarations if there are multiple.
Definition: declarationid.cpp:97
KDevelop::Declaration::isForwardDeclaration
virtual bool isForwardDeclaration() const
Determine whether this declaration is a forward declaration.
Definition: declaration.cpp:653
KDevelop::DeclarationId::setSpecialization
void setSpecialization(const IndexedInstantiationInformation &spec)
Set the specialization index (see class documentation).
Definition: declarationid.cpp:87
KDevelop::PersistentSymbolTable::filteredDeclarations
FilteredDeclarationIterator filteredDeclarations(const IndexedQualifiedIdentifier &id, const TopDUContext::IndexedRecursiveImports &visibility) const
Retrieves an iterator to all declarations of the given id, filtered by the visibility given through v...
Definition: persistentsymboltable.cpp:318
duchain.h
KDevelop::TopDUContext
The top context in a definition-use chain for one source file.
Definition: topducontext.h:113
KDevelop::IndexedDeclaration
Represents a declaration only by its global indices.
Definition: indexeddeclaration.h:33
KDevelop::PersistentSymbolTable::self
static PersistentSymbolTable & self()
Definition: persistentsymboltable.cpp:486
KDevelop::IndexedQualifiedIdentifier
A helper-class to store an identifier by index in a type-safe way.
Definition: identifier.h:95
instantiationinformation.h
KDevelop::DeclarationId::~DeclarationId
~DeclarationId()
Definition: declarationid.cpp:60
KDevelop::PersistentSymbolTable::Declarations
ConstantConvenientEmbeddedSet< IndexedDeclaration, IndexedDeclarationHandler > Declarations
Definition: persistentsymboltable.h:128
KDevelop::Declaration::additionalIdentity
virtual uint additionalIdentity() const
This hash-value should differentiate between multiple different declarations that have the same quali...
Definition: declaration.cpp:663
KDevelop::DeclarationId::specialization
IndexedInstantiationInformation specialization() const
Retrieve the specialization index (see class documentation).
Definition: declarationid.cpp:92
KDevelop::Declaration::topContext
TopDUContext * topContext() const override
Determine the top context to which this object belongs.
Definition: declaration.cpp:636
KDevelop::DUChain::self
static DUChain * self()
Returns the global static instance.
Definition: duchain.cpp:1219
declaration.h
KDevelop::DeclarationId::DeclarationId
DeclarationId(const IndexedQualifiedIdentifier &id=IndexedQualifiedIdentifier(), uint additionalId=0, const IndexedInstantiationInformation &specialization=IndexedInstantiationInformation())
Constructor for indirect access to a declaration.
Definition: declarationid.cpp:31
KDevelop::DeclarationId::operator=
DeclarationId & operator=(const DeclarationId &rhs)
Definition: declarationid.cpp:67
KDevelop::TopDUContext::recursiveImportIndices
const IndexedRecursiveImports & recursiveImportIndices() const
Returns the set of all recursively imported top-contexts.
Definition: topducontext.cpp:384
ducontext.h
KDevelop::PersistentSymbolTable::declarations
void declarations(const IndexedQualifiedIdentifier &id, uint &count, const IndexedDeclaration *&declarations) const
Retrieves all the declarations for a given IndexedQualifiedIdentifier in an efficient way...
Definition: persistentsymboltable.cpp:391
KDevVarLengthArray
KDevelop::TopDUContext::topContext
TopDUContext * topContext() const override
Find the top context.
Definition: topducontext.cpp:950
KDevelop::QualifiedIdentifier
Represents a qualified identifier.
Definition: identifier.h:245
KDevelop::IndexedDeclaration::data
Declaration * data() const
Definition: indexeddeclaration.h:47
KDevelop::DeclarationId::m_directData
IndexedDeclaration m_directData
Definition: declarationid.h:195
topducontext.h
KDevelop::DeclarationId
Allows clearly identifying a Declaration.
Definition: declarationid.h:50
KDevelop::Declaration::qualifiedIdentifier
QualifiedIdentifier qualifiedIdentifier() const
Determine the global qualified identifier of this declaration.
Definition: declaration.cpp:267
KDevelop::IndexedDeclaration::topContextIndex
uint topContextIndex() const
Definition: indexeddeclaration.h:88
KDevelop::Declaration::specialize
virtual Declaration * specialize(const IndexedInstantiationInformation &specialization, const TopDUContext *topContext, int upDistance=0)
Retrieve the declaration which is specialized with the given specialization index as seen from topCon...
Definition: declaration.cpp:259
persistentsymboltable.h
KDevelop::DeclarationId::qualifiedIdentifier
QualifiedIdentifier qualifiedIdentifier() const
Return the qualified identifier for this declaration.
Definition: declarationid.cpp:217
KDevelop::IndexedInstantiationInformation
KDEVPLATFORMLANGUAGE_EXPORT DECLARE_LIST_MEMBER_HASH(InstantiationInformation, templateParameters, IndexedType) class KDEVPLATFORMLANGUAGE_EXPORT IndexedInstantiationInformation IndexedInstantiationInformation(uint index)
KDevelop::PersistentSymbolTable::FilteredDeclarationIterator
ConvenientEmbeddedSetTreeFilterIterator< IndexedDeclaration, IndexedDeclarationHandler, IndexedTopDUContext, CachedIndexedRecursiveImports, DeclarationTopContextExtractor > FilteredDeclarationIterator
Definition: persistentsymboltable.h:142
KDevelop::DeclarationId::m_indirectData
Indirect m_indirectData
Definition: declarationid.h:194
declarationid.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Dec 9 2019 02:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevelop/kdevplatform/language/duchain

Skip menu "kdevelop/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