| 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 30 matching lines...) Expand all Loading... |
| 41 "[chromium-style] _LAST/Last constants of enum types must have the maximal " | 41 "[chromium-style] _LAST/Last constants of enum types must have the maximal " |
| 42 "value for any constant of that type."; | 42 "value for any constant of that type."; |
| 43 const char kNoteInheritance[] = "[chromium-style] %0 inherits from %1 here"; | 43 const char kNoteInheritance[] = "[chromium-style] %0 inherits from %1 here"; |
| 44 const char kNoteImplicitDtor[] = | 44 const char kNoteImplicitDtor[] = |
| 45 "[chromium-style] No explicit destructor for %0 defined"; | 45 "[chromium-style] No explicit destructor for %0 defined"; |
| 46 const char kNotePublicDtor[] = | 46 const char kNotePublicDtor[] = |
| 47 "[chromium-style] Public destructor declared here"; | 47 "[chromium-style] Public destructor declared here"; |
| 48 const char kNoteProtectedNonVirtualDtor[] = | 48 const char kNoteProtectedNonVirtualDtor[] = |
| 49 "[chromium-style] Protected non-virtual destructor declared here"; | 49 "[chromium-style] Protected non-virtual destructor declared here"; |
| 50 | 50 |
| 51 bool TypeHasNonTrivialDtor(const Type* type) { | |
| 52 if (const CXXRecordDecl* cxx_r = type->getAsCXXRecordDecl()) | |
| 53 return !cxx_r->hasTrivialDestructor(); | |
| 54 | |
| 55 return false; | |
| 56 } | |
| 57 | |
| 58 // Returns the underlying Type for |type| by expanding typedefs and removing | 51 // Returns the underlying Type for |type| by expanding typedefs and removing |
| 59 // any namespace qualifiers. This is similar to desugaring, except that for | 52 // any namespace qualifiers. This is similar to desugaring, except that for |
| 60 // ElaboratedTypes, desugar will unwrap too much. | 53 // ElaboratedTypes, desugar will unwrap too much. |
| 61 const Type* UnwrapType(const Type* type) { | 54 const Type* UnwrapType(const Type* type) { |
| 62 if (const ElaboratedType* elaborated = dyn_cast<ElaboratedType>(type)) | 55 if (const ElaboratedType* elaborated = dyn_cast<ElaboratedType>(type)) |
| 63 return UnwrapType(elaborated->getNamedType().getTypePtr()); | 56 return UnwrapType(elaborated->getNamedType().getTypePtr()); |
| 64 if (const TypedefType* typedefed = dyn_cast<TypedefType>(type)) | 57 if (const TypedefType* typedefed = dyn_cast<TypedefType>(type)) |
| 65 return UnwrapType(typedefed->desugar().getTypePtr()); | 58 return UnwrapType(typedefed->desugar().getTypePtr()); |
| 66 return type; | 59 return type; |
| 67 } | 60 } |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } | 550 } |
| 558 } | 551 } |
| 559 } | 552 } |
| 560 | 553 |
| 561 void FindBadConstructsConsumer::CountType(const Type* type, | 554 void FindBadConstructsConsumer::CountType(const Type* type, |
| 562 int* trivial_member, | 555 int* trivial_member, |
| 563 int* non_trivial_member, | 556 int* non_trivial_member, |
| 564 int* templated_non_trivial_member) { | 557 int* templated_non_trivial_member) { |
| 565 switch (type->getTypeClass()) { | 558 switch (type->getTypeClass()) { |
| 566 case Type::Record: { | 559 case Type::Record: { |
| 560 auto* record_decl = type->getAsCXXRecordDecl(); |
| 567 // Simplifying; the whole class isn't trivial if the dtor is, but | 561 // Simplifying; the whole class isn't trivial if the dtor is, but |
| 568 // we use this as a signal about complexity. | 562 // we use this as a signal about complexity. |
| 569 if (TypeHasNonTrivialDtor(type)) | 563 // Note that if a record doesn't have a definition, it doesn't matter how |
| 564 // it's counted, since the translation unit will fail to build. In that |
| 565 // case, just count it as a trivial member to avoid emitting warnings that |
| 566 // might be spurious. |
| 567 if (!record_decl->hasDefinition() || record_decl->hasTrivialDestructor()) |
| 568 (*trivial_member)++; |
| 569 else |
| 570 (*non_trivial_member)++; | 570 (*non_trivial_member)++; |
| 571 else | |
| 572 (*trivial_member)++; | |
| 573 break; | 571 break; |
| 574 } | 572 } |
| 575 case Type::TemplateSpecialization: { | 573 case Type::TemplateSpecialization: { |
| 576 TemplateName name = | 574 TemplateName name = |
| 577 dyn_cast<TemplateSpecializationType>(type)->getTemplateName(); | 575 dyn_cast<TemplateSpecializationType>(type)->getTemplateName(); |
| 578 bool whitelisted_template = false; | 576 bool whitelisted_template = false; |
| 579 | 577 |
| 580 // HACK: I'm at a loss about how to get the syntax checker to get | 578 // HACK: I'm at a loss about how to get the syntax checker to get |
| 581 // whether a template is externed or not. For the first pass here, | 579 // whether a template is externed or not. For the first pass here, |
| 582 // just do retarded string comparisons. | 580 // just do retarded string comparisons. |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 // one of those, it means there is at least one member after a factory. | 868 // one of those, it means there is at least one member after a factory. |
| 871 if (weak_ptr_factory_location.isValid() && | 869 if (weak_ptr_factory_location.isValid() && |
| 872 !param_is_weak_ptr_factory_to_self) { | 870 !param_is_weak_ptr_factory_to_self) { |
| 873 diagnostic().Report(weak_ptr_factory_location, | 871 diagnostic().Report(weak_ptr_factory_location, |
| 874 diag_weak_ptr_factory_order_); | 872 diag_weak_ptr_factory_order_); |
| 875 } | 873 } |
| 876 } | 874 } |
| 877 } | 875 } |
| 878 | 876 |
| 879 } // namespace chrome_checker | 877 } // namespace chrome_checker |
| OLD | NEW |