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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 bool IsMatching(const MatcherType& matcher, | 55 bool IsMatching(const MatcherType& matcher, |
56 const NodeType& node, | 56 const NodeType& node, |
57 clang::ASTContext& context) { | 57 clang::ASTContext& context) { |
58 return !match(matcher, node, context).empty(); | 58 return !match(matcher, node, context).empty(); |
59 } | 59 } |
60 | 60 |
61 const clang::ast_matchers::internal:: | 61 const clang::ast_matchers::internal:: |
62 VariadicDynCastAllOfMatcher<clang::Expr, clang::UnresolvedMemberExpr> | 62 VariadicDynCastAllOfMatcher<clang::Expr, clang::UnresolvedMemberExpr> |
63 unresolvedMemberExpr; | 63 unresolvedMemberExpr; |
64 | 64 |
| 65 const clang::ast_matchers::internal:: |
| 66 VariadicDynCastAllOfMatcher<clang::Expr, clang::DependentScopeDeclRefExpr> |
| 67 dependentScopeDeclRefExpr; |
| 68 |
| 69 const clang::ast_matchers::internal:: |
| 70 VariadicDynCastAllOfMatcher<clang::Expr, clang::CXXDependentScopeMemberExpr> |
| 71 cxxDependentScopeMemberExpr; |
| 72 |
65 AST_MATCHER(clang::FunctionDecl, isOverloadedOperator) { | 73 AST_MATCHER(clang::FunctionDecl, isOverloadedOperator) { |
66 return Node.isOverloadedOperator(); | 74 return Node.isOverloadedOperator(); |
67 } | 75 } |
68 | 76 |
69 AST_MATCHER(clang::CXXMethodDecl, isInstanceMethod) { | 77 AST_MATCHER(clang::CXXMethodDecl, isInstanceMethod) { |
70 return Node.isInstance(); | 78 return Node.isInstance(); |
71 } | 79 } |
72 | 80 |
73 AST_MATCHER_P(clang::FunctionTemplateDecl, | 81 AST_MATCHER_P(clang::FunctionTemplateDecl, |
74 templatedDecl, | 82 templatedDecl, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 return inner_matcher.matches(decl, finder, builder); | 166 return inner_matcher.matches(decl, finder, builder); |
159 } | 167 } |
160 | 168 |
161 AST_MATCHER_P(clang::CXXMethodDecl, | 169 AST_MATCHER_P(clang::CXXMethodDecl, |
162 includeAllOverriddenMethods, | 170 includeAllOverriddenMethods, |
163 clang::ast_matchers::internal::Matcher<clang::CXXMethodDecl>, | 171 clang::ast_matchers::internal::Matcher<clang::CXXMethodDecl>, |
164 InnerMatcher) { | 172 InnerMatcher) { |
165 return MatchAllOverriddenMethods(Node, InnerMatcher, Finder, Builder); | 173 return MatchAllOverriddenMethods(Node, InnerMatcher, Finder, Builder); |
166 } | 174 } |
167 | 175 |
| 176 // Matches |T::m| and/or |x->T::m| and/or |x->m| CXXDependentScopeMemberExpr |
| 177 // if member |m| comes from a type that matches the InnerMatcher. |
| 178 AST_MATCHER_P(clang::CXXDependentScopeMemberExpr, |
| 179 hasMemberFromType, |
| 180 clang::ast_matchers::internal::Matcher<clang::QualType>, |
| 181 InnerMatcher) { |
| 182 // Given |T::m| and/or |x->T::m| and/or |x->m| ... |
| 183 if (clang::NestedNameSpecifier* nestedNameSpecifier = Node.getQualifier()) { |
| 184 // ... if |T| is present, then InnerMatcher has to match |T|. |
| 185 clang::QualType qualType(nestedNameSpecifier->getAsType(), 0); |
| 186 return InnerMatcher.matches(qualType, Finder, Builder); |
| 187 } else { |
| 188 // ... if there is no |T|, then InnerMatcher has to match the type of |x|. |
| 189 clang::Expr* base_expr = Node.isImplicitAccess() ? nullptr : Node.getBase(); |
| 190 return base_expr && |
| 191 InnerMatcher.matches(base_expr->getType(), Finder, Builder); |
| 192 } |
| 193 } |
| 194 |
| 195 // Matches |const Class<T>&| QualType if InnerMatcher matches |Class<T>|. |
| 196 AST_MATCHER_P(clang::QualType, |
| 197 hasBaseType, |
| 198 clang::ast_matchers::internal::Matcher<clang::Type>, |
| 199 InnerMatcher) { |
| 200 const clang::Type* type = Node.getTypePtrOrNull(); |
| 201 return type && InnerMatcher.matches(*type, Finder, Builder); |
| 202 } |
| 203 |
168 bool IsMethodOverrideOf(const clang::CXXMethodDecl& decl, | 204 bool IsMethodOverrideOf(const clang::CXXMethodDecl& decl, |
169 const char* class_name) { | 205 const char* class_name) { |
170 if (decl.getParent()->getQualifiedNameAsString() == class_name) | 206 if (decl.getParent()->getQualifiedNameAsString() == class_name) |
171 return true; | 207 return true; |
172 for (auto it = decl.begin_overridden_methods(); | 208 for (auto it = decl.begin_overridden_methods(); |
173 it != decl.end_overridden_methods(); ++it) { | 209 it != decl.end_overridden_methods(); ++it) { |
174 if (IsMethodOverrideOf(**it, class_name)) | 210 if (IsMethodOverrideOf(**it, class_name)) |
175 return true; | 211 return true; |
176 } | 212 } |
177 return false; | 213 return false; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 template <> | 560 template <> |
525 struct TargetNodeTraits<clang::DeclRefExpr> { | 561 struct TargetNodeTraits<clang::DeclRefExpr> { |
526 static clang::SourceLocation GetLoc(const clang::DeclRefExpr& expr) { | 562 static clang::SourceLocation GetLoc(const clang::DeclRefExpr& expr) { |
527 return expr.getLocation(); | 563 return expr.getLocation(); |
528 } | 564 } |
529 static const char* GetName() { return "expr"; } | 565 static const char* GetName() { return "expr"; } |
530 static const char* GetType() { return "DeclRefExpr"; } | 566 static const char* GetType() { return "DeclRefExpr"; } |
531 }; | 567 }; |
532 | 568 |
533 template <> | 569 template <> |
| 570 struct TargetNodeTraits<clang::DependentScopeDeclRefExpr> { |
| 571 static clang::SourceLocation GetLoc( |
| 572 const clang::DependentScopeDeclRefExpr& expr) { |
| 573 return expr.getLocation(); |
| 574 } |
| 575 static const char* GetName() { return "expr"; } |
| 576 }; |
| 577 |
| 578 template <> |
| 579 struct TargetNodeTraits<clang::CXXDependentScopeMemberExpr> { |
| 580 static clang::SourceLocation GetLoc( |
| 581 const clang::CXXDependentScopeMemberExpr& expr) { |
| 582 return expr.getMemberLoc(); |
| 583 } |
| 584 static const char* GetName() { return "expr"; } |
| 585 }; |
| 586 |
| 587 template <> |
534 struct TargetNodeTraits<clang::CXXCtorInitializer> { | 588 struct TargetNodeTraits<clang::CXXCtorInitializer> { |
535 static clang::SourceLocation GetLoc(const clang::CXXCtorInitializer& init) { | 589 static clang::SourceLocation GetLoc(const clang::CXXCtorInitializer& init) { |
536 assert(init.isWritten()); | 590 assert(init.isWritten()); |
537 return init.getSourceLocation(); | 591 return init.getSourceLocation(); |
538 } | 592 } |
539 static const char* GetName() { return "initializer"; } | 593 static const char* GetName() { return "initializer"; } |
540 static const char* GetType() { return "CXXCtorInitializer"; } | 594 static const char* GetType() { return "CXXCtorInitializer"; } |
541 }; | 595 }; |
542 | 596 |
543 template <> | 597 template <> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 DeclRewriterBase<clang::NamedDecl, clang::UnresolvedMemberExpr>; | 724 DeclRewriterBase<clang::NamedDecl, clang::UnresolvedMemberExpr>; |
671 | 725 |
672 using UsingDeclRewriter = DeclRewriterBase<clang::UsingDecl, clang::NamedDecl>; | 726 using UsingDeclRewriter = DeclRewriterBase<clang::UsingDecl, clang::NamedDecl>; |
673 | 727 |
674 clang::DeclarationName GetUnresolvedName( | 728 clang::DeclarationName GetUnresolvedName( |
675 const clang::UnresolvedMemberExpr& expr) { | 729 const clang::UnresolvedMemberExpr& expr) { |
676 return expr.getMemberName(); | 730 return expr.getMemberName(); |
677 } | 731 } |
678 | 732 |
679 clang::DeclarationName GetUnresolvedName( | 733 clang::DeclarationName GetUnresolvedName( |
| 734 const clang::DependentScopeDeclRefExpr& expr) { |
| 735 return expr.getDeclName(); |
| 736 } |
| 737 |
| 738 clang::DeclarationName GetUnresolvedName( |
| 739 const clang::CXXDependentScopeMemberExpr& expr) { |
| 740 return expr.getMember(); |
| 741 } |
| 742 |
| 743 clang::DeclarationName GetUnresolvedName( |
680 const clang::UnresolvedUsingValueDecl& decl) { | 744 const clang::UnresolvedUsingValueDecl& decl) { |
681 return decl.getDeclName(); | 745 return decl.getDeclName(); |
682 } | 746 } |
683 | 747 |
| 748 // Returns whether |expr_node| is used as a callee in the AST (i.e. if |
| 749 // |expr_node| needs to resolve to a method or a function). |
| 750 bool IsCallee(const clang::Expr& expr, clang::ASTContext& context) { |
| 751 auto matcher = stmt(hasParent(callExpr(callee(equalsNode(&expr))))); |
| 752 return IsMatching(matcher, expr, context); |
| 753 } |
| 754 |
| 755 // Returns whether |decl| will be used as a callee in the AST (i.e. if the value |
| 756 // brought by the using declaration will resolve to a method or a function). |
| 757 bool IsCallee(const clang::UnresolvedUsingValueDecl& decl, |
| 758 clang::ASTContext& /* context */) { |
| 759 // Caller (i.e. GuessNameForUnresolvedDependentNode) should have already |
| 760 // filtered out fields before calling |IsCallee|. |
| 761 clang::IdentifierInfo* info = GetUnresolvedName(decl).getAsIdentifierInfo(); |
| 762 assert(info); |
| 763 bool name_looks_like_a_field = info->getName().startswith(kBlinkFieldPrefix); |
| 764 assert(!name_looks_like_a_field); |
| 765 |
| 766 // Looking just at clang::UnresolvedUsingValueDecl, we cannot tell whether it |
| 767 // refers to something callable or not. Since fields should have been already |
| 768 // filtered out before calling IsCallee (see the assert above), let's assume |
| 769 // that |using Base::foo| refers to a method. |
| 770 return true; |
| 771 } |
| 772 |
684 template <typename TargetNode> | 773 template <typename TargetNode> |
685 class UnresolvedRewriterBase : public RewriterBase<TargetNode> { | 774 class UnresolvedRewriterBase : public RewriterBase<TargetNode> { |
686 public: | 775 public: |
687 using Base = RewriterBase<TargetNode>; | 776 using Base = RewriterBase<TargetNode>; |
688 | 777 |
689 explicit UnresolvedRewriterBase(std::set<Replacement>* replacements) | 778 explicit UnresolvedRewriterBase(std::set<Replacement>* replacements) |
690 : RewriterBase<TargetNode>(replacements) {} | 779 : RewriterBase<TargetNode>(replacements) {} |
691 | 780 |
692 void run(const MatchFinder::MatchResult& result) override { | 781 void run(const MatchFinder::MatchResult& result) override { |
693 const TargetNode& expr = Base::GetTargetNode(result); | 782 const TargetNode& node = Base::GetTargetNode(result); |
694 llvm::StringRef old_name = GetUnresolvedName(expr).getAsString(); | 783 |
| 784 clang::DeclarationName decl_name = GetUnresolvedName(node); |
| 785 switch (decl_name.getNameKind()) { |
| 786 // Do not rewrite this: |
| 787 // return operator T*(); |
| 788 // into this: |
| 789 // return Operator type - parameter - 0 - 0 * T * (); |
| 790 case clang::DeclarationName::NameKind::CXXConversionFunctionName: |
| 791 case clang::DeclarationName::NameKind::CXXOperatorName: |
| 792 case clang::DeclarationName::NameKind::CXXLiteralOperatorName: |
| 793 return; |
| 794 default: |
| 795 break; |
| 796 } |
| 797 |
| 798 // Make sure there is an old name + extract the old name. |
| 799 clang::IdentifierInfo* info = GetUnresolvedName(node).getAsIdentifierInfo(); |
| 800 if (!info) |
| 801 return; |
| 802 llvm::StringRef old_name = info->getName(); |
| 803 |
| 804 // Try to guess a new name. |
695 std::string new_name; | 805 std::string new_name; |
696 if (GuessNameForUnresolvedDependentNode(expr, *result.Context, old_name, | 806 if (GuessNameForUnresolvedDependentNode(node, *result.Context, old_name, |
697 new_name)) { | 807 new_name)) |
698 Base::AddReplacement(result, old_name, std::move(new_name)); | 808 Base::AddReplacement(result, old_name, std::move(new_name)); |
699 } | |
700 } | 809 } |
701 | 810 |
702 private: | 811 private: |
703 // This method calculates a new name for nodes that depend on template | 812 // This method calculates a new name for nodes that depend on template |
704 // parameters (http://en.cppreference.com/w/cpp/language/dependent_name). The | 813 // parameters (http://en.cppreference.com/w/cpp/language/dependent_name). The |
705 // renaming is based on crude heuristics, because such nodes are not bound to | 814 // renaming is based on crude heuristics, because such nodes are not bound to |
706 // a specific decl until template instantiation - at the point of rename, one | 815 // a specific decl until template instantiation - at the point of rename, one |
707 // cannot tell whether the node will eventually resolve to a field / method / | 816 // cannot tell whether the node will eventually resolve to a field / method / |
708 // constant / etc. | 817 // constant / etc. |
| 818 // |
| 819 // The method returns false if no renaming should be done. |
| 820 // Otherwise the method returns true and sets |new_name|. |
709 bool GuessNameForUnresolvedDependentNode(const TargetNode& node, | 821 bool GuessNameForUnresolvedDependentNode(const TargetNode& node, |
710 clang::ASTContext& context, | 822 clang::ASTContext& context, |
711 llvm::StringRef old_name, | 823 llvm::StringRef old_name, |
712 std::string& new_name) { | 824 std::string& new_name) { |
713 // |m_fieldName| -> |field_name_|. | 825 // |m_fieldName| -> |field_name_|. |
714 if (old_name.startswith(kBlinkFieldPrefix)) { | 826 if (old_name.startswith(kBlinkFieldPrefix)) { |
715 std::string field_name = old_name.str().substr(strlen(kBlinkFieldPrefix)); | 827 std::string field_name = old_name.substr(strlen(kBlinkFieldPrefix)); |
716 if (field_name.find('_') == std::string::npos) { | 828 if (field_name.find('_') == std::string::npos) { |
717 new_name = CamelCaseToUnderscoreCase(field_name) + "_"; | 829 new_name = CamelCaseToUnderscoreCase(field_name) + "_"; |
718 return true; | 830 return true; |
719 } | 831 } |
720 } | 832 } |
721 | 833 |
722 // |T::myMethod(...)| -> |T::MyMethod(...)|. | 834 // |T::myMethod(...)| -> |T::MyMethod(...)|. |
723 if ((old_name.find('_') == std::string::npos) && | 835 if ((old_name.find('_') == std::string::npos) && IsCallee(node, context) && |
724 !IsBlacklistedFunctionOrMethodName(old_name)) { | 836 !IsBlacklistedFunctionOrMethodName(old_name)) { |
725 new_name = old_name; | 837 new_name = old_name; |
726 new_name[0] = clang::toUppercase(new_name[0]); | 838 new_name[0] = clang::toUppercase(old_name[0]); |
727 return true; | 839 return true; |
728 } | 840 } |
729 | 841 |
730 // In the future we can consider more heuristics: | 842 // In the future we can consider more heuristics: |
731 // - "s_" and "g_" prefixes | 843 // - "s_" and "g_" prefixes |
732 // - "ALL_CAPS" | 844 // - "ALL_CAPS" |
733 // - |T::myStaticField| -> |T::kMyStaticField| | 845 // - |T::myStaticField| -> |T::kMyStaticField| |
734 // (but have to be careful not to rename |value| in WTF/TypeTraits.h?) | 846 // (but have to be careful not to rename |value| in WTF/TypeTraits.h?) |
735 return false; | 847 return false; |
736 } | 848 } |
737 }; | 849 }; |
738 | 850 |
739 using UnresolvedDependentMemberRewriter = | 851 using UnresolvedDependentMemberRewriter = |
740 UnresolvedRewriterBase<clang::UnresolvedMemberExpr>; | 852 UnresolvedRewriterBase<clang::UnresolvedMemberExpr>; |
741 | 853 |
742 using UnresolvedUsingValueDeclRewriter = | 854 using UnresolvedUsingValueDeclRewriter = |
743 UnresolvedRewriterBase<clang::UnresolvedUsingValueDecl>; | 855 UnresolvedRewriterBase<clang::UnresolvedUsingValueDecl>; |
744 | 856 |
| 857 using DependentScopeDeclRefExprRewriter = |
| 858 UnresolvedRewriterBase<clang::DependentScopeDeclRefExpr>; |
| 859 |
| 860 using CXXDependentScopeMemberExprRewriter = |
| 861 UnresolvedRewriterBase<clang::CXXDependentScopeMemberExpr>; |
| 862 |
745 } // namespace | 863 } // namespace |
746 | 864 |
747 static llvm::cl::extrahelp common_help(CommonOptionsParser::HelpMessage); | 865 static llvm::cl::extrahelp common_help(CommonOptionsParser::HelpMessage); |
748 | 866 |
749 int main(int argc, const char* argv[]) { | 867 int main(int argc, const char* argv[]) { |
750 // TODO(dcheng): Clang tooling should do this itself. | 868 // TODO(dcheng): Clang tooling should do this itself. |
751 // http://llvm.org/bugs/show_bug.cgi?id=21627 | 869 // http://llvm.org/bugs/show_bug.cgi?id=21627 |
752 llvm::InitializeNativeTarget(); | 870 llvm::InitializeNativeTarget(); |
753 llvm::InitializeNativeTargetAsmParser(); | 871 llvm::InitializeNativeTargetAsmParser(); |
754 llvm::cl::OptionCategory category( | 872 llvm::cl::OptionCategory category( |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 // using blink::X; | 1179 // using blink::X; |
1062 // matches |using blink::X|. | 1180 // matches |using blink::X|. |
1063 auto using_decl_matcher = id( | 1181 auto using_decl_matcher = id( |
1064 "decl", usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(anyOf( | 1182 "decl", usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(anyOf( |
1065 var_decl_matcher, field_decl_matcher, function_decl_matcher, | 1183 var_decl_matcher, field_decl_matcher, function_decl_matcher, |
1066 method_decl_matcher, function_template_decl_matcher, | 1184 method_decl_matcher, function_template_decl_matcher, |
1067 method_template_decl_matcher, enum_member_decl_matcher))))); | 1185 method_template_decl_matcher, enum_member_decl_matcher))))); |
1068 UsingDeclRewriter using_decl_rewriter(&replacements); | 1186 UsingDeclRewriter using_decl_rewriter(&replacements); |
1069 match_finder.addMatcher(using_decl_matcher, &using_decl_rewriter); | 1187 match_finder.addMatcher(using_decl_matcher, &using_decl_rewriter); |
1070 | 1188 |
| 1189 // Matches any QualType that refers to a blink type: |
| 1190 // - const blink::Foo& |
| 1191 // - blink::Foo* |
| 1192 // - blink::Foo<T> |
| 1193 // - ... |
| 1194 // TODO(lukasza): The matchers below can be simplified after |
| 1195 // https://llvm.org/bugs/show_bug.cgi?id=30331 is fixed. |
| 1196 // Simplified matchers: |
| 1197 // auto blink_qual_type_base_matcher = |
| 1198 // qualType(hasDeclaration(in_blink_namespace)); |
| 1199 // auto blink_qual_type_matcher = qualType(anyOf( |
| 1200 // blink_qual_type_base_matcher, |
| 1201 // pointsTo(blink_qual_type_base_matcher), |
| 1202 // references(blink_qual_type_base_matcher))); |
| 1203 auto blink_qual_type_bug_workaround_matcher1 = hasBaseType( |
| 1204 anyOf(enumType(hasDeclaration(in_blink_namespace)), |
| 1205 recordType(hasDeclaration(in_blink_namespace)), |
| 1206 templateSpecializationType(hasDeclaration(in_blink_namespace)), |
| 1207 templateTypeParmType(hasDeclaration(in_blink_namespace)), |
| 1208 typedefType(hasDeclaration(in_blink_namespace)))); |
| 1209 auto blink_qual_type_base_matcher = |
| 1210 qualType(anyOf(blink_qual_type_bug_workaround_matcher1, |
| 1211 hasBaseType(elaboratedType( |
| 1212 namesType(blink_qual_type_bug_workaround_matcher1))))); |
| 1213 auto blink_qual_type_matcher = |
| 1214 qualType(anyOf(blink_qual_type_base_matcher, pointsTo(in_blink_namespace), |
| 1215 references(in_blink_namespace))); |
| 1216 |
| 1217 // Template-dependent decl lookup ======== |
| 1218 // Given |
| 1219 // template <typename T> void f() { T::foo(); } |
| 1220 // matches |T::foo|. |
| 1221 auto dependent_scope_decl_ref_expr_matcher = |
| 1222 expr(id("expr", dependentScopeDeclRefExpr(has(nestedNameSpecifier( |
| 1223 specifiesType(blink_qual_type_matcher)))))); |
| 1224 DependentScopeDeclRefExprRewriter dependent_scope_decl_ref_expr_rewriter( |
| 1225 &replacements); |
| 1226 match_finder.addMatcher(dependent_scope_decl_ref_expr_matcher, |
| 1227 &dependent_scope_decl_ref_expr_rewriter); |
| 1228 |
| 1229 // Template-dependent member lookup ======== |
| 1230 // Given |
| 1231 // template <typename T> |
| 1232 // class Foo { |
| 1233 // void f() { T::foo(); } |
| 1234 // void g(T x) { x.bar(); } |
| 1235 // }; |
| 1236 // matches |T::foo| and |x.bar|. |
| 1237 auto cxx_dependent_scope_member_expr_matcher = |
| 1238 expr(id("expr", cxxDependentScopeMemberExpr( |
| 1239 hasMemberFromType(blink_qual_type_matcher)))); |
| 1240 CXXDependentScopeMemberExprRewriter cxx_dependent_scope_member_expr_rewriter( |
| 1241 &replacements); |
| 1242 match_finder.addMatcher(cxx_dependent_scope_member_expr_matcher, |
| 1243 &cxx_dependent_scope_member_expr_rewriter); |
| 1244 |
1071 std::unique_ptr<clang::tooling::FrontendActionFactory> factory = | 1245 std::unique_ptr<clang::tooling::FrontendActionFactory> factory = |
1072 clang::tooling::newFrontendActionFactory(&match_finder); | 1246 clang::tooling::newFrontendActionFactory(&match_finder); |
1073 int result = tool.run(factory.get()); | 1247 int result = tool.run(factory.get()); |
1074 if (result != 0) | 1248 if (result != 0) |
1075 return result; | 1249 return result; |
1076 | 1250 |
1077 #if defined(_WIN32) | 1251 #if defined(_WIN32) |
1078 HANDLE lockfd = CreateFile("rewrite-sym.lock", GENERIC_READ, FILE_SHARE_READ, | 1252 HANDLE lockfd = CreateFile("rewrite-sym.lock", GENERIC_READ, FILE_SHARE_READ, |
1079 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 1253 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
1080 OVERLAPPED overlapped = {}; | 1254 OVERLAPPED overlapped = {}; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 for (const auto& r : replacements) { | 1286 for (const auto& r : replacements) { |
1113 std::string replacement_text = r.getReplacementText().str(); | 1287 std::string replacement_text = r.getReplacementText().str(); |
1114 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 1288 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
1115 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 1289 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
1116 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 1290 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
1117 } | 1291 } |
1118 llvm::outs() << "==== END EDITS ====\n"; | 1292 llvm::outs() << "==== END EDITS ====\n"; |
1119 | 1293 |
1120 return 0; | 1294 return 0; |
1121 } | 1295 } |
OLD | NEW |