• 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
topducontext.h
Go to the documentation of this file.
1 /* This file is part of KDevelop
2  Copyright 2006 Hamish Rodda <[email protected]>
3  Copyright 2007-2009 David Nolden <[email protected]>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef KDEVPLATFORM_TOPDUCONTEXT_H
21 #define KDEVPLATFORM_TOPDUCONTEXT_H
22 
23 #include "ducontext.h"
24 #include <language/util/setrepository.h>
25 #include <QMetaType>
26 
27 template <class T>
28 class QExplicitlySharedDataPointer;
29 
30 namespace KDevelop {
31 class IAstContainer;
32 class QualifiedIdentifier;
33 class DUChain;
34 class ParsingEnvironmentFile;
35 class TopDUContextData;
36 class TopDUContextLocalPrivate;
37 class IndexedTopDUContext;
38 // class TopDUContextDynamicData;
39 class Problem;
40 class DeclarationChecker;
41 class TopDUContext;
42 
43 struct KDEVPLATFORMLANGUAGE_EXPORT RecursiveImportRepository
44 {
45  static Utils::BasicSetRepository* repository();
46 };
47 
51 using RecursiveImports = QHash<const TopDUContext*, QPair<int, const TopDUContext*>>;
52 
53 using TopDUContextPointer = DUChainPointer<TopDUContext>;
54 
55 using ProblemPointer = QExplicitlySharedDataPointer<Problem>;
56 
59 class KDEVPLATFORMLANGUAGE_EXPORT ReferencedTopDUContext
60 {
61 public:
62  ReferencedTopDUContext(TopDUContext* context = nullptr);
63  ReferencedTopDUContext(const ReferencedTopDUContext& rhs);
64  ~ReferencedTopDUContext();
65 
66  ReferencedTopDUContext& operator=(const ReferencedTopDUContext& rhs);
67 
68  inline TopDUContext* data() const
69  {
70  return m_topContext;
71  }
72 
73  inline operator TopDUContext*() const {
74  return m_topContext;
75  }
76 
77  inline bool operator==(const ReferencedTopDUContext& rhs) const
78  {
79  return m_topContext == rhs.m_topContext;
80  }
81 
82  inline bool operator!=(const ReferencedTopDUContext& rhs) const
83  {
84  return m_topContext != rhs.m_topContext;
85  }
86 
87  inline TopDUContext* operator->() const
88  {
89  return m_topContext;
90  }
91 
92  inline uint hash() const
93  {
94  return ( uint )((( quint64 )m_topContext) * 37);
95  }
96 
97 private:
98  TopDUContext* m_topContext;
99 };
100 
113 class KDEVPLATFORMLANGUAGE_EXPORT TopDUContext
114  : public DUContext
115 {
116 public:
117  explicit TopDUContext(const IndexedString& url, const RangeInRevision& range,
118  ParsingEnvironmentFile* file = nullptr);
119  explicit TopDUContext(TopDUContextData& data);
120 
121  TopDUContext& operator=(const TopDUContext& rhs) = delete;
122 
123  TopDUContext* topContext() const override;
124 
126  IndexedTopDUContext indexed() const;
127 
128  uint ownIndex() const;
129 
130  IndexedString url() const override;
131 
136  QExplicitlySharedDataPointer<ParsingEnvironmentFile> parsingEnvironmentFile() const;
137 
139  bool deleting() const;
140 
142  bool inDUChain() const override;
144  void setInDuChain(bool);
145 
147  bool isOnDisk() const;
148 
153  QList<ProblemPointer> problems() const;
154 
160  void addProblem(const ProblemPointer& problem);
161 
167  void clearProblems();
168 
174  void setProblems(const QList<ProblemPointer>& pointers);
175 
184  bool imports(const DUContext* origin, const CursorInRevision& position) const override;
185 
186  enum {
187  Identity = 4
188  };
189 
190  enum Feature : quint16 {
192  Empty = 0, //Only the top-context structure (imports etc.) is built, but no declarations and no contexts
193  SimplifiedVisibleDeclarationsAndContexts = 2, //The top-context should only contain publically simplified accessible declarations and contexts, without doing type look-up,
194  //without extended information like function-argument declarations, etc., imported contexts can be parsed with 'Empty' features
195  //This flag essentially leads to a ctags-like processing level.
196  VisibleDeclarationsAndContexts = SimplifiedVisibleDeclarationsAndContexts + 4, //Default: The top-context should only contain publically accessible declarations and contexts
197  AllDeclarationsAndContexts = VisibleDeclarationsAndContexts + 8, //The top-context should also contain non-public declarations and contexts, but no uses
198  AllDeclarationsContextsAndUses = 16 + AllDeclarationsAndContexts, //The top-context should contain uses and all declarations + contexts
199  AST = 32, //Signalizes that the ast() should be filled
200  AllDeclarationsContextsUsesAndAST = AST | AllDeclarationsContextsAndUses, //Convenience flag, combining AST and AllDeclarationsContextsAndUses
201 
203  Recursive = 64, //Request the given features on all recursively imported contexts. Only the features are applied recursively (including AST)
204  ForceUpdate = 128, //Enforce updating the top-context
205  ForceUpdateRecursive = ForceUpdate | 256, //Enforce updating the top-context and all its imports
206 
208  LastFeature = 512
209  };
210  Q_DECLARE_FLAGS(Features, Feature)
211 
212 
213  Features features() const;
215  void setFeatures(Features);
216 
225  int indexForUsedDeclaration(Declaration* declaration, bool create = true);
226 
231  Declaration* usedDeclarationForIndex(unsigned int declarationIndex) const;
232 
240  void clearUsedDeclarationIndices();
241 
245  void deleteUsesRecursively() override;
246 
255  QExplicitlySharedDataPointer<IAstContainer> ast() const;
256 
260  void setAst(const QExplicitlySharedDataPointer<IAstContainer>& ast);
261 
265  void clearAst();
266 
270  void addImportedParentContext(DUContext* context,
271  const CursorInRevision& position = CursorInRevision(), bool anonymous = false,
272  bool temporary = false) override;
277  virtual void addImportedParentContexts(const QVector<QPair<TopDUContext*, CursorInRevision>>& contexts,
278  bool temporary = false);
279 
281  void removeImportedParentContext(DUContext* context) override;
284  virtual void removeImportedParentContexts(const QList<TopDUContext*>& contexts);
285 
287  void clearImportedParentContexts() override;
288 
289  using IndexedRecursiveImports = Utils::StorableSet<IndexedTopDUContext, IndexedTopDUContextIndexConversion, RecursiveImportRepository,
290  true>;
291 
292  QVector<Import> importedParentContexts() const override;
293 
294  QVector<DUContext*> importers() const override;
295 
297  virtual QList<DUContext*> loadedImporters() const;
298 
299  CursorInRevision importPosition(const DUContext* target) const override;
300 
303  const IndexedRecursiveImports& recursiveImportIndices() const;
304 
318  void updateImportsCache();
319 
320  bool usingImportsCache() const;
321 
322  bool findDeclarationsInternal(const SearchItem::PtrList& identifiers, const CursorInRevision& position,
323  const AbstractType::Ptr& dataType, DeclarationList& ret, const TopDUContext* source,
324  SearchFlags flags, uint depth) const override;
325 
326 protected:
327  void setParsingEnvironmentFile(ParsingEnvironmentFile*);
328 
334  template <class Acceptor>
335  void applyAliases(const SearchItem::PtrList& identifiers, Acceptor& accept, const CursorInRevision& position,
336  bool canBeNamespace) const;
337 
338 protected:
339  ~TopDUContext() override;
340 
341  void clearFeaturesSatisfied();
342  void rebuildDynamicData(DUContext* parent, uint ownIndex) override;
343  //Must be called after all imported top-contexts were loaded into the du-chain
344  void rebuildDynamicImportStructure();
345 
346  struct AliasChainElement;
347  struct FindDeclarationsAcceptor;
348  struct DeclarationChecker;
349  struct ApplyAliasesBuddyInfo;
350 
351  template <class Acceptor>
352  bool applyAliases(const QualifiedIdentifier& previous, const SearchItem::Ptr& identifier, Acceptor& acceptor,
353  const CursorInRevision& position, bool canBeNamespace, ApplyAliasesBuddyInfo* buddy,
354  uint recursionDepth) const;
355  //Same as imports, without the slow access-check, for internal usage
356  bool importsPrivate(const DUContext* origin, const CursorInRevision& position) const;
357  DUCHAIN_DECLARE_DATA(TopDUContext)
358 
359 
360  void deleteSelf();
361 
362  //Most of these classes need access to m_dynamicData
363  friend class DUChain;
364  friend class DUChainPrivate;
365  friend class TopDUContextData;
366  friend class TopDUContextLocalPrivate;
367  friend class TopDUContextDynamicData;
368  friend class Declaration;
369  friend class DUContext;
370  friend class Problem;
371  friend class IndexedDeclaration;
372  friend class IndexedDUContext;
373  friend class LocalIndexedDeclaration;
374  friend class LocalIndexedDUContext;
375  friend class LocalIndexedProblem;
376  friend class DeclarationId;
377  friend class ParsingEnvironmentFile;
378 
379  TopDUContextLocalPrivate* m_local;
380 
381  class TopDUContextDynamicData* m_dynamicData;
382 };
383 
387 KDEVPLATFORMLANGUAGE_EXPORT QVector<RangeInRevision> allUses(TopDUContext* context, Declaration* declaration,
388  bool noEmptyRanges = false);
389 
390 inline uint qHash(const ReferencedTopDUContext& ctx)
391 {
392  return ctx.hash();
393 }
394 
395 #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
396 Q_DECLARE_OPERATORS_FOR_FLAGS(TopDUContext::Features)
397 #endif
398 
399 }
400 
401 #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
402 Q_DECLARE_OPERATORS_FOR_FLAGS(KDevelop::TopDUContext::Features)
403 #endif
404 
405 Q_DECLARE_TYPEINFO(KDevelop::ReferencedTopDUContext, Q_MOVABLE_TYPE);
406 Q_DECLARE_METATYPE(KDevelop::ReferencedTopDUContext)
407 
408 #endif // KDEVPLATFORM_TOPDUCONTEXT_H
KDevelop::IndexedTopDUContext
Allows simple indirect access to top-contexts with on-demand loading.
Definition: indexedtopducontext.h:35
KDevelop::Problem
An object representing a problem in preprocessing, parsing, definition-use chain compilation,...
Definition: problem.h:129
KDevelop::ReferencedTopDUContext
KDevelop can unload unused top-context at any time.
Definition: topducontext.h:59
KDevelop::RecursiveImportRepository
Definition: topducontext.h:43
KDevelop::DUChainPointer
A smart-pointer similar class that conveniently wraps around DUChainPointerData without too many dyna...
Definition: duchainpointer.h:90
QList
KDevelop::TopDUContext::IndexedRecursiveImports
Utils::StorableSet< IndexedTopDUContext, IndexedTopDUContextIndexConversion, RecursiveImportRepository, true > IndexedRecursiveImports
Definition: topducontext.h:290
KDevelop::TypePtr< AbstractType >
DUCHAIN_DECLARE_DATA
#define DUCHAIN_DECLARE_DATA(Class)
Use this to declare the data functions in your DUChainBase based class.
Definition: duchainbase.h:41
KDevelop::Declaration
Represents a single declaration in a definition-use chain.
Definition: declaration.h:51
QExplicitlySharedDataPointer
Definition: topducontext.h:28
KDevelop::TopDUContextDynamicData
This class contains dynamic data of a top-context, and also the repository that contains all the data...
Definition: topducontextdynamicdata.h:37
KDevelop::ReferencedTopDUContext::operator->
TopDUContext * operator->() const
Definition: topducontext.h:87
KDevelop::ReferencedTopDUContext::operator!=
bool operator!=(const ReferencedTopDUContext &rhs) const
Definition: topducontext.h:82
KDevelop::LocalIndexedDUContext
Represents a DUContext within a TopDUContext, without storing the TopDUContext(It must be given to da...
Definition: localindexedducontext.h:33
KDevelop::TopDUContextData
Definition: topducontextdata.h:51
KDevelop::IndexedDeclaration
Represents a declaration only by its global indices.
Definition: indexeddeclaration.h:33
KDevelop::allUses
QVector< RangeInRevision > allUses(DUContext *context, int declarationIndex, bool noEmptyUses)
Collects all uses of the given declarationIndex.
Definition: ducontext.cpp:1519
KDevelop::ReferencedTopDUContext::operator==
bool operator==(const ReferencedTopDUContext &rhs) const
Definition: topducontext.h:77
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
Q_DECLARE_TYPEINFO
Q_DECLARE_TYPEINFO(KDevelop::ReferencedTopDUContext, Q_MOVABLE_TYPE)
KDevelop::ParsingEnvironmentFile
This represents all information about a specific parsed file that is needed to match the file to a pa...
Definition: parsingenvironment.h:118
KDevelop::qHash
uint qHash(const KDevelop::DeclarationId &id)
Definition: declarationid.h:205
KDevelop::LocalIndexedDeclaration
Represents a declaration only by its index within the top-context.
Definition: localindexeddeclaration.h:32
KDevelop::ReferencedTopDUContext::hash
uint hash() const
Definition: topducontext.h:92
KDevelop::QualifiedIdentifier
Represents a qualified identifier.
Definition: identifier.h:245
KDevelop::ReferencedTopDUContext::data
TopDUContext * data() const
Definition: topducontext.h:68
KDevelop::IndexedTopDUContextIndexConversion
Definition: indexedtopducontext.h:135
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
KDevelop::LocalIndexedProblem
Represents a problem only by its index within the top-context.
Definition: problem.h:44
KDevelop::TopDUContext::m_local
TopDUContextLocalPrivate * m_local
Definition: topducontext.h:379
KDevelop::DUContext
A single context in source code, represented as a node in a directed acyclic graph.
Definition: ducontext.h:72
QVector
DeclarationChecker
QHash< const TopDUContext *, QPair< int, const TopDUContext * > >
ducontext.h
QPair
KDevelop::TopDUContext::m_dynamicData
class TopDUContextDynamicData * m_dynamicData
Definition: topducontext.h:381
KDevelop::DUChain
Holds references to all top level source file contexts.
Definition: duchain.h:54
KDevelop::TopDUContext::Feature
Feature
Definition: topducontext.h:190
KDevelop::IndexedDUContext
Represents a context only by its global indices.
Definition: indexedducontext.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Mar 3 2021 00:37:28 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