2017-12-05 18:26:41 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ParamTraitsEnumChecker.h"
|
|
|
|
#include "CustomMatchers.h"
|
|
|
|
|
2020-02-17 21:30:50 +03:00
|
|
|
void ParamTraitsEnumChecker::registerMatchers(MatchFinder *AstMatcher) {
|
2017-12-05 18:26:41 +03:00
|
|
|
AstMatcher->addMatcher(
|
2020-02-17 21:30:50 +03:00
|
|
|
classTemplateSpecializationDecl(hasName("ParamTraits")).bind("decl"),
|
|
|
|
this);
|
2017-12-05 18:26:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParamTraitsEnumChecker::check(const MatchFinder::MatchResult &Result) {
|
|
|
|
const ClassTemplateSpecializationDecl *Decl =
|
2020-02-17 21:30:50 +03:00
|
|
|
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("decl");
|
2017-12-05 18:26:41 +03:00
|
|
|
|
2020-02-17 21:30:50 +03:00
|
|
|
for (auto &Inner : Decl->decls()) {
|
|
|
|
if (auto *Def = dyn_cast<TypedefDecl>(Inner)) {
|
2017-12-05 18:26:41 +03:00
|
|
|
QualType UnderlyingType = Def->getUnderlyingType();
|
|
|
|
QualType CanonicalType = UnderlyingType.getCanonicalType();
|
|
|
|
|
|
|
|
const clang::Type *TypePtr = CanonicalType.getTypePtrOrNull();
|
|
|
|
if (!TypePtr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TypePtr->isEnumeralType()) {
|
2018-11-03 16:41:36 +03:00
|
|
|
diag(Decl->getBeginLoc(),
|
2017-12-05 18:26:41 +03:00
|
|
|
"Custom ParamTraits implementation for an enum type",
|
|
|
|
DiagnosticIDs::Error);
|
2018-11-03 16:41:36 +03:00
|
|
|
diag(Decl->getBeginLoc(),
|
2017-12-05 18:26:41 +03:00
|
|
|
"Please use a helper class for example ContiguousEnumSerializer",
|
|
|
|
DiagnosticIDs::Note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|