• 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
ducontextdynamicdata.h
Go to the documentation of this file.
1 /***************************************************************************
2 * This file is part of KDevelop *
3 * Copyright 2006 Hamish Rodda <[email protected]> *
4 * Copyright 2007-2008 David Nolden <[email protected]>*
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU Library General Public License as *
8 * published by the Free Software Foundation; either version 2 of the *
9 * License, or (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
21 
22 #ifndef DUCONTEXTDYNAMICDATA_H
23 #define DUCONTEXTDYNAMICDATA_H
24 
25 #include "ducontextdata.h"
26 
27 namespace KDevelop {
29 class DUContextDynamicData
30 {
31 private:
32  inline const DUContextData* d_func() const { return m_context->d_func(); }
33  inline DUContextData* d_func_dynamic() { return m_context->d_func_dynamic(); }
34  static inline const DUContextData* ctx_d_func(DUContext* ctx) { return ctx->d_func(); }
35  static inline DUContextDynamicData* ctx_dynamicData(DUContext* ctx) { return ctx->m_dynamicData; }
36 
37 public:
38  explicit DUContextDynamicData(DUContext*);
39  DUContextPointer m_parentContext;
40 
41  TopDUContext* m_topContext;
42 
43  uint m_indexInTopContext; //Index of this DUContext in the top-context
44 
45  DUContext* m_context;
46 
47  // cache of unserialized child contexts
48  QVector<DUContext*> m_childContexts;
49  // cache of unserialized local declarations
50  QVector<Declaration*> m_localDeclarations;
51 
58  void addChildContext(DUContext* context);
59 
63  bool removeChildContext(DUContext* context);
64 
65  void addImportedChildContext(DUContext* context);
66  void removeImportedChildContext(DUContext* context);
67 
68  void addDeclaration(Declaration* declaration);
69 
73  bool removeDeclaration(Declaration* declaration);
74 
75  //Files the scope identifier into target
76  void scopeIdentifier(bool includeClasses, QualifiedIdentifier& target) const;
77 
78  //Iterates through all visible declarations within a given context, including the ones propagated from sub-contexts
79  class VisibleDeclarationIterator
80  {
81 public:
82  struct StackEntry
83  {
84  explicit StackEntry(const DUContextDynamicData* data = nullptr)
85  : data(data)
86  , index(0)
87  , nextChild(0)
88  {
89  }
90 
91  const DUContextDynamicData* data;
92  int index;
93  uint nextChild;
94  };
95 
96  explicit VisibleDeclarationIterator(const DUContextDynamicData* data)
97  : current(data)
98  {
99  toValidPosition();
100  }
101 
102  inline Declaration* operator*() const
103  {
104  return current.data ? current.data->m_localDeclarations.value(current.index) : nullptr;
105  }
106 
107  inline VisibleDeclarationIterator& operator++()
108  {
109  ++current.index;
110  toValidPosition();
111  return *this;
112  }
113 
114  inline operator bool() const
115  {
116  return current.data && !current.data->m_localDeclarations.isEmpty();
117  }
118 
119  // Moves the cursor to the next valid position, from an invalid one
120  void toValidPosition()
121  {
122  if (!current.data || current.index < current.data->m_localDeclarations.size()) {
123  // still valid
124  return;
125  }
126 
127  do {
128  // Check if we can proceed into a propagating child-context
129  for (int a = current.nextChild; a < current.data->m_childContexts.size(); ++a) {
130  DUContext* child = current.data->m_childContexts[a];
131 
132  if (ctx_d_func(child)->m_propagateDeclarations) {
133  current.nextChild = a + 1;
134  stack.append(current);
135  current = StackEntry(ctx_dynamicData(child));
136  toValidPosition();
137  return;
138  }
139  }
140 
141  //Go up and into the next valid context
142  if (stack.isEmpty()) {
143  current = StackEntry();
144  return;
145  }
146 
147  current = stack.back();
148  stack.pop_back();
149  } while (true);
150  }
151 
152  StackEntry current;
153 
154  KDevVarLengthArray<StackEntry> stack;
155  };
156 
160  bool imports(const DUContext* context, const TopDUContext* source,
161  QSet<const DUContextDynamicData*>* recursionGuard) const;
162 };
163 }
164 
165 Q_DECLARE_TYPEINFO(KDevelop::DUContextDynamicData::VisibleDeclarationIterator::StackEntry, Q_MOVABLE_TYPE);
166 
167 #endif
KDevelop::DUContextDynamicData::m_indexInTopContext
uint m_indexInTopContext
Definition: ducontextdynamicdata.h:78
QSet
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::StackEntry::index
int index
Definition: ducontextdynamicdata.h:127
KDevelop::DUContextDynamicData::removeChildContext
bool removeChildContext(DUContext *context)
Removes the context from childContexts.
Definition: ducontext.cpp:291
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::stack
KDevVarLengthArray< StackEntry > stack
Definition: ducontextdynamicdata.h:189
KDevelop::DUContextDynamicData::m_childContexts
QVector< DUContext * > m_childContexts
Definition: ducontextdynamicdata.h:83
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::StackEntry
Definition: ducontextdynamicdata.h:117
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::operator++
VisibleDeclarationIterator & operator++()
Definition: ducontextdynamicdata.h:142
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::VisibleDeclarationIterator
VisibleDeclarationIterator(const DUContextDynamicData *data)
Definition: ducontextdynamicdata.h:131
KDevelop::DUContextDynamicData::addChildContext
void addChildContext(DUContext *context)
Adds a child context.
Definition: ducontext.cpp:255
DUContextData
KDevelop::Declaration
Represents a single declaration in a definition-use chain.
Definition: declaration.h:51
KDevelop::DUContextDynamicData::VisibleDeclarationIterator
Definition: ducontextdynamicdata.h:114
KDevelop::DUContextDynamicData::m_localDeclarations
QVector< Declaration * > m_localDeclarations
Definition: ducontextdynamicdata.h:85
KDevelop::DUContextDynamicData::m_context
DUContext * m_context
Definition: ducontextdynamicdata.h:80
KDevelop::DUContextDynamicData::addDeclaration
void addDeclaration(Declaration *declaration)
Definition: ducontext.cpp:204
ducontextdata.h
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::StackEntry::nextChild
uint nextChild
Definition: ducontextdynamicdata.h:128
KDevVarLengthArray
Q_DECLARE_TYPEINFO
Q_DECLARE_TYPEINFO(KDevelop::DUContextDynamicData::VisibleDeclarationIterator::StackEntry, Q_MOVABLE_TYPE)
KDevelop::TopDUContext
The top context in a definition-use chain for one source file.
Definition: topducontext.h:113
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::StackEntry::StackEntry
StackEntry(const DUContextDynamicData *data=nullptr)
Definition: ducontextdynamicdata.h:119
KDevelop::DUContextDynamicData::m_parentContext
DUContextPointer m_parentContext
Definition: ducontextdynamicdata.h:74
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::DUContextDynamicData::VisibleDeclarationIterator::StackEntry::data
const DUContextDynamicData * data
Definition: ducontextdynamicdata.h:126
KDevelop::QualifiedIdentifier
Represents a qualified identifier.
Definition: identifier.h:245
KDevelop::DUContextPointer
DUChainPointer< DUContext > DUContextPointer
Definition: duchainpointer.h:198
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
QVector
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::operator*
Declaration * operator*() const
Definition: ducontextdynamicdata.h:137
KDevelop::DUContextDynamicData::m_topContext
TopDUContext * m_topContext
Definition: ducontextdynamicdata.h:76
KDevelop::DUContextDynamicData::scopeIdentifier
void scopeIdentifier(bool includeClasses, QualifiedIdentifier &target) const
Definition: ducontext.cpp:170
KDevelop::DUContextDynamicData::imports
bool imports(const DUContext *context, const TopDUContext *source, QSet< const DUContextDynamicData * > *recursionGuard) const
Returns true if this context is imported by the given one, on any level.
Definition: ducontext.cpp:179
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::current
StackEntry current
Definition: ducontextdynamicdata.h:187
KDevelop::DUContextDynamicData::VisibleDeclarationIterator::toValidPosition
void toValidPosition()
Definition: ducontextdynamicdata.h:155
KDevelop::DUContextDynamicData::addImportedChildContext
void addImportedChildContext(DUContext *context)
Definition: ducontext.cpp:307
KDevelop::DUContextDynamicData::removeImportedChildContext
void removeImportedChildContext(DUContext *context)
Definition: ducontext.cpp:328
KDevelop::DUContextDynamicData::removeDeclaration
bool removeDeclaration(Declaration *declaration)
Removes the declaration from localDeclarations.
Definition: ducontext.cpp:241
KDevelop::DUContextDynamicData::DUContextDynamicData
DUContextDynamicData(DUContext *)
Definition: ducontext.cpp:163
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 09:40:52 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