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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return UnwrapType(typedefed->desugar().getTypePtr()); | 44 return UnwrapType(typedefed->desugar().getTypePtr()); |
45 return type; | 45 return type; |
46 } | 46 } |
47 | 47 |
48 // Searches for constructs that we know we don't want in the Chromium code base. | 48 // Searches for constructs that we know we don't want in the Chromium code base. |
49 class FindBadConstructsConsumer : public ChromeClassTester { | 49 class FindBadConstructsConsumer : public ChromeClassTester { |
50 public: | 50 public: |
51 FindBadConstructsConsumer(CompilerInstance& instance, | 51 FindBadConstructsConsumer(CompilerInstance& instance, |
52 bool check_refcounted_dtors, | 52 bool check_refcounted_dtors, |
53 bool check_virtuals_in_implementations, | 53 bool check_virtuals_in_implementations, |
54 bool check_inner_classes, | |
55 bool check_cc_directory) | 54 bool check_cc_directory) |
56 : ChromeClassTester(instance, check_inner_classes, check_cc_directory), | 55 : ChromeClassTester(instance, check_cc_directory), |
57 check_refcounted_dtors_(check_refcounted_dtors), | 56 check_refcounted_dtors_(check_refcounted_dtors), |
58 check_virtuals_in_implementations_(check_virtuals_in_implementations) { | 57 check_virtuals_in_implementations_(check_virtuals_in_implementations) { |
59 } | 58 } |
60 | 59 |
61 virtual void CheckChromeClass(SourceLocation record_location, | 60 virtual void CheckChromeClass(SourceLocation record_location, |
62 CXXRecordDecl* record) { | 61 CXXRecordDecl* record) { |
63 bool implementation_file = InImplementationFile(record_location); | 62 bool implementation_file = InImplementationFile(record_location); |
64 | 63 |
65 if (!implementation_file) { | 64 if (!implementation_file) { |
66 // Only check for "heavy" constructors/destructors in header files; | 65 // Only check for "heavy" constructors/destructors in header files; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 390 } |
392 } | 391 } |
393 } | 392 } |
394 }; | 393 }; |
395 | 394 |
396 class FindBadConstructsAction : public PluginASTAction { | 395 class FindBadConstructsAction : public PluginASTAction { |
397 public: | 396 public: |
398 FindBadConstructsAction() | 397 FindBadConstructsAction() |
399 : check_refcounted_dtors_(true), | 398 : check_refcounted_dtors_(true), |
400 check_virtuals_in_implementations_(true), | 399 check_virtuals_in_implementations_(true), |
401 check_inner_classes_(false), | |
402 check_cc_directory_(false) { | 400 check_cc_directory_(false) { |
403 } | 401 } |
404 | 402 |
405 protected: | 403 protected: |
406 // Overridden from PluginASTAction: | 404 // Overridden from PluginASTAction: |
407 virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance, | 405 virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance, |
408 llvm::StringRef ref) { | 406 llvm::StringRef ref) { |
409 return new FindBadConstructsConsumer( | 407 return new FindBadConstructsConsumer( |
410 instance, check_refcounted_dtors_, check_virtuals_in_implementations_, | 408 instance, check_refcounted_dtors_, check_virtuals_in_implementations_, |
411 check_inner_classes_, check_cc_directory_); | 409 check_cc_directory_); |
412 } | 410 } |
413 | 411 |
414 virtual bool ParseArgs(const CompilerInstance& instance, | 412 virtual bool ParseArgs(const CompilerInstance& instance, |
415 const std::vector<std::string>& args) { | 413 const std::vector<std::string>& args) { |
416 bool parsed = true; | 414 bool parsed = true; |
417 | 415 |
418 for (size_t i = 0; i < args.size() && parsed; ++i) { | 416 for (size_t i = 0; i < args.size() && parsed; ++i) { |
419 if (args[i] == "skip-refcounted-dtors") { | 417 if (args[i] == "skip-refcounted-dtors") { |
420 check_refcounted_dtors_ = false; | 418 check_refcounted_dtors_ = false; |
421 } else if (args[i] == "skip-virtuals-in-implementations") { | 419 } else if (args[i] == "skip-virtuals-in-implementations") { |
422 check_virtuals_in_implementations_ = false; | 420 check_virtuals_in_implementations_ = false; |
423 } else if (args[i] == "check-inner-classes") { | 421 } else if (args[i] == "check-inner-classes") { |
424 check_inner_classes_ = true; | 422 // TODO(hans): Remove this once it's removed from plugin_flags.sh. |
425 } else if (args[i] == "check-cc-directory") { | 423 } else if (args[i] == "check-cc-directory") { |
426 check_cc_directory_ = true; | 424 check_cc_directory_ = true; |
427 } else { | 425 } else { |
428 parsed = false; | 426 parsed = false; |
429 llvm::errs() << "Unknown argument: " << args[i] << "\n"; | 427 llvm::errs() << "Unknown argument: " << args[i] << "\n"; |
430 } | 428 } |
431 } | 429 } |
432 | 430 |
433 return parsed; | 431 return parsed; |
434 } | 432 } |
435 | 433 |
436 private: | 434 private: |
437 bool check_refcounted_dtors_; | 435 bool check_refcounted_dtors_; |
438 bool check_virtuals_in_implementations_; | 436 bool check_virtuals_in_implementations_; |
439 bool check_inner_classes_; | |
440 bool check_cc_directory_; | 437 bool check_cc_directory_; |
441 }; | 438 }; |
442 | 439 |
443 } // namespace | 440 } // namespace |
444 | 441 |
445 static FrontendPluginRegistry::Add<FindBadConstructsAction> | 442 static FrontendPluginRegistry::Add<FindBadConstructsAction> |
446 X("find-bad-constructs", "Finds bad C++ constructs"); | 443 X("find-bad-constructs", "Finds bad C++ constructs"); |
OLD | NEW |