1 /* This file is part of KDevelop
2 Copyright 2008 David Nolden <david.nolden.kdevelop@art-master.de>
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.
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.
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.
19 #include "specializationstore.h"
20 #include "declarationid.h"
21 #include "ducontext.h"
25 SpecializationStore::SpecializationStore() {
28 SpecializationStore::~SpecializationStore() {
31 SpecializationStore
& SpecializationStore::self() {
32 static SpecializationStore store
;
36 void SpecializationStore::set(DeclarationId declaration
, uint specialization
) {
37 Q_ASSERT(specialization
>> 16);
38 m_specializations
[declaration
] = specialization
;
41 uint
SpecializationStore::get(DeclarationId declaration
) {
42 QHash
<DeclarationId
, uint
>::const_iterator it
= m_specializations
.find(declaration
);
43 if(it
!= m_specializations
.end())
49 void SpecializationStore::clear(DeclarationId declaration
) {
50 QHash
<DeclarationId
, uint
>::iterator it
= m_specializations
.find(declaration
);
51 if(it
!= m_specializations
.end())
52 m_specializations
.erase(it
);
55 void SpecializationStore::clear() {
56 m_specializations
.clear();
59 Declaration
* SpecializationStore::applySpecialization(KDevelop::Declaration
* declaration
, KDevelop::TopDUContext
* source
, bool recursive
) {
63 uint specialization
= get(declaration
->id());
65 return declaration
->specialize(specialization
, source
);
67 if(declaration
->context() && recursive
) {
69 //Find a parent that has a specialization, and specialize this with the info and required depth
71 DUContext
* ctx
= declaration
->context();
72 uint specialization
= 0;
73 while(ctx
&& !specialization
) {
75 specialization
= get(ctx
->owner()->id());
77 ctx
= ctx
->parentContext();
81 return declaration
->specialize(specialization
, source
, depth
);
87 DUContext
* SpecializationStore::applySpecialization(KDevelop::DUContext
* context
, KDevelop::TopDUContext
* source
, bool recursive
) {
91 if(Declaration
* declaration
= context
->owner())
92 return applySpecialization(declaration
, source
, recursive
)->internalContext();
94 if(context
->parentContext() && recursive
) {
95 //Find a parent that has a specialization, and specialize this with the info and required depth
97 DUContext
* ctx
= context
->parentContext();
98 uint specialization
= 0;
99 while(ctx
&& !specialization
) {
101 specialization
= get(ctx
->owner()->id());
103 ctx
= ctx
->parentContext();
107 return context
->specialize(specialization
, source
, depth
);