File indexing completed on 2024-05-12 04:38:02

0001 /*
0002     SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #include "indexeddeclaration.h"
0008 
0009 #include "declaration.h"
0010 #include "duchain.h"
0011 #include "topducontextdynamicdata.h"
0012 
0013 using namespace KDevelop;
0014 
0015 IndexedDeclaration::IndexedDeclaration(uint topContext, uint declarationIndex)
0016     : m_topContext(topContext)
0017     , m_declarationIndex(declarationIndex)
0018 {
0019 }
0020 
0021 IndexedDeclaration::IndexedDeclaration(const Declaration* decl)
0022 {
0023     if (decl) {
0024         m_topContext = decl->topContext()->ownIndex();
0025         m_declarationIndex = decl->m_indexInTopContext;
0026     } else {
0027         m_topContext = 0;
0028         m_declarationIndex = 0;
0029     }
0030 }
0031 
0032 Declaration* IndexedDeclaration::declaration() const
0033 {
0034     if (isDummy())
0035         return nullptr;
0036 //   ENSURE_CHAIN_READ_LOCKED
0037     if (!m_topContext || !m_declarationIndex)
0038         return nullptr;
0039 
0040     TopDUContext* ctx = DUChain::self()->chainForIndex(m_topContext);
0041     if (!ctx)
0042         return nullptr;
0043 
0044     return ctx->m_dynamicData->declarationForIndex(m_declarationIndex);
0045 }