10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 12 #include "clang/Lex/Lexer.h" 20 void UnusedAliasDeclsCheck::registerMatchers(MatchFinder *Finder) {
23 if (!getLangOpts().CPlusPlus11)
28 Finder->addMatcher(namespaceAliasDecl(isExpansionInMainFile()).bind(
"alias"),
30 Finder->addMatcher(nestedNameSpecifier().bind(
"nns"),
this);
33 void UnusedAliasDeclsCheck::check(
const MatchFinder::MatchResult &
Result) {
34 if (
const auto *AliasDecl = Result.Nodes.getNodeAs<NamedDecl>(
"alias")) {
35 FoundDecls[AliasDecl] = CharSourceRange::getCharRange(
36 AliasDecl->getBeginLoc(),
37 Lexer::findLocationAfterToken(
38 AliasDecl->getEndLoc(), tok::semi, *Result.SourceManager,
44 if (
const auto *NestedName =
45 Result.Nodes.getNodeAs<NestedNameSpecifier>(
"nns")) {
46 if (
const auto *AliasDecl = NestedName->getAsNamespaceAlias()) {
47 FoundDecls[AliasDecl] = CharSourceRange();
52 void UnusedAliasDeclsCheck::onEndOfTranslationUnit() {
53 for (
const auto &FoundDecl : FoundDecls) {
54 if (!FoundDecl.second.isValid())
56 diag(FoundDecl.first->getLocation(),
"namespace alias decl %0 is unused")
57 << FoundDecl.first << FixItHint::CreateRemoval(FoundDecl.second);
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result