Bug 1324328 - Remove MozChecker and some unused code; r=mystor

This commit is contained in:
Ehsan Akhgari 2016-12-18 20:58:56 -05:00
Родитель 2f3ebccb92
Коммит 21f0768c95
11 изменённых файлов: 33 добавлений и 130 удалений

Просмотреть файл

@ -5,7 +5,6 @@
#ifndef CustomMatchers_h__
#define CustomMatchers_h__
#include "MozChecker.h"
#include "MemMoveAnnotation.h"
#include "Utils.h"
@ -15,25 +14,25 @@ namespace ast_matchers {
/// This matcher will match any function declaration that is declared as a heap
/// allocator.
AST_MATCHER(FunctionDecl, heapAllocator) {
return MozChecker::hasCustomAnnotation(&Node, "moz_heap_allocator");
return hasCustomAnnotation(&Node, "moz_heap_allocator");
}
/// This matcher will match any declaration that is marked as not accepting
/// arithmetic expressions in its arguments.
AST_MATCHER(Decl, noArithmeticExprInArgs) {
return MozChecker::hasCustomAnnotation(&Node, "moz_no_arith_expr_in_arg");
return hasCustomAnnotation(&Node, "moz_no_arith_expr_in_arg");
}
/// This matcher will match any C++ class that is marked as having a trivial
/// constructor and destructor.
AST_MATCHER(CXXRecordDecl, hasTrivialCtorDtor) {
return MozChecker::hasCustomAnnotation(&Node, "moz_trivial_ctor_dtor");
return hasCustomAnnotation(&Node, "moz_trivial_ctor_dtor");
}
/// This matcher will match any function declaration that is marked to prohibit
/// calling AddRef or Release on its return value.
AST_MATCHER(FunctionDecl, hasNoAddRefReleaseOnReturnAttr) {
return MozChecker::hasCustomAnnotation(&Node,
return hasCustomAnnotation(&Node,
"moz_no_addref_release_on_return");
}
@ -121,7 +120,7 @@ AST_MATCHER(CXXRecordDecl, hasRefCntMember) {
AST_MATCHER(QualType, hasVTable) { return typeHasVTable(Node); }
AST_MATCHER(CXXRecordDecl, hasNeedsNoVTableTypeAttr) {
return MozChecker::hasCustomAnnotation(&Node, "moz_needs_no_vtable_type");
return hasCustomAnnotation(&Node, "moz_needs_no_vtable_type");
}
/// This matcher will select classes which are non-memmovable
@ -131,12 +130,12 @@ AST_MATCHER(QualType, isNonMemMovable) {
/// This matcher will select classes which require a memmovable template arg
AST_MATCHER(CXXRecordDecl, needsMemMovableTemplateArg) {
return MozChecker::hasCustomAnnotation(&Node, "moz_needs_memmovable_type");
return hasCustomAnnotation(&Node, "moz_needs_memmovable_type");
}
/// This matcher will select classes which require all members to be memmovable
AST_MATCHER(CXXRecordDecl, needsMemMovableMembers) {
return MozChecker::hasCustomAnnotation(&Node, "moz_needs_memmovable_members");
return hasCustomAnnotation(&Node, "moz_needs_memmovable_members");
}
AST_MATCHER(CXXConstructorDecl, isInterestingImplicitCtor) {
@ -159,7 +158,7 @@ AST_MATCHER(CXXConstructorDecl, isInterestingImplicitCtor) {
// We can't call this "isImplicit" since it clashes with an existing matcher in
// clang.
AST_MATCHER(CXXConstructorDecl, isMarkedImplicit) {
return MozChecker::hasCustomAnnotation(&Node, "moz_implicit");
return hasCustomAnnotation(&Node, "moz_implicit");
}
AST_MATCHER(CXXRecordDecl, isConcreteClass) { return !Node.isAbstract(); }
@ -167,7 +166,7 @@ AST_MATCHER(CXXRecordDecl, isConcreteClass) { return !Node.isAbstract(); }
AST_MATCHER(QualType, autoNonAutoableType) {
if (const AutoType *T = Node->getContainedAutoType()) {
if (const CXXRecordDecl *Rec = T->getAsCXXRecordDecl()) {
return MozChecker::hasCustomAnnotation(Rec, "moz_non_autoable");
return hasCustomAnnotation(Rec, "moz_non_autoable");
}
}
return false;
@ -225,7 +224,7 @@ AST_MATCHER(CXXRecordDecl, hasBaseClasses) {
AST_MATCHER(CXXMethodDecl, isRequiredBaseMethod) {
const CXXMethodDecl *Decl = Node.getCanonicalDecl();
return Decl
&& MozChecker::hasCustomAnnotation(Decl, "moz_required_base_method");
&& hasCustomAnnotation(Decl, "moz_required_base_method");
}
AST_MATCHER(CXXMethodDecl, isNonVirtual) {

Просмотреть файл

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CustomTypeAnnotation.h"
#include "MozChecker.h"
CustomTypeAnnotation StackClass =
CustomTypeAnnotation("moz_stack_class", "stack");
@ -18,57 +17,6 @@ CustomTypeAnnotation NonTemporaryClass =
CustomTypeAnnotation NonParam =
CustomTypeAnnotation("moz_non_param", "non-param");
void CustomTypeAnnotation::dumpAnnotationReason(DiagnosticsEngine &Diag,
QualType T,
SourceLocation Loc) {
unsigned InheritsID = Diag.getDiagnosticIDs()->getCustomDiagID(
DiagnosticIDs::Note,
"%1 is a %0 type because it inherits from a %0 type %2");
unsigned MemberID = Diag.getDiagnosticIDs()->getCustomDiagID(
DiagnosticIDs::Note, "%1 is a %0 type because member %2 is a %0 type %3");
unsigned ArrayID = Diag.getDiagnosticIDs()->getCustomDiagID(
DiagnosticIDs::Note,
"%1 is a %0 type because it is an array of %0 type %2");
unsigned TemplID = Diag.getDiagnosticIDs()->getCustomDiagID(
DiagnosticIDs::Note,
"%1 is a %0 type because it has a template argument %0 type %2");
AnnotationReason Reason = directAnnotationReason(T);
for (;;) {
switch (Reason.Kind) {
case RK_ArrayElement:
Diag.Report(Loc, ArrayID) << Pretty << T << Reason.Type;
break;
case RK_BaseClass: {
const CXXRecordDecl *Declaration = T->getAsCXXRecordDecl();
assert(Declaration && "This type should be a C++ class");
Diag.Report(Declaration->getLocation(), InheritsID) << Pretty << T
<< Reason.Type;
break;
}
case RK_Field:
Diag.Report(Reason.Field->getLocation(), MemberID)
<< Pretty << T << Reason.Field << Reason.Type;
break;
case RK_TemplateInherited: {
const CXXRecordDecl *Declaration = T->getAsCXXRecordDecl();
assert(Declaration && "This type should be a C++ class");
Diag.Report(Declaration->getLocation(), TemplID) << Pretty << T
<< Reason.Type;
break;
}
default:
// FIXME (bug 1203263): note the original annotation.
return;
}
T = Reason.Type;
Reason = directAnnotationReason(T);
}
}
void CustomTypeAnnotation::dumpAnnotationReason(BaseCheck &Check,
QualType T,
SourceLocation Loc) {
@ -123,7 +71,7 @@ bool CustomTypeAnnotation::hasLiteralAnnotation(QualType T) const {
#else
if (const CXXRecordDecl *D = T->getAsCXXRecordDecl()) {
#endif
return hasFakeAnnotation(D) || MozChecker::hasCustomAnnotation(D, Spelling);
return hasFakeAnnotation(D) || hasCustomAnnotation(D, Spelling);
}
return false;
}
@ -176,7 +124,7 @@ CustomTypeAnnotation::directAnnotationReason(QualType T) {
// Recurse into template arguments if the annotation
// MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS is present
if (MozChecker::hasCustomAnnotation(
if (hasCustomAnnotation(
Declaration, "moz_inherit_type_annotations_from_template_args")) {
const ClassTemplateSpecializationDecl *Spec =
dyn_cast<ClassTemplateSpecializationDecl>(Declaration);

Просмотреть файл

@ -39,8 +39,6 @@ public:
bool hasEffectiveAnnotation(QualType T) {
return directAnnotationReason(T).valid();
}
void dumpAnnotationReason(DiagnosticsEngine &Diag, QualType T,
SourceLocation Loc);
void dumpAnnotationReason(BaseCheck &Check, QualType T,
SourceLocation Loc);

Просмотреть файл

@ -22,7 +22,7 @@ void ExplicitOperatorBoolChecker::check(
const CXXRecordDecl *Clazz = Method->getParent();
if (!Method->isExplicitSpecified() &&
!MozChecker::hasCustomAnnotation(Method, "moz_implicit") &&
!hasCustomAnnotation(Method, "moz_implicit") &&
!ASTIsInSystemHeader(Method->getASTContext(), *Method) &&
isInterestingDeclForImplicitConversion(Method)) {
diag(Method->getLocStart(), "bad implicit conversion operator for %0",

Просмотреть файл

@ -2,26 +2,15 @@
* 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 "MozChecker.h"
#include "DiagnosticsMatcher.h"
class MozCheckAction : public PluginASTAction {
public:
ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI,
StringRef FileName) override {
#if CLANG_VERSION_FULL >= 306
std::unique_ptr<MozChecker> Checker(llvm::make_unique<MozChecker>(CI));
ASTConsumerPtr Other(Checker->getOtherConsumer());
std::vector<ASTConsumerPtr> Consumers;
Consumers.push_back(std::move(Checker));
Consumers.push_back(std::move(Other));
return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
#else
MozChecker *Checker = new MozChecker(CI);
ASTConsumer *Consumers[] = {Checker, Checker->getOtherConsumer()};
return new MultiplexConsumer(Consumers);
#endif
void* Buffer = CI.getASTContext().Allocate<DiagnosticsMatcher>();
auto Matcher = new(Buffer) DiagnosticsMatcher(CI);
return Matcher->makeASTConsumer();
}
bool ParseArgs(const CompilerInstance &CI,

Просмотреть файл

@ -1,20 +0,0 @@
/* 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 "MozChecker.h"
#include "CustomTypeAnnotation.h"
#include "Utils.h"
bool MozChecker::hasCustomAnnotation(const Decl *D, const char *Spelling) {
iterator_range<specific_attr_iterator<AnnotateAttr>> Attrs =
D->specific_attrs<AnnotateAttr>();
for (AnnotateAttr *Attr : Attrs) {
if (Attr->getAnnotation() == Spelling) {
return true;
}
}
return false;
}

Просмотреть файл

@ -1,23 +0,0 @@
/* 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/. */
#ifndef MozChecker_h__
#define MozChecker_h__
#include "DiagnosticsMatcher.h"
class MozChecker : public ASTConsumer, public RecursiveASTVisitor<MozChecker> {
DiagnosticsMatcher Matcher;
public:
MozChecker(CompilerInstance &CI) :
Matcher(CI) {}
virtual ~MozChecker() {}
ASTConsumerPtr getOtherConsumer() { return Matcher.makeASTConsumer(); }
static bool hasCustomAnnotation(const Decl *D, const char *Spelling);
};
#endif

Просмотреть файл

@ -35,7 +35,7 @@ void MustOverrideChecker::check(
}
Parent = Parent->getDefinition();
for (const auto& M : Parent->methods()) {
if (MozChecker::hasCustomAnnotation(M, "moz_must_override"))
if (hasCustomAnnotation(M, "moz_must_override"))
MustOverrides.push_back(M);
}
}

Просмотреть файл

@ -12,7 +12,7 @@ void OverrideBaseCallChecker::registerMatchers(MatchFinder* AstMatcher) {
bool OverrideBaseCallChecker::isRequiredBaseMethod(
const CXXMethodDecl *Method) {
return MozChecker::hasCustomAnnotation(Method, "moz_required_base_method");
return hasCustomAnnotation(Method, "moz_required_base_method");
}
void OverrideBaseCallChecker::evaluateExpression(

Просмотреть файл

@ -352,12 +352,25 @@ inline const FieldDecl *getBaseRefCntMember(QualType T) {
return Clazz ? getBaseRefCntMember(Clazz) : 0;
}
inline bool hasCustomAnnotation(const Decl *D, const char *Spelling) {
iterator_range<specific_attr_iterator<AnnotateAttr>> Attrs =
D->specific_attrs<AnnotateAttr>();
for (AnnotateAttr *Attr : Attrs) {
if (Attr->getAnnotation() == Spelling) {
return true;
}
}
return false;
}
inline bool isPlacementNew(const CXXNewExpr *Expression) {
// Regular new expressions aren't placement new
if (Expression->getNumPlacementArgs() == 0)
return false;
const FunctionDecl *Declaration = Expression->getOperatorNew();
if (Declaration && MozChecker::hasCustomAnnotation(Declaration,
if (Declaration && hasCustomAnnotation(Declaration,
"moz_heap_allocator")) {
return false;
}

Просмотреть файл

@ -15,7 +15,6 @@ UNIFIED_SOURCES += [
'ExplicitOperatorBoolChecker.cpp',
'KungFuDeathGripChecker.cpp',
'MozCheckAction.cpp',
'MozChecker.cpp',
'MustOverrideChecker.cpp',
'MustUseChecker.cpp',
'NaNExprChecker.cpp',