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. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 if (const ElaboratedType* elaborated = dyn_cast<ElaboratedType>(type)) | 76 if (const ElaboratedType* elaborated = dyn_cast<ElaboratedType>(type)) |
77 return UnwrapType(elaborated->getNamedType().getTypePtr()); | 77 return UnwrapType(elaborated->getNamedType().getTypePtr()); |
78 if (const TypedefType* typedefed = dyn_cast<TypedefType>(type)) | 78 if (const TypedefType* typedefed = dyn_cast<TypedefType>(type)) |
79 return UnwrapType(typedefed->desugar().getTypePtr()); | 79 return UnwrapType(typedefed->desugar().getTypePtr()); |
80 return type; | 80 return type; |
81 } | 81 } |
82 | 82 |
83 struct FindBadConstructsOptions { | 83 struct FindBadConstructsOptions { |
84 FindBadConstructsOptions() : check_base_classes(false), | 84 FindBadConstructsOptions() : check_base_classes(false), |
85 check_virtuals_in_implementations(true), | 85 check_virtuals_in_implementations(true), |
86 check_url_directory(false), | |
87 check_weak_ptr_factory_order(false) { | 86 check_weak_ptr_factory_order(false) { |
88 } | 87 } |
89 bool check_base_classes; | 88 bool check_base_classes; |
90 bool check_virtuals_in_implementations; | 89 bool check_virtuals_in_implementations; |
91 bool check_url_directory; | |
92 bool check_weak_ptr_factory_order; | 90 bool check_weak_ptr_factory_order; |
93 }; | 91 }; |
94 | 92 |
95 // Searches for constructs that we know we don't want in the Chromium code base. | 93 // Searches for constructs that we know we don't want in the Chromium code base. |
96 class FindBadConstructsConsumer : public ChromeClassTester { | 94 class FindBadConstructsConsumer : public ChromeClassTester { |
97 public: | 95 public: |
98 FindBadConstructsConsumer(CompilerInstance& instance, | 96 FindBadConstructsConsumer(CompilerInstance& instance, |
99 const FindBadConstructsOptions& options) | 97 const FindBadConstructsOptions& options) |
100 : ChromeClassTester(instance, options.check_url_directory), | 98 : ChromeClassTester(instance), |
101 options_(options) { | 99 options_(options) { |
102 // Register warning/error messages. | 100 // Register warning/error messages. |
103 diag_method_requires_override_ = diagnostic().getCustomDiagID( | 101 diag_method_requires_override_ = diagnostic().getCustomDiagID( |
104 getErrorLevel(), kMethodRequiresOverride); | 102 getErrorLevel(), kMethodRequiresOverride); |
105 diag_method_requires_virtual_ = diagnostic().getCustomDiagID( | 103 diag_method_requires_virtual_ = diagnostic().getCustomDiagID( |
106 getErrorLevel(), kMethodRequiresVirtual); | 104 getErrorLevel(), kMethodRequiresVirtual); |
107 diag_no_explicit_dtor_ = diagnostic().getCustomDiagID( | 105 diag_no_explicit_dtor_ = diagnostic().getCustomDiagID( |
108 getErrorLevel(), kNoExplicitDtor); | 106 getErrorLevel(), kNoExplicitDtor); |
109 diag_public_dtor_ = diagnostic().getCustomDiagID( | 107 diag_public_dtor_ = diagnostic().getCustomDiagID( |
110 getErrorLevel(), kPublicDtor); | 108 getErrorLevel(), kPublicDtor); |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 const std::vector<std::string>& args) { | 731 const std::vector<std::string>& args) { |
734 bool parsed = true; | 732 bool parsed = true; |
735 | 733 |
736 for (size_t i = 0; i < args.size() && parsed; ++i) { | 734 for (size_t i = 0; i < args.size() && parsed; ++i) { |
737 if (args[i] == "skip-virtuals-in-implementations") { | 735 if (args[i] == "skip-virtuals-in-implementations") { |
738 // TODO(rsleevi): Remove this once http://crbug.com/115047 is fixed. | 736 // TODO(rsleevi): Remove this once http://crbug.com/115047 is fixed. |
739 options_.check_virtuals_in_implementations = false; | 737 options_.check_virtuals_in_implementations = false; |
740 } else if (args[i] == "check-base-classes") { | 738 } else if (args[i] == "check-base-classes") { |
741 // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed. | 739 // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed. |
742 options_.check_base_classes = true; | 740 options_.check_base_classes = true; |
743 } else if (args[i] == "check-url-directory") { | |
744 // TODO(tfarina): Remove this once http://crbug.com/229660 is fixed. | |
745 options_.check_url_directory = true; | |
746 } else if (args[i] == "check-weak-ptr-factory-order") { | 741 } else if (args[i] == "check-weak-ptr-factory-order") { |
747 // TODO(dmichael): Remove this once http://crbug.com/303818 is fixed. | 742 // TODO(dmichael): Remove this once http://crbug.com/303818 is fixed. |
748 options_.check_weak_ptr_factory_order = true; | 743 options_.check_weak_ptr_factory_order = true; |
749 } else { | 744 } else { |
750 parsed = false; | 745 parsed = false; |
751 llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n"; | 746 llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n"; |
752 } | 747 } |
753 } | 748 } |
754 | 749 |
755 return parsed; | 750 return parsed; |
756 } | 751 } |
757 | 752 |
758 private: | 753 private: |
759 FindBadConstructsOptions options_; | 754 FindBadConstructsOptions options_; |
760 }; | 755 }; |
761 | 756 |
762 } // namespace | 757 } // namespace |
763 | 758 |
764 static FrontendPluginRegistry::Add<FindBadConstructsAction> | 759 static FrontendPluginRegistry::Add<FindBadConstructsAction> |
765 X("find-bad-constructs", "Finds bad C++ constructs"); | 760 X("find-bad-constructs", "Finds bad C++ constructs"); |
OLD | NEW |