Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: tools/clang/plugins/FindBadConstructs.cpp

Issue 10828057: clang plugin: Put inner classes bugfix behind a flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: switch default Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 if (const TypedefType* typedefed = dyn_cast<TypedefType>(type)) 43 if (const TypedefType* typedefed = dyn_cast<TypedefType>(type))
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 : ChromeClassTester(instance), 54 bool check_inner_classes)
55 : ChromeClassTester(instance, check_inner_classes),
55 check_refcounted_dtors_(check_refcounted_dtors), 56 check_refcounted_dtors_(check_refcounted_dtors),
56 check_virtuals_in_implementations_(check_virtuals_in_implementations) { 57 check_virtuals_in_implementations_(check_virtuals_in_implementations) {
57 } 58 }
58 59
59 virtual void CheckChromeClass(SourceLocation record_location, 60 virtual void CheckChromeClass(SourceLocation record_location,
60 CXXRecordDecl* record) { 61 CXXRecordDecl* record) {
61 bool implementation_file = InImplementationFile(record_location); 62 bool implementation_file = InImplementationFile(record_location);
62 63
63 if (!implementation_file) { 64 if (!implementation_file) {
64 // Only check for "heavy" constructors/destructors in header files; 65 // Only check for "heavy" constructors/destructors in header files;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 break; 389 break;
389 } 390 }
390 } 391 }
391 } 392 }
392 }; 393 };
393 394
394 class FindBadConstructsAction : public PluginASTAction { 395 class FindBadConstructsAction : public PluginASTAction {
395 public: 396 public:
396 FindBadConstructsAction() 397 FindBadConstructsAction()
397 : check_refcounted_dtors_(true), 398 : check_refcounted_dtors_(true),
398 check_virtuals_in_implementations_(true) { 399 check_virtuals_in_implementations_(true),
400 check_inner_classes_(false) {
399 } 401 }
400 402
401 protected: 403 protected:
402 // Overridden from PluginASTAction: 404 // Overridden from PluginASTAction:
403 virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance, 405 virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance,
404 llvm::StringRef ref) { 406 llvm::StringRef ref) {
405 return new FindBadConstructsConsumer( 407 return new FindBadConstructsConsumer(
406 instance, check_refcounted_dtors_, check_virtuals_in_implementations_); 408 instance, check_refcounted_dtors_, check_virtuals_in_implementations_,
409 check_inner_classes_);
407 } 410 }
408 411
409 virtual bool ParseArgs(const CompilerInstance& instance, 412 virtual bool ParseArgs(const CompilerInstance& instance,
410 const std::vector<std::string>& args) { 413 const std::vector<std::string>& args) {
411 bool parsed = true; 414 bool parsed = true;
412 415
413 for (size_t i = 0; i < args.size() && parsed; ++i) { 416 for (size_t i = 0; i < args.size() && parsed; ++i) {
414 if (args[i] == "skip-refcounted-dtors") { 417 if (args[i] == "skip-refcounted-dtors") {
415 check_refcounted_dtors_ = false; 418 check_refcounted_dtors_ = false;
416 } else if (args[i] == "skip-virtuals-in-implementations") { 419 } else if (args[i] == "skip-virtuals-in-implementations") {
417 check_virtuals_in_implementations_ = false; 420 check_virtuals_in_implementations_ = false;
421 } else if (args[i] == "check-inner-classes") {
422 check_inner_classes_ = true;
418 } else { 423 } else {
419 parsed = false; 424 parsed = false;
420 llvm::errs() << "Unknown argument: " << args[i] << "\n"; 425 llvm::errs() << "Unknown argument: " << args[i] << "\n";
421 } 426 }
422 } 427 }
423 428
424 return parsed; 429 return parsed;
425 } 430 }
426 431
427 private: 432 private:
428 bool check_refcounted_dtors_; 433 bool check_refcounted_dtors_;
429 bool check_virtuals_in_implementations_; 434 bool check_virtuals_in_implementations_;
435 bool check_inner_classes_;
430 }; 436 };
431 437
432 } // namespace 438 } // namespace
433 439
434 static FrontendPluginRegistry::Add<FindBadConstructsAction> 440 static FrontendPluginRegistry::Add<FindBadConstructsAction>
435 X("find-bad-constructs", "Finds bad C++ constructs"); 441 X("find-bad-constructs", "Finds bad C++ constructs");
OLDNEW
« tools/clang/plugins/ChromeClassTester.h ('K') | « tools/clang/plugins/ChromeClassTester.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698