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