• 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
ducontext.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_DUCONTEXT_H
21 #define KDEVPLATFORM_DUCONTEXT_H
22 
23 #include <QHash>
24 #include <QList>
25 #include <QSet>
26 #include <QVector>
27 
28 #include <util/kdevvarlengtharray.h>
29 
30 #include "identifier.h"
31 #include "duchainbase.h"
32 #include "types/abstracttype.h"
33 #include "duchainpointer.h"
34 #include "declarationid.h"
35 #include "indexedducontext.h"
36 
37 #include "navigation/abstractnavigationwidget.h"
38 
39 class QWidget;
40 
41 namespace KDevelop {
42 class Declaration;
43 class DUChain;
44 class Use;
45 class TopDUContext;
46 class DUContext;
47 class DUContextData;
48 
49 class KDEVPLATFORMLANGUAGE_EXPORT DUChainVisitor
50 {
51 public:
52  virtual void visit(DUContext* context) = 0;
53  virtual void visit(Declaration* declaration) = 0;
54  virtual ~DUChainVisitor();
55 };
56 
57 using DUContextPointer = DUChainPointer<DUContext>;
58 
72 class KDEVPLATFORMLANGUAGE_EXPORT DUContext
73  : public DUChainBase
74 {
75  friend class Use;
76  friend class Declaration;
77  friend class DeclarationData;
78  friend class DUContextData;
79  friend class DUContextDynamicData;
80  friend class Definition;
81  friend class VisibleDeclarationIterator;
82 
83 public:
91  explicit DUContext(const RangeInRevision& range, DUContext* parent = nullptr, bool anonymous = false);
92  explicit DUContext(DUContextData&);
93 
98  ~DUContext() override;
99 
100  DUContext& operator=(const DUContext& rhs) = delete;
101 
102  enum ContextType : quint8 {
103  Global ,
104  Namespace ,
105  Class ,
106  Function ,
107  Template ,
108  Enum ,
109  Helper ,
113  Other
114  };
115 
116  enum SearchFlag {
117  NoSearchFlags = 0 ,
118  InImportedParentContext = 1 ,
119  OnlyContainerTypes = 2 ,
120  DontSearchInParent =
121  4 ,
122  NoUndefinedTemplateParams =
123  8 ,
124  DirectQualifiedLookup =
125  16 ,
126  NoFiltering =
127  32 ,
128  OnlyFunctions =
129  64 ,
130  NoImportsCheck =
131  128 ,
132  NoSelfLookUp =
133  256 ,
134  DontResolveAliases = 512 ,
135  LastSearchFlag = 1024
136  };
137 
138  Q_DECLARE_FLAGS(SearchFlags, SearchFlag)
139 
140  ContextType type() const;
141  void setType(ContextType type);
142 
148  Declaration* owner() const;
154  void setOwner(Declaration* decl);
155 
159  int depth() const;
160 
164  TopDUContext* topContext() const override;
165 
172  virtual void visit(DUChainVisitor& visitor);
173 
185  DUContext* findContextAt(const CursorInRevision& position, bool includeBorders = false) const;
186 
195  Declaration* findDeclarationAt(const CursorInRevision& position) const;
196 
203  DUContext* findContextIncluding(const RangeInRevision& range) const;
204 
208  QualifiedIdentifier scopeIdentifier(bool includeClasses = false) const;
209 
216  bool equalScopeIdentifier(const DUContext* rhs) const;
217 
223  QualifiedIdentifier localScopeIdentifier() const;
224 
228  IndexedQualifiedIdentifier indexedLocalScopeIdentifier() const;
229 
234  void setLocalScopeIdentifier(const QualifiedIdentifier& identifier);
235 
239  bool inSymbolTable() const;
240 
246  void setInSymbolTable(bool inSymbolTable);
247 
251  DUContext* parentContext() const;
252 
256  struct KDEVPLATFORMLANGUAGE_EXPORT Import
257  {
261  Import(DUContext* context, const DUContext* importer,
262  const CursorInRevision& position = CursorInRevision::invalid());
263  Import() : position(CursorInRevision::invalid()) { }
264  explicit Import(const DeclarationId& id, const CursorInRevision& position = CursorInRevision::invalid());
265 
266  bool operator==(const Import& rhs) const
267  {
268  return m_context == rhs.m_context && m_declaration == rhs.m_declaration;
269  }
270 
276  DUContext* context(const TopDUContext* topContext, bool instantiateIfRequired = true) const;
277 
281  uint topContextIndex() const
282  {
283  return m_context.topContextIndex();
284  }
285 
286  IndexedDUContext indexedContext() const
287  {
288  return m_context;
289  }
290 
297  bool isDirect() const;
298 
302  DeclarationId indirectDeclarationId() const
303  {
304  return m_declaration;
305  }
306 
307  CursorInRevision position;
308 
309 private:
310  //Either we store m_declaration, or m_context. That way we can resolve specialized contexts.
312  DeclarationId m_declaration;
313  IndexedDUContext m_context;
314  };
315 
325  virtual QVector<Import> importedParentContexts() const;
326 
332  virtual CursorInRevision importPosition(const DUContext* target) const;
333 
337  virtual bool imports(const DUContext* origin,
338  const CursorInRevision& position = CursorInRevision::invalid()) const;
339 
351  virtual void addImportedParentContext(DUContext* context,
352  const CursorInRevision& position = CursorInRevision::invalid(),
353  bool anonymous = false, bool temporary = false);
354 
364  bool addIndirectImport(const DUContext::Import& import);
365 
369  virtual void removeImportedParentContext(DUContext* context);
370 
374  virtual void clearImportedParentContexts();
375 
383  void setPropagateDeclarations(bool propagate);
384 
385  bool isPropagateDeclarations() const;
386 
392  virtual QVector<DUContext*> importers() const;
393 
399  KDevVarLengthArray<IndexedDUContext> indexedImporters() const;
400 
406  QVector<DUContext*> childContexts() const;
407 
413  void deleteChildContextsRecursively();
414 
421  void resortChildContexts();
422 
427  virtual bool inDUChain() const;
428 
440  virtual DUContext* specialize(const IndexedInstantiationInformation& specialization,
441  const TopDUContext* topContext, int upDistance = 0);
442 
458  QList<Declaration*> findDeclarations(const QualifiedIdentifier& identifier,
459  const CursorInRevision& position = CursorInRevision::invalid(),
460  const AbstractType::Ptr& dataType = AbstractType::Ptr(),
461  const TopDUContext* topContext = nullptr,
462  SearchFlags flags = NoSearchFlags) const;
463 
479  QList<Declaration*> findDeclarations(const IndexedIdentifier& identifier,
480  const CursorInRevision& position = CursorInRevision::invalid(),
481  const TopDUContext* topContext = nullptr,
482  SearchFlags flags = NoSearchFlags) const;
483 
487  QList<Declaration*> findDeclarations(const Identifier& identifier,
488  const CursorInRevision& position = CursorInRevision::invalid(),
489  const TopDUContext* topContext = nullptr,
490  SearchFlags flags = NoSearchFlags) const;
491 
498  QList<Declaration*> findLocalDeclarations(const IndexedIdentifier& identifier,
499  const CursorInRevision& position = CursorInRevision::invalid(),
500  const TopDUContext* topContext = nullptr,
501  const AbstractType::Ptr& dataType = AbstractType::Ptr(),
502  SearchFlags flags = NoSearchFlags) const;
503 
507  QList<Declaration*> findLocalDeclarations(const Identifier& identifier,
508  const CursorInRevision& position = CursorInRevision::invalid(),
509  const TopDUContext* topContext = nullptr,
510  const AbstractType::Ptr& dataType = AbstractType::Ptr(),
511  SearchFlags flags = NoSearchFlags) const;
512 
518  QVector<Declaration*> clearLocalDeclarations();
519 
525  void deleteLocalDeclarations();
526 
533  virtual QVector<Declaration*> localDeclarations(const TopDUContext* source = nullptr) const;
534 
541  void resortLocalDeclarations();
542 
552  DUContext* findContext(const CursorInRevision& position, DUContext* parent = nullptr) const;
553 
559  bool parentContextOf(DUContext* context) const;
560 
581  QVector<QPair<Declaration*, int>> allDeclarations(const CursorInRevision& position,
582  const TopDUContext* topContext,
583  bool searchInParents = true) const;
584 
588  void cleanIfNotEncountered(const QSet<DUChainBase*>& encountered);
589 
609  const Use* uses() const;
610 
614  int usesCount() const;
615 
619  static bool declarationHasUses(Declaration* decl);
620 
625  int findUseAt(const CursorInRevision& position) const;
626 
630  void changeUseRange(int useIndex, const RangeInRevision& range);
631 
636  void setUseDeclaration(int useIndex, int declarationIndex);
637 
649  int createUse(int declarationIndex, const RangeInRevision& range, int insertBefore = -1);
650 
656  void deleteUse(int index);
657 
661  virtual void deleteUses();
662 
666  virtual void deleteUsesRecursively();
667 
684  virtual AbstractNavigationWidget*
685  createNavigationWidget(Declaration* decl = nullptr, TopDUContext* topContext = nullptr,
686  AbstractNavigationWidget::DisplayHints hints = AbstractNavigationWidget::NoHints) const;
687 
688  enum {
689  Identity = 2
690  };
691 
702  struct KDEVPLATFORMLANGUAGE_EXPORT SearchItem
703  : public QSharedData
704  {
705  using Ptr = QExplicitlySharedDataPointer<SearchItem>;
706  using PtrList = KDevVarLengthArray<Ptr, 256>;
707 
714  explicit SearchItem(const QualifiedIdentifier& id, const Ptr& nextItem = Ptr(), int start = 0);
715 
722  SearchItem(const QualifiedIdentifier& id, const PtrList& nextItems, int start = 0);
723 
724  SearchItem(bool explicitlyGlobal, const IndexedIdentifier& id, const PtrList& nextItems);
725  SearchItem(bool explicitlyGlobal, const IndexedIdentifier& id, const Ptr& nextItem);
726 
727  bool isEmpty() const;
728  bool hasNext() const;
729 
743  void addToEachNode(const Ptr& item);
744  void addToEachNode(const PtrList& items);
745 
750  bool match(const QualifiedIdentifier& id, int offset = 0) const;
751 
755  QVector<QualifiedIdentifier> toList(const QualifiedIdentifier& prefix = QualifiedIdentifier()) const;
756 
757  void addNext(const Ptr& other);
758 
759  bool isExplicitlyGlobal;
760  IndexedIdentifier identifier;
761  PtrList next;
762  };
763 
766 
768 
769  using DeclarationList = QList<Declaration*>;
770 
793  virtual bool findDeclarationsInternal(const SearchItem::PtrList& identifiers,
794  const CursorInRevision& position, const AbstractType::Ptr& dataType,
795  DeclarationList& ret, const TopDUContext* source, SearchFlags flags,
796  uint depth) const;
797 
804  QVector<QualifiedIdentifier> fullyApplyAliases(const QualifiedIdentifier& id,
805  const TopDUContext* source) const;
806 
807 protected:
808 
815  virtual bool foundEnough(const DeclarationList& decls, SearchFlags flags) const;
816 
826  virtual void mergeDeclarationsInternal(QVector<QPair<Declaration*, int>>& definitions,
827  const CursorInRevision& position,
828  QHash<const DUContext*, bool>& hadContexts,
829  const TopDUContext* source,
830  bool searchInParents = true, int currentDepth = 0) const;
831 
832  void findLocalDeclarationsInternal(const Identifier& identifier,
833  const CursorInRevision& position,
834  const AbstractType::Ptr& dataType,
835  DeclarationList& ret,
836  const TopDUContext* source,
837  SearchFlags flags) const;
838 
839  virtual void findLocalDeclarationsInternal(const IndexedIdentifier& identifier,
840  const CursorInRevision& position,
841  const AbstractType::Ptr& dataType,
842  DeclarationList& ret,
843  const TopDUContext* source,
844  SearchFlags flags) const;
845 
855  void applyAliases(const SearchItem::PtrList& identifiers, SearchItem::PtrList& targetIdentifiers,
856  const CursorInRevision& position, bool canBeNamespace, bool onlyImports = false) const;
867  virtual void applyUpwardsAliases(SearchItem::PtrList& identifiers, const TopDUContext* source) const;
868 
869  DUContext(DUContextData& dd, const RangeInRevision& range, DUContext* parent = nullptr, bool anonymous = false);
870 
875  DUContext(DUContext& useDataFrom);
876 
883  bool isAnonymous() const;
884 
894  virtual bool shouldSearchInParent(SearchFlags flags) const;
895 
896 private:
897  void initFromTopContext();
898  void rebuildDynamicData(DUContext* parent, uint ownIndex) override;
899 
900  friend class TopDUContext;
901  friend class IndexedDUContext;
902  friend class LocalIndexedDUContext;
903  friend class TopDUContextDynamicData;
904 
905  DUCHAIN_DECLARE_DATA(DUContext)
906  class DUContextDynamicData* m_dynamicData;
907 };
908 
918 KDEVPLATFORMLANGUAGE_EXPORT const Identifier& globalImportIdentifier();
919 
928 KDEVPLATFORMLANGUAGE_EXPORT const Identifier& globalAliasIdentifier();
929 
939 KDEVPLATFORMLANGUAGE_EXPORT const IndexedIdentifier& globalIndexedImportIdentifier();
940 
949 KDEVPLATFORMLANGUAGE_EXPORT const IndexedIdentifier& globalIndexedAliasIdentifier();
950 
954 KDEVPLATFORMLANGUAGE_EXPORT QVector<RangeInRevision> allUses(DUContext* context,
955  int declarationIndex,
956  bool noEmptyRanges = false);
957 }
958 
959 Q_DECLARE_TYPEINFO(KDevelop::DUContext::Import, Q_MOVABLE_TYPE);
960 
961 KDEVPLATFORMLANGUAGE_EXPORT QDebug operator<<(QDebug dbg, const KDevelop::DUContext::Import& import);
962 
963 #endif // KDEVPLATFORM_DUCONTEXT_H
operator<<
KDEVPLATFORMLANGUAGE_EXPORT QDebug operator<<(QDebug dbg, const KDevelop::DUContext::Import &import)
Definition: ducontext.cpp:60
Q_DECLARE_TYPEINFO
Q_DECLARE_TYPEINFO(KDevelop::DUContext::Import, Q_MOVABLE_TYPE)
QSet
QSharedData
KDevelop::DUContext::Import::position
CursorInRevision position
Definition: ducontext.h:307
KDevelop::DUContext::Import::indexedContext
IndexedDUContext indexedContext() const
Definition: ducontext.h:286
KDevelop::DUContext::SearchItem::identifier
IndexedIdentifier identifier
Definition: ducontext.h:760
duchainpointer.h
KDevelop::DUChainBase
Base class for definition-use chain objects.
Definition: duchainbase.h:131
KDevelop::DUContext::SearchItem::PtrList
KDevVarLengthArray< Ptr, 256 > PtrList
Definition: ducontext.h:706
QWidget
KDevelop::DUContext::SearchItem
Represents multiple qualified identifiers in a way that is better to manipulate and allows applying n...
Definition: ducontext.h:702
QDebug
KDevelop::DUChainPointer< DUContext >
KDevelop::DUContext::ContextType
ContextType
Definition: ducontext.h:102
KDevelop::IndexedIdentifier
A helper-class to store an identifier by index in a type-safe way.
Definition: identifier.h:55
QList
KDevelop::TypePtr< AbstractType >
DUContextData
KDevelop::DUContext::Import::operator==
bool operator==(const Import &rhs) const
Definition: ducontext.h:266
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::IndexedQualifiedIdentifier
A helper-class to store an identifier by index in a type-safe way.
Definition: identifier.h:95
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::Use
Represents a position in a document where a specific declaration is used.
Definition: use.h:47
KDevelop::LocalIndexedDUContext
Represents a DUContext within a TopDUContext, without storing the TopDUContext(It must be given to da...
Definition: localindexedducontext.h:33
KDevelop::AbstractNavigationWidget
This class deleted itself when its part is deleted, so always use a QPointer when referencing it.
Definition: abstractnavigationwidget.h:38
KDevelop::globalIndexedImportIdentifier
const IndexedIdentifier & globalIndexedImportIdentifier()
This is the identifier that can be used to search namespace-import declarations, and should be used t...
Definition: ducontext.cpp:96
KDevelop::allUses
QVector< RangeInRevision > allUses(DUContext *context, int declarationIndex, bool noEmptyUses)
Collects all uses of the given declarationIndex.
Definition: ducontext.cpp:1519
KDevelop::DUContext::Import::topContextIndex
uint topContextIndex() const
Returns the top-context index, if this import is not a specialization import.
Definition: ducontext.h:281
identifier.h
KDevVarLengthArray
KDevelop::DUContext::Import::indirectDeclarationId
DeclarationId indirectDeclarationId() const
If this import is indirect, returns the imported declaration-id.
Definition: ducontext.h:302
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
KDevelop::Identifier
Represents a single unqualified identifier.
Definition: identifier.h:150
KDevelop::globalImportIdentifier
const Identifier & globalImportIdentifier()
We leak here, to prevent a possible crash during destruction, as the destructor of Identifier is not ...
Definition: ducontext.cpp:84
KDevelop::DeclarationData
Definition: declarationdata.h:35
declarationid.h
KDevelop::AbstractNavigationWidget::NoHints
Definition: abstractnavigationwidget.h:47
KDevelop::DUContextDynamicData
This class contains data that is only runtime-dependent and does not need to be stored to disk.
Definition: ducontextdynamicdata.h:46
KDevelop::DUChainVisitor
Definition: ducontext.h:49
KDevelop::QualifiedIdentifier
Represents a qualified identifier.
Definition: identifier.h:245
abstracttype.h
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::globalAliasIdentifier
const Identifier & globalAliasIdentifier()
This is the identifier that can be used to search namespace-alias declarations.
Definition: ducontext.cpp:90
KDevelop::DUContext::Import::Import
Import()
Definition: ducontext.h:263
KDevelop::DUContext::SearchItem::next
PtrList next
Definition: ducontext.h:761
QVector
KDevelop::globalIndexedAliasIdentifier
const IndexedIdentifier & globalIndexedAliasIdentifier()
This is the identifier that can be used to search namespace-alias declarations.
Definition: ducontext.cpp:102
QHash
abstractnavigationwidget.h
QPair
KDevelop::DUContext::SearchItem::isExplicitlyGlobal
bool isExplicitlyGlobal
Definition: ducontext.h:759
indexedducontext.h
duchainbase.h
KDevelop::DUContext::SearchFlag
SearchFlag
Definition: ducontext.h:116
KDevelop::IndexedDUContext
Represents a context only by its global indices.
Definition: indexedducontext.h:35
KDevelop::DUContext::Import
Represents an imported parent context.
Definition: ducontext.h:256
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 19 2021 23:36:33 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