You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
989 B

  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "UseBespokeEnumClassCheck.h"
  4. #include <clang/AST/Type.h>
  5. #include <clang/ASTMatchers/ASTMatchFinder.h>
  6. namespace clang {
  7. namespace tidy {
  8. namespace cmake {
  9. using namespace ast_matchers;
  10. UseBespokeEnumClassCheck::UseBespokeEnumClassCheck(StringRef Name,
  11. ClangTidyContext* Context)
  12. : ClangTidyCheck(Name, Context)
  13. {
  14. }
  15. void UseBespokeEnumClassCheck::registerMatchers(MatchFinder* Finder)
  16. {
  17. Finder->addMatcher(
  18. parmVarDecl(
  19. hasTypeLoc(typeLoc(loc(qualType(asString("_Bool")))).bind("type"))),
  20. this);
  21. }
  22. void UseBespokeEnumClassCheck::check(MatchFinder::MatchResult const& Result)
  23. {
  24. TypeLoc const* Node = Result.Nodes.getNodeAs<TypeLoc>("type");
  25. this->diag(Node->getBeginLoc(),
  26. "use a bespoke enum class instead of booleans as parameters");
  27. }
  28. }
  29. }
  30. }