| 134 | } |
| 135 | |
| 136 | Declaration* DeclarationId::declaration(const TopDUContext* top, bool instantiateIfRequired) const |
| 137 | { |
| 138 | Declaration* ret = nullptr; |
| 139 | |
| 140 | if (m_isDirect == false) { |
| 141 | //Find the declaration by its qualified identifier and additionalIdentity |
| 142 | const auto& id = m_indirectData.identifier; |
| 143 | |
| 144 | auto visitDeclaration = [&](const IndexedDeclaration& indexedDecl) { |
| 145 | auto decl = indexedDecl.data(); |
| 146 | if (decl && m_indirectData.additionalIdentity == decl->additionalIdentity()) { |
| 147 | // Hit |
| 148 | ret = decl; |
| 149 | if (!ret->isForwardDeclaration()) { |
| 150 | return PersistentSymbolTable::VisitorState::Break; |
| 151 | } |
| 152 | } |
| 153 | return PersistentSymbolTable::VisitorState::Continue; |
| 154 | }; |
| 155 | |
| 156 | if (top) { |
| 157 | // Do filtering |
| 158 | PersistentSymbolTable::self().visitFilteredDeclarations(id, top->recursiveImportIndices(), |
| 159 | visitDeclaration); |
| 160 | } else { |
| 161 | //Just accept anything |
| 162 | PersistentSymbolTable::self().visitDeclarations(id, [&](const IndexedDeclaration& indexedDecl) { |
| 163 | ///@todo think this over once we don't pull in all imported top-context any more |
| 164 | //Don't trigger loading of top-contexts from here, it will create a lot of problems |
| 165 | if (DUChain::self()->isInMemory(indexedDecl.topContextIndex())) { |
| 166 | return visitDeclaration(indexedDecl); |
| 167 | } |
| 168 | return PersistentSymbolTable::VisitorState::Continue; |
| 169 | }); |
| 170 | } |
| 171 | } else { |
| 172 | //Find the declaration by m_topContext and m_declaration |
| 173 | ret = m_directData.declaration(); |
| 174 | } |
| 175 | |
| 176 | if (ret) { |
| 177 | if (m_specialization.isValid()) { |
| 178 | const TopDUContext* topContextForSpecialization = top; |
| 179 | if (!instantiateIfRequired) |
| 180 | topContextForSpecialization = nullptr; //If we don't want to instantiate new declarations, set the top-context to zero, so specialize(..) will only look-up |
| 181 | else if (!topContextForSpecialization) |
| 182 | topContextForSpecialization = ret->topContext(); |
| 183 | |
| 184 | return ret->specialize(m_specialization, topContextForSpecialization); |
| 185 | } else { |
| 186 | return ret; |
| 187 | } |
| 188 | } else |
| 189 | return nullptr; |
| 190 | } |
| 191 | |
| 192 | QualifiedIdentifier DeclarationId::qualifiedIdentifier() const |
| 193 | { |