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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 const char kGeneratedFileRegex[] = "^gen/|/gen/"; | 52 const char kGeneratedFileRegex[] = "^gen/|/gen/"; |
53 | 53 |
54 const clang::ast_matchers::internal:: | 54 const clang::ast_matchers::internal:: |
55 VariadicDynCastAllOfMatcher<clang::Expr, clang::UnresolvedMemberExpr> | 55 VariadicDynCastAllOfMatcher<clang::Expr, clang::UnresolvedMemberExpr> |
56 unresolvedMemberExpr; | 56 unresolvedMemberExpr; |
57 | 57 |
58 AST_MATCHER(clang::FunctionDecl, isOverloadedOperator) { | 58 AST_MATCHER(clang::FunctionDecl, isOverloadedOperator) { |
59 return Node.isOverloadedOperator(); | 59 return Node.isOverloadedOperator(); |
60 } | 60 } |
61 | 61 |
62 AST_MATCHER(clang::CXXMethodDecl, isUserProvidedInstanceMethod) { | |
63 return Node.isUserProvided() && Node.isInstance(); | |
64 } | |
65 | |
62 AST_MATCHER_P(clang::FunctionTemplateDecl, | 66 AST_MATCHER_P(clang::FunctionTemplateDecl, |
63 templatedDecl, | 67 templatedDecl, |
64 clang::ast_matchers::internal::Matcher<clang::FunctionDecl>, | 68 clang::ast_matchers::internal::Matcher<clang::FunctionDecl>, |
65 InnerMatcher) { | 69 InnerMatcher) { |
66 return InnerMatcher.matches(*Node.getTemplatedDecl(), Finder, Builder); | 70 return InnerMatcher.matches(*Node.getTemplatedDecl(), Finder, Builder); |
67 } | 71 } |
68 | 72 |
69 // If |InnerMatcher| matches |top|, then the returned matcher will match: | 73 // If |InnerMatcher| matches |top|, then the returned matcher will match: |
70 // - |top::function| | 74 // - |top::function| |
71 // - |top::Class::method| | 75 // - |top::Class::method| |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 | 637 |
634 // Field, variable, and enum declarations ======== | 638 // Field, variable, and enum declarations ======== |
635 // Given | 639 // Given |
636 // int x; | 640 // int x; |
637 // struct S { | 641 // struct S { |
638 // int y; | 642 // int y; |
639 // enum { VALUE }; | 643 // enum { VALUE }; |
640 // }; | 644 // }; |
641 // matches |x|, |y|, and |VALUE|. | 645 // matches |x|, |y|, and |VALUE|. |
642 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); | 646 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); |
643 auto is_type_trait_value = | 647 auto is_type_trait_value = varDecl( |
644 varDecl(hasName("value"), hasStaticStorageDuration(), isPublic(), | 648 hasName("value"), hasStaticStorageDuration(), isPublic(), |
645 hasType(isConstQualified()), hasType(booleanType()), | 649 hasType(isConstQualified()), hasType(booleanType()), |
646 unless(hasAncestor(recordDecl(has(functionDecl()))))); | 650 unless(hasAncestor( |
651 recordDecl(has(cxxMethodDecl(isUserProvidedInstanceMethod())))))); | |
dcheng
2016/09/01 21:04:21
Might be slightly nicer to compose the isUserProvi
Łukasz Anforowicz
2016/09/01 21:39:45
Done. Also - it turns out that isUserProvided is
| |
647 auto var_decl_matcher = | 652 auto var_decl_matcher = |
648 id("decl", varDecl(in_blink_namespace, unless(is_type_trait_value))); | 653 id("decl", varDecl(in_blink_namespace, unless(is_type_trait_value))); |
649 auto enum_member_decl_matcher = | 654 auto enum_member_decl_matcher = |
650 id("decl", enumConstantDecl(in_blink_namespace)); | 655 id("decl", enumConstantDecl(in_blink_namespace)); |
651 | 656 |
652 FieldDeclRewriter field_decl_rewriter(&replacements); | 657 FieldDeclRewriter field_decl_rewriter(&replacements); |
653 match_finder.addMatcher(field_decl_matcher, &field_decl_rewriter); | 658 match_finder.addMatcher(field_decl_matcher, &field_decl_rewriter); |
654 | 659 |
655 VarDeclRewriter var_decl_rewriter(&replacements); | 660 VarDeclRewriter var_decl_rewriter(&replacements); |
656 match_finder.addMatcher(var_decl_matcher, &var_decl_rewriter); | 661 match_finder.addMatcher(var_decl_matcher, &var_decl_rewriter); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
926 for (const auto& r : replacements) { | 931 for (const auto& r : replacements) { |
927 std::string replacement_text = r.getReplacementText().str(); | 932 std::string replacement_text = r.getReplacementText().str(); |
928 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 933 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
929 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 934 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
930 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 935 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
931 } | 936 } |
932 llvm::outs() << "==== END EDITS ====\n"; | 937 llvm::outs() << "==== END EDITS ====\n"; |
933 | 938 |
934 return 0; | 939 return 0; |
935 } | 940 } |
OLD | NEW |