Bug 1324315 - Refactor the clang plugin to use a framework similar to clang-tidy's; r=mystor
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user