• 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
specializationstore.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 "specializationstore.h"
20 #include "declarationid.h"
21 #include "ducontext.h"
22 #include "declaration.h"
23 
24 namespace KDevelop {
25 SpecializationStore::SpecializationStore()
26 {
27 }
28 
29 SpecializationStore::~SpecializationStore()
30 {
31 }
32 
33 SpecializationStore& SpecializationStore::self()
34 {
35  static SpecializationStore store;
36  return store;
37 }
38 
39 void SpecializationStore::set(const DeclarationId& declaration,
40  const IndexedInstantiationInformation& specialization)
41 {
42  Q_ASSERT(specialization.index() >> 16);
43  m_specializations[declaration] = specialization;
44 }
45 
46 IndexedInstantiationInformation SpecializationStore::get(const DeclarationId& declaration)
47 {
48  QHash<DeclarationId, IndexedInstantiationInformation>::const_iterator it = m_specializations.constFind(declaration);
49  if (it != m_specializations.constEnd())
50  return *it;
51  else
52  return IndexedInstantiationInformation();
53 }
54 
55 void SpecializationStore::clear(const DeclarationId& declaration)
56 {
57  QHash<DeclarationId, IndexedInstantiationInformation>::iterator it = m_specializations.find(declaration);
58  if (it != m_specializations.end())
59  m_specializations.erase(it);
60 }
61 
62 void SpecializationStore::clear()
63 {
64  m_specializations.clear();
65 }
66 
67 Declaration* SpecializationStore::applySpecialization(Declaration* declaration, TopDUContext* source,
68  bool recursive)
69 {
70  if (!declaration)
71  return nullptr;
72 
73  IndexedInstantiationInformation specialization = get(declaration->id());
74  if (specialization.index())
75  return declaration->specialize(specialization, source);
76 
77  if (declaration->context() && recursive) {
78  //Find a parent that has a specialization, and specialize this with the info and required depth
79  int depth = 0;
80  DUContext* ctx = declaration->context();
81  IndexedInstantiationInformation specialization;
82  while (ctx && !specialization.index()) {
83  if (ctx->owner())
84  specialization = get(ctx->owner()->id());
85  ++depth;
86  ctx = ctx->parentContext();
87  }
88 
89  if (specialization.index())
90  return declaration->specialize(specialization, source, depth);
91  }
92 
93  return declaration;
94 }
95 
96 DUContext* SpecializationStore::applySpecialization(DUContext* context, TopDUContext* source,
97  bool recursive)
98 {
99  if (!context)
100  return nullptr;
101 
102  if (Declaration* declaration = context->owner())
103  return applySpecialization(declaration, source, recursive)->internalContext();
104 
105  if (context->parentContext() && recursive) {
106  //Find a parent that has a specialization, and specialize this with the info and required depth
107  int depth = 0;
108  DUContext* ctx = context->parentContext();
109  IndexedInstantiationInformation specialization;
110  while (ctx && !specialization.index()) {
111  if (ctx->owner())
112  specialization = get(ctx->owner()->id());
113  ++depth;
114  ctx = ctx->parentContext();
115  }
116 
117  if (specialization.index())
118  return context->specialize(specialization, source, depth);
119  }
120 
121  return context;
122 }
123 }
KDevelop::SpecializationStore::get
IndexedInstantiationInformation get(const DeclarationId &declaration)
Gets the registered specialization for the given declaration-id, or zero.
Definition: specializationstore.cpp:46
KDevelop::SpecializationStore::self
static SpecializationStore & self()
Definition: specializationstore.cpp:33
KDevelop::Declaration
Represents a single declaration in a definition-use chain.
Definition: declaration.h:51
KDevelop::SpecializationStore::applySpecialization
KDevelop::Declaration * applySpecialization(KDevelop::Declaration *declaration, KDevelop::TopDUContext *source, bool recursive=true)
Applies the known specializations for the given declaration using the Declaration::specialize() funct...
Definition: specializationstore.cpp:67
KDevelop::DUContext::specialize
virtual DUContext * specialize(const IndexedInstantiationInformation &specialization, const TopDUContext *topContext, int upDistance=0)
Retrieve the context which is specialized with the given specialization as seen from the given topCon...
Definition: ducontext.cpp:1200
QHash::iterator
declaration.h
KDevelop::TopDUContext
The top context in a definition-use chain for one source file.
Definition: topducontext.h:113
KDevelop::Declaration::context
DUContext * context() const
Access the parent context of this declaration.
Definition: declaration.cpp:279
KDevelop::DeclarationId
Allows clearly identifying a Declaration.
Definition: declarationid.h:50
KDevelop::Declaration::id
virtual DeclarationId id(bool forceDirect=false) const
Definition: declaration.cpp:564
declarationid.h
KDevelop::SpecializationStore
This class allows dynamic management of "current" specializations for declarations.
Definition: specializationstore.h:41
QHash::const_iterator
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
specializationstore.h
KDevelop::Declaration::internalContext
DUContext * internalContext() const
Retrieve the context that is opened by this declaration, if one exists.
Definition: declaration.cpp:425
KDevelop::SpecializationStore::clear
void clear()
Clears all registered specializations.
Definition: specializationstore.cpp:62
KDevelop::DUContext::owner
Declaration * owner() const
If this context was opened by a declaration or definition, this returns that item.
Definition: ducontext.cpp:486
KDevelop::SpecializationStore::set
void set(const DeclarationId &declaration, const IndexedInstantiationInformation &specialization)
Adds/updates the current specialization for the given declaration-id.
Definition: specializationstore.cpp:39
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
ducontext.h
KDevelop::DUContext::parentContext
DUContext * parentContext() const
Returns the immediate parent context of this context.
Definition: ducontext.cpp:512
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