Source code

Revision control

Other Tools

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#include "ParamTraitsEnumChecker.h"
6
#include "CustomMatchers.h"
7
8
void ParamTraitsEnumChecker::registerMatchers(MatchFinder* AstMatcher) {
9
AstMatcher->addMatcher(
10
classTemplateSpecializationDecl(hasName("ParamTraits")).bind("decl"), this);
11
}
12
13
void ParamTraitsEnumChecker::check(const MatchFinder::MatchResult &Result) {
14
const ClassTemplateSpecializationDecl *Decl =
15
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("decl");
16
17
for (auto& Inner : Decl->decls()) {
18
if (auto* Def = dyn_cast<TypedefDecl>(Inner)) {
19
QualType UnderlyingType = Def->getUnderlyingType();
20
QualType CanonicalType = UnderlyingType.getCanonicalType();
21
22
const clang::Type *TypePtr = CanonicalType.getTypePtrOrNull();
23
if (!TypePtr) {
24
return;
25
}
26
27
if (TypePtr->isEnumeralType()) {
28
diag(Decl->getBeginLoc(),
29
"Custom ParamTraits implementation for an enum type",
30
DiagnosticIDs::Error);
31
diag(Decl->getBeginLoc(),
32
"Please use a helper class for example ContiguousEnumSerializer",
33
DiagnosticIDs::Note);
34
}
35
}
36
}
37
}