| 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 #include "clang/AST/AST.h" | 20 #include "clang/AST/AST.h" |
| 21 #include "clang/AST/ASTConsumer.h" | 21 #include "clang/AST/ASTConsumer.h" |
| 22 #include "clang/AST/Attr.h" | 22 #include "clang/AST/Attr.h" |
| 23 #include "clang/AST/CXXInheritance.h" | 23 #include "clang/AST/CXXInheritance.h" |
| 24 #include "clang/AST/RecursiveASTVisitor.h" |
| 24 #include "clang/AST/TypeLoc.h" | 25 #include "clang/AST/TypeLoc.h" |
| 25 #include "clang/Basic/SourceManager.h" | 26 #include "clang/Basic/SourceManager.h" |
| 26 | 27 |
| 27 #include "ChromeClassTester.h" | 28 #include "ChromeClassTester.h" |
| 28 #include "Options.h" | 29 #include "Options.h" |
| 29 | 30 |
| 30 namespace chrome_checker { | 31 namespace chrome_checker { |
| 31 | 32 |
| 32 // Searches for constructs that we know we don't want in the Chromium code base. | 33 // Searches for constructs that we know we don't want in the Chromium code base. |
| 33 class FindBadConstructsConsumer : public ChromeClassTester { | 34 class FindBadConstructsConsumer |
| 35 : public clang::RecursiveASTVisitor<FindBadConstructsConsumer>, |
| 36 public ChromeClassTester { |
| 34 public: | 37 public: |
| 35 FindBadConstructsConsumer(clang::CompilerInstance& instance, | 38 FindBadConstructsConsumer(clang::CompilerInstance& instance, |
| 36 const Options& options); | 39 const Options& options); |
| 37 | 40 |
| 41 // RecursiveASTVisitor: |
| 42 bool VisitDecl(clang::Decl* decl); |
| 43 |
| 38 // ChromeClassTester overrides: | 44 // ChromeClassTester overrides: |
| 39 void CheckChromeClass(clang::SourceLocation record_location, | 45 void CheckChromeClass(clang::SourceLocation record_location, |
| 40 clang::CXXRecordDecl* record) override; | 46 clang::CXXRecordDecl* record) override; |
| 41 void CheckChromeEnum(clang::SourceLocation enum_location, | 47 void CheckChromeEnum(clang::SourceLocation enum_location, |
| 42 clang::EnumDecl* enum_decl) override; | 48 clang::EnumDecl* enum_decl) override; |
| 43 | 49 |
| 44 private: | 50 private: |
| 45 // The type of problematic ref-counting pattern that was encountered. | 51 // The type of problematic ref-counting pattern that was encountered. |
| 46 enum RefcountIssue { None, ImplicitDestructor, PublicDestructor }; | 52 enum RefcountIssue { None, ImplicitDestructor, PublicDestructor }; |
| 47 | 53 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 unsigned diag_protected_non_virtual_dtor_; | 96 unsigned diag_protected_non_virtual_dtor_; |
| 91 unsigned diag_weak_ptr_factory_order_; | 97 unsigned diag_weak_ptr_factory_order_; |
| 92 unsigned diag_bad_enum_last_value_; | 98 unsigned diag_bad_enum_last_value_; |
| 93 unsigned diag_note_inheritance_; | 99 unsigned diag_note_inheritance_; |
| 94 unsigned diag_note_implicit_dtor_; | 100 unsigned diag_note_implicit_dtor_; |
| 95 unsigned diag_note_public_dtor_; | 101 unsigned diag_note_public_dtor_; |
| 96 unsigned diag_note_protected_non_virtual_dtor_; | 102 unsigned diag_note_protected_non_virtual_dtor_; |
| 97 }; | 103 }; |
| 98 | 104 |
| 99 } // namespace chrome_checker | 105 } // namespace chrome_checker |
| OLD | NEW |