Bug 1324315 - Refactor the clang plugin to use a framework similar to clang-tidy's; r=mystor

This commit is contained in:
Ehsan Akhgari
2016-12-17 21:14:37 -05:00
parent 8e6e79ff90
commit 682fa26f9e
52 changed files with 690 additions and 407 deletions

View File

@@ -5,24 +5,17 @@
#include "ExplicitImplicitChecker.h"
#include "CustomMatchers.h"
void ExplicitImplicitChecker::registerMatcher(MatchFinder& AstMatcher) {
AstMatcher.addMatcher(cxxConstructorDecl(isInterestingImplicitCtor(),
ofClass(allOf(isConcreteClass(),
decl().bind("class"))),
unless(isMarkedImplicit()))
void ExplicitImplicitChecker::registerMatchers(MatchFinder* AstMatcher) {
AstMatcher->addMatcher(cxxConstructorDecl(isInterestingImplicitCtor(),
ofClass(allOf(isConcreteClass(),
decl().bind("class"))),
unless(isMarkedImplicit()))
.bind("ctor"),
this);
}
void ExplicitImplicitChecker::run(
void ExplicitImplicitChecker::check(
const MatchFinder::MatchResult &Result) {
DiagnosticsEngine &Diag = Result.Context->getDiagnostics();
unsigned ErrorID = Diag.getDiagnosticIDs()->getCustomDiagID(
DiagnosticIDs::Error, "bad implicit conversion constructor for %0");
unsigned NoteID = Diag.getDiagnosticIDs()->getCustomDiagID(
DiagnosticIDs::Note,
"consider adding the explicit keyword to the constructor");
// We've already checked everything in the matcher, so we just have to report
// the error.
@@ -31,6 +24,8 @@ void ExplicitImplicitChecker::run(
const CXXRecordDecl *Declaration =
Result.Nodes.getNodeAs<CXXRecordDecl>("class");
Diag.Report(Ctor->getLocation(), ErrorID) << Declaration->getDeclName();
Diag.Report(Ctor->getLocation(), NoteID);
diag(Ctor->getLocation(), "bad implicit conversion constructor for %0",
DiagnosticIDs::Error) << Declaration->getDeclName();
diag(Ctor->getLocation(), "consider adding the explicit keyword to the constructor",
DiagnosticIDs::Note);
}