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_ |
| 21 #define TOOLS_CLANG_PLUGINS_FINDBADCONSTRUCTSCONSUMER_H_ |
| 22 |
20 #include "clang/AST/AST.h" | 23 #include "clang/AST/AST.h" |
21 #include "clang/AST/ASTConsumer.h" | 24 #include "clang/AST/ASTConsumer.h" |
22 #include "clang/AST/Attr.h" | 25 #include "clang/AST/Attr.h" |
23 #include "clang/AST/CXXInheritance.h" | 26 #include "clang/AST/CXXInheritance.h" |
24 #include "clang/AST/RecursiveASTVisitor.h" | 27 #include "clang/AST/RecursiveASTVisitor.h" |
25 #include "clang/AST/TypeLoc.h" | 28 #include "clang/AST/TypeLoc.h" |
26 #include "clang/Basic/SourceManager.h" | 29 #include "clang/Basic/SourceManager.h" |
| 30 #include "clang/Basic/SourceLocation.h" |
27 | 31 |
28 #include "ChromeClassTester.h" | 32 #include "ChromeClassTester.h" |
29 #include "Options.h" | 33 #include "Options.h" |
| 34 #include "SuppressibleDiagnosticBuilder.h" |
30 | 35 |
31 namespace chrome_checker { | 36 namespace chrome_checker { |
32 | 37 |
33 // Searches for constructs that we know we don't want in the Chromium code base. | 38 // Searches for constructs that we know we don't want in the Chromium code base. |
34 class FindBadConstructsConsumer | 39 class FindBadConstructsConsumer |
35 : public clang::RecursiveASTVisitor<FindBadConstructsConsumer>, | 40 : public clang::RecursiveASTVisitor<FindBadConstructsConsumer>, |
36 public ChromeClassTester { | 41 public ChromeClassTester { |
37 public: | 42 public: |
38 FindBadConstructsConsumer(clang::CompilerInstance& instance, | 43 FindBadConstructsConsumer(clang::CompilerInstance& instance, |
39 const Options& options); | 44 const Options& options); |
(...skipping 10 matching lines...) Expand all Loading... |
50 private: | 55 private: |
51 // The type of problematic ref-counting pattern that was encountered. | 56 // The type of problematic ref-counting pattern that was encountered. |
52 enum RefcountIssue { None, ImplicitDestructor, PublicDestructor }; | 57 enum RefcountIssue { None, ImplicitDestructor, PublicDestructor }; |
53 | 58 |
54 void CheckCtorDtorWeight(clang::SourceLocation record_location, | 59 void CheckCtorDtorWeight(clang::SourceLocation record_location, |
55 clang::CXXRecordDecl* record); | 60 clang::CXXRecordDecl* record); |
56 | 61 |
57 bool InTestingNamespace(const clang::Decl* record); | 62 bool InTestingNamespace(const clang::Decl* record); |
58 bool IsMethodInBannedOrTestingNamespace(const clang::CXXMethodDecl* method); | 63 bool IsMethodInBannedOrTestingNamespace(const clang::CXXMethodDecl* method); |
59 | 64 |
| 65 // Returns a diagnostic builder that only emits the diagnostic if the spelling |
| 66 // location (the actual characters that make up the token) is not in an |
| 67 // ignored file. This is useful for situations where the token might originate |
| 68 // from a macro in a system header: warning isn't useful, since system headers |
| 69 // generally can't be easily updated. |
| 70 SuppressibleDiagnosticBuilder ReportIfSpellingLocNotIgnored( |
| 71 clang::SourceLocation loc, |
| 72 unsigned diagnostic_id); |
| 73 |
60 void CheckVirtualMethods(clang::SourceLocation record_location, | 74 void CheckVirtualMethods(clang::SourceLocation record_location, |
61 clang::CXXRecordDecl* record, | 75 clang::CXXRecordDecl* record, |
62 bool warn_on_inline_bodies); | 76 bool warn_on_inline_bodies); |
63 void CheckVirtualSpecifiers(const clang::CXXMethodDecl* method); | 77 void CheckVirtualSpecifiers(const clang::CXXMethodDecl* method); |
64 void CheckVirtualBodies(const clang::CXXMethodDecl* method); | 78 void CheckVirtualBodies(const clang::CXXMethodDecl* method); |
65 | 79 |
66 void CountType(const clang::Type* type, | 80 void CountType(const clang::Type* type, |
67 int* trivial_member, | 81 int* trivial_member, |
68 int* non_trivial_member, | 82 int* non_trivial_member, |
69 int* templated_non_trivial_member); | 83 int* templated_non_trivial_member); |
(...skipping 23 matching lines...) Expand all Loading... |
93 unsigned diag_protected_non_virtual_dtor_; | 107 unsigned diag_protected_non_virtual_dtor_; |
94 unsigned diag_weak_ptr_factory_order_; | 108 unsigned diag_weak_ptr_factory_order_; |
95 unsigned diag_bad_enum_last_value_; | 109 unsigned diag_bad_enum_last_value_; |
96 unsigned diag_note_inheritance_; | 110 unsigned diag_note_inheritance_; |
97 unsigned diag_note_implicit_dtor_; | 111 unsigned diag_note_implicit_dtor_; |
98 unsigned diag_note_public_dtor_; | 112 unsigned diag_note_public_dtor_; |
99 unsigned diag_note_protected_non_virtual_dtor_; | 113 unsigned diag_note_protected_non_virtual_dtor_; |
100 }; | 114 }; |
101 | 115 |
102 } // namespace chrome_checker | 116 } // namespace chrome_checker |
| 117 |
| 118 #endif // TOOLS_CLANG_PLUGINS_FINDBADCONSTRUCTSCONSUMER_H_ |
OLD | NEW |