• 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
duchainutils.cpp
Go to the documentation of this file.
1 /*
2  * DUChain Utilities
3  *
4  * Copyright 2007 Hamish Rodda <[email protected]>
5  * Copyright 2007-2008 David Nolden <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Library General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public
18  * License along with this program; if not, write to the
19  * Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #include "duchainutils.h"
24 
25 #include <algorithm>
26 
27 #include <interfaces/icore.h>
28 #include <interfaces/ilanguagecontroller.h>
29 
30 #include "../interfaces/ilanguagesupport.h"
31 #include "../assistant/staticassistantsmanager.h"
32 #include <debug.h>
33 
34 #include "declaration.h"
35 #include "classfunctiondeclaration.h"
36 #include "ducontext.h"
37 #include "duchain.h"
38 #include "use.h"
39 #include "duchainlock.h"
40 #include "classmemberdeclaration.h"
41 #include "functiondefinition.h"
42 #include "specializationstore.h"
43 #include "persistentsymboltable.h"
44 #include "classdeclaration.h"
45 #include "parsingenvironment.h"
46 
47 #include <QStandardPaths>
48 
49 using namespace KDevelop;
50 using namespace KTextEditor;
51 
52 CodeCompletionModel::CompletionProperties DUChainUtils::completionProperties(const Declaration* dec)
53 {
54  CodeCompletionModel::CompletionProperties p;
55 
56  if(dec->context()->type() == DUContext::Class) {
57  if (const auto* member = dynamic_cast<const ClassMemberDeclaration*>(dec)) {
58  switch (member->accessPolicy()) {
59  case Declaration::Public:
60  p |= CodeCompletionModel::Public;
61  break;
62  case Declaration::Protected:
63  p |= CodeCompletionModel::Protected;
64  break;
65  case Declaration::Private:
66  p |= CodeCompletionModel::Private;
67  break;
68  default:
69  break;
70  }
71 
72  if (member->isStatic())
73  p |= CodeCompletionModel::Static;
74  if (member->isAuto())
75  {}//TODO
76  if (member->isFriend())
77  p |= CodeCompletionModel::Friend;
78  if (member->isRegister())
79  {}//TODO
80  if (member->isExtern())
81  {}//TODO
82  if (member->isMutable())
83  {}//TODO
84  }
85  }
86 
87  if (const auto* function = dynamic_cast<const AbstractFunctionDeclaration*>(dec)) {
88  p |= CodeCompletionModel::Function;
89  if (function->isVirtual())
90  p |= CodeCompletionModel::Virtual;
91  if (function->isInline())
92  p |= CodeCompletionModel::Inline;
93  if (function->isExplicit())
94  {}//TODO
95  }
96 
97  if( dec->isTypeAlias() )
98  p |= CodeCompletionModel::TypeAlias;
99 
100  if (dec->abstractType()) {
101  switch (dec->abstractType()->whichType()) {
102  case AbstractType::TypeIntegral:
103  p |= CodeCompletionModel::Variable;
104  break;
105  case AbstractType::TypePointer:
106  p |= CodeCompletionModel::Variable;
107  break;
108  case AbstractType::TypeReference:
109  p |= CodeCompletionModel::Variable;
110  break;
111  case AbstractType::TypeFunction:
112  p |= CodeCompletionModel::Function;
113  break;
114  case AbstractType::TypeStructure:
115  p |= CodeCompletionModel::Class;
116  break;
117  case AbstractType::TypeArray:
118  p |= CodeCompletionModel::Variable;
119  break;
120  case AbstractType::TypeEnumeration:
121  p |= CodeCompletionModel::Enum;
122  break;
123  case AbstractType::TypeEnumerator:
124  p |= CodeCompletionModel::Variable;
125  break;
126  case AbstractType::TypeAbstract:
127  case AbstractType::TypeDelayed:
128  case AbstractType::TypeUnsure:
129  case AbstractType::TypeAlias:
130  // TODO
131  break;
132  }
133 
134  if( dec->abstractType()->modifiers() & AbstractType::ConstModifier )
135  p |= CodeCompletionModel::Const;
136 
137  if( dec->kind() == Declaration::Instance && !dec->isFunctionDeclaration() )
138  p |= CodeCompletionModel::Variable;
139  }
140 
141  if (dec->context()) {
142  if( dec->context()->type() == DUContext::Global )
143  p |= CodeCompletionModel::GlobalScope;
144  else if( dec->context()->type() == DUContext::Namespace )
145  p |= CodeCompletionModel::NamespaceScope;
146  else if( dec->context()->type() != DUContext::Class && dec->context()->type() != DUContext::Enum )
147  p |= CodeCompletionModel::LocalScope;
148  }
149 
150  return p;
151 }
156 #define RETURN_CACHED_ICON(name) {static QIcon icon(QIcon( \
157  QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kdevelop/pics/" name ".png"))\
158  ).pixmap(QSize(16, 16)));\
159  return icon;}
160 
161 QIcon DUChainUtils::iconForProperties(KTextEditor::CodeCompletionModel::CompletionProperties p)
162 {
163 
164  if( (p & CodeCompletionModel::Variable) )
165  if( (p & CodeCompletionModel::Protected) )
166  RETURN_CACHED_ICON("CVprotected_var")
167  else if( p & CodeCompletionModel::Private )
168  RETURN_CACHED_ICON("CVprivate_var")
169  else
170  RETURN_CACHED_ICON("CVpublic_var")
171  else
172  if( (p & CodeCompletionModel::Union) && (p & CodeCompletionModel::Protected) )
173  RETURN_CACHED_ICON("protected_union")
174 
175  else if( p & CodeCompletionModel::Enum )
176  if( p & CodeCompletionModel::Protected )
177  RETURN_CACHED_ICON("protected_enum")
178  else if( p & CodeCompletionModel::Private )
179  RETURN_CACHED_ICON("private_enum")
180  else
181  RETURN_CACHED_ICON("enum")
182 
183  else if( p & CodeCompletionModel::Struct )
184  if( p & CodeCompletionModel::Private )
185  RETURN_CACHED_ICON("private_struct")
186  else
187  RETURN_CACHED_ICON("struct")
188 
189  else if( p & CodeCompletionModel::Slot )
190  if( p & CodeCompletionModel::Protected )
191  RETURN_CACHED_ICON("CVprotected_slot")
192  else if( p & CodeCompletionModel::Private )
193  RETURN_CACHED_ICON("CVprivate_slot")
194  else if(p & CodeCompletionModel::Public )
195  RETURN_CACHED_ICON("CVpublic_slot")
196  else RETURN_CACHED_ICON("slot")
197  else if( p & CodeCompletionModel::Signal )
198  if( p & CodeCompletionModel::Protected )
199  RETURN_CACHED_ICON("CVprotected_signal")
200  else
201  RETURN_CACHED_ICON("signal")
202 
203  else if( p & CodeCompletionModel::Class )
204  if( (p & CodeCompletionModel::Class) && (p & CodeCompletionModel::Protected) )
205  RETURN_CACHED_ICON("protected_class")
206  else if( (p & CodeCompletionModel::Class) && (p & CodeCompletionModel::Private) )
207  RETURN_CACHED_ICON("private_class")
208  else
209  RETURN_CACHED_ICON("code-class")
210 
211  else if( p & CodeCompletionModel::Union )
212  if( p & CodeCompletionModel::Private )
213  RETURN_CACHED_ICON("private_union")
214  else
215  RETURN_CACHED_ICON("union")
216 
217  else if( p & CodeCompletionModel::TypeAlias )
218  if ((p & CodeCompletionModel::Const) /*|| (p & CodeCompletionModel::Volatile)*/)
219  RETURN_CACHED_ICON("CVtypedef")
220  else
221  RETURN_CACHED_ICON("typedef")
222 
223  else if( p & CodeCompletionModel::Function ) {
224  if( p & CodeCompletionModel::Protected )
225  RETURN_CACHED_ICON("protected_function")
226  else if( p & CodeCompletionModel::Private )
227  RETURN_CACHED_ICON("private_function")
228  else
229  RETURN_CACHED_ICON("code-function")
230  }
231 
232  if( p & CodeCompletionModel::Protected )
233  RETURN_CACHED_ICON("protected_field")
234  else if( p & CodeCompletionModel::Private )
235  RETURN_CACHED_ICON("private_field")
236  else
237  RETURN_CACHED_ICON("field")
238 
239  return QIcon();
240 }
241 
242 QIcon DUChainUtils::iconForDeclaration(const Declaration* dec)
243 {
244  return iconForProperties(completionProperties(dec));
245 }
246 
247 TopDUContext* DUChainUtils::contentContextFromProxyContext(TopDUContext* top)
248 {
249  if(!top)
250  return nullptr;
251  if(top->parsingEnvironmentFile() && top->parsingEnvironmentFile()->isProxyContext()) {
252  if(!top->importedParentContexts().isEmpty())
253  {
254  DUContext* ctx = top->importedParentContexts().at(0).context(nullptr);
255  if(!ctx)
256  return nullptr;
257  TopDUContext* ret = ctx->topContext();
258  if(!ret)
259  return nullptr;
260  if(ret->url() != top->url())
261  qCDebug(LANGUAGE) << "url-mismatch between content and proxy:" << top->url().toUrl() << ret->url().toUrl();
262  if(ret->url() == top->url() && !ret->parsingEnvironmentFile()->isProxyContext())
263  return ret;
264  }
265  else {
266  qCDebug(LANGUAGE) << "Proxy-context imports no content-context";
267  }
268  } else
269  return top;
270  return nullptr;
271 }
272 
273 TopDUContext* DUChainUtils::standardContextForUrl(const QUrl& url, bool preferProxyContext) {
274  KDevelop::TopDUContext* chosen = nullptr;
275 
276  const auto languages = ICore::self()->languageController()->languagesForUrl(url);
277 
278  for (const auto language : languages) {
279  if(!chosen)
280  {
281  chosen = language->standardContext(url, preferProxyContext);
282  }
283  }
284 
285  if(!chosen)
286  chosen = DUChain::self()->chainForDocument(IndexedString(url), preferProxyContext);
287 
288  if(!chosen && preferProxyContext)
289  return standardContextForUrl(url, false); // Fall back to a normal context
290 
291  return chosen;
292 }
293 
294 struct ItemUnderCursorInternal
295 {
296  Declaration* declaration;
297  DUContext* context;
298  RangeInRevision range;
299 };
300 
301 ItemUnderCursorInternal itemUnderCursorInternal(const CursorInRevision& c, DUContext* ctx, RangeInRevision::ContainsBehavior behavior)
302 {
303  //Search all collapsed sub-contexts. In C++, those can contain declarations that have ranges out of the context
304  const auto childContexts = ctx->childContexts();
305  for (DUContext* subCtx : childContexts) {
306  //This is a little hacky, but we need it in case of foreach macros and similar stuff
307  if(subCtx->range().contains(c, behavior) || subCtx->range().isEmpty() || subCtx->range().start.line == c.line || subCtx->range().end.line == c.line) {
308  ItemUnderCursorInternal sub = itemUnderCursorInternal(c, subCtx, behavior);
309  if(sub.declaration) {
310  return sub;
311  }
312  }
313  }
314 
315  const auto localDeclarations = ctx->localDeclarations();
316  for (Declaration* decl : localDeclarations) {
317  if(decl->range().contains(c, behavior)) {
318  return {decl, ctx, decl->range()};
319  }
320  }
321 
322  //Try finding a use under the cursor
323  for(int a = 0; a < ctx->usesCount(); ++a) {
324  if(ctx->uses()[a].m_range.contains(c, behavior)) {
325  return {ctx->topContext()->usedDeclarationForIndex(ctx->uses()[a].m_declarationIndex), ctx, ctx->uses()[a].m_range};
326  }
327  }
328 
329  return {nullptr, nullptr, RangeInRevision()};
330 }
331 
332 DUChainUtils::ItemUnderCursor DUChainUtils::itemUnderCursor(const QUrl& url, const KTextEditor::Cursor& cursor)
333 {
334  KDevelop::TopDUContext* top = standardContextForUrl(url.adjusted(QUrl::NormalizePathSegments));
335 
336  if(!top) {
337  return {nullptr, nullptr, KTextEditor::Range()};
338  }
339 
340  ItemUnderCursorInternal decl = itemUnderCursorInternal(top->transformToLocalRevision(cursor), top, RangeInRevision::Default);
341  if (decl.declaration == nullptr)
342  {
343  decl = itemUnderCursorInternal(top->transformToLocalRevision(cursor), top, RangeInRevision::IncludeBackEdge);
344  }
345  return {decl.declaration, decl.context, top->transformFromLocalRevision(decl.range)};
346 }
347 
348 Declaration* DUChainUtils::declarationForDefinition(Declaration* definition, TopDUContext* topContext)
349 {
350  if(!definition)
351  return nullptr;
352 
353  if(!topContext)
354  topContext = definition->topContext();
355 
356  if(dynamic_cast<FunctionDefinition*>(definition)) {
357  Declaration* ret = static_cast<FunctionDefinition*>(definition)->declaration();
358  if(ret)
359  return ret;
360  }
361 
362  return definition;
363 }
364 
365 Declaration* DUChainUtils::declarationInLine(const KTextEditor::Cursor& _cursor, DUContext* ctx) {
366  if(!ctx)
367  return nullptr;
368 
369  CursorInRevision cursor = ctx->transformToLocalRevision(_cursor);
370 
371  const auto localDeclarations = ctx->localDeclarations();
372  for (Declaration* decl : localDeclarations) {
373  if(decl->range().start.line == cursor.line)
374  return decl;
375  DUContext* funCtx = functionContext(decl);
376  if(funCtx && funCtx->range().contains(cursor))
377  return decl;
378  }
379 
380  const auto childContexts = ctx->childContexts();
381  for (DUContext* child : childContexts){
382  Declaration* decl = declarationInLine(_cursor, child);
383  if(decl)
384  return decl;
385  }
386 
387  return nullptr;
388 }
389 
390 DUChainUtils::DUChainItemFilter::~DUChainItemFilter() {
391 }
392 
393 void DUChainUtils::collectItems( DUContext* context, DUChainItemFilter& filter ) {
394 
395  QVector<DUContext*> children = context->childContexts();
396  QVector<Declaration*> localDeclarations = context->localDeclarations();
397 
398  QVector<DUContext*>::const_iterator childIt = children.constBegin();
399  QVector<Declaration*>::const_iterator declIt = localDeclarations.constBegin();
400 
401  while(childIt != children.constEnd() || declIt != localDeclarations.constEnd()) {
402 
403  DUContext* child = nullptr;
404  if(childIt != children.constEnd())
405  child = *childIt;
406 
407  Declaration* decl = nullptr;
408  if(declIt != localDeclarations.constEnd())
409  decl = *declIt;
410 
411  if(decl) {
412  if(child && child->range().start.line >= decl->range().start.line)
413  child = nullptr;
414  }
415 
416  if(child) {
417  if(decl && decl->range().start >= child->range().start)
418  decl = nullptr;
419  }
420 
421  if(decl) {
422  if( filter.accept(decl) ) {
423  //Action is done in the filter
424  }
425 
426  ++declIt;
427  continue;
428  }
429 
430  if(child) {
431  if( filter.accept(child) )
432  collectItems(child, filter);
433  ++childIt;
434  continue;
435  }
436  }
437 }
438 
439 KDevelop::DUContext* DUChainUtils::argumentContext(KDevelop::Declaration* decl) {
440  DUContext* internal = decl->internalContext();
441  if( !internal )
442  return nullptr;
443  if( internal->type() == DUContext::Function )
444  return internal;
445  const auto importedParentContexts = internal->importedParentContexts();
446  for (const DUContext::Import& ctx : importedParentContexts) {
447  if( ctx.context(decl->topContext()) )
448  if( ctx.context(decl->topContext())->type() == DUContext::Function )
449  return ctx.context(decl->topContext());
450  }
451  return nullptr;
452 }
453 
454 QList<IndexedDeclaration> DUChainUtils::collectAllVersions(Declaration* decl) {
455  QList<IndexedDeclaration> ret;
456  ret << IndexedDeclaration(decl);
457 
458  if(decl->inSymbolTable())
459  {
460  uint count;
461  const IndexedDeclaration* allDeclarations;
462  PersistentSymbolTable::self().declarations(decl->qualifiedIdentifier(), count, allDeclarations);
463  for(uint a = 0; a < count; ++a)
464  if(!(allDeclarations[a] == IndexedDeclaration(decl)))
465  ret << allDeclarations[a];
466  }
467 
468  return ret;
469 }
470 
471 static QList<Declaration*> inheritersInternal(const Declaration* decl, uint& maxAllowedSteps, bool collectVersions)
472 {
473  QList<Declaration*> ret;
474 
475  if(!dynamic_cast<const ClassDeclaration*>(decl))
476  return ret;
477 
478  if(maxAllowedSteps == 0)
479  return ret;
480 
481  if(decl->internalContext() && decl->internalContext()->type() == DUContext::Class) {
482  const auto indexedImporters = decl->internalContext()->indexedImporters();
483  for (const IndexedDUContext importer : indexedImporters) {
484 
485  DUContext* imp = importer.data();
486 
487  if(!imp)
488  continue;
489 
490  if(imp->type() == DUContext::Class && imp->owner())
491  ret << imp->owner();
492 
493  --maxAllowedSteps;
494 
495  if(maxAllowedSteps == 0)
496  return ret;
497  }
498  }
499 
500  if(collectVersions && decl->inSymbolTable()) {
501  uint count;
502  const IndexedDeclaration* allDeclarations;
503  PersistentSymbolTable::self().declarations(decl->qualifiedIdentifier(), count, allDeclarations);
504  for(uint a = 0; a < count; ++a) {
505  ++maxAllowedSteps;
506 
507  if(allDeclarations[a].data() && allDeclarations[a].data() != decl) {
508  ret += inheritersInternal(allDeclarations[a].data(), maxAllowedSteps, false);
509  }
510 
511  if(maxAllowedSteps == 0)
512  return ret;
513  }
514  }
515 
516  return ret;
517 }
518 
519 QList<Declaration*> DUChainUtils::inheriters(const Declaration* decl, uint& maxAllowedSteps, bool collectVersions)
520 {
521  auto inheriters = inheritersInternal(decl, maxAllowedSteps, collectVersions);
522 
523  // remove duplicates
524  std::sort(inheriters.begin(), inheriters.end());
525  inheriters.erase(std::unique(inheriters.begin(), inheriters.end()), inheriters.end());
526 
527  return inheriters;
528 }
529 
530 QList<Declaration*> DUChainUtils::overriders(const Declaration* currentClass, const Declaration* overriddenDeclaration, uint& maxAllowedSteps) {
531  QList<Declaration*> ret;
532 
533  if(maxAllowedSteps == 0)
534  return ret;
535 
536  if(currentClass != overriddenDeclaration->context()->owner() && currentClass->internalContext())
537  ret += currentClass->internalContext()->findLocalDeclarations(overriddenDeclaration->identifier(), CursorInRevision::invalid(), currentClass->topContext(), overriddenDeclaration->abstractType());
538 
539  const auto inheriters = DUChainUtils::inheriters(currentClass, maxAllowedSteps);
540  for (Declaration* inheriter : inheriters) {
541  ret += overriders(inheriter, overriddenDeclaration, maxAllowedSteps);
542  }
543 
544  return ret;
545 }
546 
547 static bool hasUse(DUContext* context, int usedDeclarationIndex) {
548  if(usedDeclarationIndex == std::numeric_limits<int>::max())
549  return false;
550 
551  for(int a = 0; a < context->usesCount(); ++a)
552  if(context->uses()[a].m_declarationIndex == usedDeclarationIndex)
553  return true;
554 
555  const auto childContexts = context->childContexts();
556  return std::any_of(childContexts.begin(), childContexts.end(), [&](DUContext* child) {
557  return hasUse(child, usedDeclarationIndex);
558  });
559 }
560 
561 bool DUChainUtils::contextHasUse(DUContext* context, Declaration* declaration) {
562  return hasUse(context, context->topContext()->indexForUsedDeclaration(declaration, false));
563 }
564 
565 static uint countUses(DUContext* context, int usedDeclarationIndex) {
566  if(usedDeclarationIndex == std::numeric_limits<int>::max())
567  return 0;
568 
569  uint ret = 0;
570 
571  for(int a = 0; a < context->usesCount(); ++a)
572  if(context->uses()[a].m_declarationIndex == usedDeclarationIndex)
573  ++ret;
574 
575  const auto childContexts = context->childContexts();
576  for (DUContext* child : childContexts) {
577  ret += countUses(child, usedDeclarationIndex);
578  }
579 
580  return ret;
581 }
582 
583 uint DUChainUtils::contextCountUses(DUContext* context, Declaration* declaration) {
584  return countUses(context, context->topContext()->indexForUsedDeclaration(declaration, false));
585 }
586 
587 Declaration* DUChainUtils::overridden(const Declaration* decl) {
588  const auto* classFunDecl = dynamic_cast<const ClassFunctionDeclaration*>(decl);
589  if(!classFunDecl || !classFunDecl->isVirtual())
590  return nullptr;
591 
592  QList<Declaration*> decls;
593 
594  const auto importedParentContexts = decl->context()->importedParentContexts();
595  for (const DUContext::Import &import : importedParentContexts) {
596  DUContext* ctx = import.context(decl->topContext());
597  if(ctx)
598  decls += ctx->findDeclarations(QualifiedIdentifier(decl->identifier()),
599  CursorInRevision::invalid(), decl->abstractType(), decl->topContext(), DUContext::DontSearchInParent);
600  }
601 
602  auto it = std::find_if(decls.constBegin(), decls.constEnd(), [&](Declaration* found) {
603  const auto* foundClassFunDecl = dynamic_cast<const ClassFunctionDeclaration*>(found);
604  return (foundClassFunDecl && foundClassFunDecl->isVirtual());
605  });
606 
607  return (it != decls.constEnd()) ? *it : nullptr;
608 }
609 
610 DUContext* DUChainUtils::functionContext(Declaration* decl) {
611  DUContext* functionContext = decl->internalContext();
612  if(functionContext && functionContext->type() != DUContext::Function) {
613  const auto importedParentContexts = functionContext->importedParentContexts();
614  for (const DUContext::Import& import : importedParentContexts) {
615  DUContext* ctx = import.context(decl->topContext());
616  if(ctx && ctx->type() == DUContext::Function)
617  functionContext = ctx;
618  }
619  }
620 
621  if(functionContext && functionContext->type() == DUContext::Function)
622  return functionContext;
623  return nullptr;
624 }
625 
626 QVector<KDevelop::Problem::Ptr> KDevelop::DUChainUtils::allProblemsForContext(const KDevelop::ReferencedTopDUContext& top)
627 {
628  QVector<KDevelop::Problem::Ptr> ret;
629 
630  const auto problems = top->problems();
631  const auto contextProblems = ICore::self()->languageController()->staticAssistantsManager()->problemsForContext(top);
632  ret.reserve(problems.size() + contextProblems.size());
633 
634  for (const auto& p : problems) {
635  ret << p;
636  }
637  for (const auto& p : contextProblems) {
638  ret << p;
639  }
640 
641  return ret;
642 }
643 
KDevelop::DUChainUtils::itemUnderCursor
KDEVPLATFORMLANGUAGE_EXPORT ItemUnderCursor itemUnderCursor(const QUrl &url, const KTextEditor::Cursor &cursor)
Returns 1.
Definition: duchainutils.cpp:332
duchainlock.h
KDevelop::DUContext::findDeclarations
QList< Declaration * > findDeclarations(const QualifiedIdentifier &identifier, const CursorInRevision &position=CursorInRevision::invalid(), const AbstractType::Ptr &dataType=AbstractType::Ptr(), const TopDUContext *topContext=nullptr, SearchFlags flags=NoSearchFlags) const
Searches for and returns a declaration with a given identifier in this context, which is currently ac...
Definition: ducontext.cpp:792
KDevelop::TopDUContext::usedDeclarationForIndex
Declaration * usedDeclarationForIndex(unsigned int declarationIndex) const
Tries to retrieve the used declaration.
Definition: topducontext.cpp:1146
KDevelop::DUContext::indexedImporters
KDevVarLengthArray< IndexedDUContext > indexedImporters() const
Returns the list of indexed importers.
Definition: ducontext.cpp:886
KDevelop::DUContext::Global
A context that declares functions, namespaces or classes.
Definition: ducontext.h:103
KDevelop::PersistentSymbolTable::self
static PersistentSymbolTable & self()
Definition: persistentsymboltable.cpp:494
KDevelop::AbstractType::TypeStructure
a structure
Definition: abstracttype.h:220
KDevelop::AbstractType::TypePointer
a pointer
Definition: abstracttype.h:217
KDevelop::DUChainUtils::standardContextForUrl
KDEVPLATFORMLANGUAGE_EXPORT KDevelop::TopDUContext * standardContextForUrl(const QUrl &url, bool preferProxyContext=false)
Asks the language-plugins for standard-contexts for the given url, and returns one if available.
Definition: duchainutils.cpp:273
KDevelop::DUChainUtils::DUChainItemFilter
Definition: duchainutils.h:90
QUrl
duchainutils.h
KDevelop::TopDUContext::indexForUsedDeclaration
int indexForUsedDeclaration(Declaration *declaration, bool create=true)
Retrieves or creates a local index that is to be used for referencing the given.
Definition: topducontext.cpp:1159
KDevelop::ReferencedTopDUContext
KDevelop can unload unused top-context at any time.
Definition: topducontext.h:59
KDevelop::DUChainUtils::collectAllVersions
KDEVPLATFORMLANGUAGE_EXPORT QList< IndexedDeclaration > collectAllVersions(Declaration *decl)
Uses the persistent symbol table to find all occurrences of this declaration, based on its identifier...
Definition: duchainutils.cpp:454
KDevelop::DUChainUtils::iconForProperties
KDEVPLATFORMLANGUAGE_EXPORT QIcon iconForProperties(KTextEditor::CodeCompletionModel::CompletionProperties p)
Definition: duchainutils.cpp:161
KDevelop::TopDUContext::importedParentContexts
QVector< Import > importedParentContexts() const override
Returns the list of imported parent contexts for this context.
Definition: topducontext.cpp:1024
KDevelop::DUChainUtils::DUChainItemFilter::~DUChainItemFilter
virtual ~DUChainItemFilter()
Definition: duchainutils.cpp:390
KDevelop::DUChainUtils::contentContextFromProxyContext
KDEVPLATFORMLANGUAGE_EXPORT TopDUContext * contentContextFromProxyContext(TopDUContext *top)
Returns the content-context associated to the given proxy-contex.
Definition: duchainutils.cpp:247
QVector::constEnd
const_iterator constEnd() const
KDevelop::AbstractType::TypeUnsure
may represent multiple different types
Definition: abstracttype.h:226
KDevelop::Use::m_declarationIndex
int m_declarationIndex
Definition: use.h:61
KDevelop::DUChainUtils::declarationInLine
KDEVPLATFORMLANGUAGE_EXPORT Declaration * declarationInLine(const KTextEditor::Cursor &cursor, KDevelop::DUContext *ctx)
Returns the first declaration in the given line.
Definition: duchainutils.cpp:365
KDevelop::Declaration::isFunctionDeclaration
virtual bool isFunctionDeclaration() const
Determine whether this declaration is a function declaration.
Definition: declaration.cpp:655
QList::constBegin
const_iterator constBegin() const
KDevelop::DUChainBase::transformFromLocalRevision
KTextEditor::Cursor transformFromLocalRevision(const CursorInRevision &cursor) const
KDevelop::DUChainUtils::contextCountUses
KDEVPLATFORMLANGUAGE_EXPORT uint contextCountUses(DUContext *context, Declaration *declaration)
Returns the total count of uses of the given declaration under the given context.
Definition: duchainutils.cpp:583
QList
KDevelop::AbstractType::TypeFunction
a function
Definition: abstracttype.h:219
KDevelop::Declaration::identifier
Identifier identifier() const
Access this declaration's identifier.
Definition: declaration.cpp:204
countUses
static uint countUses(DUContext *context, int usedDeclarationIndex)
Definition: duchainutils.cpp:565
KDevelop::DUChainUtils::overriders
KDEVPLATFORMLANGUAGE_EXPORT QList< Declaration * > overriders(const Declaration *currentClass, const Declaration *overriddenDeclaration, uint &maxAllowedSteps)
Gets all functions that override the function overriddenDeclaration, starting the search at currentCl...
Definition: duchainutils.cpp:530
classmemberdeclaration.h
KDevelop::ParsingEnvironmentFile::isProxyContext
bool isProxyContext() const
A language-specific flag used by C++ to mark one context as a proxy of another.
Definition: parsingenvironment.cpp:177
KDevelop::AbstractType::TypeArray
an array
Definition: abstracttype.h:221
KDevelop::TopDUContext::parsingEnvironmentFile
QExplicitlySharedDataPointer< ParsingEnvironmentFile > parsingEnvironmentFile() const
Definition: topducontext.cpp:567
KDevelop::Declaration
Represents a single declaration in a definition-use chain.
Definition: declaration.h:51
KDevelop::AbstractType::TypeEnumerator
an enumerator type
Definition: abstracttype.h:224
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:399
KDevelop::DUContext::topContext
TopDUContext * topContext() const override
Find the top context.
Definition: ducontext.cpp:1499
KDevelop::DUChainUtils::argumentContext
KDEVPLATFORMLANGUAGE_EXPORT DUContext * argumentContext(Declaration *decl)
Definition: duchainutils.cpp:439
KDevelop::DUChain::chainForDocument
TopDUContext * chainForDocument(const QUrl &document, bool proxyContext=false) const
Return any chain for the given document If available, the version accepting IndexedString should be u...
Definition: duchain.cpp:1389
KDevelop::Declaration::isTypeAlias
bool isTypeAlias() const
Determine if this declaration is a type-alias (in c++ typedef).
Definition: declaration.cpp:538
KDevelop::TopDUContext::url
IndexedString url() const override
Definition: topducontext.cpp:1228
KDevelop::DUContext::importedParentContexts
virtual QVector< Import > importedParentContexts() const
Returns the list of imported parent contexts for this context.
Definition: ducontext.cpp:1220
KDevelop::Declaration::Public
a public declaration
Definition: declaration.h:57
KDevelop::Use::m_range
RangeInRevision m_range
Definition: use.h:60
KDevelop::IndexedDeclaration
Represents a declaration only by its global indices.
Definition: indexeddeclaration.h:33
KDevelop::AbstractType::TypeAbstract
an abstract type
Definition: abstracttype.h:215
KDevelop::DUChainUtils::ItemUnderCursor
Definition: duchainutils.h:71
KDevelop::Declaration::kind
Kind kind() const
Returns the kind of this declaration.
Definition: declaration.cpp:78
KDevelop::DUChainUtils::collectItems
KDEVPLATFORMLANGUAGE_EXPORT void collectItems(DUContext *context, DUChainItemFilter &filter)
walks a context, all its sub-contexts, and all its declarations in exactly the order they appear in t...
Definition: duchainutils.cpp:393
declaration.h
KDevelop::DUChainBase::transformToLocalRevision
CursorInRevision transformToLocalRevision(const KTextEditor::Cursor &cursor) const
Transforms the given cursor in the current document revision to its according position in the parsed ...
Definition: duchainbase.cpp:176
KDevelop::Declaration::Instance
An instance of a type is declared("MyClass m;")
Definition: declaration.h:65
KDevelop::DUChainBase::range
RangeInRevision range() const
Returns the range assigned to this object, in the document revision when this document was last parse...
Definition: duchainbase.cpp:152
KDevelop::Declaration::topContext
TopDUContext * topContext() const override
Determine the top context to which this object belongs.
Definition: declaration.cpp:633
KDevelop::DUChainUtils::overridden
KDEVPLATFORMLANGUAGE_EXPORT Declaration * overridden(const Declaration *decl)
Returns the declaration that is overridden by the given one, or zero.
Definition: duchainutils.cpp:587
KDevelop::AbstractType::ConstModifier
Definition: abstracttype.h:105
KDevelop::Declaration::inSymbolTable
bool inSymbolTable() const
Access whether this declaration is in the symbol table.
Definition: declaration.cpp:573
KDevelop::TopDUContext
The top context in a definition-use chain for one source file.
Definition: topducontext.h:113
use.h
KDevelop::Declaration::context
DUContext * context() const
Access the parent context of this declaration.
Definition: declaration.cpp:279
QIcon
itemUnderCursorInternal
ItemUnderCursorInternal itemUnderCursorInternal(const CursorInRevision &c, DUContext *ctx, RangeInRevision::ContainsBehavior behavior)
Definition: duchainutils.cpp:301
KDevelop::DUChainUtils::allProblemsForContext
KDEVPLATFORMLANGUAGE_EXPORT QVector< KDevelop::Problem::Ptr > allProblemsForContext(const ReferencedTopDUContext &top)
Definition: duchainutils.cpp:626
QVector::reserve
void reserve(int size)
KTextEditor
Definition: duchainbase.h:29
KDevelop::DUContext::Class
A context that declares class members.
Definition: ducontext.h:105
KDevelop::DUContext::DontSearchInParent
IF this flag is set, findDeclarations(..) will not search for the identifier in parent-contexts(which...
Definition: ducontext.h:120
KDevelop::Declaration::Private
a private declaration
Definition: declaration.h:59
KDevelop::DUChainUtils::functionContext
KDEVPLATFORMLANGUAGE_EXPORT DUContext * functionContext(Declaration *decl)
If the given declaration is a function-declaration, this follows the context-structure up to the func...
Definition: duchainutils.cpp:610
KDevelop::DUContext::childContexts
QVector< DUContext * > childContexts() const
Returns the list of immediate child contexts for this context.
Definition: ducontext.cpp:479
persistentsymboltable.h
KDevelop::IndexedDeclaration::data
Declaration * data() const
Definition: indexeddeclaration.h:47
KDevelop::DUContext::findLocalDeclarations
QList< Declaration * > findLocalDeclarations(const IndexedIdentifier &identifier, const CursorInRevision &position=CursorInRevision::invalid(), const TopDUContext *topContext=nullptr, const AbstractType::Ptr &dataType=AbstractType::Ptr(), SearchFlags flags=NoSearchFlags) const
Returns the type of any identifier defined in this context, or null if one is not found.
Definition: ducontext.cpp:535
KDevelop::Declaration::qualifiedIdentifier
QualifiedIdentifier qualifiedIdentifier() const
Determine the global qualified identifier of this declaration.
Definition: declaration.cpp:267
KDevelop::DUChainUtils::inheriters
KDEVPLATFORMLANGUAGE_EXPORT QList< Declaration * > inheriters(const Declaration *decl, uint &maxAllowedSteps, bool collectVersions=true)
If the given declaration is a class, this gets all classes that inherit this one.
Definition: duchainutils.cpp:519
QList::constEnd
const_iterator constEnd() const
KDevelop::TopDUContext::problems
QList< ProblemPointer > problems() const
Returns a list of all problems encountered while parsing this top-context.
Definition: topducontext.cpp:963
KDevelop::AbstractType::TypeDelayed
a delayed type
Definition: abstracttype.h:222
KDevelop::QualifiedIdentifier
Represents a qualified identifier.
Definition: identifier.h:245
RETURN_CACHED_ICON
#define RETURN_CACHED_ICON(name)
We have to construct the item from the pixmap, else the icon will be marked as "load on demand",...
Definition: duchainutils.cpp:156
functiondefinition.h
duchain.h
KDevelop::Declaration::Protected
a protected declaration
Definition: declaration.h:58
classfunctiondeclaration.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::DUChainUtils::completionProperties
KDEVPLATFORMLANGUAGE_EXPORT KTextEditor::CodeCompletionModel::CompletionProperties completionProperties(const Declaration *dec)
Definition: duchainutils.cpp:52
KDevelop::DUContext::Namespace
A context that declares namespace members.
Definition: ducontext.h:104
KDevelop::AbstractType::TypeAlias
a type-alias type
Definition: abstracttype.h:225
KDevelop::DUContext::usesCount
int usesCount() const
Returns the count of uses that can be accessed through uses()
Definition: ducontext.cpp:1333
KDevelop::DUChainUtils::declarationForDefinition
KDEVPLATFORMLANGUAGE_EXPORT Declaration * declarationForDefinition(Declaration *definition, TopDUContext *topContext=nullptr)
If the given declaration is a definition, and has a real declaration attached, returns that declarati...
Definition: duchainutils.cpp:348
specializationstore.h
parsingenvironment.h
QVector
KDevelop::Declaration::internalContext
DUContext * internalContext() const
Retrieve the context that is opened by this declaration, if one exists.
Definition: declaration.cpp:425
inheritersInternal
static QList< Declaration * > inheritersInternal(const Declaration *decl, uint &maxAllowedSteps, bool collectVersions)
Definition: duchainutils.cpp:471
KDevelop::Declaration::abstractType
AbstractType::Ptr abstractType() const
Access this declaration's type.
Definition: declaration.cpp:243
KDevelop::DUContext::owner
Declaration * owner() const
If this context was opened by a declaration or definition, this returns that item.
Definition: ducontext.cpp:486
QVector::constBegin
const_iterator constBegin() const
KDevelop::DUContext::uses
const Use * uses() const
Uses: A "Use" represents any position in a document where a Declaration is used literally.
Definition: ducontext.cpp:1321
KDevelop::DUContext::localDeclarations
virtual QVector< Declaration * > localDeclarations(const TopDUContext *source=nullptr) const
Returns all local declarations.
Definition: ducontext.cpp:967
KDevelop::DUContext::type
ContextType type() const
Definition: ducontext.cpp:1134
classdeclaration.h
ducontext.h
KDevelop::DUChainUtils::iconForDeclaration
KDEVPLATFORMLANGUAGE_EXPORT QIcon iconForDeclaration(const Declaration *dec)
Definition: duchainutils.cpp:242
KDevelop::AbstractType::TypeIntegral
an integral
Definition: abstracttype.h:216
KDevelop::DUContext::Function
A context that declares function-arguments.
Definition: ducontext.h:106
hasUse
static bool hasUse(DUContext *context, int usedDeclarationIndex)
Definition: duchainutils.cpp:547
KDevelop::DUChainUtils::contextHasUse
KDEVPLATFORMLANGUAGE_EXPORT bool contextHasUse(DUContext *context, Declaration *declaration)
Returns whether the given context or any of its child-contexts contain a use of the given declaration...
Definition: duchainutils.cpp:561
KDevelop::DUContext::Enum
A context that contains a list of enumerators.
Definition: ducontext.h:108
KDevelop::AbstractType::TypeReference
a reference
Definition: abstracttype.h:218
KDevelop::AbstractType::TypeEnumeration
an enumeration type
Definition: abstracttype.h:223
KDevelop::DUChain::self
static DUChain * self()
Returns the global static instance.
Definition: duchain.cpp:1230
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 Fri Apr 9 2021 23:29:59 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