File indexing completed on 2024-05-12 04:38:02
0001 /* 0002 SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org> 0003 SPDX-FileCopyrightText: 2007-2009 David Nolden <david.nolden.kdevelop@art-master.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #include "indexedducontext.h" 0009 0010 #include "ducontext.h" 0011 #include "ducontextdata.h" 0012 #include "ducontextdynamicdata.h" 0013 #include "topducontext.h" 0014 #include "duchain.h" 0015 #include "topducontextdynamicdata.h" 0016 0017 using namespace KDevelop; 0018 0019 IndexedDUContext::IndexedDUContext(uint topContext, uint contextIndex) 0020 : m_topContext(topContext) 0021 , m_contextIndex(contextIndex) 0022 { 0023 } 0024 0025 IndexedDUContext::IndexedDUContext(DUContext* ctx) 0026 { 0027 if (ctx) { 0028 m_topContext = ctx->topContext()->ownIndex(); 0029 m_contextIndex = ctx->m_dynamicData->m_indexInTopContext; 0030 } else { 0031 m_topContext = 0; 0032 m_contextIndex = 0; 0033 } 0034 } 0035 0036 IndexedTopDUContext IndexedDUContext::indexedTopContext() const 0037 { 0038 if (isDummy()) { 0039 return IndexedTopDUContext(); 0040 } 0041 return IndexedTopDUContext(m_topContext); 0042 } 0043 0044 DUContext* IndexedDUContext::context() const 0045 { 0046 if (isDummy()) 0047 return nullptr; 0048 // ENSURE_CHAIN_READ_LOCKED 0049 if (!m_topContext) 0050 return nullptr; 0051 0052 TopDUContext* ctx = DUChain::self()->chainForIndex(m_topContext); 0053 if (!ctx) 0054 return nullptr; 0055 0056 if (!m_contextIndex) 0057 return ctx; 0058 0059 return ctx->m_dynamicData->contextForIndex(m_contextIndex); 0060 }