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

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

Issue 2490473007: Improved check for trivial templates. (Closed)
Patch Set: GNU asm change was out of scope for this CL. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | tools/clang/plugins/tests/trivial_ctor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 "clang/Sema/Sema.h" 10 #include "clang/Sema/Sema.h"
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 (*non_trivial_member)++; 646 (*non_trivial_member)++;
647 break; 647 break;
648 } 648 }
649 case Type::TemplateSpecialization: { 649 case Type::TemplateSpecialization: {
650 TemplateName name = 650 TemplateName name =
651 dyn_cast<TemplateSpecializationType>(type)->getTemplateName(); 651 dyn_cast<TemplateSpecializationType>(type)->getTemplateName();
652 bool whitelisted_template = false; 652 bool whitelisted_template = false;
653 653
654 // HACK: I'm at a loss about how to get the syntax checker to get 654 // HACK: I'm at a loss about how to get the syntax checker to get
655 // whether a template is externed or not. For the first pass here, 655 // whether a template is externed or not. For the first pass here,
656 // just do retarded string comparisons. 656 // just do simple string comparisons.
657 if (TemplateDecl* decl = name.getAsTemplateDecl()) { 657 if (TemplateDecl* decl = name.getAsTemplateDecl()) {
658 std::string base_name = decl->getNameAsString(); 658 std::string base_name = decl->getNameAsString();
659 if (base_name == "basic_string") 659 if (base_name == "basic_string")
660 whitelisted_template = true; 660 whitelisted_template = true;
661 } 661 }
662 662
663 if (whitelisted_template) 663 if (whitelisted_template)
664 (*non_trivial_member)++; 664 (*non_trivial_member)++;
665 else 665 else
666 (*templated_non_trivial_member)++; 666 (*templated_non_trivial_member)++;
667 break; 667 break;
668 } 668 }
669 case Type::Elaborated: { 669 case Type::Elaborated: {
670 CountType(dyn_cast<ElaboratedType>(type)->getNamedType().getTypePtr(), 670 CountType(dyn_cast<ElaboratedType>(type)->getNamedType().getTypePtr(),
671 trivial_member, 671 trivial_member,
672 non_trivial_member, 672 non_trivial_member,
673 templated_non_trivial_member); 673 templated_non_trivial_member);
674 break; 674 break;
675 } 675 }
676 case Type::Typedef: { 676 case Type::Typedef: {
677 while (const TypedefType* TT = dyn_cast<TypedefType>(type)) { 677 while (const TypedefType* TT = dyn_cast<TypedefType>(type)) {
678 type = TT->getDecl()->getUnderlyingType().getTypePtr(); 678 if (auto* decl = TT->getDecl()) {
679 const std::string name = decl->getNameAsString();
680 auto* context = decl->getDeclContext();
681 if (name == "atomic_int" && context->isStdNamespace()) {
682 (*trivial_member)++;
683 return;
684 }
685 type = decl->getUnderlyingType().getTypePtr();
686 }
679 } 687 }
680 CountType(type, 688 CountType(type,
681 trivial_member, 689 trivial_member,
682 non_trivial_member, 690 non_trivial_member,
683 templated_non_trivial_member); 691 templated_non_trivial_member);
684 break; 692 break;
685 } 693 }
686 default: { 694 default: {
687 // Stupid assumption: anything we see that isn't the above is a POD 695 // Stupid assumption: anything we see that isn't the above is a POD
688 // or reference type. 696 // or reference type.
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 } 1022 }
1015 } else if (non_reference_type->isPointerType()) { 1023 } else if (non_reference_type->isPointerType()) {
1016 non_reference_type = non_reference_type->getPointeeType(); 1024 non_reference_type = non_reference_type->getPointeeType();
1017 continue; 1025 continue;
1018 } 1026 }
1019 break; 1027 break;
1020 } 1028 }
1021 } 1029 }
1022 1030
1023 } // namespace chrome_checker 1031 } // namespace chrome_checker
OLDNEW
« no previous file with comments | « no previous file | tools/clang/plugins/tests/trivial_ctor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698