//===--- MySecondCheckCheck.cpp - clang-tidy ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "MySecondCheckCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

using namespace clang::ast_matchers;

namespace clang {
namespace tidy {
namespace gjb {

void MySecondCheckCheck::registerMatchers(MatchFinder *Finder) {
  // FIXME: Add matchers.
  Finder->addMatcher(functionDecl(isExpansionInMainFile())
                         .bind("func"),
                     this);
}

void MySecondCheckCheck::check(const MatchFinder::MatchResult &Result) {
  // FIXME: Add callback implementation.

  if (const auto *MatchedDecl =
          Result.Nodes.getNodeAs<FunctionDecl>("func")){
    /// Func doesn't used in main file
    if (!MatchedDecl->isUsed() && MatchedDecl->getName() != "main")
      diag(MatchedDecl->getLocation(),
           "Function '%0' has never be used in main file")
          << MatchedDecl->getName();
  }
}

} // namespace gjb
} // namespace tidy
} // namespace clang
