| 558 | } |
| 559 | |
| 560 | void Annotator::registerReference(clang::NamedDecl* decl, clang::SourceRange range, Annotator::TokenType type, |
| 561 | Annotator::DeclType declType, std::string typeText, |
| 562 | clang::NamedDecl *usedContext) |
| 563 | { |
| 564 | //annonymouse namespace, anonymous struct, or unnamed argument. |
| 565 | if (decl->getDeclName().isIdentifier() && decl->getName().empty()) |
| 566 | return; |
| 567 | |
| 568 | clang::SourceManager &sm = getSourceMgr(); |
| 569 | |
| 570 | Visibility visibility = getVisibility(decl); |
| 571 | |
| 572 | // Interesting definitions |
| 573 | if (declType == Annotator::Definition && visibility == Visibility::Global) { |
| 574 | if (llvm::isa<clang::TagDecl>(decl) || (llvm::isa<clang::FunctionDecl>(decl) |
| 575 | && decl->getDeclName().isIdentifier() && decl->getName() == "main")) { |
| 576 | if (decl->getDeclContext()->isNamespace() || decl->getDeclContext()->isTranslationUnit()) { |
| 577 | registerInterestingDefinition(range, decl); |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | // When the end location is invalid, this is a virtual range with no matching tokens |
| 583 | // (eg implicit conversion) |
| 584 | bool isVirtualLocation = range.getEnd().isInvalid(); |
| 585 | if (isVirtualLocation) |
| 586 | range = range.getBegin(); |
| 587 | |
| 588 | if (!range.getBegin().isFileID()) { //macro expension. |
| 589 | clang::SourceLocation expensionloc = sm.getExpansionLoc(range.getBegin()); |
| 590 | clang::FileID FID = sm.getFileID(expensionloc); |
| 591 | if (!shouldProcess(FID) || sm.getMacroArgExpandedLocation(range.getBegin()) != |
| 592 | sm.getMacroArgExpandedLocation(range.getEnd())) { |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | clang::SourceLocation spel1 = sm.getSpellingLoc(range.getBegin()); |
| 597 | clang::SourceLocation spel2 = sm.getSpellingLoc(range.getEnd()); |
| 598 | if (sm.getFileID(spel1) != FID |
| 599 | || sm.getFileID(spel2) != FID) { |
| 600 | |
| 601 | if (visibility == Visibility::Global) { |
| 602 | if (usedContext && typeText.empty() && declType == Use) { |
| 603 | typeText = getContextStr(usedContext); |
| 604 | } |
| 605 | addReference(getReferenceAndTitle(decl).first, range, type, declType, typeText, decl); |
| 606 | } |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | range = {spel1, spel2 }; |
| 611 | } |
| 612 | clang::FileID FID = sm.getFileID(range.getBegin()); |
| 613 | |
| 614 | if (!isVirtualLocation && FID != sm.getFileID(range.getEnd())) |
| 615 | return; |
| 616 | |
| 617 | if (!shouldProcess(FID)) |
no test coverage detected