| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Changes Blink-style names to Chrome-style names. Currently transforms: | 5 // Changes Blink-style names to Chrome-style names. Currently transforms: |
| 6 // fields: | 6 // fields: |
| 7 // int m_operationCount => int operation_count_ | 7 // int m_operationCount => int operation_count_ |
| 8 // variables (including parameters): | 8 // variables (including parameters): |
| 9 // int mySuperVariable => int my_super_variable | 9 // int mySuperVariable => int my_super_variable |
| 10 // constants: | 10 // constants: |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 } | 484 } |
| 485 | 485 |
| 486 AST_MATCHER(clang::FunctionDecl, isBlacklistedFunction) { | 486 AST_MATCHER(clang::FunctionDecl, isBlacklistedFunction) { |
| 487 return IsBlacklistedFunction(Node); | 487 return IsBlacklistedFunction(Node); |
| 488 } | 488 } |
| 489 | 489 |
| 490 AST_MATCHER(clang::CXXMethodDecl, isBlacklistedMethod) { | 490 AST_MATCHER(clang::CXXMethodDecl, isBlacklistedMethod) { |
| 491 return IsBlacklistedMethod(Node); | 491 return IsBlacklistedMethod(Node); |
| 492 } | 492 } |
| 493 | 493 |
| 494 bool IsKnownTraitName(clang::StringRef name) { |
| 495 // This set of names is globally a type trait throughout chromium. |
| 496 return name == "safeToCompareToEmptyOrDeleted"; |
| 497 } |
| 498 |
| 499 AST_MATCHER(clang::VarDecl, isKnownTraitName) { |
| 500 return IsKnownTraitName(Node.getName()); |
| 501 } |
| 502 |
| 494 // Helper to convert from a camelCaseName to camel_case_name. It uses some | 503 // Helper to convert from a camelCaseName to camel_case_name. It uses some |
| 495 // heuristics to try to handle acronyms in camel case names correctly. | 504 // heuristics to try to handle acronyms in camel case names correctly. |
| 496 std::string CamelCaseToUnderscoreCase(StringRef input) { | 505 std::string CamelCaseToUnderscoreCase(StringRef input) { |
| 497 std::string output; | 506 std::string output; |
| 498 bool needs_underscore = false; | 507 bool needs_underscore = false; |
| 499 bool was_lowercase = false; | 508 bool was_lowercase = false; |
| 500 bool was_uppercase = false; | 509 bool was_uppercase = false; |
| 501 bool first_char = true; | 510 bool first_char = true; |
| 502 // Iterate in reverse to minimize the amount of backtracking. | 511 // Iterate in reverse to minimize the amount of backtracking. |
| 503 for (const unsigned char* i = input.bytes_end() - 1; i >= input.bytes_begin(); | 512 for (const unsigned char* i = input.bytes_end() - 1; i >= input.bytes_begin(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 718 |
| 710 return false; | 719 return false; |
| 711 } | 720 } |
| 712 | 721 |
| 713 AST_MATCHER(clang::FunctionDecl, shouldPrefixFunctionName) { | 722 AST_MATCHER(clang::FunctionDecl, shouldPrefixFunctionName) { |
| 714 return ShouldPrefixFunctionName(Node.getName().str()); | 723 return ShouldPrefixFunctionName(Node.getName().str()); |
| 715 } | 724 } |
| 716 | 725 |
| 717 bool GetNameForDecl(const clang::FunctionDecl& decl, | 726 bool GetNameForDecl(const clang::FunctionDecl& decl, |
| 718 clang::ASTContext& context, | 727 clang::ASTContext& context, |
| 728 bool for_type_trait, |
| 719 std::string& name) { | 729 std::string& name) { |
| 720 name = decl.getName().str(); | 730 name = decl.getName().str(); |
| 721 name[0] = clang::toUppercase(name[0]); | 731 name[0] = clang::toUppercase(name[0]); |
| 722 | 732 |
| 723 // Given | 733 // Given |
| 724 // class Foo {}; | 734 // class Foo {}; |
| 725 // class DerivedFoo : class Foo; | 735 // class DerivedFoo : class Foo; |
| 726 // using Bar = Foo; | 736 // using Bar = Foo; |
| 727 // Bar f1(); // <- |Bar| would be matched by hasString("Bar") below. | 737 // Bar f1(); // <- |Bar| would be matched by hasString("Bar") below. |
| 728 // Bar f2(); // <- |Bar| would be matched by hasName("Foo") below. | 738 // Bar f2(); // <- |Bar| would be matched by hasName("Foo") below. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 756 // And also check hardcoded list of function names to prefix with "Get". | 766 // And also check hardcoded list of function names to prefix with "Get". |
| 757 shouldPrefixFunctionName())); | 767 shouldPrefixFunctionName())); |
| 758 if (IsMatching(conflict_matcher, decl, context)) | 768 if (IsMatching(conflict_matcher, decl, context)) |
| 759 name = "Get" + name; | 769 name = "Get" + name; |
| 760 | 770 |
| 761 return true; | 771 return true; |
| 762 } | 772 } |
| 763 | 773 |
| 764 bool GetNameForDecl(const clang::EnumConstantDecl& decl, | 774 bool GetNameForDecl(const clang::EnumConstantDecl& decl, |
| 765 clang::ASTContext& context, | 775 clang::ASTContext& context, |
| 776 bool for_type_trait, |
| 766 std::string& name) { | 777 std::string& name) { |
| 767 StringRef original_name = decl.getName(); | 778 StringRef original_name = decl.getName(); |
| 768 | 779 |
| 769 // If it's already correct leave it alone. | 780 // If it's already correct leave it alone. |
| 770 if (original_name.size() >= 2 && original_name[0] == 'k' && | 781 if (original_name.size() >= 2 && original_name[0] == 'k' && |
| 771 clang::isUppercase(original_name[1])) | 782 clang::isUppercase(original_name[1])) |
| 772 return false; | 783 return false; |
| 773 | 784 |
| 774 bool is_shouty = true; | 785 bool is_shouty = true; |
| 775 for (char c : original_name) { | 786 for (char c : original_name) { |
| 776 if (!clang::isUppercase(c) && !clang::isDigit(c) && c != '_') { | 787 if (!clang::isUppercase(c) && !clang::isDigit(c) && c != '_') { |
| 777 is_shouty = false; | 788 is_shouty = false; |
| 778 break; | 789 break; |
| 779 } | 790 } |
| 780 } | 791 } |
| 781 | 792 |
| 782 if (is_shouty) | 793 if (is_shouty) |
| 783 return false; | 794 return false; |
| 784 | 795 |
| 785 name = 'k'; // k prefix on enum values. | 796 name = 'k'; // k prefix on enum values. |
| 786 name += original_name; | 797 name += original_name; |
| 787 name[1] = clang::toUppercase(name[1]); | 798 name[1] = clang::toUppercase(name[1]); |
| 788 return true; | 799 return true; |
| 789 } | 800 } |
| 790 | 801 |
| 791 bool GetNameForDecl(const clang::FieldDecl& decl, | 802 bool GetNameForDecl(const clang::FieldDecl& decl, |
| 792 clang::ASTContext& context, | 803 clang::ASTContext& context, |
| 804 bool for_type_trait, |
| 793 std::string& name) { | 805 std::string& name) { |
| 794 StringRef original_name = decl.getName(); | 806 StringRef original_name = decl.getName(); |
| 795 bool member_prefix = original_name.startswith(kBlinkFieldPrefix); | 807 bool member_prefix = original_name.startswith(kBlinkFieldPrefix); |
| 796 | 808 |
| 797 StringRef rename_part = !member_prefix | 809 StringRef rename_part = !member_prefix |
| 798 ? original_name | 810 ? original_name |
| 799 : original_name.substr(strlen(kBlinkFieldPrefix)); | 811 : original_name.substr(strlen(kBlinkFieldPrefix)); |
| 800 name = CamelCaseToUnderscoreCase(rename_part); | 812 name = CamelCaseToUnderscoreCase(rename_part); |
| 801 | 813 |
| 802 // Assume that prefix of m_ was intentional and always replace it with a | 814 // Assume that prefix of m_ was intentional and always replace it with a |
| 803 // suffix _. | 815 // suffix _. |
| 804 if (member_prefix && name.back() != '_') | 816 if (member_prefix && name.back() != '_') |
| 805 name += '_'; | 817 name += '_'; |
| 806 | 818 |
| 807 return true; | 819 return true; |
| 808 } | 820 } |
| 809 | 821 |
| 810 bool GetNameForDecl(const clang::VarDecl& decl, | 822 bool GetNameForDecl(const clang::VarDecl& decl, |
| 811 clang::ASTContext& context, | 823 clang::ASTContext& context, |
| 824 bool for_type_trait, |
| 812 std::string& name) { | 825 std::string& name) { |
| 813 StringRef original_name = decl.getName(); | 826 StringRef original_name = decl.getName(); |
| 814 | 827 |
| 815 // Nothing to do for unnamed parameters. | 828 // Nothing to do for unnamed parameters. |
| 816 if (clang::isa<clang::ParmVarDecl>(decl)) { | 829 if (clang::isa<clang::ParmVarDecl>(decl)) { |
| 817 if (original_name.empty()) | 830 if (original_name.empty()) |
| 818 return false; | 831 return false; |
| 819 | 832 |
| 820 // Check if |decl| and |decl.getLocation| are in sync. We need to skip | 833 // Check if |decl| and |decl.getLocation| are in sync. We need to skip |
| 821 // out-of-sync ParmVarDecls to avoid renaming buggy ParmVarDecls that | 834 // out-of-sync ParmVarDecls to avoid renaming buggy ParmVarDecls that |
| (...skipping 15 matching lines...) Expand all Loading... |
| 837 } | 850 } |
| 838 | 851 |
| 839 // static class members match against VarDecls. Blink style dictates that | 852 // static class members match against VarDecls. Blink style dictates that |
| 840 // these should be prefixed with `s_`, so strip that off. Also check for `m_` | 853 // these should be prefixed with `s_`, so strip that off. Also check for `m_` |
| 841 // and strip that off too, for code that accidentally uses the wrong prefix. | 854 // and strip that off too, for code that accidentally uses the wrong prefix. |
| 842 if (original_name.startswith(kBlinkStaticMemberPrefix)) | 855 if (original_name.startswith(kBlinkStaticMemberPrefix)) |
| 843 original_name = original_name.substr(strlen(kBlinkStaticMemberPrefix)); | 856 original_name = original_name.substr(strlen(kBlinkStaticMemberPrefix)); |
| 844 else if (original_name.startswith(kBlinkFieldPrefix)) | 857 else if (original_name.startswith(kBlinkFieldPrefix)) |
| 845 original_name = original_name.substr(strlen(kBlinkFieldPrefix)); | 858 original_name = original_name.substr(strlen(kBlinkFieldPrefix)); |
| 846 | 859 |
| 860 // Type traits are written in_this_form rather than kInThisForm and not like |
| 861 // members. |
| 862 if (for_type_trait) { |
| 863 name = CamelCaseToUnderscoreCase(original_name); |
| 864 return true; |
| 865 } |
| 866 |
| 847 bool is_const = IsProbablyConst(decl, context); | 867 bool is_const = IsProbablyConst(decl, context); |
| 848 if (is_const) { | 868 if (is_const) { |
| 849 // Don't try to rename constants that already conform to Chrome style. | 869 // Don't try to rename constants that already conform to Chrome style. |
| 850 if (original_name.size() >= 2 && original_name[0] == 'k' && | 870 if (original_name.size() >= 2 && original_name[0] == 'k' && |
| 851 clang::isUppercase(original_name[1])) | 871 clang::isUppercase(original_name[1])) |
| 852 return false; | 872 return false; |
| 853 // Or names are spelt with underscore casing. While they are actually | 873 // Or names are spelt with underscore casing. While they are actually |
| 854 // compile consts, the author wrote it explicitly as a variable not as | 874 // compile consts, the author wrote it explicitly as a variable not as |
| 855 // a constant (they would have used kFormat otherwise here), so preserve | 875 // a constant (they would have used kFormat otherwise here), so preserve |
| 856 // it rather than try to mangle a kFormat out of it. | 876 // it rather than try to mangle a kFormat out of it. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 875 // not. | 895 // not. |
| 876 if (!is_const && decl.isStaticDataMember()) { | 896 if (!is_const && decl.isStaticDataMember()) { |
| 877 name += '_'; | 897 name += '_'; |
| 878 } | 898 } |
| 879 | 899 |
| 880 return true; | 900 return true; |
| 881 } | 901 } |
| 882 | 902 |
| 883 bool GetNameForDecl(const clang::FunctionTemplateDecl& decl, | 903 bool GetNameForDecl(const clang::FunctionTemplateDecl& decl, |
| 884 clang::ASTContext& context, | 904 clang::ASTContext& context, |
| 905 bool for_type_trait, |
| 885 std::string& name) { | 906 std::string& name) { |
| 886 clang::FunctionDecl* templated_function = decl.getTemplatedDecl(); | 907 clang::FunctionDecl* templated_function = decl.getTemplatedDecl(); |
| 887 return GetNameForDecl(*templated_function, context, name); | 908 return GetNameForDecl(*templated_function, context, for_type_trait, name); |
| 888 } | 909 } |
| 889 | 910 |
| 890 bool GetNameForDecl(const clang::NamedDecl& decl, | 911 bool GetNameForDecl(const clang::NamedDecl& decl, |
| 891 clang::ASTContext& context, | 912 clang::ASTContext& context, |
| 913 bool for_type_trait, |
| 892 std::string& name) { | 914 std::string& name) { |
| 893 if (auto* function = clang::dyn_cast<clang::FunctionDecl>(&decl)) | 915 if (auto* function = clang::dyn_cast<clang::FunctionDecl>(&decl)) |
| 894 return GetNameForDecl(*function, context, name); | 916 return GetNameForDecl(*function, context, for_type_trait, name); |
| 895 if (auto* var = clang::dyn_cast<clang::VarDecl>(&decl)) | 917 if (auto* var = clang::dyn_cast<clang::VarDecl>(&decl)) |
| 896 return GetNameForDecl(*var, context, name); | 918 return GetNameForDecl(*var, context, for_type_trait, name); |
| 897 if (auto* field = clang::dyn_cast<clang::FieldDecl>(&decl)) | 919 if (auto* field = clang::dyn_cast<clang::FieldDecl>(&decl)) |
| 898 return GetNameForDecl(*field, context, name); | 920 return GetNameForDecl(*field, context, for_type_trait, name); |
| 899 if (auto* function_template = | 921 if (auto* function_template = |
| 900 clang::dyn_cast<clang::FunctionTemplateDecl>(&decl)) | 922 clang::dyn_cast<clang::FunctionTemplateDecl>(&decl)) |
| 901 return GetNameForDecl(*function_template, context, name); | 923 return GetNameForDecl(*function_template, context, for_type_trait, name); |
| 902 if (auto* enumc = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) | 924 if (auto* enumc = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) |
| 903 return GetNameForDecl(*enumc, context, name); | 925 return GetNameForDecl(*enumc, context, for_type_trait, name); |
| 904 | 926 |
| 905 return false; | 927 return false; |
| 906 } | 928 } |
| 907 | 929 |
| 908 bool GetNameForDecl(const clang::UsingDecl& decl, | 930 bool GetNameForDecl(const clang::UsingDecl& decl, |
| 909 clang::ASTContext& context, | 931 clang::ASTContext& context, |
| 932 bool for_type_trait, |
| 910 std::string& name) { | 933 std::string& name) { |
| 911 assert(decl.shadow_size() > 0); | 934 assert(decl.shadow_size() > 0); |
| 912 | 935 |
| 913 // If a using declaration's targeted declaration is a set of overloaded | 936 // If a using declaration's targeted declaration is a set of overloaded |
| 914 // functions, it can introduce multiple shadowed declarations. Just using the | 937 // functions, it can introduce multiple shadowed declarations. Just using the |
| 915 // first one is OK, since overloaded functions have the same name, by | 938 // first one is OK, since overloaded functions have the same name, by |
| 916 // definition. | 939 // definition. |
| 917 return GetNameForDecl(*decl.shadow_begin()->getTargetDecl(), context, name); | 940 return GetNameForDecl(*decl.shadow_begin()->getTargetDecl(), context, |
| 941 for_type_trait, name); |
| 918 } | 942 } |
| 919 | 943 |
| 920 template <typename Type> | 944 template <typename Type> |
| 921 struct TargetNodeTraits; | 945 struct TargetNodeTraits; |
| 922 | 946 |
| 923 template <> | 947 template <> |
| 924 struct TargetNodeTraits<clang::NamedDecl> { | 948 struct TargetNodeTraits<clang::NamedDecl> { |
| 925 static clang::SourceLocation GetLoc(const clang::NamedDecl& decl) { | 949 static clang::SourceLocation GetLoc(const clang::NamedDecl& decl) { |
| 926 return decl.getLocation(); | 950 return decl.getLocation(); |
| 927 } | 951 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl"); | 1136 const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl"); |
| 1113 assert(decl); | 1137 assert(decl); |
| 1114 llvm::StringRef old_name = decl->getName(); | 1138 llvm::StringRef old_name = decl->getName(); |
| 1115 | 1139 |
| 1116 // Return early if there's no name to be renamed. | 1140 // Return early if there's no name to be renamed. |
| 1117 if (!decl->getIdentifier()) | 1141 if (!decl->getIdentifier()) |
| 1118 return; | 1142 return; |
| 1119 | 1143 |
| 1120 // Get the new name. | 1144 // Get the new name. |
| 1121 std::string new_name; | 1145 std::string new_name; |
| 1122 if (!GetNameForDecl(*decl, *result.Context, new_name)) | 1146 if (!GetNameForDecl(*decl, *result.Context, for_type_traits_, new_name)) |
| 1123 return; // If false, the name was not suitable for renaming. | 1147 return; // If false, the name was not suitable for renaming. |
| 1124 | 1148 |
| 1125 // Check if we are able to rewrite the decl (to avoid rewriting if the | 1149 // Check if we are able to rewrite the decl (to avoid rewriting if the |
| 1126 // decl's identifier is part of macro##Token##Concatenation). | 1150 // decl's identifier is part of macro##Token##Concatenation). |
| 1127 clang::SourceLocation decl_loc = | 1151 clang::SourceLocation decl_loc = |
| 1128 TargetNodeTraits<clang::NamedDecl>::GetLoc(*decl); | 1152 TargetNodeTraits<clang::NamedDecl>::GetLoc(*decl); |
| 1129 if (!Base::GenerateReplacement(result, decl_loc, old_name, new_name, | 1153 if (!Base::GenerateReplacement(result, decl_loc, old_name, new_name, |
| 1130 nullptr)) | 1154 nullptr)) |
| 1131 return; | 1155 return; |
| 1132 | 1156 |
| 1133 Base::AddReplacement(result, old_name, std::move(new_name)); | 1157 Base::AddReplacement(result, old_name, std::move(new_name)); |
| 1134 } | 1158 } |
| 1159 |
| 1160 void set_for_type_traits(bool set) { for_type_traits_ = set; } |
| 1161 |
| 1162 protected: |
| 1163 bool for_type_traits_ = false; |
| 1135 }; | 1164 }; |
| 1136 | 1165 |
| 1137 using FieldDeclRewriter = DeclRewriterBase<clang::FieldDecl, clang::NamedDecl>; | 1166 using FieldDeclRewriter = DeclRewriterBase<clang::FieldDecl, clang::NamedDecl>; |
| 1138 using VarDeclRewriter = DeclRewriterBase<clang::VarDecl, clang::NamedDecl>; | 1167 using VarDeclRewriter = DeclRewriterBase<clang::VarDecl, clang::NamedDecl>; |
| 1139 using MemberRewriter = DeclRewriterBase<clang::FieldDecl, clang::MemberExpr>; | 1168 using MemberRewriter = DeclRewriterBase<clang::FieldDecl, clang::MemberExpr>; |
| 1140 using DeclRefRewriter = DeclRewriterBase<clang::VarDecl, clang::DeclRefExpr>; | 1169 using DeclRefRewriter = DeclRewriterBase<clang::VarDecl, clang::DeclRefExpr>; |
| 1141 using FieldDeclRefRewriter = | 1170 using FieldDeclRefRewriter = |
| 1142 DeclRewriterBase<clang::FieldDecl, clang::DeclRefExpr>; | 1171 DeclRewriterBase<clang::FieldDecl, clang::DeclRefExpr>; |
| 1143 using FunctionDeclRewriter = | 1172 using FunctionDeclRewriter = |
| 1144 DeclRewriterBase<clang::FunctionDecl, clang::NamedDecl>; | 1173 DeclRewriterBase<clang::FunctionDecl, clang::NamedDecl>; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 | 1480 |
| 1452 // Field, variable, and enum declarations ======== | 1481 // Field, variable, and enum declarations ======== |
| 1453 // Given | 1482 // Given |
| 1454 // int x; | 1483 // int x; |
| 1455 // struct S { | 1484 // struct S { |
| 1456 // int y; | 1485 // int y; |
| 1457 // enum { VALUE }; | 1486 // enum { VALUE }; |
| 1458 // }; | 1487 // }; |
| 1459 // matches |x|, |y|, and |VALUE|. | 1488 // matches |x|, |y|, and |VALUE|. |
| 1460 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); | 1489 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); |
| 1461 auto is_type_trait_value = | 1490 auto is_type_trait_value = varDecl( |
| 1462 varDecl(hasName("value"), hasStaticStorageDuration(), isPublic(), | 1491 anyOf(hasName("value"), isKnownTraitName()), hasStaticStorageDuration(), |
| 1463 hasType(isConstQualified()), | 1492 isPublic(), hasType(isConstQualified()), |
| 1464 hasType(type(anyOf(builtinType(), enumType()))), | 1493 hasType(type(anyOf(builtinType(), enumType()))), |
| 1465 unless(hasAncestor(recordDecl( | 1494 unless(hasAncestor(recordDecl( |
| 1466 has(cxxMethodDecl(isUserProvided(), isInstanceMethod())))))); | 1495 has(cxxMethodDecl(isUserProvided(), isInstanceMethod())))))); |
| 1467 auto var_decl_matcher = | 1496 auto var_decl_matcher = |
| 1468 id("decl", varDecl(in_blink_namespace, unless(is_type_trait_value))); | 1497 id("decl", varDecl(in_blink_namespace, unless(is_type_trait_value))); |
| 1498 auto type_trait_matcher = |
| 1499 id("decl", varDecl(is_type_trait_value, unless(hasName("value")))); |
| 1469 auto enum_member_decl_matcher = | 1500 auto enum_member_decl_matcher = |
| 1470 id("decl", enumConstantDecl(in_blink_namespace)); | 1501 id("decl", enumConstantDecl(in_blink_namespace)); |
| 1471 | 1502 |
| 1472 FieldDeclRewriter field_decl_rewriter(&replacements); | 1503 FieldDeclRewriter field_decl_rewriter(&replacements); |
| 1473 match_finder.addMatcher(field_decl_matcher, &field_decl_rewriter); | 1504 match_finder.addMatcher(field_decl_matcher, &field_decl_rewriter); |
| 1474 | 1505 |
| 1475 VarDeclRewriter var_decl_rewriter(&replacements); | 1506 VarDeclRewriter var_decl_rewriter(&replacements); |
| 1476 match_finder.addMatcher(var_decl_matcher, &var_decl_rewriter); | 1507 match_finder.addMatcher(var_decl_matcher, &var_decl_rewriter); |
| 1477 | 1508 |
| 1509 VarDeclRewriter type_trait_rewriter(&replacements); |
| 1510 type_trait_rewriter.set_for_type_traits(true); |
| 1511 match_finder.addMatcher(type_trait_matcher, &type_trait_rewriter); |
| 1512 |
| 1478 EnumConstantDeclRewriter enum_member_decl_rewriter(&replacements); | 1513 EnumConstantDeclRewriter enum_member_decl_rewriter(&replacements); |
| 1479 match_finder.addMatcher(enum_member_decl_matcher, &enum_member_decl_rewriter); | 1514 match_finder.addMatcher(enum_member_decl_matcher, &enum_member_decl_rewriter); |
| 1480 | 1515 |
| 1481 // Field, variable, and enum references ======== | 1516 // Field, variable, and enum references ======== |
| 1482 // Given | 1517 // Given |
| 1483 // bool x = true; | 1518 // bool x = true; |
| 1484 // if (x) { | 1519 // if (x) { |
| 1485 // ... | 1520 // ... |
| 1486 // } | 1521 // } |
| 1487 // matches |x| in if (x). | 1522 // matches |x| in if (x). |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 for (const auto& r : replacements) { | 1848 for (const auto& r : replacements) { |
| 1814 std::string replacement_text = r.getReplacementText().str(); | 1849 std::string replacement_text = r.getReplacementText().str(); |
| 1815 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 1850 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
| 1816 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 1851 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
| 1817 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 1852 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
| 1818 } | 1853 } |
| 1819 llvm::outs() << "==== END EDITS ====\n"; | 1854 llvm::outs() << "==== END EDITS ====\n"; |
| 1820 | 1855 |
| 1821 return 0; | 1856 return 0; |
| 1822 } | 1857 } |
| OLD | NEW |