Bug 1410472 - clang-plugin follows the LLVM coding style for real r=mystor
MozReview-Commit-ID: AXrQEjWzxvg
This commit is contained in:
@@ -5,23 +5,22 @@
|
||||
#include "MustOverrideChecker.h"
|
||||
#include "CustomMatchers.h"
|
||||
|
||||
void MustOverrideChecker::registerMatchers(MatchFinder* AstMatcher) {
|
||||
void MustOverrideChecker::registerMatchers(MatchFinder *AstMatcher) {
|
||||
AstMatcher->addMatcher(cxxRecordDecl(isDefinition()).bind("class"), this);
|
||||
}
|
||||
|
||||
void MustOverrideChecker::registerPPCallbacks(CompilerInstance& CI) {
|
||||
void MustOverrideChecker::registerPPCallbacks(CompilerInstance &CI) {
|
||||
this->CI = &CI;
|
||||
}
|
||||
|
||||
void MustOverrideChecker::check(
|
||||
const MatchFinder::MatchResult &Result) {
|
||||
void MustOverrideChecker::check(const MatchFinder::MatchResult &Result) {
|
||||
auto D = Result.Nodes.getNodeAs<CXXRecordDecl>("class");
|
||||
|
||||
// Look through all of our immediate bases to find methods that need to be
|
||||
// overridden
|
||||
typedef std::vector<CXXMethodDecl *> OverridesVector;
|
||||
OverridesVector MustOverrides;
|
||||
for (const auto& Base : D->bases()) {
|
||||
for (const auto &Base : D->bases()) {
|
||||
// The base is either a class (CXXRecordDecl) or it's a templated class...
|
||||
CXXRecordDecl *Parent = Base.getType()
|
||||
.getDesugaredType(D->getASTContext())
|
||||
@@ -34,15 +33,15 @@ void MustOverrideChecker::check(
|
||||
continue;
|
||||
}
|
||||
Parent = Parent->getDefinition();
|
||||
for (const auto& M : Parent->methods()) {
|
||||
for (const auto &M : Parent->methods()) {
|
||||
if (hasCustomAnnotation(M, "moz_must_override"))
|
||||
MustOverrides.push_back(M);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& O : MustOverrides) {
|
||||
for (auto &O : MustOverrides) {
|
||||
bool Overridden = false;
|
||||
for (const auto& M : D->methods()) {
|
||||
for (const auto &M : D->methods()) {
|
||||
// The way that Clang checks if a method M overrides its parent method
|
||||
// is if the method has the same name but would not overload.
|
||||
if (getNameChecked(M) == getNameChecked(O) &&
|
||||
@@ -52,9 +51,8 @@ void MustOverrideChecker::check(
|
||||
}
|
||||
}
|
||||
if (!Overridden) {
|
||||
diag(D->getLocation(), "%0 must override %1",
|
||||
DiagnosticIDs::Error) << D->getDeclName()
|
||||
<< O->getDeclName();
|
||||
diag(D->getLocation(), "%0 must override %1", DiagnosticIDs::Error)
|
||||
<< D->getDeclName() << O->getDeclName();
|
||||
diag(O->getLocation(), "function to override is here",
|
||||
DiagnosticIDs::Note);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user