Chromium Code Reviews| 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 #include "FindBadConstructsConsumer.h" | 5 #include "FindBadConstructsConsumer.h" |
| 6 | 6 |
| 7 #include "clang/Frontend/CompilerInstance.h" | 7 #include "clang/Frontend/CompilerInstance.h" |
| 8 #include "clang/AST/Attr.h" | 8 #include "clang/AST/Attr.h" |
| 9 #include "clang/Lex/Lexer.h" | 9 #include "clang/Lex/Lexer.h" |
| 10 #include "llvm/Support/raw_ostream.h" | 10 #include "llvm/Support/raw_ostream.h" |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 } | 501 } |
| 502 } | 502 } |
| 503 | 503 |
| 504 void FindBadConstructsConsumer::CheckVirtualBodies( | 504 void FindBadConstructsConsumer::CheckVirtualBodies( |
| 505 const CXXMethodDecl* method) { | 505 const CXXMethodDecl* method) { |
| 506 // Virtual methods should not have inline definitions beyond "{}". This | 506 // Virtual methods should not have inline definitions beyond "{}". This |
| 507 // only matters for header files. | 507 // only matters for header files. |
| 508 if (method->hasBody() && method->hasInlineBody()) { | 508 if (method->hasBody() && method->hasInlineBody()) { |
| 509 if (CompoundStmt* cs = dyn_cast<CompoundStmt>(method->getBody())) { | 509 if (CompoundStmt* cs = dyn_cast<CompoundStmt>(method->getBody())) { |
| 510 if (cs->size()) { | 510 if (cs->size()) { |
| 511 emitWarning(cs->getLBracLoc(), | 511 SourceLocation loc = cs->getLBracLoc(); |
| 512 "virtual methods with non-empty bodies shouldn't be " | 512 // CR_BEGIN_MSG_MAP_EX and BEGIN_SAFE_MSG_MAP_EX try to be compatible |
| 513 "declared inline."); | 513 // to BEGIN_MSG_MAP(_EX). So even though they are in chrome code, |
| 514 // we can't easily fix them, so explicilty whitelist them here. | |
|
scottmg
2015/05/07 22:43:30
"explicitly"
Nico
2015/05/07 22:50:31
Done.
| |
| 515 bool emit = true; | |
| 516 if (loc.isMacroID()) { | |
| 517 SourceManager& manager = instance().getSourceManager(); | |
| 518 if (InBannedDirectory(manager.getSpellingLoc(loc))) | |
| 519 emit = false; | |
| 520 else { | |
| 521 StringRef name = Lexer::getImmediateMacroName( | |
| 522 loc, manager, instance().getLangOpts()); | |
| 523 if (name == "CR_BEGIN_MSG_MAP_EX" || | |
| 524 name == "BEGIN_SAFE_MSG_MAP_EX") | |
| 525 emit = false; | |
| 526 } | |
| 527 } | |
| 528 if (emit) | |
| 529 emitWarning(cs->getLBracLoc(), | |
|
dcheng
2015/05/07 22:43:14
Nit: loc?
Nico
2015/05/07 22:50:31
Done.
| |
| 530 "virtual methods with non-empty bodies shouldn't be " | |
| 531 "declared inline."); | |
| 514 } | 532 } |
| 515 } | 533 } |
| 516 } | 534 } |
| 517 } | 535 } |
| 518 | 536 |
| 519 void FindBadConstructsConsumer::CountType(const Type* type, | 537 void FindBadConstructsConsumer::CountType(const Type* type, |
| 520 int* trivial_member, | 538 int* trivial_member, |
| 521 int* non_trivial_member, | 539 int* non_trivial_member, |
| 522 int* templated_non_trivial_member) { | 540 int* templated_non_trivial_member) { |
| 523 switch (type->getTypeClass()) { | 541 switch (type->getTypeClass()) { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 824 // one of those, it means there is at least one member after a factory. | 842 // one of those, it means there is at least one member after a factory. |
| 825 if (weak_ptr_factory_location.isValid() && | 843 if (weak_ptr_factory_location.isValid() && |
| 826 !param_is_weak_ptr_factory_to_self) { | 844 !param_is_weak_ptr_factory_to_self) { |
| 827 diagnostic().Report(weak_ptr_factory_location, | 845 diagnostic().Report(weak_ptr_factory_location, |
| 828 diag_weak_ptr_factory_order_); | 846 diag_weak_ptr_factory_order_); |
| 829 } | 847 } |
| 830 } | 848 } |
| 831 } | 849 } |
| 832 | 850 |
| 833 } // namespace chrome_checker | 851 } // namespace chrome_checker |
| OLD | NEW |