MCPcopy Create free account
hub / github.com/KDE/kdevelop / Visitor

Method Visitor

plugins/clang/duchain/builder.cpp:1561–1646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1559}
1560
1561Visitor::Visitor(CXTranslationUnit tu, CXFile file,
1562 const IncludeFileContexts& includes, const bool update)
1563 : m_file(file)
1564 , m_includes(includes)
1565 , m_parentContext(nullptr)
1566 , m_update(update)
1567{
1568 CXCursor tuCursor = clang_getTranslationUnitCursor(tu);
1569 auto top = includes[file];
1570
1571 // when updating, this contains child contexts that should be kept alive
1572 // even when they are not part of the AST anymore
1573 // this is required for some assistants, such as the signature assistant
1574 QSet<DUContext*> keepAliveContexts;
1575 {
1576 DUChainReadLocker lock;
1577 const auto problems = top->problems();
1578 for (const auto& problem : problems) {
1579 const auto& desc = problem->description();
1580 if (desc.startsWith(QLatin1String("Return type of out-of-line definition of '"))
1581 && desc.endsWith(QLatin1String("' differs from that in the declaration"))) {
1582 auto ctx = top->findContextAt(problem->range().start);
1583 // keep the context and its parents alive
1584 // this also keeps declarations in this context alive
1585 while (ctx) {
1586 keepAliveContexts << ctx;
1587 ctx = ctx->parentContext();
1588 }
1589 }
1590 }
1591 }
1592
1593 CurrentContext parent(top, keepAliveContexts);
1594 m_parentContext = &parent;
1595 clang_visitChildren(tuCursor, &visitCursor, this);
1596
1597 if (m_update) {
1598 DUChainWriteLocker lock;
1599 top->deleteUsesRecursively();
1600 }
1601 for (const auto &contextUses : m_uses) {
1602 for (const auto &cursor : contextUses.second) {
1603 auto referenced = referencedCursor(cursor);
1604 if (clang_Cursor_isNull(referenced)) {
1605 continue;
1606 }
1607 // first, try the canonical referenced cursor
1608 // this is important to get the correct function declaration e.g.
1609 auto canonicalReferenced = clang_getCanonicalCursor(referenced);
1610 auto used = findDeclaration(canonicalReferenced);
1611
1612 if (!used) {
1613 // if the above failed, try the non-canonicalized version as a fallback
1614 // this is required for friend declarations that occur before
1615 // the real declaration. there, the canonical cursor points to
1616 // the friend declaration which is not what we are looking for
1617 used = findDeclaration(referenced);
1618 }

Callers

nothing calls this directly

Calls 13

referencedCursorFunction · 0.85
findDeclarationFunction · 0.85
rangeInRevisionForUseFunction · 0.85
endsWithMethod · 0.80
findContextAtMethod · 0.80
createUseMethod · 0.80
problemsMethod · 0.45
descriptionMethod · 0.45
rangeMethod · 0.45
parentContextMethod · 0.45
deleteUsesRecursivelyMethod · 0.45

Tested by

no test coverage detected