ClangTidyModule.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===--- tools/extra/clang-tidy/ClangTidyModule.cpp - Clang tidy tool -----===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. ///
  9. /// \file Implements classes required to build clang-tidy modules.
  10. ///
  11. //===----------------------------------------------------------------------===//
  12. #include "ClangTidyModule.h"
  13. #include "ClangTidyCheck.h"
  14. namespace clang::tidy {
  15. void ClangTidyCheckFactories::registerCheckFactory(StringRef Name,
  16. CheckFactory Factory) {
  17. Factories.insert_or_assign(Name, std::move(Factory));
  18. }
  19. std::vector<std::unique_ptr<ClangTidyCheck>>
  20. ClangTidyCheckFactories::createChecks(ClangTidyContext *Context) const {
  21. std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
  22. for (const auto &Factory : Factories) {
  23. if (Context->isCheckEnabled(Factory.getKey()))
  24. Checks.emplace_back(Factory.getValue()(Factory.getKey(), Context));
  25. }
  26. return Checks;
  27. }
  28. std::vector<std::unique_ptr<ClangTidyCheck>>
  29. ClangTidyCheckFactories::createChecksForLanguage(
  30. ClangTidyContext *Context) const {
  31. std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
  32. const LangOptions &LO = Context->getLangOpts();
  33. for (const auto &Factory : Factories) {
  34. if (!Context->isCheckEnabled(Factory.getKey()))
  35. continue;
  36. std::unique_ptr<ClangTidyCheck> Check =
  37. Factory.getValue()(Factory.getKey(), Context);
  38. if (Check->isLanguageVersionSupported(LO))
  39. Checks.push_back(std::move(Check));
  40. }
  41. return Checks;
  42. }
  43. ClangTidyOptions ClangTidyModule::getModuleOptions() {
  44. return ClangTidyOptions();
  45. }
  46. } // namespace clang::tidy