summaryrefslogtreecommitdiff
path: root/Utilities/ClangTidyModule/UseBespokeEnumClassCheck.cxx
blob: 26f37493747488b09e90dea83cbd1a1286e2c0f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#include "UseBespokeEnumClassCheck.h"

#include <clang/AST/Type.h>
#include <clang/ASTMatchers/ASTMatchFinder.h>

namespace clang {
namespace tidy {
namespace cmake {
using namespace ast_matchers;

UseBespokeEnumClassCheck::UseBespokeEnumClassCheck(StringRef Name,
                                                   ClangTidyContext* Context)
  : ClangTidyCheck(Name, Context)
{
}

void UseBespokeEnumClassCheck::registerMatchers(MatchFinder* Finder)
{
  Finder->addMatcher(
    parmVarDecl(
      hasTypeLoc(typeLoc(loc(qualType(asString("_Bool")))).bind("type"))),
    this);
}

void UseBespokeEnumClassCheck::check(const MatchFinder::MatchResult& Result)
{
  const TypeLoc* Node = Result.Nodes.getNodeAs<TypeLoc>("type");
  this->diag(Node->getBeginLoc(),
             "use a bespoke enum class instead of booleans as parameters");
}
}
}
}