| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file defines a bunch of recurring problems in the Chromium C++ code. | 5 // This file defines a bunch of recurring problems in the Chromium C++ code. |
| 6 // | 6 // |
| 7 // Checks that are implemented: | 7 // Checks that are implemented: |
| 8 // - Constructors/Destructors should not be inlined if they are of a complex | 8 // - Constructors/Destructors should not be inlined if they are of a complex |
| 9 // class type. | 9 // class type. |
| 10 // - Missing "virtual" keywords on methods that should be virtual. | 10 // - Missing "virtual" keywords on methods that should be virtual. |
| 11 // - Non-annotated overriding virtual methods. | 11 // - Non-annotated overriding virtual methods. |
| 12 // - Virtual methods with nonempty implementations in their headers. | 12 // - Virtual methods with nonempty implementations in their headers. |
| 13 // - Classes that derive from base::RefCounted / base::RefCountedThreadSafe | 13 // - Classes that derive from base::RefCounted / base::RefCountedThreadSafe |
| 14 // should have protected or private destructors. | 14 // should have protected or private destructors. |
| 15 // - WeakPtrFactory members that refer to their outer class should be the last | 15 // - WeakPtrFactory members that refer to their outer class should be the last |
| 16 // member. | 16 // member. |
| 17 // - Enum types with a xxxx_LAST or xxxxLast const actually have that constant | 17 // - Enum types with a xxxx_LAST or xxxxLast const actually have that constant |
| 18 // have the maximal value for that type. | 18 // have the maximal value for that type. |
| 19 | 19 |
| 20 #ifndef TOOLS_CLANG_PLUGINS_FINDBADCONSTRUCTSCONSUMER_H_ | 20 #ifndef TOOLS_CLANG_PLUGINS_FINDBADCONSTRUCTSCONSUMER_H_ |
| 21 #define TOOLS_CLANG_PLUGINS_FINDBADCONSTRUCTSCONSUMER_H_ | 21 #define TOOLS_CLANG_PLUGINS_FINDBADCONSTRUCTSCONSUMER_H_ |
| 22 | 22 |
| 23 #include <memory> |
| 24 |
| 23 #include "clang/AST/AST.h" | 25 #include "clang/AST/AST.h" |
| 24 #include "clang/AST/ASTConsumer.h" | 26 #include "clang/AST/ASTConsumer.h" |
| 25 #include "clang/AST/Attr.h" | 27 #include "clang/AST/Attr.h" |
| 26 #include "clang/AST/CXXInheritance.h" | 28 #include "clang/AST/CXXInheritance.h" |
| 27 #include "clang/AST/RecursiveASTVisitor.h" | 29 #include "clang/AST/RecursiveASTVisitor.h" |
| 28 #include "clang/AST/TypeLoc.h" | 30 #include "clang/AST/TypeLoc.h" |
| 29 #include "clang/Basic/SourceManager.h" | 31 #include "clang/Basic/SourceManager.h" |
| 30 #include "clang/Basic/SourceLocation.h" | 32 #include "clang/Basic/SourceLocation.h" |
| 31 | 33 |
| 34 #include "CheckIPCVisitor.h" |
| 32 #include "ChromeClassTester.h" | 35 #include "ChromeClassTester.h" |
| 33 #include "Options.h" | 36 #include "Options.h" |
| 34 #include "SuppressibleDiagnosticBuilder.h" | 37 #include "SuppressibleDiagnosticBuilder.h" |
| 35 | 38 |
| 36 namespace chrome_checker { | 39 namespace chrome_checker { |
| 37 | 40 |
| 38 // Searches for constructs that we know we don't want in the Chromium code base. | 41 // Searches for constructs that we know we don't want in the Chromium code base. |
| 39 class FindBadConstructsConsumer | 42 class FindBadConstructsConsumer |
| 40 : public clang::RecursiveASTVisitor<FindBadConstructsConsumer>, | 43 : public clang::RecursiveASTVisitor<FindBadConstructsConsumer>, |
| 41 public ChromeClassTester { | 44 public ChromeClassTester { |
| 42 public: | 45 public: |
| 43 FindBadConstructsConsumer(clang::CompilerInstance& instance, | 46 FindBadConstructsConsumer(clang::CompilerInstance& instance, |
| 44 const Options& options); | 47 const Options& options); |
| 45 | 48 |
| 49 void Traverse(clang::ASTContext& context); |
| 50 |
| 46 // RecursiveASTVisitor: | 51 // RecursiveASTVisitor: |
| 52 bool TraverseDecl(clang::Decl* decl); |
| 47 bool VisitDecl(clang::Decl* decl); | 53 bool VisitDecl(clang::Decl* decl); |
| 54 bool VisitTemplateSpecializationType(clang::TemplateSpecializationType* spec); |
| 55 bool VisitCallExpr(clang::CallExpr* call_expr); |
| 48 | 56 |
| 49 // ChromeClassTester overrides: | 57 // ChromeClassTester overrides: |
| 50 void CheckChromeClass(clang::SourceLocation record_location, | 58 void CheckChromeClass(clang::SourceLocation record_location, |
| 51 clang::CXXRecordDecl* record) override; | 59 clang::CXXRecordDecl* record) override; |
| 52 void CheckChromeEnum(clang::SourceLocation enum_location, | 60 void CheckChromeEnum(clang::SourceLocation enum_location, |
| 53 clang::EnumDecl* enum_decl) override; | 61 clang::EnumDecl* enum_decl) override; |
| 54 | 62 |
| 55 private: | 63 private: |
| 56 // The type of problematic ref-counting pattern that was encountered. | 64 // The type of problematic ref-counting pattern that was encountered. |
| 57 enum RefcountIssue { None, ImplicitDestructor, PublicDestructor }; | 65 enum RefcountIssue { None, ImplicitDestructor, PublicDestructor }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 clang::CXXBasePath& path, | 99 clang::CXXBasePath& path, |
| 92 void* user_data); | 100 void* user_data); |
| 93 void PrintInheritanceChain(const clang::CXXBasePath& path); | 101 void PrintInheritanceChain(const clang::CXXBasePath& path); |
| 94 unsigned DiagnosticForIssue(RefcountIssue issue); | 102 unsigned DiagnosticForIssue(RefcountIssue issue); |
| 95 void CheckRefCountedDtors(clang::SourceLocation record_location, | 103 void CheckRefCountedDtors(clang::SourceLocation record_location, |
| 96 clang::CXXRecordDecl* record); | 104 clang::CXXRecordDecl* record); |
| 97 | 105 |
| 98 void CheckWeakPtrFactoryMembers(clang::SourceLocation record_location, | 106 void CheckWeakPtrFactoryMembers(clang::SourceLocation record_location, |
| 99 clang::CXXRecordDecl* record); | 107 clang::CXXRecordDecl* record); |
| 100 | 108 |
| 109 void ParseFunctionTemplates(clang::TranslationUnitDecl* decl); |
| 110 |
| 101 unsigned diag_method_requires_override_; | 111 unsigned diag_method_requires_override_; |
| 102 unsigned diag_redundant_virtual_specifier_; | 112 unsigned diag_redundant_virtual_specifier_; |
| 103 unsigned diag_base_method_virtual_and_final_; | 113 unsigned diag_base_method_virtual_and_final_; |
| 104 unsigned diag_no_explicit_dtor_; | 114 unsigned diag_no_explicit_dtor_; |
| 105 unsigned diag_public_dtor_; | 115 unsigned diag_public_dtor_; |
| 106 unsigned diag_protected_non_virtual_dtor_; | 116 unsigned diag_protected_non_virtual_dtor_; |
| 107 unsigned diag_weak_ptr_factory_order_; | 117 unsigned diag_weak_ptr_factory_order_; |
| 108 unsigned diag_bad_enum_last_value_; | 118 unsigned diag_bad_enum_last_value_; |
| 109 unsigned diag_note_inheritance_; | 119 unsigned diag_note_inheritance_; |
| 110 unsigned diag_note_implicit_dtor_; | 120 unsigned diag_note_implicit_dtor_; |
| 111 unsigned diag_note_public_dtor_; | 121 unsigned diag_note_public_dtor_; |
| 112 unsigned diag_note_protected_non_virtual_dtor_; | 122 unsigned diag_note_protected_non_virtual_dtor_; |
| 123 |
| 124 std::unique_ptr<CheckIPCVisitor> ipc_visitor_; |
| 113 }; | 125 }; |
| 114 | 126 |
| 115 } // namespace chrome_checker | 127 } // namespace chrome_checker |
| 116 | 128 |
| 117 #endif // TOOLS_CLANG_PLUGINS_FINDBADCONSTRUCTSCONSUMER_H_ | 129 #endif // TOOLS_CLANG_PLUGINS_FINDBADCONSTRUCTSCONSUMER_H_ |
| OLD | NEW |