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

Method createDeclarationCommon

plugins/clang/duchain/builder.cpp:397–451  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395//BEGIN create*
396 template<CXCursorKind CK, class DeclType>
397 DeclType* createDeclarationCommon(CXCursor cursor, const Identifier& id)
398 {
399 auto range = ClangHelpers::cursorSpellingNameRange(cursor, id);
400
401 if (id.isEmpty()) {
402 // This is either an anonymous function parameter e.g.: void f(int);
403 // Or anonymous struct/class/union e.g.: struct {} anonymous;
404 // Set empty range for it
405 range.end = range.start;
406 }
407
408 // check if cursor is inside a macro expansion (refer to rangeInRevisionForUse)
409 auto clangRange = clang_Cursor_getSpellingNameRange(cursor, 0, 0);
410 unsigned int expansionLocOffset;
411 const auto clangRangeStart = clang_getRangeStart(clangRange);
412 clang_getExpansionLocation(clangRangeStart, nullptr, nullptr, nullptr, &expansionLocOffset);
413 if (m_macroExpansionLocations.contains(expansionLocOffset)) {
414 unsigned int fileLocOffset;
415 clang_getFileLocation(clangRangeStart, nullptr, nullptr, nullptr, &fileLocOffset);
416 // Set empty ranges for declarations inside macro expansion
417 if (fileLocOffset == expansionLocOffset) {
418 range.end = range.start;
419 }
420 }
421
422 if (m_update) {
423 const IndexedIdentifier indexedId(id);
424 DUChainWriteLocker lock;
425 auto it = m_parentContext->previousChildDeclarations.begin();
426 while (it != m_parentContext->previousChildDeclarations.end()) {
427 auto decl = dynamic_cast<DeclType*>(*it);
428 if (decl && decl->indexedIdentifier() == indexedId) {
429 decl->setRange(range);
430 m_parentContext->resortLocalDeclarations = true;
431 setDeclData<CK>(cursor, decl);
432 m_cursorToDeclarationCache[cursor] = decl;
433 m_parentContext->previousChildDeclarations.erase(it);
434 return decl;
435 }
436 ++it;
437 }
438 }
439 auto decl = new DeclType(range, nullptr);
440 decl->setIdentifier(id);
441#if CINDEX_VERSION_MINOR >= 32
442 decl->setExplicitlyTyped(clang_getCursorType(cursor).kind != CXType_Auto);
443#endif
444 m_cursorToDeclarationCache[cursor] = decl;
445 setDeclData<CK>(cursor, decl);
446 {
447 DUChainWriteLocker lock;
448 decl->setContext(m_parentContext->context);
449 }
450 return decl;
451 }
452
453 template<CXCursorKind CK, class DeclType>
454 Declaration* createDeclaration(CXCursor cursor, const Identifier& id, DUContext *context)

Callers

nothing calls this directly

Calls 8

setRangeMethod · 0.80
setExplicitlyTypedMethod · 0.80
isEmptyMethod · 0.45
containsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
setIdentifierMethod · 0.45
setContextMethod · 0.45

Tested by

no test coverage detected