| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (const TypedefType* typedefed = dyn_cast<TypedefType>(type)) | 68 if (const TypedefType* typedefed = dyn_cast<TypedefType>(type)) |
| 69 return UnwrapType(typedefed->desugar().getTypePtr()); | 69 return UnwrapType(typedefed->desugar().getTypePtr()); |
| 70 return type; | 70 return type; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Searches for constructs that we know we don't want in the Chromium code base. | 73 // Searches for constructs that we know we don't want in the Chromium code base. |
| 74 class FindBadConstructsConsumer : public ChromeClassTester { | 74 class FindBadConstructsConsumer : public ChromeClassTester { |
| 75 public: | 75 public: |
| 76 FindBadConstructsConsumer(CompilerInstance& instance, | 76 FindBadConstructsConsumer(CompilerInstance& instance, |
| 77 bool check_base_classes, | 77 bool check_base_classes, |
| 78 bool check_virtuals_in_implementations) | 78 bool check_virtuals_in_implementations, |
| 79 : ChromeClassTester(instance), | 79 bool check_url_directory) |
| 80 : ChromeClassTester(instance, check_url_directory), |
| 80 check_base_classes_(check_base_classes), | 81 check_base_classes_(check_base_classes), |
| 81 check_virtuals_in_implementations_(check_virtuals_in_implementations) { | 82 check_virtuals_in_implementations_(check_virtuals_in_implementations) { |
| 82 // Register warning/error messages. | 83 // Register warning/error messages. |
| 83 diag_method_requires_override_ = diagnostic().getCustomDiagID( | 84 diag_method_requires_override_ = diagnostic().getCustomDiagID( |
| 84 getErrorLevel(), kMethodRequiresOverride); | 85 getErrorLevel(), kMethodRequiresOverride); |
| 85 diag_method_requires_virtual_ = diagnostic().getCustomDiagID( | 86 diag_method_requires_virtual_ = diagnostic().getCustomDiagID( |
| 86 getErrorLevel(), kMethodRequiresVirtual); | 87 getErrorLevel(), kMethodRequiresVirtual); |
| 87 diag_no_explicit_dtor_ = diagnostic().getCustomDiagID( | 88 diag_no_explicit_dtor_ = diagnostic().getCustomDiagID( |
| 88 getErrorLevel(), kNoExplicitDtor); | 89 getErrorLevel(), kNoExplicitDtor); |
| 89 diag_public_dtor_ = diagnostic().getCustomDiagID( | 90 diag_public_dtor_ = diagnostic().getCustomDiagID( |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 PrintInheritanceChain(*it); | 613 PrintInheritanceChain(*it); |
| 613 } | 614 } |
| 614 } | 615 } |
| 615 } | 616 } |
| 616 }; | 617 }; |
| 617 | 618 |
| 618 class FindBadConstructsAction : public PluginASTAction { | 619 class FindBadConstructsAction : public PluginASTAction { |
| 619 public: | 620 public: |
| 620 FindBadConstructsAction() | 621 FindBadConstructsAction() |
| 621 : check_base_classes_(false), | 622 : check_base_classes_(false), |
| 622 check_virtuals_in_implementations_(true) { | 623 check_virtuals_in_implementations_(true), |
| 624 check_url_directory_(false) { |
| 623 } | 625 } |
| 624 | 626 |
| 625 protected: | 627 protected: |
| 626 // Overridden from PluginASTAction: | 628 // Overridden from PluginASTAction: |
| 627 virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance, | 629 virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance, |
| 628 llvm::StringRef ref) { | 630 llvm::StringRef ref) { |
| 629 return new FindBadConstructsConsumer( | 631 return new FindBadConstructsConsumer( |
| 630 instance, check_base_classes_, check_virtuals_in_implementations_); | 632 instance, check_base_classes_, check_virtuals_in_implementations_, |
| 633 check_url_directory_); |
| 631 } | 634 } |
| 632 | 635 |
| 633 virtual bool ParseArgs(const CompilerInstance& instance, | 636 virtual bool ParseArgs(const CompilerInstance& instance, |
| 634 const std::vector<std::string>& args) { | 637 const std::vector<std::string>& args) { |
| 635 bool parsed = true; | 638 bool parsed = true; |
| 636 | 639 |
| 637 for (size_t i = 0; i < args.size() && parsed; ++i) { | 640 for (size_t i = 0; i < args.size() && parsed; ++i) { |
| 638 if (args[i] == "skip-virtuals-in-implementations") { | 641 if (args[i] == "skip-virtuals-in-implementations") { |
| 639 // TODO(rsleevi): Remove this once http://crbug.com/115047 is fixed. | 642 // TODO(rsleevi): Remove this once http://crbug.com/115047 is fixed. |
| 640 check_virtuals_in_implementations_ = false; | 643 check_virtuals_in_implementations_ = false; |
| 641 } else if (args[i] == "check-base-classes") { | 644 } else if (args[i] == "check-base-classes") { |
| 642 // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed. | 645 // TODO(rsleevi): Remove this once http://crbug.com/123295 is fixed. |
| 643 check_base_classes_ = true; | 646 check_base_classes_ = true; |
| 647 } else if (args[i] == "check-url-directory") { |
| 648 // TODO(tfarina): Remove this once http://crbug.com/229660 is fixed. |
| 649 check_url_directory_ = true; |
| 644 } else { | 650 } else { |
| 645 parsed = false; | 651 parsed = false; |
| 646 llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n"; | 652 llvm::errs() << "Unknown clang plugin argument: " << args[i] << "\n"; |
| 647 } | 653 } |
| 648 } | 654 } |
| 649 | 655 |
| 650 return parsed; | 656 return parsed; |
| 651 } | 657 } |
| 652 | 658 |
| 653 private: | 659 private: |
| 654 bool check_base_classes_; | 660 bool check_base_classes_; |
| 655 bool check_virtuals_in_implementations_; | 661 bool check_virtuals_in_implementations_; |
| 662 bool check_url_directory_; |
| 656 }; | 663 }; |
| 657 | 664 |
| 658 } // namespace | 665 } // namespace |
| 659 | 666 |
| 660 static FrontendPluginRegistry::Add<FindBadConstructsAction> | 667 static FrontendPluginRegistry::Add<FindBadConstructsAction> |
| 661 X("find-bad-constructs", "Finds bad C++ constructs"); | 668 X("find-bad-constructs", "Finds bad C++ constructs"); |
| OLD | NEW |